ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18s2a_2

Dependencies:   mbed

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 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 7:9bd49beccdd1 10
Psy1990 8:32825d724856 11 // gap from edge of screen
Psy1990 8:32825d724856 12 #define GAP 2
Psy1990 7:9bd49beccdd1 13
Psy1990 7:9bd49beccdd1 14
Psy1990 7:9bd49beccdd1 15 class SnakeEngine
Psy1990 7:9bd49beccdd1 16 {
Psy1990 7:9bd49beccdd1 17
Psy1990 7:9bd49beccdd1 18 public:
Psy1990 7:9bd49beccdd1 19 SnakeEngine();
Psy1990 7:9bd49beccdd1 20 ~SnakeEngine();
Psy1990 7:9bd49beccdd1 21
Psy1990 9:25597bc0cecc 22 void init(int apple_size, int snake_speed, int snake_score);
Psy1990 10:3e37b58e8600 23 void read_input(Gamepad &pad); //Allows us to read the input from the thumbstick
Psy1990 10:3e37b58e8600 24 void update(Gamepad &pad); //Allows us to update the gamepad
Psy1990 10:3e37b58e8600 25 void draw(N5110 &lcd); //Allows us to draw on the screen
Psy1990 7:9bd49beccdd1 26
Psy1990 7:9bd49beccdd1 27 private:
Psy1990 7:9bd49beccdd1 28
Psy1990 7:9bd49beccdd1 29 void print_score(N5110 &lcd);
Psy1990 7:9bd49beccdd1 30
Psy1990 10:3e37b58e8600 31 int sx; //Snake X
Psy1990 10:3e37b58e8600 32 int sy; //Snake Y
Psy1990 10:3e37b58e8600 33 int ax; //Apple X
Psy1990 10:3e37b58e8600 34 int ay; //Apple Y
Psy1990 10:3e37b58e8600 35 int _apple_size; //Apple size is defined and taken from main.cpp
Psy1990 10:3e37b58e8600 36 int _snake_speed; //Stores the speed the snake goes
Psy1990 10:3e37b58e8600 37 int _snake_score; //Stores the score
Psy1990 7:9bd49beccdd1 38
Psy1990 10:3e37b58e8600 39 Snake _s; //Allows us to use the Snake
Psy1990 10:3e37b58e8600 40 Apple _a; //Allows us to use the Apple
Psy1990 10:3e37b58e8600 41 Direction _d; //Direction
Psy1990 10:3e37b58e8600 42 float _mag; //Magnitude
Psy1990 7:9bd49beccdd1 43
Psy1990 7:9bd49beccdd1 44 };
Psy1990 7:9bd49beccdd1 45
Psy1990 7:9bd49beccdd1 46 #endif