The game is finished
Dependencies: mbed Gamepad N5110 mbed-rtos
Enemy/Enemy.cpp
- Committer:
- RexRoshan
- Date:
- 2019-05-09
- Revision:
- 14:c7302ffe6eab
- Parent:
- 7:574c66ebd8b0
File content as of revision 14:c7302ffe6eab:
#include "Enemy.h" // nothing doing in the constructor and destructor Enemy::Enemy() { } Enemy::~Enemy() { } // first enemy sprite int enemy1 [7][8] = { {0,1,1,0,0,0,0,1}, {0,0,0,1,1,1,1,1}, {0,0,1,0,0,1,1,0}, {0,1,0,0,1,1,1,0}, {0,0,1,0,0,1,1,0}, {0,0,0,1,1,1,1,1}, {0,1,1,0,0,0,0,1}, }; void Enemy::init(int a,int b) // initialising the x and y position of the enemy { _a = a; // x position of the enemy _b = b; // y position of the enemy _health = 0; // start health from zero } void Enemy::location() { int _speed = 5; // distance the enemy moves srand(time(NULL)); int direction = rand() % 4; // randomise initial direction. // 4 possibilities. Get random modulo and set location accordingly if (direction == 0) { // North _a = _a; _b += _speed; } else if (direction == 1) { //South _a = _a; _b -= _speed; } else if (direction == 2) { //West _a -= _speed; _b = _b; } else { // East _a += _speed; _b = _b; } } void Enemy::enemy(N5110 &lcd) { // Draws the first enemy lcd.drawSprite(_a,_b,7,8,(int *)enemy1); } void Enemy::update() // Moves the position of the enemy when the enemy dies { _fast = 2.0; // Movement speed = 2 so that it is not too fast _b+=_speed; // moves the y-position downwards } void Enemy::add_health() { // adds health _health++; } int Enemy::get_health() { // gets the value of health return _health; } Vector2D Enemy::get_enemy_pos() { //gets the position of the first enemy Vector2D e = {_a,_b}; return e; } void Enemy::set_enemy_pos(Vector2D e) { //sets the position of the first enemy of stage 2 _a = e.x; _b = e.y; }