Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F132238
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
6 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/ZombieEntity.cpp b/src/ZombieEntity.cpp
index 764ed42..d6e83c1 100644
--- a/src/ZombieEntity.cpp
+++ b/src/ZombieEntity.cpp
@@ -1,248 +1,253 @@
#include "ZombieEntity.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"
ZombieEntity::ZombieEntity(float x, float y, bool invocated)
: EnemyEntity (ImageManager::getInstance().getImage(IMAGE_ZOMBIE), x, y)
{
imagesProLine = 11;
this->invocated = invocated;
frame = 1;
dyingFrame = 10;
bloodColor = BloodRed;
shadowFrame = 9;
deathFrame = FRAME_CORPSE_ZOMBIE;
if (invocated) enemyType = EnemyTypeZombie_invocated;
else enemyType = EnemyTypeZombie;
hp = ZOMBIE_HP;
creatureSpeed = ZOMBIE_SPEED;
direction = rand() % 4;
clockTurn = rand() % 2 == 0;
compute(false);
timer = 5 + rand() % 6;
- attackTimer = 2.0f;
+ attackTimer = 0.9f;
meleeDamages = ZOMBIE_DAMAGE;
agonizingSound = SOUND_ZOMBIE_DYING;
height = 80;
sprite.setOrigin(32.0f, 60.0f);
resistance[ResistanceFrozen] = ResistanceHigh;
resistance[ResistanceRecoil] = ResistanceHigh;
resistance[ResistancePoison] = ResistanceImmune;
}
void ZombieEntity::animate(float delay)
{
if (isAgonising)
{
if (hpDisplay > hp) hpDisplay--;
if (h < -0.01f)
{
isAgonising = false;
isDying = true;
game().addCorpse(x, y, deathFrame);
if (dyingSound != SOUND_NONE) SoundManager::getInstance().playSound(dyingSound);
}
else
{
frame = dyingFrame;
hVelocity -= 700.0f * delay;
h += hVelocity * delay;
}
return;
}
else if (age > 0.0f)
{
if (attackTimer <= 0.0f && attack())
{
attackTimer = 2.0f;
giveRecoil(false, Vector2D(velocity.x * 3.0f, velocity.y * 3.0f), 2.5f);
}
else
{
timer -= delay;
attackTimer -= delay;
if (timer < 0.0f)
{
SoundManager::getInstance().playSound(SOUND_ZOMBIE_00 + rand() % 2);
timer = 5 + rand() % 6;
if (rand() % 3 == 0) clockTurn = !clockTurn;
compute(true);
}
}
frame = ((int)(age * 4.0f)) % 4;
if (frame == 3) frame = 1;
if (facingDirection == 4 || facingDirection == 6) frame += 3;
isMirroring = (facingDirection == 4 );
if (facingDirection == 8) frame += 6;
}
EnemyEntity::animate(delay);
z = y + 17;
}
bool ZombieEntity::attack()
{
Vector2D playerPos = game().getPlayerPosition();
bool attacking = false;
// left ?
if (playerPos.x < x && playerPos.y > y - 15 && playerPos.y < y + 15 && canSee(playerPos.x, playerPos.y))
{
direction = 3;
velocity.x = -creatureSpeed;
velocity.y = 0;
facingDirection = 4;
attacking = true;
}
// right ?
else if (playerPos.x > x && playerPos.y > y - 15 && playerPos.y < y + 15 && canSee(playerPos.x, playerPos.y))
{
direction = 1;
velocity.x = creatureSpeed;
velocity.y = 0;
facingDirection = 6;
attacking = true;
}
// down ?
else if (playerPos.y > y && playerPos.x > x - 15 && playerPos.x < x + 15 && canSee(playerPos.x, playerPos.y))
{
direction = 2;
velocity.x = 0;
velocity.y = creatureSpeed;
facingDirection = 2;
attacking = true;
}
// up ?
else if (playerPos.y < y && playerPos.x > x - 15 && playerPos.x < x + 15 && canSee(playerPos.x, playerPos.y))
{
direction = 0;
velocity.x = 0;
velocity.y = -creatureSpeed;
facingDirection = 8;
attacking = true;
}
if (attacking) SoundManager::getInstance().playSound(SOUND_ZOMBIE_ATTACKING);
return attacking;
}
void ZombieEntity::compute(bool turn)
{
if (turn)
{
if (clockTurn)
{
direction++;
if (direction == 4) direction = 0;
}
else
{
direction--;
if (direction < 0) direction = 3;
}
}
switch (direction)
{
case 0:
velocity.x = 0;
velocity.y = -creatureSpeed;
facingDirection = 8;
break;
case 1:
velocity.x = creatureSpeed;
velocity.y = 0;
facingDirection = 6;
break;
case 2:
velocity.x = 0;
velocity.y = creatureSpeed;
facingDirection = 2;
break;
case 3:
velocity.x = -creatureSpeed;
velocity.y = 0;
facingDirection = 4;
break;
}
}
void ZombieEntity::calculateBB()
{
boundingBox.left = (int)x - 14;
boundingBox.width = 28;
boundingBox.top = (int)y - 18;
boundingBox.height = 36;
}
void ZombieEntity::collideMapRight()
{
if (recoil.active)
{
if (recoil.stun) recoil.velocity.x = -recoil.velocity.x * 0.3f;
else (recoil.active = false);
}
else compute(true);
}
void ZombieEntity::collideMapLeft()
{
if (recoil.active)
{
if (recoil.stun) recoil.velocity.x = -recoil.velocity.x * 0.3f;
else (recoil.active = false);
}
else compute(true);
}
void ZombieEntity::collideMapTop()
{
if (recoil.active)
{
if (recoil.stun) recoil.velocity.y = -recoil.velocity.y * 0.3f;
else (recoil.active = false);
}
else compute(true);
}
void ZombieEntity::collideMapBottom()
{
if (recoil.active)
{
if (recoil.stun) recoil.velocity.y = -recoil.velocity.y * 0.3f;
else (recoil.active = false);
}
else compute(true);
}
void ZombieEntity::collideWithEnemy(EnemyEntity* entity)
{
if (entity->getMovingStyle() == movWalking)
{
Vector2D recoilVector = Vector2D(entity->getX(), entity->getY()).vectorTo(Vector2D(x, y), 50.0f);
giveRecoil(false, recoilVector, 0.2f);
compute(true);
}
}
void ZombieEntity::drop()
{
if (!invocated) EnemyEntity::drop();
}
+
+bool ZombieEntity::isAttacking()
+{
+ return attackTimer > 1.0f;
+}
diff --git a/src/ZombieEntity.h b/src/ZombieEntity.h
index f07459f..50eb740 100644
--- a/src/ZombieEntity.h
+++ b/src/ZombieEntity.h
@@ -1,33 +1,34 @@
#ifndef ZOMBIEENTITY_H
#define ZOMBIEENTITY_H
#include "EnemyEntity.h"
class ZombieEntity : public EnemyEntity
{
public:
ZombieEntity(float x, float y, bool invocated);
virtual void animate(float delay);
virtual void calculateBB();
+ virtual bool isAttacking();
protected:
virtual void collideMapRight();
virtual void collideMapLeft();
virtual void collideMapTop();
virtual void collideMapBottom();
virtual void collideWithEnemy(EnemyEntity* entity) override;
virtual void drop();
private:
bool invocated;
int direction;
bool clockTurn;
float timer;
float attackTimer;
void compute(bool turn);
bool attack();
};
#endif // ZOMBIEENTITY_H
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Jun 16, 12:31 AM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
70540
Default Alt Text
(6 KB)
Attached To
Mode
R78 witchblast
Attached
Detach File
Event Timeline