![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
test 1 doc
Diff: Ennemy/Enemy.cpp
- Revision:
- 10:9317a62bd4d0
- Parent:
- 9:9830d3a78572
- Child:
- 11:b3024ab59fa5
diff -r 9830d3a78572 -r 9317a62bd4d0 Ennemy/Enemy.cpp --- a/Ennemy/Enemy.cpp Wed May 27 00:49:39 2020 +0000 +++ b/Ennemy/Enemy.cpp Wed May 27 02:00:08 2020 +0000 @@ -1,76 +1,123 @@ #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) +#include "EnemySprites.h" +//constructor +Enemy::Enemy(bool type, int spawnX, int spawnY) { _enY = spawnY; _enX = spawnX; + if( spawnX > WIDTH/2) { - eDir = 1; //right + xDir = 1; //right } else { - eDir = 0; //left + xDir = 0; //left } + + if ( spawnY > HEIGHT/2) { + yDir = 1; //up + } else { + yDir = 0; //down + } + _type = type; + } + +//deconstructor Enemy::~Enemy() {} - -void Enemy::update(int eYpos, bool efall) +//update +void Enemy::update(int _evx, int _evy) { - // 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; + if( _type == 0 ) { + // go left or right depending on direction + switch (xDir) { + case 1: + _enX -= _evx; + //switch direction when it hits a wall + if(_enX + 7 > WIDTH || _enX < 0) { + xDir = 0; + break; + } break; - } - break; - case 0: - _enX +=2; - //switch direction when it hits a wall - if(_enX + 8 > WIDTH || _enX < 0) { - eDir = 1; + case 0: + _enX += _evx; + //switch direction when it hits a wall + if(_enX + 7 > WIDTH || _enX < 0) { + xDir = 1; + break; + } break; - } - break; + } } - - //fall down - switch (efall) { - case 1: - _enY +=3; - break; - case 2: - _enY = eYpos; - break; + if( _type == 1 ) { +// go up or down depending on direction + switch (yDir) { + case 1: + _enY -= _evy; + //switch direction when it hits a wall + if(_enY + 5 > HEIGHT || _enY < 0) { + yDir = 0; + break; + } + break; + case 0: + _enY += _evy; + //switch direction when it hits a wall + if(_enY + 5 > HEIGHT || _enY < 0) { + yDir = 1; + break; + } + break; + } } - - } - +//draw void Enemy::draw(N5110 &lcd) { - Bitmap bit_en(s_enemy, 6, 7 ); - bit_en.render(lcd, _enX, _enY); + switch(_type) { + case 1: // vertical + drawVertical(lcd); + break; + case 0: // horizontal + drawHoriz(lcd); + break; + } } +// sub draw +void Enemy::drawVertical(N5110 &lcd) +{ + if (yDir == 0 ) { + Bitmap vertDown(s_enemy2_inv, 5, 7); + vertDown.render(lcd, _enX, _enY); + } else { + Bitmap vertUp(s_enemy2, 5, 7); + vertUp.render(lcd, _enX, _enY); + } +} + +// sub draw +void Enemy::drawHoriz(N5110 &lcd) +{ + if (xDir == 1) { + Bitmap horLeft(s_enemy1_inv, 5, 7); + horLeft.render(lcd, _enX, _enY); + } else { + Bitmap horRight(s_enemy1, 5, 7); + horRight.render(lcd, _enX, _enY); + + } + +} + +//mutator void Enemy::set_pos(int x, int y) { _enX = x; @@ -79,17 +126,7 @@ } -bool Enemy::fell() -{ - if( _enY + 6 > HEIGHT) { - _fell = true; - } else { - _fell = false; - } - return _fell; -} - - +//accessor Vector2D Enemy::get_pos() { Vector2D pos = {_enX, _enY};