Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F131740
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
15 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/ZombieDarkEntity.cpp b/src/ZombieDarkEntity.cpp
index 38e729a..5ebadf2 100644
--- a/src/ZombieDarkEntity.cpp
+++ b/src/ZombieDarkEntity.cpp
@@ -1,339 +1,345 @@
#include "ZombieDarkEntity.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"
ZombieDarkEntity::ZombieDarkEntity(float x, float y)
: EnemyEntity (ImageManager::getInstance().getImage(IMAGE_ZOMBIE), x, y),
currentTile(0, 0),
targetTile(0, 0)
{
imagesProLine = 11;
frame = 11;
dyingFrame = 21;
bloodColor = BloodRed;
shadowFrame = 9;
deathFrame = FRAME_CORPSE_ZOMBIE_DARK;
enemyType = EnemyTypeZombieDark;
hp = ZOMBIE_HP;
creatureSpeed = ZOMBIE_SPEED;
meleeDamages = ZOMBIE_DAMAGE;
agonizingSound = SOUND_ZOMBIE_DYING;
currentDirection = 2 + 2 * rand()%4;
+ facingDirection = currentDirection;
+ nextFacingDirection = currentDirection;
+
height = 80;
sprite.setOrigin(32.0f, 60.0f);
attackTimer = 0.9f;
resistance[ResistanceFrozen] = ResistanceHigh;
resistance[ResistanceRecoil] = ResistanceHigh;
resistance[ResistancePoison] = ResistanceImmune;
findNextGoal();
}
void ZombieDarkEntity::animate(float delay)
{
if (age > 0.0f && !isAgonising)
{
// goal reached ?
if (currentDirection == 6 && x > (targetTile.x * TILE_WIDTH + TILE_WIDTH / 2) ) findNextGoal();
else if (currentDirection == 4 && x < (targetTile.x * TILE_WIDTH + TILE_WIDTH / 2) ) findNextGoal();
else if (currentDirection == 2 && y > (targetTile.y * TILE_HEIGHT + TILE_HEIGHT / 2 - 5) ) findNextGoal();
else if (currentDirection == 8 && y < (targetTile.y * TILE_HEIGHT + TILE_HEIGHT / 2 - 5) ) findNextGoal();
+ checkNextFacing(delay);
+
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;
frame += 11;
attackTimer -= delay;
}
EnemyEntity::animate(delay);
z = y + 17;
}
void ZombieDarkEntity::calculateBB()
{
boundingBox.left = (int)x - 14;
boundingBox.width = 28;
boundingBox.top = (int)y - 18;
boundingBox.height = 36;
}
void ZombieDarkEntity::collideMapRight()
{
if (recoil.active)
{
if (recoil.stun) recoil.velocity.x = -recoil.velocity.x * 0.3f;
else (recoil.active = false);
}
findNextRandomGoal();
}
void ZombieDarkEntity::collideMapLeft()
{
if (recoil.active)
{
if (recoil.stun) recoil.velocity.x = -recoil.velocity.x * 0.3f;
else (recoil.active = false);
}
findNextRandomGoal();
}
void ZombieDarkEntity::collideMapTop()
{
if (recoil.active)
{
if (recoil.stun) recoil.velocity.y = -recoil.velocity.y * 0.3f;
else (recoil.active = false);
}
findNextRandomGoal();
}
void ZombieDarkEntity::collideMapBottom()
{
if (recoil.active)
{
if (recoil.stun) recoil.velocity.y = -recoil.velocity.y * 0.3f;
else (recoil.active = false);
}
findNextRandomGoal();
}
void ZombieDarkEntity::collideWithEnemy(EnemyEntity* entity)
{
if (entity->getMovingStyle() == movWalking)
{
if (currentDirection == 6 && entity->getX() > x)
{
currentDirection = 4;
targetTile = IntCoord(currentTile.x - 1, currentTile.y);
}
else if (currentDirection == 4 && entity->getX() < x)
{
currentDirection = 6;
targetTile = IntCoord(currentTile.x + 1, currentTile.y);
}
else if (currentDirection == 8 && entity->getY() < y)
{
currentDirection = 2;
targetTile = IntCoord(currentTile.x, currentTile.y + 1);
}
else if (currentDirection == 2 && entity->getY() > y)
{
currentDirection = 8;
targetTile = IntCoord(currentTile.x, currentTile.y - 1);
}
switch (currentDirection)
{
case 4: velocity.x = - creatureSpeed; velocity.y = 0.0f; break;
case 6: velocity.x = + creatureSpeed; velocity.y = 0.0f; break;
case 2: velocity.y = + creatureSpeed; velocity.x = 0.0f; break;
case 8: velocity.y = - creatureSpeed; velocity.x = 0.0f; break;
default: break;
}
- facingDirection = currentDirection;
+ nextFacingDirection = currentDirection;
}
}
void ZombieDarkEntity::findNextGoal()
{
currentTile = getCurrentTile();
float xPlayer = game().getPlayerPosition().x;
float yPlayer = game().getPlayerPosition().y;
float xDist = abs(x - xPlayer);
float yDist = abs(y - yPlayer);
int playerDirecion;
if (xDist >= yDist)
{
if (xPlayer > x) playerDirecion = 6;
else playerDirecion = 4;
}
else
{
if (yPlayer > y) playerDirecion = 2;
else playerDirecion = 8;
}
switch (currentDirection)
{
case 4:
if (playerDirecion != 6)
currentDirection = playerDirecion;
else
{
if (yPlayer > y) currentDirection = 2;
else currentDirection = 8;
}
break;
case 6:
if (playerDirecion != 4)
currentDirection = playerDirecion;
else
{
if (yPlayer > y) currentDirection = 2;
else currentDirection = 8;
}
break;
case 2:
if (playerDirecion != 8)
currentDirection = playerDirecion;
else
{
if (xPlayer > x) currentDirection = 6;
else currentDirection = 4;
}
break;
case 8:
if (playerDirecion != 2)
currentDirection = playerDirecion;
else
{
if (xPlayer > x) currentDirection = 6;
else currentDirection = 4;
}
break;
default: break;
}
switch (currentDirection)
{
case 4:
velocity.x = - creatureSpeed;
velocity.y = 0.0f;
targetTile = IntCoord(currentTile.x - 2, currentTile.y);
break;
case 6:
velocity.x = + creatureSpeed;
velocity.y = 0.0f;
targetTile = IntCoord(currentTile.x + 2, currentTile.y);
break;
case 2:
velocity.y = + creatureSpeed;
velocity.x = 0.0f;
targetTile = IntCoord(currentTile.x, currentTile.y + 2);
break;
case 8:
velocity.y = - creatureSpeed;
velocity.x = 0.0f;
targetTile = IntCoord(currentTile.x, currentTile.y - 2);
break;
default: break;
}
- facingDirection = currentDirection;
+ nextFacingDirection = currentDirection;
if (currentDirection == playerDirecion && attackTimer <= 0.0f)
{
giveRecoil(false, Vector2D(velocity.x * 2.0f, velocity.y * 2.0f), 1.5f);
attackTimer = 2.0f;
SoundManager::getInstance().playSound(SOUND_ZOMBIE_ATTACKING);
+ facingTimer = -1.0f;
}
else
SoundManager::getInstance().playSound(SOUND_ZOMBIE_00 + rand() % 2);
}
void ZombieDarkEntity::findNextRandomGoal()
{
currentTile = getCurrentTile();
DungeonMap* dMap = game().getCurrentMap();
int backDirection = 0;
switch (currentDirection)
{
case 4: backDirection = 6; break;
case 6: backDirection = 4; break;
case 2: backDirection = 8; break;
case 8: backDirection = 2; break;
default: break;
}
bool ok = false;
{
int r = 0;
while (!ok)
{
r++;
if (r == 150) // watchdog
ok = true;
else if (r == 40)
{
backDirection = 5;
}
int newDir = rand() % 4;
if (newDir == 0)
{
if (backDirection != 4 && currentTile.x > 1 && (currentTile.y % 2 != 0) && dMap->isWalkable(currentTile.x - 1, currentTile.y))
{
currentDirection = 4;
targetTile = IntCoord(currentTile.x - 1, currentTile.y);
ok = true;
}
}
else if (newDir == 1)
{
if (backDirection != 6 && currentTile.x < MAP_WIDTH - 2 && (currentTile.y % 2 != 0) && dMap->isWalkable(currentTile.x + 1, currentTile.y))
{
currentDirection = 6;
targetTile = IntCoord(currentTile.x + 1, currentTile.y);
ok = true;
}
}
else if (newDir == 2)
{
if (backDirection != 8 && currentTile.y > 1 && (currentTile.x % 2 != 0) && dMap->isWalkable(currentTile.x, currentTile.y - 1))
{
currentDirection = 8;
targetTile = IntCoord(currentTile.x, currentTile.y - 1);
ok = true;
}
}
else
{
if (backDirection != 2 && currentTile.y < MAP_HEIGHT - 2 && (currentTile.x % 2 != 0) && dMap->isWalkable(currentTile.x, currentTile.y + 1))
{
currentDirection = 2;
targetTile = IntCoord(currentTile.x, currentTile.y + 1);
ok = true;
}
}
}
}
switch (currentDirection)
{
case 4: velocity.x = - creatureSpeed; velocity.y = 0.0f; break;
case 6: velocity.x = + creatureSpeed; velocity.y = 0.0f; break;
case 2: velocity.y = + creatureSpeed; velocity.x = 0.0f; break;
case 8: velocity.y = - creatureSpeed; velocity.x = 0.0f; break;
default: break;
}
- facingDirection = currentDirection;
+ nextFacingDirection = currentDirection;
}
void ZombieDarkEntity::collideWithBolt(BoltEntity* boltEntity)
{
EnemyEntity::collideWithBolt(boltEntity);
}
bool ZombieDarkEntity::isAttacking()
{
return attackTimer > 1.0f;
}
diff --git a/src/ZombieEntity.cpp b/src/ZombieEntity.cpp
index d6e83c1..65f58dc 100644
--- a/src/ZombieEntity.cpp
+++ b/src/ZombieEntity.cpp
@@ -1,253 +1,262 @@
#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;
+ facingDirection = direction;
+ nextFacingDirection = direction;
clockTurn = rand() % 2 == 0;
compute(false);
timer = 5 + rand() % 6;
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);
}
}
+ checkNextFacing(delay);
+
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);
+ if (attacking)
+ {
+ SoundManager::getInstance().playSound(SOUND_ZOMBIE_ATTACKING);
+ facingTimer = 0.2f;
+ nextFacingDirection = facingDirection;
+ }
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;
+ nextFacingDirection = 8;
break;
case 1:
velocity.x = creatureSpeed;
velocity.y = 0;
- facingDirection = 6;
+ nextFacingDirection = 6;
break;
case 2:
velocity.x = 0;
velocity.y = creatureSpeed;
- facingDirection = 2;
+ nextFacingDirection = 2;
break;
case 3:
velocity.x = -creatureSpeed;
velocity.y = 0;
- facingDirection = 4;
+ nextFacingDirection = 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;
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Jun 16, 12:20 AM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
70752
Default Alt Text
(15 KB)
Attached To
Mode
R78 witchblast
Attached
Detach File
Event Timeline