ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Committer:
el17m2h
Date:
Sat Apr 13 17:37:52 2019 +0000
Revision:
5:8814d6de77d0
Parent:
4:8ec314f806ae
Child:
6:848d1e4c1a31
Created an update function for the doodler to change its position depending on the user moving the joystick left or right.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17m2h 2:360a6c301a4e 1 #include "Engine.h"
el17m2h 2:360a6c301a4e 2
el17m2h 2:360a6c301a4e 3 Engine::Engine(){
el17m2h 2:360a6c301a4e 4 }
el17m2h 2:360a6c301a4e 5 Engine::~Engine(){
el17m2h 2:360a6c301a4e 6 }
el17m2h 2:360a6c301a4e 7
el17m2h 4:8ec314f806ae 8 void Engine::init(int floors_width, int floors_height, int doodler_radius){
el17m2h 5:8814d6de77d0 9 _floors_width = floors_width;
el17m2h 2:360a6c301a4e 10 _floors_height = floors_height;
el17m2h 4:8ec314f806ae 11 _doodler_radius = doodler_radius;
el17m2h 4:8ec314f806ae 12
el17m2h 5:8814d6de77d0 13 _dood.init(_doodler_radius);
el17m2h 4:8ec314f806ae 14
el17m2h 5:8814d6de77d0 15 // screen WIDTH =84 (but floors only visible to 70): 0 left, 70 right
el17m2h 4:8ec314f806ae 16 // FLOORS_WIDTH = 10
el17m2h 3:116913e97fd7 17 // x- coordinate of floors position is fixed
el17m2h 4:8ec314f806ae 18 srand(time(0)); // initializes random number generator
el17m2h 4:8ec314f806ae 19 _f1x = rand()%6; // random floors position between 0 and 5
el17m2h 5:8814d6de77d0 20 _f2x = 8 +(rand()%6);
el17m2h 5:8814d6de77d0 21 _f3x = 16 +(rand()%6);
el17m2h 5:8814d6de77d0 22 _f4x = 24 +(rand()%6);
el17m2h 5:8814d6de77d0 23 _f5x = 32 +(rand()%6);
el17m2h 5:8814d6de77d0 24 _f6x = 40 +(rand()%6);
el17m2h 5:8814d6de77d0 25 _f7x = 48 +(rand()%6);
el17m2h 5:8814d6de77d0 26 _f8x = 56 +(rand()%6);
el17m2h 5:8814d6de77d0 27 _f9x = 64 +(rand()%6);
el17m2h 5:8814d6de77d0 28 _f10x = 70/2; // one floor always at the middle bottom initially
el17m2h 3:116913e97fd7 29
el17m2h 5:8814d6de77d0 30 // screen HEIGHT = 48 (0 up & 48 down)
el17m2h 4:8ec314f806ae 31 // FLOORS_HEIGHT = 2
el17m2h 3:116913e97fd7 32 // y -coordinate for each floor position (depends on doodler)
el17m2h 4:8ec314f806ae 33 _f1y = rand()%46; // random floors position between 0 and 45
el17m2h 4:8ec314f806ae 34 _f2y = rand()%46;
el17m2h 4:8ec314f806ae 35 _f3y = rand()%46;
el17m2h 5:8814d6de77d0 36 _f4y = 10+(rand()%36);
el17m2h 4:8ec314f806ae 37 _f5y = rand()%46;
el17m2h 4:8ec314f806ae 38 _f6y = rand()%46;
el17m2h 4:8ec314f806ae 39 _f7y = rand()%46;
el17m2h 4:8ec314f806ae 40 _f8y = rand()%46;
el17m2h 4:8ec314f806ae 41 _f9y = rand()%46;
el17m2h 5:8814d6de77d0 42 _f10y = 46; // one floor always at the middle bottom initially
el17m2h 2:360a6c301a4e 43
el17m2h 3:116913e97fd7 44 _f1.init(_f1x, _f1y, _floors_width, _floors_height);
el17m2h 3:116913e97fd7 45 _f2.init(_f2x, _f2y, _floors_width, _floors_height);
el17m2h 3:116913e97fd7 46 _f3.init(_f3x, _f3y, _floors_width, _floors_height);
el17m2h 3:116913e97fd7 47 _f4.init(_f4x, _f4y, _floors_width, _floors_height);
el17m2h 3:116913e97fd7 48 _f5.init(_f5x, _f5y, _floors_width, _floors_height);
el17m2h 3:116913e97fd7 49 _f6.init(_f6x, _f6y, _floors_width, _floors_height);
el17m2h 3:116913e97fd7 50 _f7.init(_f7x, _f7y, _floors_width, _floors_height);
el17m2h 3:116913e97fd7 51 _f8.init(_f8x, _f8y, _floors_width, _floors_height);
el17m2h 3:116913e97fd7 52 _f9.init(_f9x, _f9y, _floors_width, _floors_height);
el17m2h 5:8814d6de77d0 53 _f10.init(_f10x, _f10y, _floors_width, _floors_height);
el17m2h 5:8814d6de77d0 54 }
el17m2h 5:8814d6de77d0 55
el17m2h 5:8814d6de77d0 56 void Engine::read_input(Gamepad &pad){
el17m2h 5:8814d6de77d0 57 _d = pad.get_direction();
el17m2h 5:8814d6de77d0 58 _mag = pad.get_mag();
el17m2h 2:360a6c301a4e 59 }
el17m2h 2:360a6c301a4e 60
el17m2h 2:360a6c301a4e 61 void Engine::draw(N5110 &lcd){
el17m2h 4:8ec314f806ae 62 _dood.draw(lcd);
el17m2h 2:360a6c301a4e 63 _f1.draw(lcd);
el17m2h 2:360a6c301a4e 64 _f2.draw(lcd);
el17m2h 2:360a6c301a4e 65 _f3.draw(lcd);
el17m2h 2:360a6c301a4e 66 _f4.draw(lcd);
el17m2h 2:360a6c301a4e 67 _f5.draw(lcd);
el17m2h 2:360a6c301a4e 68 _f6.draw(lcd);
el17m2h 2:360a6c301a4e 69 _f7.draw(lcd);
el17m2h 2:360a6c301a4e 70 _f8.draw(lcd);
el17m2h 2:360a6c301a4e 71 _f9.draw(lcd);
el17m2h 2:360a6c301a4e 72 _f10.draw(lcd);
el17m2h 2:360a6c301a4e 73
el17m2h 5:8814d6de77d0 74 }
el17m2h 5:8814d6de77d0 75
el17m2h 5:8814d6de77d0 76 void Engine::update(Gamepad &pad){
el17m2h 5:8814d6de77d0 77 _dood.update(_d, _mag);
el17m2h 5:8814d6de77d0 78 _f1.update();
el17m2h 5:8814d6de77d0 79 _f2.update();
el17m2h 5:8814d6de77d0 80 _f3.update();
el17m2h 5:8814d6de77d0 81 _f4.update();
el17m2h 5:8814d6de77d0 82 _f5.update();
el17m2h 5:8814d6de77d0 83 _f6.update();
el17m2h 5:8814d6de77d0 84 _f7.update();
el17m2h 5:8814d6de77d0 85 _f8.update();
el17m2h 5:8814d6de77d0 86 _f9.update();
el17m2h 5:8814d6de77d0 87 _f10.update();
el17m2h 5:8814d6de77d0 88
el17m2h 5:8814d6de77d0 89 }