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
Diff: Enemy/Enemy.cpp
- Revision:
- 4:4d673fb2d9dc
- Parent:
- 0:99fa5a619081
- Child:
- 6:1fcfd331c047
--- a/Enemy/Enemy.cpp Thu Apr 25 16:31:27 2019 +0000 +++ b/Enemy/Enemy.cpp Sun May 05 17:41:46 2019 +0000 @@ -11,6 +11,7 @@ } +// first enemy sprite int enemy1 [7][8] = { {0,1,1,0,0,0,0,1}, @@ -23,31 +24,12 @@ }; -//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 Enemy::init(int a,int b) +void Enemy::init(int a,int b) // initialising the x and y position of the enemy { - _a = a; - _b = b; + _a = a; // x position of the enemy + _b = b; // y position of the enemy _health = 0; // start health from zero } @@ -55,31 +37,33 @@ void Enemy::enemy(N5110 &lcd) { - // draw the first enemy + // draws the first enemy lcd.drawSprite(_a,_b,7,8,(int *)enemy1); } -void Enemy::update() +void Enemy::update() // moves the position of the enemy when the enemy dies { - _speed = 2.0; // scale is arbitrary, could be changed in future - // update y value depending on direction of movement - // North is decrement as origin is at the top-left so decreasing moves up - _b+=_speed; + _speed = 2.0; // set at 2 so that it is not too fast + + _b+=_speed; // moves the y-position downwards } void Enemy::add_health() { + // increments the value of health by 1 _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; } \ No newline at end of file