Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enemy #1

Merged
merged 13 commits into from
Feb 10, 2019
Prev Previous commit
Next Next commit
HELP ME
  • Loading branch information
halfofning committed Feb 8, 2019
commit 1cc53124da9c6c4e4bbbcf3b6a98a2292c7ebc8b
57 changes: 20 additions & 37 deletions src/enemy.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SEnemy : public System
private:
Graphics * graphics;
int MIN_MAX_RAND(int min, int max) { return rand() % (max - min + 1) + min; }
int enemyMap[20][1]; // row, column
float timer = 0;

public:
CSprite enemySprite;
Expand All @@ -26,16 +26,12 @@ class SEnemy : public System
System::addComponentType(CEnemyInteractable::id);

this->graphics = _graphics;
setEnemies(1);
//setEnemies(1);
enemySprite.setPosition(MIN_MAX_RAND(0, GAME_WIDTH - 64), 0);
}

inline void setEnemies(int value)
{
for (int row = 0; row < 1; row++) {
for (int column = 0; column < 20; column++) {
enemyMap[row][column] = 1;
}
}
}

virtual void updateComponents(float delta, BaseComponent** components)
Expand All @@ -44,36 +40,23 @@ class SEnemy : public System
CCollidable* collider = (CCollidable*)components[1];
CEnemyInteractable* enemyInteractable = (CEnemyInteractable*)components[2];

for (int column = 0; column < 20; column++) {
for (int row = 0; row < 1; row++) {

enemySprite.setPosition((column * 64), (row * 64));

if (enemyMap[row][column] == 1) {

// Draw enemies
//enemySprite.setPosition(MIN_MAX_RAND(0, GAME_WIDTH - 64), 0);

graphics->spriteBegin();
enemySprite.spriteData.texture = enemySprite.textureManager->getTexture();
graphics->drawSprite(enemySprite.spriteData);
graphics->spriteEnd();


// Check collision
CCollidable enemyCollider;
enemyCollider.angle = enemySprite.getAngle();
enemyCollider.center = *enemySprite.getCenter();
enemyCollider.scale = enemySprite.getScale();

Vec2 collisionVector = Vec2(0, 0);
if (collider->collideBox(enemyCollider, collisionVector) == true) {
motion->collidedDelta =
collider->bounce(enemyCollider, collisionVector);
motion->colliding = true;
}
}
}
// Draw enemies
graphics->spriteBegin();
enemySprite.spriteData.texture = enemySprite.textureManager->getTexture();
graphics->drawSprite(enemySprite.spriteData);
graphics->spriteEnd();

// Check collision
CCollidable enemyCollider;
enemyCollider.angle = enemySprite.getAngle();
enemyCollider.center = *enemySprite.getCenter();
enemyCollider.scale = enemySprite.getScale();

Vec2 collisionVector = Vec2(0, 0);
if (collider->collideBox(enemyCollider, collisionVector) == true) {
motion->collidedDelta =
collider->bounce(enemyCollider, collisionVector);
motion->colliding = true;
}
}
};