Laila Al Badwawi 200906179 SpaceInvaders I declare this my own independent work and understand the university rules on plagiarism.
Dependencies: mbed
Diff: Alien/Alien.cpp
- Revision:
- 92:8a1b14488ca5
- Parent:
- 91:f9e2ff484014
- Child:
- 96:01434284987f
--- a/Alien/Alien.cpp Sun Apr 28 19:44:34 2019 +0000 +++ b/Alien/Alien.cpp Sun May 05 01:27:55 2019 +0000 @@ -12,7 +12,7 @@ } -const int Alien[12][10] = { + int Alien_sprite[12][10] = { { 0,0,0,0,0,1,1,1,0,0 }, { 0,0,0,0,0,1,1,1,0,0 }, { 0,0,0,1,1,1,1,0,0,0 }, @@ -33,15 +33,15 @@ void Alien::init(int size,int speed) { - + _size = size; - - - - - + + + + + srand(time(NULL)); - int direction = rand() % 8; // randomise initial direction. + int direction = rand() % 8; // randomise initial direction. // 4 possibilities. Get random modulo and set velocities accordingly if (direction == 0) { @@ -58,21 +58,22 @@ _velocity.y = -speed; } } - - - void Alien::draw(N5110 &lcd) + + + +void Alien::draw(N5110&lcd) { - lcd.drawSprite(x_Alien,y_Alien,12,10,(int *)Alien); + lcd.drawSprite(x_Alien,y_Alien,12,10,(int *)Alien_sprite); } - - void Alien::update() + +void Alien::update() { _x += _velocity.x; _y += _velocity.y; - } - - void Alien::set_velocity(Vector2D v) +} + +void Alien::set_velocity(Vector2D v) { _velocity.x = v.x; _velocity.y = v.y;