Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: Bullets/Bullets.cpp
- Revision:
- 7:0434857199cf
- Parent:
- 5:51fd6635141f
- Child:
- 8:0c6d6ed55851
--- a/Bullets/Bullets.cpp Fri May 22 14:58:55 2020 +0000 +++ b/Bullets/Bullets.cpp Fri May 22 15:46:14 2020 +0000 @@ -1,8 +1,22 @@ #include "Bullets.h" Serial pcb(USBTX, USBRX); -Bullets::Bullets() +Bullets::Bullets(int ex, int wy, Direction d) { - + _x = ex; + _y = wy; + if (d == N) { + _dir = 0; + } + else if (d == E) { + _dir = 1; + } + else if (d == S) { + _dir = 2; + } + else if (d == W) { + _dir = 3; + } + //pcb.printf("Direction = %d", _dir); } Bullets::~Bullets() @@ -10,44 +24,32 @@ } -void Bullets::init(int ex, int wy, int d) -{ - _size = 1; - _speed = 4; - _x = ex; - _y = wy; - - if (d == 0) { - _dir = 0; - } else if (d == 1) { - _dir = 1; - } else if (d == 2) { - _dir = 2; - } else { - _dir = 3; - } - //pcb.printf("Direction = %d", _dir); -} - void Bullets::draw(N5110 &lcd) { + lcd.drawRect(_x,_y,1,1,FILL_BLACK); +} + +void Bullets::update() +{ if(_dir == 0){ - lcd.drawLine(_x,_y, _x, 0,1); + _y = _y-2; } else if (_dir == 1){ - lcd.drawLine(_x,_y, WIDTH, _y,1); + _x = _x+2; } else if (_dir == 2){ - lcd.drawLine(_x,_y, _x, HEIGHT,1); + _y = _y+2; } else if (_dir == 3){ - lcd.drawLine(_x,_y, 0, _y,1); + _x = _x-2; } } - -void Bullets::update(int ex, int wy) -{ - _x = ex; - _y = wy; -} \ No newline at end of file +int Bullets::get_x(){ + return _x; + } + +int Bullets::get_y(){ + return _y; + } + \ No newline at end of file