Nemesis game, fourth enemy

Enemy4.cpp

Committer:
musallambseiso
Date:
2017-05-03
Revision:
3:c94be48251b5
Parent:
2:1f2d27210997

File content as of revision 3:c94be48251b5:

#include "Enemy4.h"

Enemy4::Enemy4()
{
}

Enemy4::~Enemy4()
{
}


// Initializion method:

void Enemy4::init(int speed)
{
    _x = rand() % 63 + 84;  // Starting x position is randomized off screen. Creates a random ship generation.
    _y = 21;                // Starting y position (fixed, fourth lane)

    _velocity.x = -speed;   // Velocity is based on the speed, which is input when method is used.
    _velocity.y = 0;
}


// Draws fourth enemy ship onto LCD:

void Enemy4::draw(N5110 &lcd)
{
    lcd.drawLine(_x,_y,_x,_y+5,1);
    lcd.drawLine(_x-1,_y,_x-1,_y+5,1);
    lcd.drawLine(_x-2,_y+1,_x-2,_y+4,1);
    lcd.drawLine(_x-3,_y+1,_x-3,_y+4,1);
    lcd.drawLine(_x-4,_y+2,_x-4,_y+3,1);
}


// Updates fourth enemy ship's position:

void Enemy4::update()
{
    // X and y positions depend on velocity:
    _x += _velocity.x;
    _y += _velocity.y;
}


// Obtains fourth enemy ship's current position:

Vector2D Enemy4::get_pos()
{
    Vector2D p = {_x,_y};
    return p;
}