Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F108441
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/SausageEntity.cpp b/src/SausageEntity.cpp
index 2683c06..4b1258e 100644
--- a/src/SausageEntity.cpp
+++ b/src/SausageEntity.cpp
@@ -1,183 +1,190 @@
#include "SausageEntity.h"
#include "ExplosionEntity.h"
#include "sfml_game/SpriteEntity.h"
#include "sfml_game/ImageManager.h"
#include "sfml_game/SoundManager.h"
#include "Constants.h"
#include "WitchBlastGame.h"
SausageEntity::SausageEntity(float x, float y, bool invocated)
: EnemyEntity (ImageManager::getInstance().getImage(IMAGE_SAUSAGE), x, y)
{
creatureSpeed = 0.0f;
hp = 18;
meleeDamages = 5;
this->invocated = invocated;
if (invocated) type = ENTITY_ENEMY_INVOCATED;
age = 0.0f;
enemyType = invocated ? EnemyTypeSausage_invocated : EnemyTypeSausage;
frame = 1;
shadowFrame = 3;
deathFrame = FRAME_CORPSE_SLIME_VIOLET;
agonizingSound = SOUND_NONE;
width = 48;
height = 48;
sprite.setOrigin(24, 24);
h = 0;
state = 0;
timer = 0.5f + 0.1f *( rand() % 12);
canExplode = false;
+ isNew = true;
}
void SausageEntity::render(sf::RenderTarget* app)
{
if (!isDying && shadowFrame > -1)
{
// shadow
sprite.setPosition(x, y);
sprite.setTextureRect(sf::IntRect(shadowFrame * width, 0, width, height));
app->draw(sprite);
}
sprite.setPosition(x, y - h);
sprite.setTextureRect(sf::IntRect(frame * width, 0, width, height));
app->draw(sprite);
if (game().getShowLogical())
{
displayBoundingBox(app);
displayCenterAndZ(app);
}
}
void SausageEntity::animate(float delay)
{
+ isNew = false;
float sausDelay = delay;
if (specialState[SpecialStateIce].active) sausDelay = delay * specialState[SpecialStateIce].param1;
timer -= sausDelay;
if (timer <= 0.0f)
{
if (state == 0) // waiting
{
state++;
hVelocity = 450.0f;
}
else if (state == 2) // waiting in air
{
state++;
}
}
if (state == 1 || state == 3) // jumping / falling
{
hVelocity -= 750.0f * sausDelay;
if (state == 1 && /*hVelocity <= 0.0f*/ h > 35)
{
state = 2;
timer = 0.4f;
hVelocity = -100.0f;
}
else
h += hVelocity * sausDelay;
if (h <= 0.0f)
{
h = 0.0f;
state = 0;
timer = 1.0f;
}
}
if (h > 1.0f)
{
frame = ((int)(age * 20)) % 4;
if (frame == 3) frame = 1;
}
else
frame = 1;
EnemyEntity::animate(delay);
// frame
z = y + 14;
}
+bool SausageEntity::canCollide()
+{
+ return (!isNew);
+}
+
void SausageEntity::calculateBB()
{
boundingBox.left = (int)x - 16;
boundingBox.width = 32;
boundingBox.top = (int)y - 14;
boundingBox.height = 28;
}
void SausageEntity::collideMapRight()
{
velocity.x = -velocity.x * 0.8f;
}
void SausageEntity::collideMapLeft()
{
velocity.x = -velocity.x * 0.8f;
}
void SausageEntity::collideMapTop()
{
velocity.y = -velocity.y * 0.8f;
}
void SausageEntity::collideMapBottom()
{
velocity.y = -velocity.y * 0.8f;
}
void SausageEntity::readCollidingEntity(CollidingSpriteEntity* entity)
{
if (!isDying && !isAgonising && collideWithEntity(entity))
{
if (entity->getType() == ENTITY_PLAYER || entity->getType() == ENTITY_BOLT )
{
PlayerEntity* playerEntity = dynamic_cast<PlayerEntity*>(entity);
BoltEntity* boltEntity = dynamic_cast<BoltEntity*>(entity);
if (playerEntity != NULL && !playerEntity->isDead()) dying();
else if (boltEntity != NULL && !boltEntity->getDying() && boltEntity->getAge() > 0.05f) collideWithBolt(boltEntity);
}
else // collision with other enemy ?
{
if (entity->getType() >= ENTITY_ENEMY && entity->getType() <= ENTITY_ENEMY_MAX)
{
if (this != entity)
{
EnemyEntity* enemyEntity = static_cast<EnemyEntity*>(entity);
if (enemyEntity->canCollide()) collideWithEnemy(enemyEntity);
}
}
}
}
}
void SausageEntity::collideWithEnemy(EnemyEntity* entity)
{
if (recoil.active && recoil.stun) return;
Vector2D vel = Vector2D(entity->getX(), entity->getY()).vectorTo(Vector2D(x, y), 50.0f );
giveRecoil(false, vel, 0.3f);
}
void SausageEntity::dying()
{
EnemyEntity::dying();
new ExplosionEntity(x, y, ExplosionTypeStandard, 18, EnemyTypeNone, true);
SoundManager::getInstance().playSound(SOUND_BOOM_00);
}
void SausageEntity::drop()
{
if (!invocated) EnemyEntity::drop();
}
diff --git a/src/SausageEntity.h b/src/SausageEntity.h
index 627ab92..1e07ad8 100644
--- a/src/SausageEntity.h
+++ b/src/SausageEntity.h
@@ -1,32 +1,34 @@
#ifndef SAUSAGEENTITY_H
#define SAUSAGEENTITY_H
#include "EnemyEntity.h"
class SausageEntity : public EnemyEntity
{
public:
SausageEntity(float x, float y, bool invocated);
- virtual void animate(float delay);
- virtual void render(sf::RenderTarget* app);
- virtual void calculateBB();
+ virtual void animate(float delay) override;
+ virtual void render(sf::RenderTarget* app) override;
+ virtual void calculateBB() override;
+ virtual bool canCollide() override;
protected:
- virtual void collideMapRight();
- virtual void collideMapLeft();
- virtual void collideMapTop();
- virtual void collideMapBottom();
+ virtual void collideMapRight() override;
+ virtual void collideMapLeft() override;
+ virtual void collideMapTop() override;
+ virtual void collideMapBottom() override;
virtual void readCollidingEntity(CollidingSpriteEntity* entity) override;
virtual void collideWithEnemy(EnemyEntity* entity) override;
- virtual void dying();
- virtual void drop();
+ virtual void dying() override;
+ virtual void drop() override;
private:
bool invocated;
+ bool isNew;
float timer;
int state;
};
#endif // SAUSAGEENTITY_H
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Wed, Apr 1, 5:57 AM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
57345
Default Alt Text
(5 KB)
Attached To
Mode
R78 witchblast
Attached
Detach File
Event Timeline