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@12:200a1266ceee, 2019-05-02 (annotated)
- Committer:
- S_Tingle
- Date:
- Thu May 02 19:59:05 2019 +0000
- Revision:
- 12:200a1266ceee
- Child:
- 13:c3b550fc2445
Enemy2 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 | 12:200a1266ceee | 33 | |
S_Tingle | 12:200a1266ceee | 34 | if (southCollision(x_enem, y_enem, lcd) == true && northCollision(x_enem, y_enem, lcd) == false){ |
S_Tingle | 12:200a1266ceee | 35 | y_enem -= accel; |
S_Tingle | 12:200a1266ceee | 36 | } else if (northCollision(x_enem, y_enem, lcd) == true && southCollision(x_enem, y_enem, lcd) == false){ |
S_Tingle | 12:200a1266ceee | 37 | y_enem += accel; |
S_Tingle | 12:200a1266ceee | 38 | } |
S_Tingle | 12:200a1266ceee | 39 | } |
S_Tingle | 12:200a1266ceee | 40 | |
S_Tingle | 12:200a1266ceee | 41 | |
S_Tingle | 12:200a1266ceee | 42 | bool Enemy2::northCollision(int x, int y, N5110 &lcd){ |
S_Tingle | 12:200a1266ceee | 43 | |
S_Tingle | 12:200a1266ceee | 44 | for (int i = 0; i < 7; i++) { |
S_Tingle | 12:200a1266ceee | 45 | if (lcd.getPixel(x + i,y + 1) == 1) { |
S_Tingle | 12:200a1266ceee | 46 | return true; |
S_Tingle | 12:200a1266ceee | 47 | } |
S_Tingle | 12:200a1266ceee | 48 | } |
S_Tingle | 12:200a1266ceee | 49 | return false; |
S_Tingle | 12:200a1266ceee | 50 | } |
S_Tingle | 12:200a1266ceee | 51 | |
S_Tingle | 12:200a1266ceee | 52 | bool Enemy2::southCollision(int x, int y, N5110 &lcd){ |
S_Tingle | 12:200a1266ceee | 53 | |
S_Tingle | 12:200a1266ceee | 54 | for (int i = 0; i < 7; i++) { |
S_Tingle | 12:200a1266ceee | 55 | if (lcd.getPixel(x + i,y + 7) == 1) { |
S_Tingle | 12:200a1266ceee | 56 | return true; |
S_Tingle | 12:200a1266ceee | 57 | } |
S_Tingle | 12:200a1266ceee | 58 | } |
S_Tingle | 12:200a1266ceee | 59 | return false; |
S_Tingle | 12:200a1266ceee | 60 | } |