2 Replies - 2355 Views - Last Post: 30 March 2011 - 10:49 AM Rate Topic: -----

#1 zombiepotion  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 30-March 11

Question re: structuring a simple 2d platformer game engine

Posted 30 March 2011 - 08:47 AM

I am a newb, teaching myself.

I am programming a simple 2d platformer game engine and was wondering if people who have experience with structuring this can give me tips on designing the game structure, specifically with regards to this situation:

I have three object classes, worldObj, tileMapObj, and entityObj. The worldObj contains the tileMapObj (which is the game level), and the entityObj (which in this case will be the player's character). The tileMap is a 1d array of tiles which gets treated like a 2d array (20 columns by 10 rows = 200 tiles).

The entity will have a variable for what tile it is in, an integer representing the tile its feet are located in. One basic thing I will need is a function to determine that integer. I know how to do the math for that, my question is *how to decide which object performs the function of determining what tile the entity is on*.

Should the world look at the tileMap, and tell the entity which tile it is on? So something like: world.setTile(entityObj, tileMapObj);

Should the entity class refer to the worldObj's tileMapObj and tell itself what tile it is on? Something like: entity.setTile(world.tileMapObj);

Should the world pass the tileMapObj to the entityObj so the entity can tell itself what tile it is on? Like this: entity.setTile(tileMapObj);

Any suggestions on how to make these kinds of decisions would be appreciated. For what it's worth, I am working in Processing (a Java preprocessor). Obviously I'm not asking for code examples, just explanations of how this kind of game engine should be structured.

Is This A Good Question/Topic? 0
  • +

Replies To: Question re: structuring a simple 2d platformer game engine

#2 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,199
  • Joined: 14-February 08

Re: Question re: structuring a simple 2d platformer game engine

Posted 30 March 2011 - 10:23 AM

I would think that your entity object would be responsible for getting it's current tile location. Makes sense, yes? The entity object will be responsible for checking whether it can move to the next tile so it should have the ability to check which tile it's on.
Was This Post Helpful? 1
  • +
  • -

#3 zombiepotion  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 30-March 11

Re: Question re: structuring a simple 2d platformer game engine

Posted 30 March 2011 - 10:49 AM

View Poststayscrisp, on 30 March 2011 - 10:23 AM, said:

I would think that your entity object would be responsible for getting it's current tile location. Makes sense, yes? The entity object will be responsible for checking whether it can move to the next tile so it should have the ability to check which tile it's on.

Ok that does make sense, I just am wondering how should it get information on the tileMap? If the worldObj is the parent, and the entityObj and tileMapObj are siblings, what's the best way to arrange the transfer of information between them? I guess this is where the question might be less about structure and more about what works best for the programming language. The relationships between object classes in Java is something I need to learn more about.

In fact, here is a java specific question that maybe someone can answer for me:
Lets say I have a worldObj called 'theWorld', and inside that is a tileMapObj called 'levelMap', and an entityObj called 'player'. If I define the entityObj class as containing a tileMapObj called 'worldMap', and then set player.worldMap = world.levelMap, does that create a copy of the world.levelMap (taking up extra memory) or does it create a reference to the world.levelMap?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1