Nemesis game, first enemy
Diff: Enemy1.cpp
- Revision:
- 8:2ced844d8292
- Parent:
- 7:3d951a743dbe
--- a/Enemy1.cpp Tue May 02 22:13:59 2017 +0000 +++ b/Enemy1.cpp Wed May 03 20:03:46 2017 +0000 @@ -2,24 +2,27 @@ Enemy1::Enemy1() { - } Enemy1::~Enemy1() { +} -} + +// Initializion method: void Enemy1::init(int speed) { - int x = rand() % 63 + 84; - _x = x; - _y = 1; + _x = rand() % 63 + 84; // Starting x position is randomized off screen. Creates a random ship generation. + _y = 1; // Starting y position (fixed, first lane) - _velocity.x = -speed; + _velocity.x = -speed; // Velocity is based on the speed, which is input when method is used. _velocity.y = 0; } + +// Draws first enemy ship onto LCD: + void Enemy1::draw(N5110 &lcd) { lcd.drawLine(_x,_y,_x,_y+5,1); @@ -29,12 +32,19 @@ lcd.drawLine(_x-4,_y+2,_x-4,_y+3,1); } + +// Updates first enemy ship's position: + void Enemy1::update() { + // X and y positions depend on velocity: _x += _velocity.x; _y += _velocity.y; } + +// Obtains first enemy ship's current position: + Vector2D Enemy1::get_pos() { Vector2D p = {_x,_y};