Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Engine/Engine.cpp
- Committer:
- el17m2h
- Date:
- 2019-04-13
- Revision:
- 5:8814d6de77d0
- Parent:
- 4:8ec314f806ae
- Child:
- 6:848d1e4c1a31
File content as of revision 5:8814d6de77d0:
#include "Engine.h"
Engine::Engine(){
}
Engine::~Engine(){
}
void Engine::init(int floors_width, int floors_height, int doodler_radius){
_floors_width = floors_width;
_floors_height = floors_height;
_doodler_radius = doodler_radius;
_dood.init(_doodler_radius);
// screen WIDTH =84 (but floors only visible to 70): 0 left, 70 right
// FLOORS_WIDTH = 10
// x- coordinate of floors position is fixed
srand(time(0)); // initializes random number generator
_f1x = rand()%6; // random floors position between 0 and 5
_f2x = 8 +(rand()%6);
_f3x = 16 +(rand()%6);
_f4x = 24 +(rand()%6);
_f5x = 32 +(rand()%6);
_f6x = 40 +(rand()%6);
_f7x = 48 +(rand()%6);
_f8x = 56 +(rand()%6);
_f9x = 64 +(rand()%6);
_f10x = 70/2; // one floor always at the middle bottom initially
// screen HEIGHT = 48 (0 up & 48 down)
// FLOORS_HEIGHT = 2
// y -coordinate for each floor position (depends on doodler)
_f1y = rand()%46; // random floors position between 0 and 45
_f2y = rand()%46;
_f3y = rand()%46;
_f4y = 10+(rand()%36);
_f5y = rand()%46;
_f6y = rand()%46;
_f7y = rand()%46;
_f8y = rand()%46;
_f9y = rand()%46;
_f10y = 46; // one floor always at the middle bottom initially
_f1.init(_f1x, _f1y, _floors_width, _floors_height);
_f2.init(_f2x, _f2y, _floors_width, _floors_height);
_f3.init(_f3x, _f3y, _floors_width, _floors_height);
_f4.init(_f4x, _f4y, _floors_width, _floors_height);
_f5.init(_f5x, _f5y, _floors_width, _floors_height);
_f6.init(_f6x, _f6y, _floors_width, _floors_height);
_f7.init(_f7x, _f7y, _floors_width, _floors_height);
_f8.init(_f8x, _f8y, _floors_width, _floors_height);
_f9.init(_f9x, _f9y, _floors_width, _floors_height);
_f10.init(_f10x, _f10y, _floors_width, _floors_height);
}
void Engine::read_input(Gamepad &pad){
_d = pad.get_direction();
_mag = pad.get_mag();
}
void Engine::draw(N5110 &lcd){
_dood.draw(lcd);
_f1.draw(lcd);
_f2.draw(lcd);
_f3.draw(lcd);
_f4.draw(lcd);
_f5.draw(lcd);
_f6.draw(lcd);
_f7.draw(lcd);
_f8.draw(lcd);
_f9.draw(lcd);
_f10.draw(lcd);
}
void Engine::update(Gamepad &pad){
_dood.update(_d, _mag);
_f1.update();
_f2.update();
_f3.update();
_f4.update();
_f5.update();
_f6.update();
_f7.update();
_f8.update();
_f9.update();
_f10.update();
}