Liu Liting 201199465

Dependencies:   mbed N5110

Committer:
Ting12138
Date:
Thu May 14 15:42:14 2020 +0000
Revision:
13:a57a48e5e256
Parent:
12:3b7811c3502c
the 2645 project

Who changed what in which revision?

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