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@23:9be87557b89a, 2019-05-08 (annotated)
- Committer:
- el17m2h
- Date:
- Wed May 08 08:46:11 2019 +0000
- Revision:
- 23:9be87557b89a
- Parent:
- 20:a359092079b0
- Child:
- 29:15e9640646b7
Added a sprite for the doodler and the enemy.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17m2h | 20:a359092079b0 | 1 | #include "Enemy.h" |
el17m2h | 20:a359092079b0 | 2 | Enemy::Enemy(){ |
el17m2h | 20:a359092079b0 | 3 | } |
el17m2h | 20:a359092079b0 | 4 | Enemy::~Enemy(){ |
el17m2h | 20:a359092079b0 | 5 | } |
el17m2h | 20:a359092079b0 | 6 | |
el17m2h | 20:a359092079b0 | 7 | void Enemy::init(float floor_pos_x, float floor_pos_y){ // sets its position |
el17m2h | 20:a359092079b0 | 8 | _radius = 3; |
el17m2h | 20:a359092079b0 | 9 | _position.x = floor_pos_x + 4; |
el17m2h | 20:a359092079b0 | 10 | _position.y = floor_pos_y + 4; |
el17m2h | 20:a359092079b0 | 11 | } |
el17m2h | 20:a359092079b0 | 12 | |
el17m2h | 20:a359092079b0 | 13 | void Enemy::draw(N5110 &lcd){ |
el17m2h | 23:9be87557b89a | 14 | const int image [16][16] = { |
el17m2h | 23:9be87557b89a | 15 | {0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0}, |
el17m2h | 23:9be87557b89a | 16 | {0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0}, |
el17m2h | 23:9be87557b89a | 17 | {0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0}, |
el17m2h | 23:9be87557b89a | 18 | {0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0}, |
el17m2h | 23:9be87557b89a | 19 | {0,0,1,0,1,0,0,0,0,0,0,1,0,1,0,0}, |
el17m2h | 23:9be87557b89a | 20 | {0,0,1,0,1,1,1,0,0,1,1,1,0,1,0,0}, |
el17m2h | 23:9be87557b89a | 21 | {0,0,1,0,1,1,1,0,0,1,1,1,0,1,0,0}, |
el17m2h | 23:9be87557b89a | 22 | {0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0}, |
el17m2h | 23:9be87557b89a | 23 | {0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0}, |
el17m2h | 23:9be87557b89a | 24 | {0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0}, |
el17m2h | 23:9be87557b89a | 25 | {0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0}, |
el17m2h | 23:9be87557b89a | 26 | {0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0}, |
el17m2h | 23:9be87557b89a | 27 | {0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0}, |
el17m2h | 23:9be87557b89a | 28 | {0,0,1,1,1,0,0,1,1,0,0,1,1,1,0,0}, |
el17m2h | 23:9be87557b89a | 29 | {0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0}, |
el17m2h | 23:9be87557b89a | 30 | {0,0,1,0,0,0,1,0,0,1,0,0,0,1,0,0}, |
el17m2h | 23:9be87557b89a | 31 | }; |
el17m2h | 23:9be87557b89a | 32 | lcd.drawSprite(_position.x, _position.y, 16, 16,(int*)image); |
el17m2h | 20:a359092079b0 | 33 | } |
el17m2h | 20:a359092079b0 | 34 | |
el17m2h | 20:a359092079b0 | 35 | void Enemy::update(float floor_pos_x, float floor_pos_y){ // decides if it gets erased |
el17m2h | 20:a359092079b0 | 36 | bullet_pos_y = b.get_position_y(); |
el17m2h | 20:a359092079b0 | 37 | _position.x = floor_pos_x + 4; |
el17m2h | 20:a359092079b0 | 38 | _position.y = floor_pos_y + 4; |
el17m2h | 20:a359092079b0 | 39 | if (_position.y + 3 > bullet_pos_y){ |
el17m2h | 20:a359092079b0 | 40 | _position.x = 90; // out of the screen and if pos x = 90 then lower point |
el17m2h | 20:a359092079b0 | 41 | } |
el17m2h | 20:a359092079b0 | 42 | } |
el17m2h | 20:a359092079b0 | 43 | |
el17m2h | 20:a359092079b0 | 44 | Vector2D Enemy::get_position(){ |
el17m2h | 20:a359092079b0 | 45 | Vector2D p = {_position.x,_position.y}; |
el17m2h | 20:a359092079b0 | 46 | return p; |
el17m2h | 20:a359092079b0 | 47 | } |
el17m2h | 20:a359092079b0 | 48 | |
el17m2h | 20:a359092079b0 | 49 | void Enemy::set_position(Vector2D pos){ |
el17m2h | 20:a359092079b0 | 50 | _position.x = pos.x; |
el17m2h | 20:a359092079b0 | 51 | _position.y = pos.y; |
el17m2h | 20:a359092079b0 | 52 | } |