ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Committer:
el17m2h
Date:
Wed May 08 17:24:35 2019 +0000
Revision:
26:d16a5b1e0ace
Parent:
24:67dc71a8f009
Child:
29:15e9640646b7
Added comments for the documentation file.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17m2h 1:0001cb3eb053 1 #include "Floors.h"
el17m2h 1:0001cb3eb053 2 Floors::Floors(){
el17m2h 1:0001cb3eb053 3 }
el17m2h 1:0001cb3eb053 4 Floors::~Floors(){
el17m2h 1:0001cb3eb053 5 }
el17m2h 3:116913e97fd7 6
el17m2h 11:2041290b5a74 7 void Floors::init(int y, int width, int height){
el17m2h 1:0001cb3eb053 8 _height = height;
el17m2h 1:0001cb3eb053 9 _width = width;
el17m2h 22:0d2ac98a8b48 10 // x-coordinate initially random: 2-30 or 40-71 so doodler falls to bottom floor
el17m2h 22:0d2ac98a8b48 11 int decide = rand() % 2;
el17m2h 22:0d2ac98a8b48 12 if (decide == 0){ // right
el17m2h 22:0d2ac98a8b48 13 _position.x = 2 + (rand()% 28);
el17m2h 22:0d2ac98a8b48 14 } else { // left
el17m2h 22:0d2ac98a8b48 15 _position.x = 40 + (rand()% 31);
el17m2h 22:0d2ac98a8b48 16 }
el17m2h 14:529f798adae4 17 _position.y = y;
el17m2h 1:0001cb3eb053 18 }
el17m2h 1:0001cb3eb053 19
el17m2h 1:0001cb3eb053 20 void Floors::draw(N5110 &lcd){
el17m2h 14:529f798adae4 21 lcd.drawRect(_position.x, _position.y, _width, _height, FILL_BLACK);
el17m2h 1:0001cb3eb053 22 }
el17m2h 1:0001cb3eb053 23
el17m2h 15:4efa04a6a376 24 void Floors::update(float doodler_pos_y){
el17m2h 11:2041290b5a74 25 // when they leave the screen they will re-appear in random x-coordinate so that 10 floors are always on screen
el17m2h 20:a359092079b0 26 //rectangle (1-82 & 9 - 48 )
el17m2h 21:6b16ca9834e6 27 if (_position.y > 45 ){
el17m2h 26:d16a5b1e0ace 28 _position.y = 9;
el17m2h 26:d16a5b1e0ace 29 _position.x = 1 + (rand()% 70);
el17m2h 26:d16a5b1e0ace 30 place = rand()% 8;
el17m2h 26:d16a5b1e0ace 31 if (place == 2){ // 1/8 chance of placing an enemy
el17m2h 26:d16a5b1e0ace 32 _eny.init(_position.x, _position.y);
el17m2h 26:d16a5b1e0ace 33 }
el17m2h 20:a359092079b0 34 }
el17m2h 24:67dc71a8f009 35 if (doodler_pos_y < 25){ // shift floors once doodler reaches over halfway the screen
el17m2h 15:4efa04a6a376 36 _position.y += 1;
el17m2h 20:a359092079b0 37 _eny.update(_position.x, _position.y);
el17m2h 15:4efa04a6a376 38 }
el17m2h 9:5e53bca2a4c2 39 }
el17m2h 9:5e53bca2a4c2 40
el17m2h 14:529f798adae4 41 Vector2D Floors::get_position(){
el17m2h 14:529f798adae4 42 Vector2D p = {_position.x,_position.y};
el17m2h 9:5e53bca2a4c2 43 return p;
el17m2h 5:8814d6de77d0 44 }
el17m2h 5:8814d6de77d0 45
el17m2h 14:529f798adae4 46 void Floors::set_position(Vector2D pos){
el17m2h 14:529f798adae4 47 _position.x = pos.x;
el17m2h 14:529f798adae4 48 _position.y = pos.y;
el17m2h 21:6b16ca9834e6 49 }