![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
test 1 doc
Diff: Ennemy/Enemy.cpp
- Revision:
- 8:d19b30a6cd69
- Child:
- 9:9830d3a78572
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Ennemy/Enemy.cpp Tue May 26 22:15:42 2020 +0000 @@ -0,0 +1,90 @@ +#include "Enemy.h" +int s_enemy[] = { + + 1,1,1,1,1,1,1, + 1,1,1,0,1,0,1, + 1,1,1,0,1,0,1, + 1,1,1,1,1,1,1, + 1,1,1,1,1,1,1, + 0,1,1,0,1,1,0, + +}; +Enemy::Enemy(int spawnX, int spawnY) +{ + _enY = spawnY; + _enX = spawnX; + if( spawnX > WIDTH/2) { + eDir = 1; //right + } else { + eDir = 0; //left + } +} +Enemy::~Enemy() {} + + + +void Enemy::update(int eYpos, bool efall) +{ + + // go left or right depending on direction + switch (eDir) { + case 1: + _enX -= 2; + //switch direction when it hits a wall + if(_enX + 8 > WIDTH || _enX < 0) { + eDir = 0; + break; + } + break; + case 0: + _enX +=2; + //switch direction when it hits a wall + if(_enX + 8 > WIDTH || _enX < 0) { + eDir = 1; + break; + } + break; + } + + + //fall down + switch (efall) { + case 1: + _enY +=3; + break; + case 2: + _enY = eYpos; + break; + } + + +} + + + + +void Enemy::draw(N5110 &lcd) +{ + Bitmap bit_en(s_enemy, 6, 7 ); + bit_en.render(lcd, _enX, _enY); +} + + + + +bool Enemy::fell() +{ + if( _enY + 6 > HEIGHT) { + _fell = true; + } else { + _fell = false; + } + return _fell; +} + + +Vector2D Enemy::get_pos() +{ + Vector2D pos = {_enX, _enY}; + return pos; +}