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@8:0c6d6ed55851, 2020-05-22 (annotated)
- Committer:
- Albutt
- Date:
- Fri May 22 16:54:10 2020 +0000
- Revision:
- 8:0c6d6ed55851
- Parent:
- 6:546eba371942
- Child:
- 9:62fe47a1374f
Collision with Enemy
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Albutt | 5:51fd6635141f | 1 | #include "Enemy.h" |
| Albutt | 5:51fd6635141f | 2 | #include <Bitmap.h> |
| Albutt | 6:546eba371942 | 3 | Serial pce(USBTX, USBRX); |
| Albutt | 5:51fd6635141f | 4 | // nothing doing in the constructor and destructor |
| Albutt | 6:546eba371942 | 5 | Enemy::Enemy(int seed) |
| Albutt | 5:51fd6635141f | 6 | { |
| Albutt | 5:51fd6635141f | 7 | |
| Albutt | 6:546eba371942 | 8 | srand(seed); |
| Albutt | 6:546eba371942 | 9 | four = (rand()%4)+1; |
| Albutt | 8:0c6d6ed55851 | 10 | //pce.printf("%d",four); |
| Albutt | 6:546eba371942 | 11 | if(four == 1){ |
| Albutt | 6:546eba371942 | 12 | _x = 0; |
| Albutt | 6:546eba371942 | 13 | _y = rand()%48; |
| Albutt | 6:546eba371942 | 14 | } |
| Albutt | 6:546eba371942 | 15 | else if(four == 2){ |
| Albutt | 6:546eba371942 | 16 | _x = 84; |
| Albutt | 6:546eba371942 | 17 | _y = rand()%48; |
| Albutt | 6:546eba371942 | 18 | } |
| Albutt | 6:546eba371942 | 19 | else if(four == 3){ |
| Albutt | 6:546eba371942 | 20 | _y = 0; |
| Albutt | 6:546eba371942 | 21 | _x = rand()%84; |
| Albutt | 6:546eba371942 | 22 | } |
| Albutt | 6:546eba371942 | 23 | else if(four == 4){ |
| Albutt | 6:546eba371942 | 24 | _y = 48; |
| Albutt | 6:546eba371942 | 25 | _x = rand()%84; |
| Albutt | 6:546eba371942 | 26 | } |
| Albutt | 5:51fd6635141f | 27 | } |
| Albutt | 5:51fd6635141f | 28 | |
| Albutt | 5:51fd6635141f | 29 | Enemy::~Enemy() |
| Albutt | 5:51fd6635141f | 30 | { |
| Albutt | 5:51fd6635141f | 31 | |
| Albutt | 5:51fd6635141f | 32 | } |
| Albutt | 5:51fd6635141f | 33 | |
| Albutt | 5:51fd6635141f | 34 | void Enemy::init() |
| Albutt | 5:51fd6635141f | 35 | { |
| Albutt | 5:51fd6635141f | 36 | } |
| Albutt | 5:51fd6635141f | 37 | |
| Albutt | 5:51fd6635141f | 38 | void Enemy::draw(N5110 &lcd) |
| Albutt | 5:51fd6635141f | 39 | { |
| Albutt | 5:51fd6635141f | 40 | lcd.drawRect(_x,_y,3,3,FILL_TRANSPARENT); |
| Albutt | 5:51fd6635141f | 41 | } |
| Albutt | 5:51fd6635141f | 42 | |
| Albutt | 5:51fd6635141f | 43 | void Enemy::update(int player_x, int player_y) |
| Albutt | 5:51fd6635141f | 44 | { |
| Albutt | 5:51fd6635141f | 45 | if(_x<player_x){ |
| Albutt | 5:51fd6635141f | 46 | _x++; |
| Albutt | 5:51fd6635141f | 47 | } |
| Albutt | 5:51fd6635141f | 48 | else if(_x > player_x){ |
| Albutt | 5:51fd6635141f | 49 | _x--; |
| Albutt | 5:51fd6635141f | 50 | } |
| Albutt | 5:51fd6635141f | 51 | |
| Albutt | 5:51fd6635141f | 52 | if(_y < player_y){ |
| Albutt | 5:51fd6635141f | 53 | _y++; |
| Albutt | 5:51fd6635141f | 54 | } |
| Albutt | 5:51fd6635141f | 55 | else if (_y > player_y){ |
| Albutt | 5:51fd6635141f | 56 | _y--; |
| Albutt | 8:0c6d6ed55851 | 57 | } |
| Albutt | 5:51fd6635141f | 58 | } |
| Albutt | 5:51fd6635141f | 59 | int Enemy::get_x() |
| Albutt | 5:51fd6635141f | 60 | { |
| Albutt | 5:51fd6635141f | 61 | return _x; |
| Albutt | 5:51fd6635141f | 62 | |
| Albutt | 5:51fd6635141f | 63 | } |
| Albutt | 5:51fd6635141f | 64 | int Enemy::get_y() |
| Albutt | 5:51fd6635141f | 65 | { |
| Albutt | 5:51fd6635141f | 66 | return _y; |
| Albutt | 5:51fd6635141f | 67 | |
| Albutt | 5:51fd6635141f | 68 | } |
| Albutt | 8:0c6d6ed55851 | 69 | void Enemy::dead(){ |
| Albutt | 8:0c6d6ed55851 | 70 | _x = 2147483647; |
| Albutt | 8:0c6d6ed55851 | 71 | } |
| Albutt | 8:0c6d6ed55851 | 72 | void Enemy::reset(int seed){ |
| Albutt | 8:0c6d6ed55851 | 73 | srand(seed); |
| Albutt | 8:0c6d6ed55851 | 74 | four = (rand()%4)+1; |
| Albutt | 8:0c6d6ed55851 | 75 | //pce.printf("%d",four); |
| Albutt | 8:0c6d6ed55851 | 76 | if(four == 1){ |
| Albutt | 8:0c6d6ed55851 | 77 | _x = 0; |
| Albutt | 8:0c6d6ed55851 | 78 | _y = rand()%48; |
| Albutt | 8:0c6d6ed55851 | 79 | } |
| Albutt | 8:0c6d6ed55851 | 80 | else if(four == 2){ |
| Albutt | 8:0c6d6ed55851 | 81 | _x = 84; |
| Albutt | 8:0c6d6ed55851 | 82 | _y = rand()%48; |
| Albutt | 8:0c6d6ed55851 | 83 | } |
| Albutt | 8:0c6d6ed55851 | 84 | else if(four == 3){ |
| Albutt | 8:0c6d6ed55851 | 85 | _y = 0; |
| Albutt | 8:0c6d6ed55851 | 86 | _x = rand()%84; |
| Albutt | 8:0c6d6ed55851 | 87 | } |
| Albutt | 8:0c6d6ed55851 | 88 | else if(four == 4){ |
| Albutt | 8:0c6d6ed55851 | 89 | _y = 48; |
| Albutt | 8:0c6d6ed55851 | 90 | _x = rand()%84; |
| Albutt | 8:0c6d6ed55851 | 91 | } |
| Albutt | 8:0c6d6ed55851 | 92 | } |