ELEC2645 (2018/19) / Mbed 2 deprecated el17rrrs

Dependencies:   mbed Gamepad N5110 mbed-rtos

Enemy/Enemy21.cpp

Committer:
RexRoshan
Date:
2019-05-09
Revision:
0:d9cf94b41df3

File content as of revision 0:d9cf94b41df3:

#include "Enemy21.h"

// nothing doing in the constructor and destructor
Enemy21::Enemy21()
{

}

Enemy21::~Enemy21()
{

}       

// sprite of the first enemy for stage 2
int enemy21 [7][7] ={
    
{0,0,0,0,0,1,1},
{0,0,0,0,0,1,1},
{0,0,0,0,1,0,0},
{0,0,0,1,0,0,0},
{0,0,1,0,0,0,0},
{1,1,0,0,0,0,0},
{1,1,0,0,0,0,0},

};
   
void Enemy21::init(int a,int b,int speed) // initialising the x and y position of the enemy and movement speed of the enemy 
{
  
    _a = a;       // x position of the first enemy for stage 2
    _b = b;       // y position of the first enemy for stage 2
    
    _health = 0;  // start health from zero

    int direction = rand() % 2; // randomise initial direction. 
    
    // 2 possibilities. Get random modulo and set movement accordingly
     if (direction == 0) {
        _movement.x = 0;
        _movement.y = speed; // move up
    } else {
       _movement.x = 0;
       _movement.y = -speed; // move down
       } 
}

void Enemy21::enemy2(N5110 &lcd)
{

    // Draws the first enemy for stage 2
    lcd.drawSprite(_a,_b,7,7,(int *)enemy21);
    
}

void Enemy21::update()
{
    _a += _movement.x; // updates the x position
    _b += _movement.y; // updates the y position
     
}


Vector2D Enemy21::get_movement()
{
    // gets the movement of the enemy
    Vector2D m = {_movement.x,_movement.y};
    return m;
}

void Enemy21::set_movement(Vector2D m)
{
    // sets the movement of the enemy
    _movement.x = m.x;
    _movement.y = m.y;
}
  
void Enemy21::add_health()
{
    // increments the value of health by 1
    _health++;
}

int Enemy21::get_health()
{
    // gets the value of health
    return _health;
}

Vector2D Enemy21::get_enemy21_pos() 
{
    //gets the position of the first enemy of stage 2
    Vector2D e = {_a,_b};
    return e;    
}

void Enemy21::set_enemy21_pos(Vector2D e)
{
    //sets the position of the first enemy of stage 2
    _a = e.x;
    _b = e.y;
}