ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18ajst

Dependencies:   mbed

Committer:
Albutt
Date:
Tue May 26 14:33:14 2020 +0000
Revision:
14:2d7e41f46879
Parent:
12:c557b6c9b17a
Enemy Death Animation

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 14:2d7e41f46879 3 //constructor defines x, y and the direction of travel
Albutt 12:c557b6c9b17a 4 Bullets::Bullets(int ex, int wy, int d)
Albutt 4:b16b6078a432 5 {
Albutt 14:2d7e41f46879 6 //direction defaults to zero if the joystick hasn't been used yet
Albutt 9:62fe47a1374f 7 _dir = 0;
Albutt 7:0434857199cf 8 _x = ex;
Albutt 7:0434857199cf 9 _y = wy;
Albutt 12:c557b6c9b17a 10 _dir = d;
Albutt 7:0434857199cf 11 //pcb.printf("Direction = %d", _dir);
Albutt 4:b16b6078a432 12 }
Albutt 4:b16b6078a432 13
Albutt 4:b16b6078a432 14 Bullets::~Bullets()
Albutt 4:b16b6078a432 15 {
Albutt 4:b16b6078a432 16
Albutt 4:b16b6078a432 17 }
Albutt 14:2d7e41f46879 18 //draws a 1-by-1 rectangle at x and y
Albutt 4:b16b6078a432 19 void Bullets::draw(N5110 &lcd)
Albutt 4:b16b6078a432 20 {
Albutt 5:51fd6635141f 21
Albutt 7:0434857199cf 22 lcd.drawRect(_x,_y,1,1,FILL_BLACK);
Albutt 7:0434857199cf 23 }
Albutt 14:2d7e41f46879 24 //bullets travels in a straight line in a direction
Albutt 7:0434857199cf 25 void Bullets::update()
Albutt 7:0434857199cf 26 {
Albutt 4:b16b6078a432 27 if(_dir == 0){
Albutt 8:0c6d6ed55851 28 _y = _y-3;
Albutt 4:b16b6078a432 29 }
Albutt 4:b16b6078a432 30 else if (_dir == 1){
Albutt 8:0c6d6ed55851 31 _x = _x+3;
Albutt 4:b16b6078a432 32 }
Albutt 4:b16b6078a432 33 else if (_dir == 2){
Albutt 8:0c6d6ed55851 34 _y = _y+3;
Albutt 4:b16b6078a432 35 }
Albutt 4:b16b6078a432 36 else if (_dir == 3){
Albutt 8:0c6d6ed55851 37 _x = _x-3;
Albutt 4:b16b6078a432 38 }
Albutt 4:b16b6078a432 39 }
Albutt 14:2d7e41f46879 40 //accessors
Albutt 7:0434857199cf 41 int Bullets::get_x(){
Albutt 7:0434857199cf 42 return _x;
Albutt 7:0434857199cf 43 }
Albutt 7:0434857199cf 44
Albutt 7:0434857199cf 45 int Bullets::get_y(){
Albutt 7:0434857199cf 46 return _y;
Albutt 7:0434857199cf 47 }
Albutt 14:2d7e41f46879 48 //shots that "die" go offscreen (where main them deletes them in line 224)
Albutt 14:2d7e41f46879 49 //Avoids vector becoming zero, which causes errors in the GameRun loop
Albutt 9:62fe47a1374f 50 void Bullets::dead(){
Albutt 14:2d7e41f46879 51 _x = 1000;
Albutt 9:62fe47a1374f 52 _y = 1000;
Albutt 9:62fe47a1374f 53 }
Albutt 7:0434857199cf 54