ELEC2645 (2018/19) / Mbed 2 deprecated 2645_Project_SiutingWong201186503

Dependencies:   mbed

Committer:
davidwst421
Date:
Thu May 09 08:20:36 2019 +0000
Revision:
16:a5f5bc55d1bb
Parent:
14:13e82f720bea
Last version with Doxygen & comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
davidwst421 0:fd8eda608206 1 #include "Wall.h"
davidwst421 0:fd8eda608206 2
davidwst421 0:fd8eda608206 3 Wall::Wall()
davidwst421 0:fd8eda608206 4 {
davidwst421 0:fd8eda608206 5
davidwst421 0:fd8eda608206 6 }
davidwst421 0:fd8eda608206 7
davidwst421 0:fd8eda608206 8 Wall::~Wall()
davidwst421 0:fd8eda608206 9 {
davidwst421 0:fd8eda608206 10
davidwst421 0:fd8eda608206 11 }
davidwst421 0:fd8eda608206 12
davidwst421 0:fd8eda608206 13 void Wall::init(int x,int gap,int width,int speed) {
davidwst421 0:fd8eda608206 14
davidwst421 14:13e82f720bea 15 _x = x; // wall x starting postion and updating position
davidwst421 14:13e82f720bea 16 _gap = gap; // gap represents the distance between the wall
davidwst421 8:97576c8761a8 17 int uncertainty = rand() % (47 - _gap);
davidwst421 14:13e82f720bea 18 _height = uncertainty; // get random height for the wall
davidwst421 14:13e82f720bea 19 _width = width; // fixed width
davidwst421 14:13e82f720bea 20 _speed = speed; // adjuctable speed
davidwst421 0:fd8eda608206 21 }
davidwst421 0:fd8eda608206 22
davidwst421 0:fd8eda608206 23 void Wall::draw1(N5110 &lcd) {
davidwst421 0:fd8eda608206 24 // draw wall in screen buffer.
davidwst421 0:fd8eda608206 25 lcd.drawRect(_x,0,_width,_height,FILL_BLACK);
davidwst421 0:fd8eda608206 26 }
davidwst421 0:fd8eda608206 27
davidwst421 0:fd8eda608206 28 void Wall::draw2(N5110 &lcd) {
davidwst421 14:13e82f720bea 29 lcd.drawRect(_x,(_gap + _height),_width,(HEIGHT - (_gap + _height)),FILL_BLACK); // draw the wall near the bottom
davidwst421 0:fd8eda608206 30 }
davidwst421 0:fd8eda608206 31
davidwst421 0:fd8eda608206 32 void Wall::update() {
davidwst421 14:13e82f720bea 33 _x -= _speed; // speed is arbitrary, could be changed in the future, and the wall is shifting to left
davidwst421 0:fd8eda608206 34 }
davidwst421 0:fd8eda608206 35
davidwst421 14:13e82f720bea 36 void Wall::reset() { // when the wall is off from the left screen, replace it back to the right side and continue the game
davidwst421 7:193c0fd7afdd 37 _x = 149;
davidwst421 8:97576c8761a8 38 int uncertainty = rand() % (47 - _gap);
davidwst421 1:f09ff0ed98fd 39 _height = uncertainty;
davidwst421 0:fd8eda608206 40 }
davidwst421 0:fd8eda608206 41
davidwst421 14:13e82f720bea 42 int Wall::get_x() { // get x position and wall height for collision logic function
davidwst421 1:f09ff0ed98fd 43 return _x;
davidwst421 1:f09ff0ed98fd 44 }
davidwst421 1:f09ff0ed98fd 45 int Wall::get_height() {
davidwst421 0:fd8eda608206 46 return _height;
davidwst421 0:fd8eda608206 47 }