ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18ajst

Dependencies:   mbed

Committer:
Albutt
Date:
Sat May 23 13:26:19 2020 +0000
Revision:
9:62fe47a1374f
Parent:
8:0c6d6ed55851
Child:
12:c557b6c9b17a
Multiple Enemies Spawning, Bullets Despawn when hit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Albutt 4:b16b6078a432 1 #include "Bullets.h"
Albutt 4:b16b6078a432 2 Serial pcb(USBTX, USBRX);
Albutt 7:0434857199cf 3 Bullets::Bullets(int ex, int wy, Direction d)
Albutt 4:b16b6078a432 4 {
Albutt 9:62fe47a1374f 5 _dir = 0;
Albutt 7:0434857199cf 6 _x = ex;
Albutt 7:0434857199cf 7 _y = wy;
Albutt 7:0434857199cf 8 if (d == N) {
Albutt 7:0434857199cf 9 _dir = 0;
Albutt 7:0434857199cf 10 }
Albutt 7:0434857199cf 11 else if (d == E) {
Albutt 7:0434857199cf 12 _dir = 1;
Albutt 7:0434857199cf 13 }
Albutt 7:0434857199cf 14 else if (d == S) {
Albutt 7:0434857199cf 15 _dir = 2;
Albutt 7:0434857199cf 16 }
Albutt 7:0434857199cf 17 else if (d == W) {
Albutt 7:0434857199cf 18 _dir = 3;
Albutt 7:0434857199cf 19 }
Albutt 7:0434857199cf 20 //pcb.printf("Direction = %d", _dir);
Albutt 4:b16b6078a432 21 }
Albutt 4:b16b6078a432 22
Albutt 4:b16b6078a432 23 Bullets::~Bullets()
Albutt 4:b16b6078a432 24 {
Albutt 4:b16b6078a432 25
Albutt 4:b16b6078a432 26 }
Albutt 4:b16b6078a432 27
Albutt 4:b16b6078a432 28 void Bullets::draw(N5110 &lcd)
Albutt 4:b16b6078a432 29 {
Albutt 5:51fd6635141f 30
Albutt 7:0434857199cf 31 lcd.drawRect(_x,_y,1,1,FILL_BLACK);
Albutt 7:0434857199cf 32 }
Albutt 7:0434857199cf 33
Albutt 7:0434857199cf 34 void Bullets::update()
Albutt 7:0434857199cf 35 {
Albutt 4:b16b6078a432 36 if(_dir == 0){
Albutt 8:0c6d6ed55851 37 _y = _y-3;
Albutt 4:b16b6078a432 38 }
Albutt 4:b16b6078a432 39 else if (_dir == 1){
Albutt 8:0c6d6ed55851 40 _x = _x+3;
Albutt 4:b16b6078a432 41 }
Albutt 4:b16b6078a432 42 else if (_dir == 2){
Albutt 8:0c6d6ed55851 43 _y = _y+3;
Albutt 4:b16b6078a432 44 }
Albutt 4:b16b6078a432 45 else if (_dir == 3){
Albutt 8:0c6d6ed55851 46 _x = _x-3;
Albutt 4:b16b6078a432 47 }
Albutt 4:b16b6078a432 48 }
Albutt 7:0434857199cf 49 int Bullets::get_x(){
Albutt 7:0434857199cf 50 return _x;
Albutt 7:0434857199cf 51 }
Albutt 7:0434857199cf 52
Albutt 7:0434857199cf 53 int Bullets::get_y(){
Albutt 7:0434857199cf 54 return _y;
Albutt 7:0434857199cf 55 }
Albutt 9:62fe47a1374f 56
Albutt 9:62fe47a1374f 57 void Bullets::dead(){
Albutt 9:62fe47a1374f 58 _x = 2147483647;
Albutt 9:62fe47a1374f 59 _y = 1000;
Albutt 9:62fe47a1374f 60 }
Albutt 7:0434857199cf 61