This is the description
Dependencies: mbed Menu Joystick
Enemy/Enemy.cpp@0:59cbc5800eb6, 2020-04-27 (annotated)
- Committer:
- mrkang
- Date:
- Mon Apr 27 14:04:30 2020 +0000
- Revision:
- 0:59cbc5800eb6
Starwars
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mrkang | 0:59cbc5800eb6 | 1 | #include "Enemy.h" |
mrkang | 0:59cbc5800eb6 | 2 | Enemy::Enemy(int mode) |
mrkang | 0:59cbc5800eb6 | 3 | { |
mrkang | 0:59cbc5800eb6 | 4 | if ( mode == 0) |
mrkang | 0:59cbc5800eb6 | 5 | _blood = 1; |
mrkang | 0:59cbc5800eb6 | 6 | else if(mode == 1) |
mrkang | 0:59cbc5800eb6 | 7 | _blood = 2; |
mrkang | 0:59cbc5800eb6 | 8 | else if(mode == 2) |
mrkang | 0:59cbc5800eb6 | 9 | _blood = 3; |
mrkang | 0:59cbc5800eb6 | 10 | } |
mrkang | 0:59cbc5800eb6 | 11 | Enemy::~Enemy() |
mrkang | 0:59cbc5800eb6 | 12 | { |
mrkang | 0:59cbc5800eb6 | 13 | |
mrkang | 0:59cbc5800eb6 | 14 | } |
mrkang | 0:59cbc5800eb6 | 15 | void Enemy::init(int sizeX,int sizeY) |
mrkang | 0:59cbc5800eb6 | 16 | { |
mrkang | 0:59cbc5800eb6 | 17 | _sizeX = sizeX; |
mrkang | 0:59cbc5800eb6 | 18 | _sizeY = sizeY; |
mrkang | 0:59cbc5800eb6 | 19 | _x = rand()%(84-_sizeX); |
mrkang | 0:59cbc5800eb6 | 20 | _y = 0; |
mrkang | 0:59cbc5800eb6 | 21 | _speed = 1; |
mrkang | 0:59cbc5800eb6 | 22 | } |
mrkang | 0:59cbc5800eb6 | 23 | Vector2D Enemy::getPos() |
mrkang | 0:59cbc5800eb6 | 24 | { |
mrkang | 0:59cbc5800eb6 | 25 | Vector2D p = {_x,_y}; |
mrkang | 0:59cbc5800eb6 | 26 | return p; |
mrkang | 0:59cbc5800eb6 | 27 | } |
mrkang | 0:59cbc5800eb6 | 28 | void Enemy::update() |
mrkang | 0:59cbc5800eb6 | 29 | { |
mrkang | 0:59cbc5800eb6 | 30 | _y+=_speed; |
mrkang | 0:59cbc5800eb6 | 31 | } |
mrkang | 0:59cbc5800eb6 | 32 | void Enemy::setBlood(int harm){ |
mrkang | 0:59cbc5800eb6 | 33 | _blood-=harm; |
mrkang | 0:59cbc5800eb6 | 34 | } |
mrkang | 0:59cbc5800eb6 | 35 | void Enemy::draw(N5110 &lcd,int mode) |
mrkang | 0:59cbc5800eb6 | 36 | { |
mrkang | 0:59cbc5800eb6 | 37 | int enemy[60] = { |
mrkang | 0:59cbc5800eb6 | 38 | 1,1,1,1,1,1,1,1,1,1,1,1, |
mrkang | 0:59cbc5800eb6 | 39 | 1,1,1,1,1,1,1,1,1,1,1,1, |
mrkang | 0:59cbc5800eb6 | 40 | 1,1,1,1,1,1,1,1,1,1,1,1, |
mrkang | 0:59cbc5800eb6 | 41 | 1,1,1,1,1,1,1,1,1,1,1,1, |
mrkang | 0:59cbc5800eb6 | 42 | 1,1,1,1,1,1,1,1,1,1,1,1 }; |
mrkang | 0:59cbc5800eb6 | 43 | int enemyNormal[60] = { |
mrkang | 0:59cbc5800eb6 | 44 | 1,1,1,1,1,1,1,1,1,1,1,1, |
mrkang | 0:59cbc5800eb6 | 45 | 1,1,1,1,1,1,1,1,1,1,1,1, |
mrkang | 0:59cbc5800eb6 | 46 | 1,1,1,1,1,1,1,1,1,1,1,1, |
mrkang | 0:59cbc5800eb6 | 47 | 1,1,1,1,1,1,1,1,1,1,1,1, |
mrkang | 0:59cbc5800eb6 | 48 | 1,1,1,1,1,1,1,1,1,1,1,1 }; |
mrkang | 0:59cbc5800eb6 | 49 | int enemyHard[60] = { |
mrkang | 0:59cbc5800eb6 | 50 | 1,1,1,1,1,1,1,1,1,1,1,1, |
mrkang | 0:59cbc5800eb6 | 51 | 1,1,1,1,1,1,1,1,1,1,1,1, |
mrkang | 0:59cbc5800eb6 | 52 | 1,1,1,1,1,1,1,1,1,1,1,1, |
mrkang | 0:59cbc5800eb6 | 53 | 1,1,1,1,1,1,1,1,1,1,1,1, |
mrkang | 0:59cbc5800eb6 | 54 | 1,1,1,1,1,1,1,1,1,1,1,1 }; |
mrkang | 0:59cbc5800eb6 | 55 | if(mode == 0){ |
mrkang | 0:59cbc5800eb6 | 56 | Bitmap sprite(enemy,_sizeY,_sizeX); |
mrkang | 0:59cbc5800eb6 | 57 | sprite.render(lcd,_x,_y); |
mrkang | 0:59cbc5800eb6 | 58 | }else if(mode == 1){ |
mrkang | 0:59cbc5800eb6 | 59 | Bitmap sprite(enemyNormal,_sizeY,_sizeX); |
mrkang | 0:59cbc5800eb6 | 60 | sprite.render(lcd,_x,_y); |
mrkang | 0:59cbc5800eb6 | 61 | }else if(mode == 2){ |
mrkang | 0:59cbc5800eb6 | 62 | Bitmap sprite(enemyHard,_sizeY,_sizeX); |
mrkang | 0:59cbc5800eb6 | 63 | sprite.render(lcd,_x,_y); |
mrkang | 0:59cbc5800eb6 | 64 | } |
mrkang | 0:59cbc5800eb6 | 65 | } |
mrkang | 0:59cbc5800eb6 | 66 | int Enemy::getBlood(){ |
mrkang | 0:59cbc5800eb6 | 67 | return _blood; |
mrkang | 0:59cbc5800eb6 | 68 | } |
mrkang | 0:59cbc5800eb6 | 69 | void Enemy::setSpeed(int speed){ |
mrkang | 0:59cbc5800eb6 | 70 | _speed = speed; |
mrkang | 0:59cbc5800eb6 | 71 | } |
mrkang | 0:59cbc5800eb6 | 72 | int Enemy::getSpeed(){ |
mrkang | 0:59cbc5800eb6 | 73 | return _speed; |
mrkang | 0:59cbc5800eb6 | 74 | } |