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

Dependencies:   mbed

Committer:
davidwst421
Date:
Wed May 08 19:44:17 2019 +0000
Revision:
1:f09ff0ed98fd
Parent:
0:fd8eda608206
Child:
7:193c0fd7afdd
change wall

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 // 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 0:fd8eda608206 29 lcd.drawRect(_x,(_gap + _height),_width,(HEIGHT - (_gap + _height)),FILL_BLACK);
davidwst421 0:fd8eda608206 30 }
davidwst421 0:fd8eda608206 31
davidwst421 0:fd8eda608206 32 void Wall::update() {
davidwst421 0:fd8eda608206 33 // scale is arbitrary, could be changed in the future
davidwst421 0:fd8eda608206 34 _x -= _speed;
davidwst421 0:fd8eda608206 35 }
davidwst421 0:fd8eda608206 36
davidwst421 0:fd8eda608206 37 void Wall::reset() {
davidwst421 0:fd8eda608206 38 _x = 99;
davidwst421 0:fd8eda608206 39 int uncertainty = rand() % 39;
davidwst421 1:f09ff0ed98fd 40 _height = uncertainty;
davidwst421 0:fd8eda608206 41 }
davidwst421 0:fd8eda608206 42
davidwst421 1:f09ff0ed98fd 43 int Wall::get_x() {
davidwst421 1:f09ff0ed98fd 44 return _x;
davidwst421 1:f09ff0ed98fd 45 }
davidwst421 1:f09ff0ed98fd 46 int Wall::get_height() {
davidwst421 0:fd8eda608206 47 return _height;
davidwst421 0:fd8eda608206 48 }