ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Committer:
el17m2h
Date:
Wed Apr 17 16:58:01 2019 +0000
Revision:
11:2041290b5a74
Parent:
10:e1d2289705ef
Child:
12:c5123abb4fbe
I added a function in the engine cpp to shift the floors when the doodler goes beyond the middle. I also added a function in the floors cpp that will check if the floors leave the screen so that it will move the floor to the top and in a random x-pos

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17m2h 1:0001cb3eb053 1 #include "Floors.h"
el17m2h 1:0001cb3eb053 2
el17m2h 1:0001cb3eb053 3 Floors::Floors(){
el17m2h 1:0001cb3eb053 4 }
el17m2h 1:0001cb3eb053 5 Floors::~Floors(){
el17m2h 1:0001cb3eb053 6 }
el17m2h 3:116913e97fd7 7
el17m2h 11:2041290b5a74 8 void Floors::init(int y, int width, int height){
el17m2h 1:0001cb3eb053 9 _height = height;
el17m2h 1:0001cb3eb053 10 _width = width;
el17m2h 11:2041290b5a74 11 // x-coordinate initially random: screen =84 (visible to 84-FLOORS_WIDTH): 0 left, 70 right
el17m2h 11:2041290b5a74 12 _pos.x = rand()% 74;
el17m2h 9:5e53bca2a4c2 13 _pos.y = y;
el17m2h 1:0001cb3eb053 14 }
el17m2h 1:0001cb3eb053 15
el17m2h 1:0001cb3eb053 16 void Floors::draw(N5110 &lcd){
el17m2h 9:5e53bca2a4c2 17 lcd.drawRect(_pos.x, _pos.y, _width, _height, FILL_BLACK);
el17m2h 1:0001cb3eb053 18 }
el17m2h 1:0001cb3eb053 19
el17m2h 10:e1d2289705ef 20 void Floors::update(Vector2D current_pos){
el17m2h 11:2041290b5a74 21 // when they leave the screen they will re-appear in random x-coordinate so that 10 floors are always on screen
el17m2h 10:e1d2289705ef 22 _pos = current_pos;
el17m2h 11:2041290b5a74 23 srand(time(0));
el17m2h 11:2041290b5a74 24 if (_pos.y > 48 ){
el17m2h 11:2041290b5a74 25 _pos.y = 0;
el17m2h 11:2041290b5a74 26 _pos.x = rand()% 74;
el17m2h 11:2041290b5a74 27 srand(time(0));
el17m2h 11:2041290b5a74 28 }
el17m2h 11:2041290b5a74 29 set_pos(_pos);
el17m2h 9:5e53bca2a4c2 30 }
el17m2h 9:5e53bca2a4c2 31
el17m2h 9:5e53bca2a4c2 32 Vector2D Floors::get_pos(){
el17m2h 9:5e53bca2a4c2 33 Vector2D p = {_pos.x,_pos.y};
el17m2h 9:5e53bca2a4c2 34 return p;
el17m2h 5:8814d6de77d0 35 }
el17m2h 5:8814d6de77d0 36
el17m2h 1:0001cb3eb053 37 void Floors::set_pos(Vector2D p){
el17m2h 9:5e53bca2a4c2 38 _pos.x = p.x;
el17m2h 9:5e53bca2a4c2 39 _pos.y = p.y;
el17m2h 1:0001cb3eb053 40 }