Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Gamepad N5110 mbed-rtos
Enemy/EnemyBoss.cpp
- Committer:
- RexRoshan
- Date:
- 2019-04-25
- Revision:
- 3:bf9624e5b0c3
- Parent:
- 1:45493d1d0689
- Child:
- 4:4d673fb2d9dc
File content as of revision 3:bf9624e5b0c3:
#include "EnemyBoss.h" // nothing doing in the constructor and destructor EnemyBoss::EnemyBoss() { } EnemyBoss::~EnemyBoss() { } AnalogIn noisy(PTB0); int enemy2 [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}, }; int boss [13][13] = { {0,0,0,0,0,1,1,1,1,1,0,0,0}, {0,0,0,0,0,0,1,1,1,0,0,0,0}, {0,0,1,1,1,1,1,1,1,1,1,1,1}, {0,0,0,0,0,1,0,1,0,0,1,0,0}, {0,0,0,0,1,0,1,0,1,0,1,0,0}, {0,0,0,1,0,0,0,1,0,1,1,0,0}, {1,1,1,1,0,1,0,1,0,1,1,0,0}, {0,0,0,1,0,0,0,1,0,1,1,0,0}, {0,0,0,0,1,0,1,0,1,0,1,0,0}, {0,0,0,0,0,1,0,1,0,0,1,0,0}, {0,0,1,1,1,1,1,1,1,1,1,1,1}, {0,0,0,0,0,0,1,1,1,0,0,0,0}, {0,0,0,0,0,1,1,1,1,1,0,0,0}, }; void EnemyBoss::init(int a,int b,int c,int d,int e,int f,int speed) { _a = a; _b = b; _c = c; _d = d; _e = e; _f = f; _health = 0; // start health from zero _health1 = 0; _health2 = 0; rand(100000*noisy.read()); int direction = rand() % 8; // randomise initial direction. // 4 possibilities. Get random modulo and set movement accordingly if (direction == 0) { _movement.x = speed; _movement.y = speed; } else if (direction == 1) { _movement.x = speed; _movement.y = -speed; } else if (direction == 2) { _movement.x = speed; _movement.y = speed; } else if (direction == 3) { _movement.x = speed; _movement.y = +speed; } else if (direction == 4) { _movement.x = +speed; _movement.y = +speed; } else if (direction == 5) { _movement.x = +speed; _movement.y = speed; } else if (direction == 6) { _movement.x = -speed; _movement.y = speed; }else { _movement.x = -speed; _movement.y = -speed; } } void EnemyBoss::enemyboss(N5110 &lcd) { // draw the second-one enemy lcd.drawSprite(_a,_b,13,13,(int *)boss); lcd.drawSprite(_c,_d,7,8,(int *)enemy2); lcd.drawSprite(_e,_f,7,8,(int *)enemy2); } void EnemyBoss::update() { _a += _movement.x; _b += _movement.y; } Vector2D EnemyBoss::get_movement() { Vector2D m = {_movement.x,_movement.y}; return m; } void EnemyBoss::set_movement(Vector2D m) { _movement.x = m.x; _movement.y = m.y; } void EnemyBoss::add_health_boss() { _health++; } int EnemyBoss::get_health_boss() { return _health; } void EnemyBoss::add_health_enemy1() { _health1++; } int EnemyBoss::get_health_enemy1() { return _health1; } void EnemyBoss::add_health_enemy2() { _health2++; } int EnemyBoss::get_health_enemy2() { return _health2; } Vector2D EnemyBoss::get_enemyboss_pos() { Vector2D e = {_a,_b}; return e; } Vector2D EnemyBoss::get_enemy1_pos() { Vector2D d = {_c,_d}; return d; } Vector2D EnemyBoss::get_enemy2_pos() { Vector2D c = {_e,_f}; return c; } void EnemyBoss::set_enemyboss_pos(Vector2D e) { _a = e.x; _b = e.y; } void EnemyBoss::set_enemy1_pos(Vector2D d) { _c = d.x; _d = d.y; } void EnemyBoss::set_enemy2_pos(Vector2D c) { _e = c.x; _f = c.y; }