ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Committer:
el17m2h
Date:
Wed Apr 17 17:53:27 2019 +0000
Revision:
12:c5123abb4fbe
Parent:
11:2041290b5a74
Child:
13:10851784af9a
I fixed the direction of the floors and them being in a random x position when they reappear at the top.

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 12:c5123abb4fbe 20 void Floors::update(){
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 12:c5123abb4fbe 22 _pos = get_pos();
el17m2h 11:2041290b5a74 23 if (_pos.y > 48 ){
el17m2h 11:2041290b5a74 24 _pos.y = 0;
el17m2h 12:c5123abb4fbe 25 _pos.x = rand()% 74;
el17m2h 11:2041290b5a74 26 }
el17m2h 11:2041290b5a74 27 set_pos(_pos);
el17m2h 9:5e53bca2a4c2 28 }
el17m2h 9:5e53bca2a4c2 29
el17m2h 9:5e53bca2a4c2 30 Vector2D Floors::get_pos(){
el17m2h 9:5e53bca2a4c2 31 Vector2D p = {_pos.x,_pos.y};
el17m2h 9:5e53bca2a4c2 32 return p;
el17m2h 5:8814d6de77d0 33 }
el17m2h 5:8814d6de77d0 34
el17m2h 1:0001cb3eb053 35 void Floors::set_pos(Vector2D p){
el17m2h 9:5e53bca2a4c2 36 _pos.x = p.x;
el17m2h 9:5e53bca2a4c2 37 _pos.y = p.y;
el17m2h 1:0001cb3eb053 38 }