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
Enemy/Enemy.cpp@37:71f2cd073739, 2019-05-09 (annotated)
- Committer:
- el17m2h
- Date:
- Thu May 09 14:30:45 2019 +0000
- Revision:
- 37:71f2cd073739
- Parent:
- 33:de130e274391
Added comments to the enemy class documentation.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17m2h | 20:a359092079b0 | 1 | #include "Enemy.h" |
el17m2h | 29:15e9640646b7 | 2 | Enemy::Enemy() |
el17m2h | 29:15e9640646b7 | 3 | { |
el17m2h | 20:a359092079b0 | 4 | } |
el17m2h | 29:15e9640646b7 | 5 | Enemy::~Enemy() |
el17m2h | 29:15e9640646b7 | 6 | { |
el17m2h | 29:15e9640646b7 | 7 | } |
el17m2h | 37:71f2cd073739 | 8 | |
el17m2h | 37:71f2cd073739 | 9 | // Function to set the enemy's position on top of the floor's position |
el17m2h | 37:71f2cd073739 | 10 | void Enemy::update(Vector2D floor_pos) |
el17m2h | 29:15e9640646b7 | 11 | { |
el17m2h | 31:5c4acae51026 | 12 | _position.x = floor_pos.x + 7 - 6; // the + 7 for the centre of the floor and the + 6 for the centre of the ghost |
el17m2h | 31:5c4acae51026 | 13 | _position.y = floor_pos.y - 1 - 13; // the - 1 is so that it is on top of the floor's position |
el17m2h | 29:15e9640646b7 | 14 | // and the + 15 is so that it considers the position of the feet of the ghost (not the top) |
el17m2h | 20:a359092079b0 | 15 | } |
el17m2h | 20:a359092079b0 | 16 | |
el17m2h | 37:71f2cd073739 | 17 | // Draws the enemy to the screen |
el17m2h | 29:15e9640646b7 | 18 | void Enemy::draw(N5110 &lcd) |
el17m2h | 29:15e9640646b7 | 19 | { |
el17m2h | 30:863565e9859f | 20 | const int image [12][12] = { |
el17m2h | 29:15e9640646b7 | 21 | {0,0,0,0,1,1,1,1,0,0,0,0}, |
el17m2h | 29:15e9640646b7 | 22 | {0,0,1,1,0,0,0,0,1,1,0,0}, |
el17m2h | 29:15e9640646b7 | 23 | {0,1,0,0,0,0,0,0,0,0,1,0}, |
el17m2h | 30:863565e9859f | 24 | {1,0,0,1,0,0,0,0,1,0,0,1}, |
el17m2h | 29:15e9640646b7 | 25 | {1,0,1,1,1,0,0,1,1,1,0,1}, |
el17m2h | 30:863565e9859f | 26 | {1,0,0,1,0,0,0,0,1,0,0,1}, |
el17m2h | 29:15e9640646b7 | 27 | {1,0,0,0,0,0,0,0,0,0,0,1}, |
el17m2h | 29:15e9640646b7 | 28 | {1,0,0,0,0,0,0,0,0,0,0,1}, |
el17m2h | 29:15e9640646b7 | 29 | {1,0,0,0,0,0,0,0,0,0,0,1}, |
el17m2h | 29:15e9640646b7 | 30 | {1,1,1,0,0,1,1,0,0,1,1,1}, |
el17m2h | 29:15e9640646b7 | 31 | {1,1,0,1,1,0,0,1,1,0,1,1}, |
el17m2h | 29:15e9640646b7 | 32 | {1,0,0,0,1,0,0,1,0,0,0,1}, |
el17m2h | 23:9be87557b89a | 33 | }; |
el17m2h | 30:863565e9859f | 34 | lcd.drawSprite(_position.x, _position.y, 12, 12,(int*)image); |
el17m2h | 20:a359092079b0 | 35 | } |
el17m2h | 20:a359092079b0 | 36 | |
el17m2h | 33:de130e274391 | 37 | // Called in floors file if enemy is meant to get erased (moves the ghost out of the screen's visibility |
el17m2h | 33:de130e274391 | 38 | void Enemy::erase(){ _position.x = 90; _position.y = 50; } |
el17m2h | 20:a359092079b0 | 39 | |
el17m2h | 33:de130e274391 | 40 | Vector2D Enemy::get_position(){ Vector2D p = {_position.x,_position.y}; return p; } |