Search code examples
c++dictionarygame-loop

2D Game map movement


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.


Solution

  • 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.