Albert Tan-Mulligan
/
ELEC2645_Project_el18ajst
Diff: Enemy/Enemy.cpp
- Revision:
- 14:2d7e41f46879
- Parent:
- 10:71ced616a64f
- Child:
- 15:3dbb3f4d7ae6
--- a/Enemy/Enemy.cpp Tue May 26 12:49:15 2020 +0000 +++ b/Enemy/Enemy.cpp Tue May 26 14:33:14 2020 +0000 @@ -1,24 +1,25 @@ #include "Enemy.h" #include <Bitmap.h> Serial pce(USBTX, USBRX); +//Constructor with seed, to spawn enemies at random places on edge of screen Enemy::Enemy(int seed) { srand(seed); - four = (rand()%4)+1; - //pce.printf("%d",four); - if(four == 1){ + _four = (rand()%4)+1; + //pce.printf("%d",_four); + if(_four == 1){ _x = 0; _y = rand()%48; } - else if(four == 2){ + else if(_four == 2){ _x = 84; _y = rand()%48; } - else if(four == 3){ + else if(_four == 3){ _y = 0; _x = rand()%84; } - else if(four == 4){ + else if(_four == 4){ _y = 48; _x = rand()%84; } @@ -28,16 +29,12 @@ { } - -void Enemy::init() -{ -} - void Enemy::draw(N5110 &lcd) { lcd.drawRect(_x,_y,3,3,FILL_TRANSPARENT); } +//updates enemy with player x and y so it can walk towards the player void Enemy::update(int player_x, int player_y) { if(_x<player_x){ @@ -55,6 +52,7 @@ } } +//accessor functions int Enemy::get_x() { return _x; @@ -65,24 +63,44 @@ return _y; } -void Enemy::reset(int seed){ +//resets enemies each time it gets shot +void Enemy::reset(int seed, N5110 &lcd){ + DeathAnimation(lcd); srand(seed); - four = (rand()%4)+1; - //pce.printf("%d",four); - if(four == 1){ + _four = (rand()%4)+1; + //pce.printf("%d", _four); + if(_four == 1){ _x = 0; _y = rand()%48; } - else if(four == 2){ + else if(_four == 2){ _x = 84; _y = rand()%48; } - else if(four == 3){ + else if(_four == 3){ _y = 0; _x = rand()%84; } - else if(four == 4){ + else if(_four == 4){ _y = 48; _x = rand()%84; } } +//Eenmy Death Animation +void Enemy::DeathAnimation(N5110 &lcd){ + int sprite_data[] = { + 1,0,1,0,1, + 0,1,1,1,0, + 1,1,0,1,1, + 0,1,1,1,0, + 1,0,1,0,1 + }; + + + Bitmap death(sprite_data, 5, 5); + + //Render Bitmap at x & y + death.render(lcd, _x - 1, _y - 1); + lcd.refresh(); + wait(0.01); + }