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@16:37d98c281eb3, 2019-05-08 (annotated)
- Committer:
- S_Tingle
- Date:
- Wed May 08 09:05:27 2019 +0000
- Revision:
- 16:37d98c281eb3
- Parent:
- 14:d0650d0de063
- Child:
- 21:7d4827af00d6
collect + damage + menu
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 | 14:d0650d0de063 | 17 | int Enemy2::get_x_enem(){ |
S_Tingle | 12:200a1266ceee | 18 | return x_enem; |
S_Tingle | 12:200a1266ceee | 19 | } |
S_Tingle | 12:200a1266ceee | 20 | |
S_Tingle | 14:d0650d0de063 | 21 | int Enemy2::get_y_enem(){ |
S_Tingle | 12:200a1266ceee | 22 | return y_enem; |
S_Tingle | 12:200a1266ceee | 23 | } |
S_Tingle | 12:200a1266ceee | 24 | |
S_Tingle | 12:200a1266ceee | 25 | void Enemy2::drawSprite(N5110 &lcd){ |
S_Tingle | 16:37d98c281eb3 | 26 | lcd.drawSprite(x_enem, y_enem,7,7,(int *)enemy_B); |
S_Tingle | 12:200a1266ceee | 27 | } |
S_Tingle | 12:200a1266ceee | 28 | |
S_Tingle | 12:200a1266ceee | 29 | void Enemy2::movement(N5110 &lcd){ |
S_Tingle | 12:200a1266ceee | 30 | accel = 1; |
S_Tingle | 16:37d98c281eb3 | 31 | _incrementer_enem2++; |
S_Tingle | 16:37d98c281eb3 | 32 | if ( _incrementer_enem2 == 28 ) { _incrementer_enem2 = 0; } |
S_Tingle | 16:37d98c281eb3 | 33 | if ( _incrementer_enem2 >= 0 && _incrementer_enem2 <= 13) { y_enem++; } |
S_Tingle | 16:37d98c281eb3 | 34 | else if ( _incrementer_enem2 >= 14 && _incrementer_enem2 <= 27) { y_enem--; } |
S_Tingle | 12:200a1266ceee | 35 | } |
S_Tingle | 12:200a1266ceee | 36 | |
S_Tingle | 12:200a1266ceee | 37 | bool Enemy2::northCollision(int x, int y, N5110 &lcd){ |
S_Tingle | 12:200a1266ceee | 38 | |
S_Tingle | 12:200a1266ceee | 39 | for (int i = 0; i < 7; i++) { |
S_Tingle | 13:c3b550fc2445 | 40 | if (lcd.getPixel(x + i,y) == 1) { |
S_Tingle | 12:200a1266ceee | 41 | return true; |
S_Tingle | 12:200a1266ceee | 42 | } |
S_Tingle | 12:200a1266ceee | 43 | } |
S_Tingle | 12:200a1266ceee | 44 | return false; |
S_Tingle | 12:200a1266ceee | 45 | } |
S_Tingle | 12:200a1266ceee | 46 | |
S_Tingle | 12:200a1266ceee | 47 | bool Enemy2::southCollision(int x, int y, N5110 &lcd){ |
S_Tingle | 12:200a1266ceee | 48 | |
S_Tingle | 12:200a1266ceee | 49 | for (int i = 0; i < 7; i++) { |
S_Tingle | 12:200a1266ceee | 50 | if (lcd.getPixel(x + i,y + 7) == 1) { |
S_Tingle | 12:200a1266ceee | 51 | return true; |
S_Tingle | 12:200a1266ceee | 52 | } |
S_Tingle | 12:200a1266ceee | 53 | } |
S_Tingle | 12:200a1266ceee | 54 | return false; |
S_Tingle | 16:37d98c281eb3 | 55 | } |
S_Tingle | 16:37d98c281eb3 | 56 | |
S_Tingle | 16:37d98c281eb3 | 57 | bool Enemy2::collidePlayer(int x, int y, Gamepad &pad) { |
S_Tingle | 16:37d98c281eb3 | 58 | |
S_Tingle | 16:37d98c281eb3 | 59 | for (int ix = 0; ix < 7; ix++) { |
S_Tingle | 16:37d98c281eb3 | 60 | for (int iy = 0; iy < 7; iy++) { |
S_Tingle | 16:37d98c281eb3 | 61 | if ( x + ix == x_enem + 3 && |
S_Tingle | 16:37d98c281eb3 | 62 | y + iy == y_enem + 3 ) { |
S_Tingle | 16:37d98c281eb3 | 63 | pad.tone(400,0.5); |
S_Tingle | 16:37d98c281eb3 | 64 | return true; |
S_Tingle | 16:37d98c281eb3 | 65 | |
S_Tingle | 16:37d98c281eb3 | 66 | } |
S_Tingle | 16:37d98c281eb3 | 67 | } |
S_Tingle | 16:37d98c281eb3 | 68 | } |
S_Tingle | 16:37d98c281eb3 | 69 | return false; |
S_Tingle | 12:200a1266ceee | 70 | } |