ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Committer:
el17m2h
Date:
Thu Apr 18 14:54:51 2019 +0000
Revision:
13:10851784af9a
Parent:
12:c5123abb4fbe
Child:
14:529f798adae4
Fixed the order of functions in the update section of the engine so that the doodler and floors are updated after checking both the floors collision and the shift of the floors

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 13:10851784af9a 12 int _array[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74};
el17m2h 13:10851784af9a 13 // excluding centre so doodler falls to the floor at bottom
el17m2h 13:10851784af9a 14 _pos.x = _array[rand()%(sizeof(_array) / sizeof *_array)];
el17m2h 9:5e53bca2a4c2 15 _pos.y = y;
el17m2h 1:0001cb3eb053 16 }
el17m2h 1:0001cb3eb053 17
el17m2h 1:0001cb3eb053 18 void Floors::draw(N5110 &lcd){
el17m2h 9:5e53bca2a4c2 19 lcd.drawRect(_pos.x, _pos.y, _width, _height, FILL_BLACK);
el17m2h 1:0001cb3eb053 20 }
el17m2h 1:0001cb3eb053 21
el17m2h 12:c5123abb4fbe 22 void Floors::update(){
el17m2h 11:2041290b5a74 23 // when they leave the screen they will re-appear in random x-coordinate so that 10 floors are always on screen
el17m2h 12:c5123abb4fbe 24 _pos = get_pos();
el17m2h 11:2041290b5a74 25 if (_pos.y > 48 ){
el17m2h 13:10851784af9a 26 _pos.y = 0;
el17m2h 12:c5123abb4fbe 27 _pos.x = rand()% 74;
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 }