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 19:42:34 2020 +0000
Revision:
11:ba20e1b516a1
Parent:
10:3e37b58e8600
Child:
13:c20acb3b1adf
The x and y position of the snake can no longer leave the game area. Next to do is make the game end when it touches the edge!

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 11:ba20e1b516a1 7 /** Snake Class File
Psy1990 11:ba20e1b516a1 8 * @brief Class containing the snake for the actual game.
Psy1990 11:ba20e1b516a1 9 * @author Simon Atkinson
Psy1990 11:ba20e1b516a1 10 * @date June 2020
Psy1990 11:ba20e1b516a1 11 */
Psy1990 8:32825d724856 12
Psy1990 8:32825d724856 13 class Snake
Psy1990 8:32825d724856 14 {
Psy1990 8:32825d724856 15 public:
Psy1990 8:32825d724856 16
Psy1990 8:32825d724856 17 Snake();
Psy1990 8:32825d724856 18 ~Snake();
Psy1990 10:3e37b58e8600 19 void init(int _x, int _y, int _score, int _speed); // Setting up the values to be used
Psy1990 10:3e37b58e8600 20 void draw(N5110 &lcd); // For drawing the snake on the screen allows the use of the LCD
Psy1990 10:3e37b58e8600 21 void update(Direction d,float mag); // Gets the direction from the thumbstick
Psy1990 10:3e37b58e8600 22 void add_score(); //Eating an apple will add to the score
Psy1990 10:3e37b58e8600 23 int get_score(); // So we can display the score in game!
Psy1990 10:3e37b58e8600 24 Vector2D get_pos(); // Gets the position of the snake
Psy1990 10:3e37b58e8600 25 Vector2D get_move(); // Gets the value the determines how fast the snake moves
Psy1990 10:3e37b58e8600 26 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 27 void set_move(Vector2D m);
Psy1990 9:25597bc0cecc 28
Psy1990 10:3e37b58e8600 29
Psy1990 8:32825d724856 30
Psy1990 8:32825d724856 31 private:
Psy1990 8:32825d724856 32
Psy1990 10:3e37b58e8600 33 Vector2D _move; //Move value
Psy1990 10:3e37b58e8600 34 Vector2D _d; // Direction
Psy1990 10:3e37b58e8600 35 int _x; // X position of snake
Psy1990 10:3e37b58e8600 36 int _y; // Y Position of snake
Psy1990 10:3e37b58e8600 37 int _score; // Scoring system
Psy1990 10:3e37b58e8600 38 int _speed; // Speed the snake goes
Psy1990 8:32825d724856 39
Psy1990 8:32825d724856 40
Psy1990 8:32825d724856 41 };
Psy1990 8:32825d724856 42 #endif