Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 19, 2013 3:02 pm

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Tue Apr 05, 2011 5:11 pm 
Offline

Joined: Tue Apr 05, 2011 4:56 pm
Posts: 12
Hi everybody !

First, please excuse me for my poor english, but i'm french ;)

That'll do a couple of week I'm searching a way how to place some object on a tile map. I explain myself :

I've a tiled map in 2D. Player will be able to set trap on floor, or take some objects in cabinet, or other coffer, also let them on floor to make barriers.

But I don't found a way to make it with tiles, so do you have an idea about how to bypass this problem? Using sprite? Or another idea?

Thanks for your future replies :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 06, 2011 8:55 am 
Offline
Slick Zombie

Joined: Wed Apr 02, 2008 1:32 pm
Posts: 1313
Location: Italy
You can use "layers" of different tiles, for example:
1) floor
2) walls
3) objects
4) traps

and then load and "translate" into your game object (see my Jpacman example, in particular Map class)

_________________
Blog | Last game Gravity Duck tribute | In progress Gravity Duck tribute


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 06, 2011 11:01 am 
Offline

Joined: Tue Apr 05, 2011 4:56 pm
Posts: 12
Thanks for your reply :)

I better understand principe of layers now :)
But in your code I don't understand why you use a Vector2f object in plaec of using sprites :?:

Why did you choose it?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 06, 2011 11:51 am 
Offline
Slick Zombie

Joined: Wed Apr 02, 2008 1:32 pm
Posts: 1313
Location: Italy
It's old code, just to store position of a tile representing an object :D

In MarteEngine I have a better code about load entity, see here method loadEntityFromMap loads from layer "entity" position of entities and then add to World entity as StaticObject

_________________
Blog | Last game Gravity Duck tribute | In progress Gravity Duck tribute


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 06, 2011 12:32 pm 
Offline

Joined: Tue Apr 05, 2011 4:56 pm
Posts: 12
I read the part of code you mentionned below ;)

But there you're just adding to world, tiles who already exists ;-)

In my cas I would like to put by example, a TNT block on floor. But TNT is, in example, in a tileset who is not load with map ;) So I need to take his reference in this Tileset (possible I think) and put it on a layer at player's position, but how to render it?

I don't know if you could see what I want :D


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 06, 2011 6:48 pm 
Offline
Slick Zombie

Joined: Wed Apr 02, 2008 1:32 pm
Posts: 1313
Location: Italy
if you could explain better :D

_________________
Blog | Last game Gravity Duck tribute | In progress Gravity Duck tribute


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 06, 2011 7:14 pm 
Offline

Joined: Tue Apr 05, 2011 4:56 pm
Posts: 12
Ok i'll try :D

In your code, I thought that you add some tiles who already exists in map. But maybe am I wrong ;)

So, what I want to do is, I have ,by example, a tileset of Object (like guns,food,traps...) Player could be able to drop them on floor (place for build, set trap or let on floor for other player (Maybe...later :D))
So I would like to take tiles who are in another tileset and put it on actual playing world :)

Would I maybe load them in an entity who'll contain them for later?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 07, 2011 7:32 am 
Offline
Slick Zombie

Joined: Wed Apr 02, 2008 1:32 pm
Posts: 1313
Location: Italy
ok! Now I understand better!

Problem is not about tiled or map, but about add at runtime something in game, for example: player drop a trap.
Imagine you have following code (not real code!)

Code:
if (player press T){
   Trap t = new Trap(player.x, player.y)
   add t to the World
}


If I'm right your problem is in "add t to the World" part. When you load your level from tiled you must have some sort of list of tiles object and so on.
In MarteEngine you have an object named World here there is a list of entities, where you have all reference to entities (tiles, traps, object, player all have the same supertype), so you can update them or render them: please have a look to Worldin MarteEngine for an example of it :D
With this approach, you problem is trivial, you have just to add to List of entities your trap and next time World render entities trap will be added to screen (and added to update logic, for example to make it explode when an enemy is near) (see Tank Example: when player fire, a new missile is created and added to world)

_________________
Blog | Last game Gravity Duck tribute | In progress Gravity Duck tribute


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 07, 2011 7:58 am 
Offline

Joined: Tue Apr 05, 2011 4:56 pm
Posts: 12
Hohoho !! Thanks you Gornova81 !!

I understand now :D I see what you explain and understand why now :)

My game code can now be continue, thanks to you ! (Perhaps will your pseudo appear in my future Credits Games :D)

Thanks a lot :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 07, 2011 10:14 am 
Offline
Slick Zombie

Joined: Wed Apr 02, 2008 1:32 pm
Posts: 1313
Location: Italy
yeah! :D glad to be helpful!

p.s: try MarteEngine, help you a lot about this "base stuff" and you can focus on make games :D

_________________
Blog | Last game Gravity Duck tribute | In progress Gravity Duck tribute


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 07, 2011 11:32 am 
Offline

Joined: Tue Apr 05, 2011 4:56 pm
Posts: 12
Ok :) I'll do it ;)

But at same time I've 2 books of java games develloping to read :D


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group