Final Submission. I have read and agreed with Statement of Academic Integrity.

Dependencies:   mbed Gamepad N5110 Joystick

Committer:
el16dlc
Date:
Wed May 08 21:26:27 2019 +0000
Revision:
2:0bd6711eae26
Parent:
1:b9f3b7d869d8
Child:
3:660de4311976
3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el16dlc 1:b9f3b7d869d8 1 #include "Game_engine.h"
el16dlc 2:0bd6711eae26 2 #include "Snake.h"
el16dlc 1:b9f3b7d869d8 3
el16dlc 1:b9f3b7d869d8 4 GameEngine::GameEngine() {
el16dlc 1:b9f3b7d869d8 5 }
el16dlc 1:b9f3b7d869d8 6
el16dlc 1:b9f3b7d869d8 7 GameEngine::~GameEngine() {
el16dlc 1:b9f3b7d869d8 8 }
el16dlc 2:0bd6711eae26 9 Snake snake;
el16dlc 1:b9f3b7d869d8 10
el16dlc 2:0bd6711eae26 11 void GameEngine::init() {
el16dlc 2:0bd6711eae26 12 snake.init();
el16dlc 2:0bd6711eae26 13 }
el16dlc 1:b9f3b7d869d8 14 void GameEngine::draw(N5110 &lcd) {
el16dlc 1:b9f3b7d869d8 15 lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT); // Draws screen limits
el16dlc 2:0bd6711eae26 16 snake.draw_head(lcd);
el16dlc 2:0bd6711eae26 17 }
el16dlc 2:0bd6711eae26 18
el16dlc 2:0bd6711eae26 19 void GameEngine::get_dir(Gamepad &gamepad) {
el16dlc 2:0bd6711eae26 20 if ( gamepad.check_event(Gamepad::Y_PRESSED) ) {
el16dlc 2:0bd6711eae26 21 _direction = 0;
el16dlc 2:0bd6711eae26 22 }
el16dlc 2:0bd6711eae26 23 if ( gamepad.check_event(Gamepad::A_PRESSED) ) {
el16dlc 2:0bd6711eae26 24 _direction = 1;
el16dlc 2:0bd6711eae26 25 }
el16dlc 2:0bd6711eae26 26 if ( gamepad.check_event(Gamepad::X_PRESSED) ) {
el16dlc 2:0bd6711eae26 27 _direction = 2;
el16dlc 2:0bd6711eae26 28 }
el16dlc 2:0bd6711eae26 29 if ( gamepad.check_event(Gamepad::B_PRESSED) ) {
el16dlc 2:0bd6711eae26 30 _direction = 3;
el16dlc 2:0bd6711eae26 31 }
el16dlc 2:0bd6711eae26 32 }
el16dlc 2:0bd6711eae26 33
el16dlc 2:0bd6711eae26 34 void GameEngine::snake_move() {
el16dlc 2:0bd6711eae26 35 if (_direction == 0) {
el16dlc 2:0bd6711eae26 36 snake.set_snake_posY (snake.get_snake_posY()- 4);
el16dlc 2:0bd6711eae26 37 } else if (_direction == 1) {
el16dlc 2:0bd6711eae26 38 snake.set_snake_posY (snake.get_snake_posY()+ 4);
el16dlc 2:0bd6711eae26 39 } else if (_direction == 2) {
el16dlc 2:0bd6711eae26 40 snake.set_snake_posX (snake.get_snake_posX()- 4);
el16dlc 2:0bd6711eae26 41 } else if (_direction == 3) {
el16dlc 2:0bd6711eae26 42 snake.set_snake_posX (snake.get_snake_posX()+ 4);
el16dlc 2:0bd6711eae26 43 }
el16dlc 1:b9f3b7d869d8 44 }