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
Diff: Enemy/Enemy.cpp
- Revision:
- 29:15e9640646b7
- Parent:
- 23:9be87557b89a
- Child:
- 30:863565e9859f
--- a/Enemy/Enemy.cpp Wed May 08 18:02:11 2019 +0000 +++ b/Enemy/Enemy.cpp Wed May 08 21:11:35 2019 +0000 @@ -1,52 +1,48 @@ #include "Enemy.h" -Enemy::Enemy(){ -} -Enemy::~Enemy(){ +Enemy::Enemy() +{ } - -void Enemy::init(float floor_pos_x, float floor_pos_y){ // sets its position - _radius = 3; - _position.x = floor_pos_x + 4; - _position.y = floor_pos_y + 4; +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 - 15; // 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 [16][16] = { - {0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0}, - {0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0}, - {0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0}, - {0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0}, - {0,0,1,0,1,0,0,0,0,0,0,1,0,1,0,0}, - {0,0,1,0,1,1,1,0,0,1,1,1,0,1,0,0}, - {0,0,1,0,1,1,1,0,0,1,1,1,0,1,0,0}, - {0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0}, - {0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0}, - {0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0}, - {0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0}, - {0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0}, - {0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0}, - {0,0,1,1,1,0,0,1,1,0,0,1,1,1,0,0}, - {0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0}, - {0,0,1,0,0,0,1,0,0,1,0,0,0,1,0,0}, +void Enemy::draw(N5110 &lcd) +{ + const int image [16][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,1,0,0,0,0,0,0,0,0,1,1}, + {1,0,1,0,0,0,0,0,0,1,0,1}, + {1,0,1,1,1,0,0,1,1,1,0,1}, + {1,0,1,1,1,0,0,1,1,1,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,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, 16, 16,(int*)image); + lcd.drawSprite(_position.x, _position.y, 16, 12,(int*)image); } -void Enemy::update(float floor_pos_x, float floor_pos_y){ // decides if it gets erased - bullet_pos_y = b.get_position_y(); - _position.x = floor_pos_x + 4; - _position.y = floor_pos_y + 4; - if (_position.y + 3 > bullet_pos_y){ - _position.x = 90; // out of the screen and if pos x = 90 then lower point - } +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 Enemy::get_position() +{ Vector2D p = {_position.x,_position.y}; return p; -} - -void Enemy::set_position(Vector2D pos){ - _position.x = pos.x; - _position.y = pos.y; } \ No newline at end of file