James Heavey / Mbed 2 deprecated 2665-Breakout-Game

Dependencies:   mbed

Committer:
jamesheavey
Date:
Tue Jan 05 01:14:11 2021 +0000
Revision:
0:92b180c8d407
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jamesheavey 0:92b180c8d407 1 #include "Laser.h"
jamesheavey 0:92b180c8d407 2
jamesheavey 0:92b180c8d407 3 Laser::Laser()
jamesheavey 0:92b180c8d407 4 {
jamesheavey 0:92b180c8d407 5
jamesheavey 0:92b180c8d407 6 }
jamesheavey 0:92b180c8d407 7
jamesheavey 0:92b180c8d407 8 Laser::~Laser()
jamesheavey 0:92b180c8d407 9 {
jamesheavey 0:92b180c8d407 10
jamesheavey 0:92b180c8d407 11 }
jamesheavey 0:92b180c8d407 12
jamesheavey 0:92b180c8d407 13 void Laser::init() // initialises the lasers off screen
jamesheavey 0:92b180c8d407 14 {
jamesheavey 0:92b180c8d407 15 _x = -10;
jamesheavey 0:92b180c8d407 16 _y = 0;
jamesheavey 0:92b180c8d407 17
jamesheavey 0:92b180c8d407 18 _speed_y = -2; // -2 speed in the y direction, doesnt change even off screen
jamesheavey 0:92b180c8d407 19 }
jamesheavey 0:92b180c8d407 20
jamesheavey 0:92b180c8d407 21 void Laser::draw(N5110 &lcd)
jamesheavey 0:92b180c8d407 22 {
jamesheavey 0:92b180c8d407 23 if (_x >= 0) { // only draw if on screen (more efficient?)
jamesheavey 0:92b180c8d407 24 lcd.drawRect(_x,_y,2,6,FILL_BLACK);
jamesheavey 0:92b180c8d407 25 }
jamesheavey 0:92b180c8d407 26 }
jamesheavey 0:92b180c8d407 27
jamesheavey 0:92b180c8d407 28 void Laser::update() // updates the laser's y coordinate according to its speed
jamesheavey 0:92b180c8d407 29 {
jamesheavey 0:92b180c8d407 30 _y += _speed_y;
jamesheavey 0:92b180c8d407 31 }
jamesheavey 0:92b180c8d407 32
jamesheavey 0:92b180c8d407 33 int Laser::get_x() // retrieves the lasers's x coordinate
jamesheavey 0:92b180c8d407 34 {
jamesheavey 0:92b180c8d407 35 return _x;
jamesheavey 0:92b180c8d407 36 }
jamesheavey 0:92b180c8d407 37
jamesheavey 0:92b180c8d407 38 int Laser::get_y() // retrieves the lasers's y coordinate
jamesheavey 0:92b180c8d407 39 {
jamesheavey 0:92b180c8d407 40 return _y;
jamesheavey 0:92b180c8d407 41 }
jamesheavey 0:92b180c8d407 42
jamesheavey 0:92b180c8d407 43 void Laser::set_posx(int x) // sets the laser's x coordinate
jamesheavey 0:92b180c8d407 44 {
jamesheavey 0:92b180c8d407 45 _x = x;
jamesheavey 0:92b180c8d407 46 }
jamesheavey 0:92b180c8d407 47
jamesheavey 0:92b180c8d407 48 void Laser::set_posy(int y) // sets the lasers's y coordinate
jamesheavey 0:92b180c8d407 49 {
jamesheavey 0:92b180c8d407 50 _y = y;
jamesheavey 0:92b180c8d407 51 }