ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18lg

Dependencies:   mbed

Committer:
el18lg
Date:
Wed May 27 20:57:21 2020 +0000
Revision:
4:748b3e0062f6
Parent:
3:beb0cc405b1e
Child:
5:e0f08e8022de
Started to do the body of the snake

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eencae 0:b7f1f47bb26a 1 /*
eencae 0:b7f1f47bb26a 2 ELEC2645 Embedded Systems Project
eencae 0:b7f1f47bb26a 3 School of Electronic & Electrical Engineering
eencae 0:b7f1f47bb26a 4 University of Leeds
eencae 0:b7f1f47bb26a 5 2019/20
eencae 0:b7f1f47bb26a 6
el18lg 1:bdafa20e71a0 7 Name: Lee Geer
el18lg 1:bdafa20e71a0 8 Username: el18lg
el18lg 1:bdafa20e71a0 9 Student ID Number: 201265490
el18lg 1:bdafa20e71a0 10 Date: TBC
eencae 0:b7f1f47bb26a 11 */
eencae 0:b7f1f47bb26a 12
eencae 0:b7f1f47bb26a 13 // includes
eencae 0:b7f1f47bb26a 14 #include "mbed.h"
eencae 0:b7f1f47bb26a 15 #include "Gamepad.h"
eencae 0:b7f1f47bb26a 16 #include "N5110.h"
el18lg 1:bdafa20e71a0 17 #include "FXOS8700CQ.h"
el18lg 2:c33ff63c0813 18 #include "SnakeEngine.h"
el18lg 3:beb0cc405b1e 19 #include "Head.h"
el18lg 3:beb0cc405b1e 20
eencae 0:b7f1f47bb26a 21
eencae 0:b7f1f47bb26a 22 // objects
eencae 0:b7f1f47bb26a 23 Gamepad pad;
eencae 0:b7f1f47bb26a 24 N5110 lcd;
el18lg 2:c33ff63c0813 25 SnakeEngine snake;
el18lg 3:beb0cc405b1e 26 Head _h;
el18lg 2:c33ff63c0813 27 void init();
el18lg 2:c33ff63c0813 28 void render();
el18lg 1:bdafa20e71a0 29 int main()
eencae 0:b7f1f47bb26a 30 {
el18lg 2:c33ff63c0813 31 int fps = 6; // frames per second
el18lg 2:c33ff63c0813 32
el18lg 2:c33ff63c0813 33 init(); // initialise and then display welcome screen...
el18lg 2:c33ff63c0813 34
el18lg 2:c33ff63c0813 35 render(); // first draw the initial frame
el18lg 2:c33ff63c0813 36 wait(1.0f/fps); // and wait for one frame period
el18lg 2:c33ff63c0813 37
el18lg 2:c33ff63c0813 38
el18lg 2:c33ff63c0813 39 // game loop - read input, update the game state and render the display
el18lg 2:c33ff63c0813 40 while (1) {
el18lg 2:c33ff63c0813 41 snake.read_input(pad);
el18lg 2:c33ff63c0813 42 snake.update(pad);
el18lg 2:c33ff63c0813 43 render();
el18lg 2:c33ff63c0813 44 wait(1.0f/fps);
el18lg 3:beb0cc405b1e 45
el18lg 2:c33ff63c0813 46 }
el18lg 2:c33ff63c0813 47 }
el18lg 4:748b3e0062f6 48 #define HEAD_LENGTH 1
el18lg 4:748b3e0062f6 49 #define HEAD_SPEED 2
el18lg 2:c33ff63c0813 50 // initialies all classes and libraries
el18lg 2:c33ff63c0813 51 void init()
el18lg 2:c33ff63c0813 52 {
el18lg 2:c33ff63c0813 53 // need to initialise LCD and Gamepad
el18lg 1:bdafa20e71a0 54 lcd.init();
el18lg 1:bdafa20e71a0 55 pad.init();
el18lg 2:c33ff63c0813 56
el18lg 2:c33ff63c0813 57 // initialise the game with correct ball and paddle sizes
el18lg 3:beb0cc405b1e 58 snake.init(HEAD_LENGTH,HEAD_SPEED);
el18lg 2:c33ff63c0813 59
el18lg 2:c33ff63c0813 60 }
el18lg 2:c33ff63c0813 61
el18lg 2:c33ff63c0813 62 // this function draws each frame on the LCD
el18lg 2:c33ff63c0813 63 void render()
el18lg 2:c33ff63c0813 64 {
el18lg 2:c33ff63c0813 65 // clear screen, re-draw and refresh
el18lg 2:c33ff63c0813 66 lcd.clear();
el18lg 2:c33ff63c0813 67 snake.draw(lcd);
el18lg 1:bdafa20e71a0 68 lcd.refresh();
el18lg 2:c33ff63c0813 69 }
el18lg 2:c33ff63c0813 70
el18lg 2:c33ff63c0813 71
el18lg 2:c33ff63c0813 72