Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
diff --git a/src/BatEntity.cpp b/src/BatEntity.cpp
index daf29d9..350f058 100644
--- a/src/BatEntity.cpp
+++ b/src/BatEntity.cpp
@@ -1,81 +1,90 @@
#include "BatEntity.h"
#include "PlayerEntity.h"
#include "sfml_game/SpriteEntity.h"
#include "sfml_game/ImageManager.h"
#include "sfml_game/SoundManager.h"
#include "Constants.h"
#include "WitchBlastGame.h"
BatEntity::BatEntity(float x, float y)
: EnnemyEntity (ImageManager::getImageManager()->getImage(IMAGE_BAT), x, y)
{
creatureSpeed = BAT_SPEED;
velocity = Vector2D(creatureSpeed);
hp = BAT_HP;
meleeDamages = BAT_DAMAGES;
type = ENTITY_ENNEMY;
bloodColor = bloodRed;
changingDelay = -0.5f;
shadowFrame = 3;
movingStyle = movFlying;
}
void BatEntity::animate(float delay)
{
changingDelay -= delay;
if (changingDelay < 0.0f)
{
velocity = Vector2D(creatureSpeed);
changingDelay = 0.5f + (float)(rand() % 2500) / 1000.0f;
}
if (age < 0.0f)
frame = 1;
else
frame = ((int)(age * 5.0f)) % 2;
testSpriteCollisions();
EnnemyEntity::animate(delay);
}
void BatEntity::calculateBB()
{
boundingBox.left = (int)x - width / 2 + BAT_BB_LEFT;
boundingBox.width = width - BAT_BB_WIDTH_DIFF;
boundingBox.top = (int)y - height / 2 + BAT_BB_TOP;
boundingBox.height = height - BAT_BB_HEIGHT_DIFF;
}
void BatEntity::collideMapRight()
{
velocity.x = -velocity.x;
}
void BatEntity::collideMapLeft()
{
velocity.x = -velocity.x;
}
void BatEntity::collideMapTop()
{
velocity.y = -velocity.y;
}
void BatEntity::collideMapBottom()
{
velocity.y = -velocity.y;
}
+void BatEntity::collideWithEnnemy(GameEntity* collidingEntity)
+{
+ EnnemyEntity* entity = static_cast<EnnemyEntity*>(collidingEntity);
+ if (entity->getMovingStyle() == movFlying)
+ {
+ setVelocity(Vector2D(entity->getX(), entity->getY()).vectorTo(Vector2D(x, y), BAT_SPEED ));
+ }
+}
+
void BatEntity::dying()
{
isDying = true;
SpriteEntity* deadBat = new SpriteEntity(ImageManager::getImageManager()->getImage(IMAGE_CORPSES), x, y, 64, 64);
deadBat->setZ(OFFSET_Y);
deadBat->setFrame(FRAME_CORPSE_BAT);
deadBat->setType(ENTITY_CORPSE);
for (int i = 0; i < 4; i++) game().generateBlood(x, y, bloodColor);
drop();
SoundManager::getSoundManager()->playSound(SOUND_ENNEMY_DYING);
}
diff --git a/src/BatEntity.h b/src/BatEntity.h
index 6bf571b..be9af80 100644
--- a/src/BatEntity.h
+++ b/src/BatEntity.h
@@ -1,24 +1,26 @@
#ifndef BATSPRITE_H
#define BATSPRITE_H
#include "EnnemyEntity.h"
class BatEntity : public EnnemyEntity
{
public:
BatEntity(float x, float y);
virtual void animate(float delay);
virtual void calculateBB();
protected:
virtual void collideMapRight();
virtual void collideMapLeft();
virtual void collideMapTop();
virtual void collideMapBottom();
+ virtual void collideWithEnnemy(GameEntity* collidingEntity);
+
virtual void dying();
private:
float changingDelay;
};
#endif // BATSPRITE_H

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jun 11, 11:19 AM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68708
Default Alt Text
(2 KB)

Event Timeline