官术网_书友最值得收藏!

Game design decisions

Certain versions of snake run differently; however, for the sake of paying homage to the classical approach, we will be implementing a snake that moves based on a grid, as illustrated next:

Taking this approach makes it easier to later check for collision between the snake segments and the apple. Grid movement basically means updating at a static rate. This can be achieved by utilizing a fixed time-step, which we covered back in Chapter 2, Give It Some Structure – Building the Game Framework.

The outside area symbolizes the boundaries of the game, which in the case of a grid-based movement would be in the range of [1;Width-1] and [1;Height-1]. If the snake head isn't within that range, it's safe to say that the player has crashed into a wall. All the grid segments here are 16px by 16px big; however, that can be adjusted at any time.

Unless the player runs out of lives, we want to cut the snake at the point of intersection if its head collides with its body and decrease the amount of lives left. This adds a little variety to the game without being too unbalanced.

Lastly, you've probably already picked up on the fact that we're using very simplistic graphical representations of what a snake is in this game. This is done mainly to keep things simple for now, as well as to add the charm of a classic to the mix. It wouldn't be terribly complicated to use sprites for this, however, let's not worry about that just yet.

主站蜘蛛池模板: 潞西市| 宜昌市| 阳高县| 宣恩县| 南城县| 扶余县| 封丘县| 东丰县| 忻城县| 雷州市| 舒兰市| 安多县| 綦江县| 曲沃县| 尉氏县| 四川省| 香港| 台安县| 从江县| 景东| 锡林郭勒盟| 康定县| 方山县| 张家口市| 崇州市| 田阳县| 昌图县| 杭州市| 鄂托克前旗| 封丘县| 故城县| 金平| 措勤县| 大荔县| 大理市| 临夏市| 邻水| 安岳县| 安福县| 扎赉特旗| 两当县|