Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F131238
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/GhostEntity.cpp b/src/GhostEntity.cpp
index 5878025..10cdd16 100644
--- a/src/GhostEntity.cpp
+++ b/src/GhostEntity.cpp
@@ -1,153 +1,160 @@
#include "GhostEntity.h"
#include "BoltEntity.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"
GhostEntity::GhostEntity(float x, float y)
: EnemyEntity (ImageManager::getInstance().getImage(IMAGE_GHOST), x, y)
{
frame = 0;
- dyingFrame = 3;
+ dyingFrame = 4;
deathFrame = FRAME_CORPSE_GHOST;
enemyType = EnemyTypeGhost;
hp = GHOST_HP;
creatureSpeed = GHOST_SPEED;
meleeDamages = GHOST_DAMAGE;
movingStyle = movFlying;
velocity = Vector2D(creatureSpeed);
timer = 0.0f;
+ age -= 1.2f;
bloodColor = BloodNone;
agonizingSound = SOUND_GHOST_DYING;
resistance[ResistanceFrozen] = ResistanceHigh;
resistance[ResistanceRecoil] = ResistanceHigh;
resistance[ResistancePoison] = ResistanceImmune;
}
void GhostEntity::animate(float delay)
{
if (age > 0.0f && !isAgonising)
{
timer = timer - delay;
if (timer <= 0.0f)
{
timer = 0.25f;
setVelocity(Vector2D(x, y).vectorTo(game().getPlayerPosition(), creatureSpeed ));
- computeFacingDirection();
}
frame = ((int)(age * 3.0f)) % 4;
if (frame == 3) frame = 1;
}
isMirroring = x > game().getPlayerPosition().x;
EnemyEntity::animate(delay);
z = y + 32;
}
void GhostEntity::calculateBB()
{
boundingBox.left = (int)x - 15;
boundingBox.width = 30;
boundingBox.top = (int)y - 15;
boundingBox.height = 30;
}
-int GhostEntity::getFade()
+int GhostEntity::getGhostFade()
{
float dist1 = 24000.f;
float dist2 = 40000.f;
float dist = Vector2D(x, y).distance2(game().getPlayerPosition());
- if (dist < dist1) return 100;
- else if (dist > dist2) return 0;
+ int fade;
+ if (dist < dist1) fade = 100;
+ else if (dist > dist2) fade = 0;
+ else
+ {
+ fade =((dist2 - dist) / (dist2 - dist1)) * 100;
+ if (fade < 0) fade = 0;
+ if (fade > 100) fade = 100;
+ }
+
+ if (age <= 0.0f)
+ {
+ int ageFade = 40;
+ if (age > -0.5f) ageFade = 0 - 80.0f * age;
+ return (fade > ageFade ? fade : ageFade);
+ }
- int fade =((dist2 - dist) / (dist2 - dist1)) * 100;
- if (fade < 0) fade = 0;
- if (fade > 100) fade = 100;
return fade;
}
void GhostEntity::render(sf::RenderTarget* app)
{
- int fade = getFade();
+ int fade = getGhostFade();
if (fade == 100) SoundManager::getInstance().playSound(SOUND_GHOST);
if (fade == 100 || isAgonising)
{
sf::Color color = sprite.getColor();
color.a = 255;
sprite.setColor(color);
EnemyEntity::render(app);
}
else if (fade > 0)
{
sf::Color color = sprite.getColor();
color.a = fade * 255 / 100;
sprite.setColor(color);
EnemyEntity::render(app);
}
}
void GhostEntity::collideMapRight()
{
velocity.x = -velocity.x;
if (recoil.active) recoil.velocity.x = -recoil.velocity.x;
- else computeFacingDirection();
}
void GhostEntity::collideMapLeft()
{
velocity.x = -velocity.x;
if (recoil.active) recoil.velocity.x = -recoil.velocity.x;
- else computeFacingDirection();
}
void GhostEntity::collideMapTop()
{
velocity.y = -velocity.y;
if (recoil.active) recoil.velocity.y = -recoil.velocity.y;
- else computeFacingDirection();
}
void GhostEntity::collideMapBottom()
{
velocity.y = -velocity.y;
if (recoil.active) recoil.velocity.y = -recoil.velocity.y;
- else computeFacingDirection();
}
void GhostEntity::collideWithEnemy(EnemyEntity* entity)
{
if (recoil.active && recoil.stun) return;
if (entity->getEnemyType() == EnemyTypeGhost)
{
Vector2D vel = Vector2D(entity->getX(), entity->getY()).vectorTo(Vector2D(x, y), 1.5f );
giveRecoil(false, vel, 0.3f);
}
}
void GhostEntity::collideWithBolt(BoltEntity* boltEntity)
{
- int fade = getFade();
+ int fade = getGhostFade();
if (fade <= 0) return;
if (boltEntity->getBoltType() == ShotTypeIllusion) fade = 100;
boltEntity->setDamages(boltEntity->getDamages() * fade / 100);
EnemyEntity::collideWithBolt(boltEntity);
}
void GhostEntity::drop()
{
EnemyEntity::drop();
}
diff --git a/src/GhostEntity.h b/src/GhostEntity.h
index b3cf624..3f7f597 100644
--- a/src/GhostEntity.h
+++ b/src/GhostEntity.h
@@ -1,29 +1,29 @@
#ifndef GHOSTENTITY_H
#define GHOSTENTITY_H
#include "EnemyEntity.h"
class GhostEntity : public EnemyEntity
{
public:
GhostEntity(float x, float y);
virtual void animate(float delay);
virtual void render(sf::RenderTarget* app);
virtual void calculateBB();
protected:
virtual void collideMapRight();
virtual void collideMapLeft();
virtual void collideMapTop();
virtual void collideMapBottom();
virtual void collideWithEnemy(EnemyEntity* entity) override;
virtual void collideWithBolt(BoltEntity* boltEntity);
virtual void drop();
private:
float timer;
- int getFade();
+ int getGhostFade();
};
#endif // GHOSTENTITY_H
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Jun 16, 12:09 AM (2 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
70270
Default Alt Text
(5 KB)
Attached To
Mode
R78 witchblast
Attached
Detach File
Event Timeline