0

I have a 2d randomly genrated map for a platformer made of block(squares 40 by 40) stored in an array of 30, i have a push function to move the blocks around push changes the xpos aswell as the position on the array i'm only ever drawing the 5-25 position on the array.

When i move i'll only be moving the character within the first half of the screen. so there is collision between the middle part and the 0xpos of the screen now the problem i'm having is moving the blocks .

I cant think of a way to move them so it looks natural. Any ideas on how to do it? so far i have it so that every time the character collides with one side of the screen equivilant to 40 pixels worth of velocity it pushes a block and randomly genorates another.

user23012
  • 219
  • 2
  • 16

2 Answers2

1

This kind of effects are better achieved by using some physics engine. Look for example this one. Such engines really simplify the live in game developement, and the results always worth the effort of learning how to use them.

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115
  • i might look at how it does it, but since this is for a demo for my cv i'd rather make my own for simple things as this – user23012 Jul 05 '12 at 17:57
1

Instead of trying to move all the blocks through an array it may be easier to use a standard queue.

http://www.cplusplus.com/reference/stl/queue/

With this method you would just have to deal with the movement of the blocks on the screen, and could remove the blocks from the front of the queue when they are no longer needed, adding another to the end.

Mortalitas
  • 26
  • 2