Simon Atkinson 201255483

Dependencies:   mbed

Snake Game

Summary

Hello and welcome to my Snake Game. Snake is a simple game where you control a snake and eat an apple which increases your size. Normally touching the walls will kill you, always touching yourself will make you die!

Controls

The Controls for this game are simple the Start button starts the game (who would have thought) this button is the left button on the bottom of the gamepad next to the two blue potentiometers. The Reset button on the right of the potentiometers resets the game. Once the game starts use the left thumbstick to control the movement of the snake.

If you hit the wall with your snake you will die and the game will end.

Bugs/Missing Features

Unfortunatley I wasn't able to get the game eating the apple to work, when I tried I could never get it to detect the collisions I tried a few different ways but ran out of time. Because that doesn't work the score doesn't increase and the apple doesn't spawn in a different place. I will try continue to work on this when I have time as I enjoyed doing this project even though it was very frustrating at times!

Committer:
Psy1990
Date:
Fri Jun 05 18:45:05 2020 +0000
Revision:
10:3e37b58e8600
Parent:
9:25597bc0cecc
Child:
11:ba20e1b516a1
Got movement of the snake working! Cleaned up the code of unused stuff and added comments to describe what each thing does.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Psy1990 8:32825d724856 1 #ifndef Snake_H
Psy1990 8:32825d724856 2 #define Snake_H
Psy1990 8:32825d724856 3
Psy1990 8:32825d724856 4 #include "mbed.h"
Psy1990 8:32825d724856 5 #include "N5110.h"
Psy1990 8:32825d724856 6 #include "Gamepad.h"
Psy1990 8:32825d724856 7
Psy1990 8:32825d724856 8
Psy1990 8:32825d724856 9 class Snake
Psy1990 8:32825d724856 10 {
Psy1990 8:32825d724856 11 public:
Psy1990 8:32825d724856 12
Psy1990 8:32825d724856 13 Snake();
Psy1990 8:32825d724856 14 ~Snake();
Psy1990 10:3e37b58e8600 15 void init(int _x, int _y, int _score, int _speed); // Setting up the values to be used
Psy1990 10:3e37b58e8600 16 void draw(N5110 &lcd); // For drawing the snake on the screen allows the use of the LCD
Psy1990 10:3e37b58e8600 17 void update(Direction d,float mag); // Gets the direction from the thumbstick
Psy1990 10:3e37b58e8600 18 void add_score(); //Eating an apple will add to the score
Psy1990 10:3e37b58e8600 19 int get_score(); // So we can display the score in game!
Psy1990 10:3e37b58e8600 20 Vector2D get_pos(); // Gets the position of the snake
Psy1990 10:3e37b58e8600 21 Vector2D get_move(); // Gets the value the determines how fast the snake moves
Psy1990 10:3e37b58e8600 22 Vector2D get_Direction(); // Gets the direction the snake travels in can be only North, East, South or West and the snake can't move in other directions.
Psy1990 10:3e37b58e8600 23 void set_move(Vector2D m);
Psy1990 9:25597bc0cecc 24
Psy1990 10:3e37b58e8600 25
Psy1990 8:32825d724856 26
Psy1990 8:32825d724856 27 private:
Psy1990 8:32825d724856 28
Psy1990 10:3e37b58e8600 29 Vector2D _move; //Move value
Psy1990 10:3e37b58e8600 30 Vector2D _d; // Direction
Psy1990 10:3e37b58e8600 31 int _x; // X position of snake
Psy1990 10:3e37b58e8600 32 int _y; // Y Position of snake
Psy1990 10:3e37b58e8600 33 int _score; // Scoring system
Psy1990 10:3e37b58e8600 34 int _speed; // Speed the snake goes
Psy1990 8:32825d724856 35
Psy1990 8:32825d724856 36
Psy1990 8:32825d724856 37 };
Psy1990 8:32825d724856 38 #endif