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/Enemy2.cpp@13:c3b550fc2445, 2019-05-04 (annotated)
- Committer:
- S_Tingle
- Date:
- Sat May 04 19:33:08 2019 +0000
- Revision:
- 13:c3b550fc2445
- Parent:
- 12:200a1266ceee
- Child:
- 14:d0650d0de063
Enemy1 movement working + coin added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
S_Tingle | 12:200a1266ceee | 1 | #include "Enemy2.h" |
S_Tingle | 12:200a1266ceee | 2 | |
S_Tingle | 12:200a1266ceee | 3 | Enemy2::Enemy2(){ |
S_Tingle | 12:200a1266ceee | 4 | x_enem = 67; |
S_Tingle | 12:200a1266ceee | 5 | y_enem = 20; |
S_Tingle | 12:200a1266ceee | 6 | } |
S_Tingle | 12:200a1266ceee | 7 | |
S_Tingle | 12:200a1266ceee | 8 | Enemy2::~Enemy2(){ |
S_Tingle | 12:200a1266ceee | 9 | |
S_Tingle | 12:200a1266ceee | 10 | } |
S_Tingle | 12:200a1266ceee | 11 | |
S_Tingle | 12:200a1266ceee | 12 | void Enemy2::init(int x,int y){ |
S_Tingle | 12:200a1266ceee | 13 | x_enem = x; |
S_Tingle | 12:200a1266ceee | 14 | y_enem = y; |
S_Tingle | 12:200a1266ceee | 15 | } |
S_Tingle | 12:200a1266ceee | 16 | |
S_Tingle | 12:200a1266ceee | 17 | int Enemy2::get_x_enem() |
S_Tingle | 12:200a1266ceee | 18 | { |
S_Tingle | 12:200a1266ceee | 19 | return x_enem; |
S_Tingle | 12:200a1266ceee | 20 | } |
S_Tingle | 12:200a1266ceee | 21 | |
S_Tingle | 12:200a1266ceee | 22 | int Enemy2::get_y_enem() |
S_Tingle | 12:200a1266ceee | 23 | { |
S_Tingle | 12:200a1266ceee | 24 | return y_enem; |
S_Tingle | 12:200a1266ceee | 25 | } |
S_Tingle | 12:200a1266ceee | 26 | |
S_Tingle | 12:200a1266ceee | 27 | void Enemy2::drawSprite(N5110 &lcd){ |
S_Tingle | 12:200a1266ceee | 28 | lcd.drawSprite(x_enem,y_enem,7,7,(int *)enemy_B); |
S_Tingle | 12:200a1266ceee | 29 | } |
S_Tingle | 12:200a1266ceee | 30 | |
S_Tingle | 12:200a1266ceee | 31 | void Enemy2::movement(N5110 &lcd){ |
S_Tingle | 12:200a1266ceee | 32 | accel = 1; |
S_Tingle | 13:c3b550fc2445 | 33 | for (int i = 0; i < 14; i++) { |
S_Tingle | 13:c3b550fc2445 | 34 | if (20 < y_enem < 32){ |
S_Tingle | 13:c3b550fc2445 | 35 | y_enem += accel; |
S_Tingle | 13:c3b550fc2445 | 36 | } |
S_Tingle | 13:c3b550fc2445 | 37 | if (y_enem == 32){ |
S_Tingle | 13:c3b550fc2445 | 38 | y_enem -= accel; |
S_Tingle | 13:c3b550fc2445 | 39 | } |
S_Tingle | 12:200a1266ceee | 40 | } |
S_Tingle | 12:200a1266ceee | 41 | } |
S_Tingle | 12:200a1266ceee | 42 | |
S_Tingle | 12:200a1266ceee | 43 | bool Enemy2::northCollision(int x, int y, N5110 &lcd){ |
S_Tingle | 12:200a1266ceee | 44 | |
S_Tingle | 12:200a1266ceee | 45 | for (int i = 0; i < 7; i++) { |
S_Tingle | 13:c3b550fc2445 | 46 | if (lcd.getPixel(x + i,y) == 1) { |
S_Tingle | 12:200a1266ceee | 47 | return true; |
S_Tingle | 12:200a1266ceee | 48 | } |
S_Tingle | 12:200a1266ceee | 49 | } |
S_Tingle | 12:200a1266ceee | 50 | return false; |
S_Tingle | 12:200a1266ceee | 51 | } |
S_Tingle | 12:200a1266ceee | 52 | |
S_Tingle | 12:200a1266ceee | 53 | bool Enemy2::southCollision(int x, int y, N5110 &lcd){ |
S_Tingle | 12:200a1266ceee | 54 | |
S_Tingle | 12:200a1266ceee | 55 | for (int i = 0; i < 7; i++) { |
S_Tingle | 12:200a1266ceee | 56 | if (lcd.getPixel(x + i,y + 7) == 1) { |
S_Tingle | 12:200a1266ceee | 57 | return true; |
S_Tingle | 12:200a1266ceee | 58 | } |
S_Tingle | 12:200a1266ceee | 59 | } |
S_Tingle | 12:200a1266ceee | 60 | return false; |
S_Tingle | 12:200a1266ceee | 61 | } |