Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [HELP] Placing objects on a side scrolling level.....  (Read 1691 times)

0 Members and 1 Guest are viewing this topic.

rojan_neo

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://makeagame.tumblr.com
[HELP] Placing objects on a side scrolling level.....
« on: August 18, 2011, 03:42:02 pm »
I need to write the level for my side scrolling game and I need to place different objects at different places of the level... I read that we can store the level data on a text file and then retrieve each character into a 2-D array.. and then place different objects according to the character, but I have no idea how to place the object that is retrieved from recognizing the characters in the array to their respective position on the level.
For Example; if this is my level data..
0000
0220
0000
1111
Here, if 1 is the ground, 0 empty space and 2 is any other floating object..
I can distinguish what appears on my screen through this but how can I determine where the object is loaded. For example how can I determine where the object "2" is loaded on screen

Haikarainen

  • Guest
[HELP] Placing objects on a side scrolling level.....
« Reply #1 on: August 18, 2011, 04:14:30 pm »
That is a good maploading mechanism if youre working with a tilemap.

Say all your tiles are 32x32, and your map looks ilke this:

100300
000000
002000
000000

Then the 1 is at 0x0, so take that times 32x32 = 0x0.

Then the 3, it is at 3x0, so multiply that by the tilesize and you turn up with 96x0.

Then the 2, It's at 2x2, so just multiply those coordinates with tileize, and you turn up with 64x64.

Thats how you would calculate positions according to a fixedsize tilemap with fixedsize tiles.


If you want a more dynamic approach(not fixed sizes and fixed positions like that), you could just load objects(tiles, backgrounds, buttons etc) into different std::vectors. 1 vector that contains all the tiles, 1 for all the backgrounds etc. A simple approach to how a textfile could look is :

tile "Tilenamefromresourcehandler" xpos ypos isobstacle?
tile "grassleft" 32 24 1
tile "grassmiddle" 64 24 1
background "ilikehorses" 0 0

Etc! Good luck!

rojan_neo

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://makeagame.tumblr.com
[HELP] Placing objects on a side scrolling level.....
« Reply #2 on: August 18, 2011, 04:33:53 pm »
Thank you for your reply... that was really helpful