Wednesday, July 6, 2016

Game Development: Alien Planet - Adding movable rocks






Movable rocks are good item to have when creating puzzles. For this reason I added them. Each movable rock is a sprite. The game checks if any sprite is colliding with a movable rock. If the player is colliding with a rock, then the rock speedx, or speedy is changed from zero to some value to make the rock move. The value is dependent on the direction of the player. In addition, the player current x and current y is set back to the x and y from the previous frame. This is needed to prevent the player from stepping over the rock and skipping it.


In addition to the above, a check for the rock and its collision with other rocks or tiles is needed. If so, then the rock should never move. This is done by simply setting speedx and speedy of the rock to zero, so even if the player is pushing the rock, it stops when it reaches water or collide with another rock.

Finally if any other sprite/enemy is colliding with a rock then the new x, and y for that enemy is the same as the previous frame thus preventing enemies from stepping over the movable rock. 

No comments:

Post a Comment