ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Enemy/Enemy.cpp

Committer:
el17m2h
Date:
2019-05-09
Revision:
30:863565e9859f
Parent:
29:15e9640646b7
Child:
31:5c4acae51026

File content as of revision 30:863565e9859f:

#include "Enemy.h"
Enemy::Enemy()
{
}
Enemy::~Enemy()
{
}
void Enemy::update(Vector2D floor_pos)  // sets its position
{
    _position.x = floor_pos.x + 7 - 6; // the + 7 for the centre of the floor and the + 6 for the centre of the ghost
    _position.y = floor_pos.y - 2 - 13; // the - 2 is so that it is on top of the floor's position 
    // and the + 15 is so that it considers the position of the feet of the ghost (not the top)
}

void Enemy::draw(N5110 &lcd)
{
    const int image [12][12] = {
        {0,0,0,0,1,1,1,1,0,0,0,0},
        {0,0,1,1,0,0,0,0,1,1,0,0},
        {0,1,0,0,0,0,0,0,0,0,1,0},
        {1,0,0,1,0,0,0,0,1,0,0,1},
        {1,0,1,1,1,0,0,1,1,1,0,1},
        {1,0,0,1,0,0,0,0,1,0,0,1},
        {1,0,0,0,0,0,0,0,0,0,0,1},
        {1,0,0,0,0,0,0,0,0,0,0,1},
        {1,0,0,0,0,0,0,0,0,0,0,1},
        {1,1,1,0,0,1,1,0,0,1,1,1},
        {1,1,0,1,1,0,0,1,1,0,1,1},
        {1,0,0,0,1,0,0,1,0,0,0,1},
    };
    lcd.drawSprite(_position.x, _position.y, 12, 12,(int*)image);
}

void Enemy::erase()  // decides if it gets erased
{
    _position.x = 90; // the ghost's is no longer shown on the screen
    _position.y = 50;
}

Vector2D Enemy::get_position()
{
    Vector2D p = {_position.x,_position.y};
    return p;
}