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

Dependencies:   mbed

Committer:
davidwst421
Date:
Wed May 08 18:50:21 2019 +0000
Revision:
0:fd8eda608206
Child:
1:f09ff0ed98fd
12

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 0:fd8eda608206 15 _x = x; // x value on screen is fixed
davidwst421 0:fd8eda608206 16 int uncertainty = rand() % 39;
davidwst421 0:fd8eda608206 17 _height = uncertainty; // y depends on height of screen and height of paddle
davidwst421 0:fd8eda608206 18 _gap = gap;
davidwst421 0:fd8eda608206 19 _width = width;
davidwst421 0:fd8eda608206 20 _speed = speed;
davidwst421 0:fd8eda608206 21 }
davidwst421 0:fd8eda608206 22
davidwst421 0:fd8eda608206 23 void Wall::draw1(N5110 &lcd) {
davidwst421 0:fd8eda608206 24
davidwst421 0:fd8eda608206 25 // draw wall in screen buffer.
davidwst421 0:fd8eda608206 26 lcd.drawRect(_x,0,_width,_height,FILL_BLACK);
davidwst421 0:fd8eda608206 27 }
davidwst421 0:fd8eda608206 28
davidwst421 0:fd8eda608206 29 void Wall::draw2(N5110 &lcd) {
davidwst421 0:fd8eda608206 30 lcd.drawRect(_x,(_gap + _height),_width,(HEIGHT - (_gap + _height)),FILL_BLACK);
davidwst421 0:fd8eda608206 31 }
davidwst421 0:fd8eda608206 32
davidwst421 0:fd8eda608206 33 void Wall::update() {
davidwst421 0:fd8eda608206 34 // scale is arbitrary, could be changed in the future
davidwst421 0:fd8eda608206 35 _x -= _speed;
davidwst421 0:fd8eda608206 36 }
davidwst421 0:fd8eda608206 37
davidwst421 0:fd8eda608206 38 void Wall::reset() {
davidwst421 0:fd8eda608206 39
davidwst421 0:fd8eda608206 40 _x = 99;
davidwst421 0:fd8eda608206 41 int uncertainty = rand() % 39;
davidwst421 0:fd8eda608206 42 _y = 8 + uncertainty;
davidwst421 0:fd8eda608206 43 }
davidwst421 0:fd8eda608206 44
davidwst421 0:fd8eda608206 45
davidwst421 0:fd8eda608206 46 Vector2D Wall::get_height() {
davidwst421 0:fd8eda608206 47 return _height;
davidwst421 0:fd8eda608206 48 }