ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18s2a_2

Dependencies:   mbed

Committer:
Psy1990
Date:
Fri Jun 05 19:42:34 2020 +0000
Revision:
11:ba20e1b516a1
Parent:
10:3e37b58e8600
Child:
12:8eb40a18f15d
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 7:9bd49beccdd1 1 #ifndef SNAKEENGINE_H
Psy1990 7:9bd49beccdd1 2 #define SNAKEENGINE_H
Psy1990 7:9bd49beccdd1 3
Psy1990 7:9bd49beccdd1 4 #include "mbed.h"
Psy1990 7:9bd49beccdd1 5 #include "N5110.h"
Psy1990 7:9bd49beccdd1 6 #include "Gamepad.h"
Psy1990 8:32825d724856 7 #include "Apple.h"
Psy1990 8:32825d724856 8 #include "Snake.h"
Psy1990 8:32825d724856 9 #include "Bitmap.h"
Psy1990 11:ba20e1b516a1 10 /** Apple Class File
Psy1990 11:ba20e1b516a1 11 * @brief Class containing the engine that runs the game.
Psy1990 11:ba20e1b516a1 12 * @author Simon Atkinson
Psy1990 11:ba20e1b516a1 13 * @date June 2020
Psy1990 11:ba20e1b516a1 14 */
Psy1990 7:9bd49beccdd1 15
Psy1990 8:32825d724856 16 // gap from edge of screen
Psy1990 8:32825d724856 17 #define GAP 2
Psy1990 7:9bd49beccdd1 18
Psy1990 7:9bd49beccdd1 19
Psy1990 7:9bd49beccdd1 20 class SnakeEngine
Psy1990 7:9bd49beccdd1 21 {
Psy1990 7:9bd49beccdd1 22
Psy1990 7:9bd49beccdd1 23 public:
Psy1990 7:9bd49beccdd1 24 SnakeEngine();
Psy1990 7:9bd49beccdd1 25 ~SnakeEngine();
Psy1990 7:9bd49beccdd1 26
Psy1990 9:25597bc0cecc 27 void init(int apple_size, int snake_speed, int snake_score);
Psy1990 10:3e37b58e8600 28 void read_input(Gamepad &pad); //Allows us to read the input from the thumbstick
Psy1990 10:3e37b58e8600 29 void update(Gamepad &pad); //Allows us to update the gamepad
Psy1990 10:3e37b58e8600 30 void draw(N5110 &lcd); //Allows us to draw on the screen
Psy1990 7:9bd49beccdd1 31
Psy1990 7:9bd49beccdd1 32 private:
Psy1990 7:9bd49beccdd1 33
Psy1990 7:9bd49beccdd1 34 void print_score(N5110 &lcd);
Psy1990 7:9bd49beccdd1 35
Psy1990 10:3e37b58e8600 36 int sx; //Snake X
Psy1990 10:3e37b58e8600 37 int sy; //Snake Y
Psy1990 10:3e37b58e8600 38 int ax; //Apple X
Psy1990 10:3e37b58e8600 39 int ay; //Apple Y
Psy1990 10:3e37b58e8600 40 int _apple_size; //Apple size is defined and taken from main.cpp
Psy1990 10:3e37b58e8600 41 int _snake_speed; //Stores the speed the snake goes
Psy1990 10:3e37b58e8600 42 int _snake_score; //Stores the score
Psy1990 7:9bd49beccdd1 43
Psy1990 10:3e37b58e8600 44 Snake _s; //Allows us to use the Snake
Psy1990 10:3e37b58e8600 45 Apple _a; //Allows us to use the Apple
Psy1990 10:3e37b58e8600 46 Direction _d; //Direction
Psy1990 10:3e37b58e8600 47 float _mag; //Magnitude
Psy1990 7:9bd49beccdd1 48
Psy1990 7:9bd49beccdd1 49 };
Psy1990 7:9bd49beccdd1 50
Psy1990 7:9bd49beccdd1 51 #endif