test 1 doc

Dependencies:   mbed Gamepad2

Committer:
joebarhouch
Date:
Mon May 25 16:17:58 2020 +0000
Revision:
6:00d20886e4f8
Parent:
5:928c2eee4109
Child:
7:530ca713d2b2
Implements map as an array of platforms for easier collision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joebarhouch 3:e4e1cbf750b6 1 #include "Engine.h"
joebarhouch 3:e4e1cbf750b6 2
joebarhouch 3:e4e1cbf750b6 3 Engine::Engine()
joebarhouch 3:e4e1cbf750b6 4 {
joebarhouch 3:e4e1cbf750b6 5 }
joebarhouch 3:e4e1cbf750b6 6 Engine::~Engine()
joebarhouch 3:e4e1cbf750b6 7 {
joebarhouch 3:e4e1cbf750b6 8 }
joebarhouch 3:e4e1cbf750b6 9
joebarhouch 6:00d20886e4f8 10
joebarhouch 6:00d20886e4f8 11 ////////////////////// INIT ////////////////////////////
joebarhouch 3:e4e1cbf750b6 12 void Engine::init()
joebarhouch 3:e4e1cbf750b6 13 {
joebarhouch 3:e4e1cbf750b6 14 //init coord
joebarhouch 3:e4e1cbf750b6 15 _px = WIDTH / 2;
joebarhouch 6:00d20886e4f8 16 _py = 10;
joebarhouch 6:00d20886e4f8 17
joebarhouch 6:00d20886e4f8 18
joebarhouch 3:e4e1cbf750b6 19 //init call
joebarhouch 3:e4e1cbf750b6 20 _p.init(_px, _py);
joebarhouch 3:e4e1cbf750b6 21 }
joebarhouch 3:e4e1cbf750b6 22
joebarhouch 6:00d20886e4f8 23
joebarhouch 6:00d20886e4f8 24
joebarhouch 6:00d20886e4f8 25 ////////////////////// INPUT //////////////////////////
joebarhouch 5:928c2eee4109 26 //reads direction and magnitude from the JOYSTICK to control the player
joebarhouch 3:e4e1cbf750b6 27 void Engine::read_input(Gamepad &pad)
joebarhouch 3:e4e1cbf750b6 28 {
joebarhouch 3:e4e1cbf750b6 29 _d = pad.get_direction();
joebarhouch 3:e4e1cbf750b6 30 _mag = pad.get_mag();
joebarhouch 3:e4e1cbf750b6 31 }
joebarhouch 3:e4e1cbf750b6 32
joebarhouch 6:00d20886e4f8 33 ////////////////////// DRAW ///////////////////////////
joebarhouch 6:00d20886e4f8 34 //draw both player and map
joebarhouch 3:e4e1cbf750b6 35 void Engine::draw(N5110 &lcd)
joebarhouch 3:e4e1cbf750b6 36 {
joebarhouch 6:00d20886e4f8 37
joebarhouch 3:e4e1cbf750b6 38 // player
joebarhouch 3:e4e1cbf750b6 39 _p.draw(lcd);
joebarhouch 6:00d20886e4f8 40 drawMap(lcd);
joebarhouch 6:00d20886e4f8 41
joebarhouch 3:e4e1cbf750b6 42 }
joebarhouch 3:e4e1cbf750b6 43
joebarhouch 6:00d20886e4f8 44 ////////////////////// UPDATE //////////////////////////
joebarhouch 5:928c2eee4109 45 //provide the player file with necessary Joystick values
joebarhouch 3:e4e1cbf750b6 46 void Engine::update(Gamepad &pad)
joebarhouch 3:e4e1cbf750b6 47 {
joebarhouch 6:00d20886e4f8 48 _p.update(_d,_mag);
joebarhouch 6:00d20886e4f8 49 }
joebarhouch 3:e4e1cbf750b6 50
joebarhouch 6:00d20886e4f8 51 /*
joebarhouch 6:00d20886e4f8 52 floorCollide();
joebarhouch 6:00d20886e4f8 53
joebarhouch 6:00d20886e4f8 54 if (_collision == true) {
joebarhouch 6:00d20886e4f8 55
joebarhouch 6:00d20886e4f8 56 //debug
joebarhouch 6:00d20886e4f8 57 //printf("collison\n");
joebarhouch 6:00d20886e4f8 58 } else {
joebarhouch 6:00d20886e4f8 59
joebarhouch 6:00d20886e4f8 60 //debug
joebarhouch 6:00d20886e4f8 61 //printf("no collison\n");
joebarhouch 6:00d20886e4f8 62 }
joebarhouch 3:e4e1cbf750b6 63 //enemmyCollide(pad);
joebarhouch 3:e4e1cbf750b6 64 }
joebarhouch 6:00d20886e4f8 65 */
joebarhouch 6:00d20886e4f8 66
joebarhouch 6:00d20886e4f8 67 /*
joebarhouch 6:00d20886e4f8 68 ////////////////////// FLOOR COLLISION //////////////////////////
joebarhouch 6:00d20886e4f8 69 bool Engine::floorCollide()
joebarhouch 6:00d20886e4f8 70 {
joebarhouch 6:00d20886e4f8 71 Vector2D player = _p.get_pos();
joebarhouch 6:00d20886e4f8 72 _collision = false;
joebarhouch 6:00d20886e4f8 73
joebarhouch 6:00d20886e4f8 74 if ( player.x +1 >= plat.x && player.x +1 <= plat.x + plat.width ) {
joebarhouch 6:00d20886e4f8 75 _collision = true;
joebarhouch 6:00d20886e4f8 76 } else {
joebarhouch 6:00d20886e4f8 77 _collision = false;
joebarhouch 6:00d20886e4f8 78 }
joebarhouch 6:00d20886e4f8 79 return _collision;
joebarhouch 6:00d20886e4f8 80 }
joebarhouch 3:e4e1cbf750b6 81
joebarhouch 5:928c2eee4109 82
joebarhouch 3:e4e1cbf750b6 83 */