Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F128005
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
20 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/WitchEntity.cpp b/src/WitchEntity.cpp
index bfd1118..c342081 100644
--- a/src/WitchEntity.cpp
+++ b/src/WitchEntity.cpp
@@ -1,207 +1,223 @@
#include "WitchEntity.h"
#include "BoltEntity.h"
#include "EnemyBoltEntity.h"
#include "PlayerEntity.h"
#include "RatEntity.h"
#include "BatEntity.h"
#include "sfml_game/SpriteEntity.h"
#include "sfml_game/ImageManager.h"
#include "sfml_game/SoundManager.h"
#include "Constants.h"
#include "WitchBlastGame.h"
WitchEntity::WitchEntity(float x, float y, witchTypeEnum witchType)
: EnemyEntity (ImageManager::getInstance().getImage(IMAGE_WITCH), x, y)
{
this->witchType = witchType;
imagesProLine = 8;
if (witchType == WitchTypeNormal)
{
frame = 0;
dyingFrame = 5;
deathFrame = FRAME_CORPSE_WITCH;
enemyType = EnemyTypeWitch;
}
else
{
frame = 8;
dyingFrame = 13;
deathFrame = FRAME_CORPSE_WITCH_RED;
enemyType = EnemyTypeWitchRed;
}
hp = WITCH_HP;
hpMax = hp;
creatureSpeed = WITCH_VELOCITY;
velocity = Vector2D(creatureSpeed);
meleeDamages = WITCH_DAMAGE;
bloodColor = BloodRed;
shadowFrame = 4;
height = 96;
sprite.setOrigin(32, 71);
timer = 3.0f;
escapeTimer = -1.0f;
state = 0;
agonizingSound = (sound_resources)(SOUND_WITCH_DIE_00 + rand() % 2);
}
void WitchEntity::animate(float delay)
{
if (age > 0.0f && !isAgonising)
{
if (escapeTimer > 0.0f) escapeTimer -= delay;
timer -= delay;
if (timer <= 0.0f)
{
if (state == 0)
{
state = 1;
velocity = Vector2D(0.0f, 0.0f);
SoundManager::getInstance().playSound(SOUND_WITCH_00 + rand() % 3);
timer = 0.6f;
if (rand() % 7 == 0 || !canSee(game().getPlayerPosition().x, game().getPlayerPosition().y))
{
// invoke
int x0 = x / TILE_WIDTH;
if (x0 < 1) x0 = 1;
else if(x0 > MAP_WIDTH - 2) x0 = MAP_WIDTH - 2;
x0 = x0 * TILE_WIDTH + TILE_WIDTH / 2;
int y0 = y / TILE_HEIGHT;
if (y0 < 1) y0 = 1;
else if(y0 > MAP_HEIGHT - 2) y0 = MAP_HEIGHT - 2;
y0 = y0 * TILE_HEIGHT + TILE_HEIGHT / 2;
if (witchType == WitchTypeNormal) new RatEntity(x0, y0, RatEntity::RatTypeNormal, true);
else new BatEntity(x0, y0, BatStandard, true);
SoundManager::getInstance().playSound(SOUND_INVOKE);
for(int i=0; i < 6; i++)
{
generateStar(sf::Color(200, 50, 200, 255));
generateStar(sf::Color(255, 255, 255, 255));
}
}
else
{
// fire
fire();
if (witchType == WitchTypeNormal) fire();
}
}
else if (state == 1)
{
timer = 3.5f + (rand() % 25) * 0.1f;
if (!canSee(game().getPlayerPosition().x, game().getPlayerPosition().y)) timer += 1.2f;
velocity = Vector2D(creatureSpeed);
state = 0;
}
}
if (state == 0)
{
if (escapeTimer < 0.0f && Vector2D(x, y).distance2(game().getPlayerPosition()) <= 36000)
{
velocity = game().getPlayerPosition().vectorTo(Vector2D(x, y), creatureSpeed);
escapeTimer = 2.5f;
}
frame = ((int)(age * 5.0f)) % 4;
if (frame == 2) frame = 0;
else if (frame == 3) frame = 2;
if (velocity.x > 1.0f) isMirroring = true;
else if (velocity.x < -1.0f) isMirroring = false;
}
else if (state == 1)
{
frame = 3;
isMirroring = game().getPlayer()->getX() > x;
}
if (witchType == WitchTypeRed) frame += 8;
}
EnemyEntity::animate(delay);
z = y + 20;
}
void WitchEntity::calculateBB()
{
boundingBox.left = (int)x - 16;
boundingBox.width = 32;
boundingBox.top = (int)y - 25;
boundingBox.height = 45;
}
void WitchEntity::collideMapRight()
{
velocity.x = -velocity.x;
- if (recoil.active) recoil.velocity.x = -recoil.velocity.x;
+ if (recoil.active)
+ {
+ if (recoil.stun) recoil.velocity.x = -recoil.velocity.x * 0.3f;
+ else (recoil.active = false);
+ }
else computeFacingDirection();
}
void WitchEntity::collideMapLeft()
{
velocity.x = -velocity.x;
- if (recoil.active) recoil.velocity.x = -recoil.velocity.x;
+ if (recoil.active)
+ {
+ if (recoil.stun) recoil.velocity.x = -recoil.velocity.x * 0.3f;
+ else (recoil.active = false);
+ }
else computeFacingDirection();
}
void WitchEntity::collideMapTop()
{
velocity.y = -velocity.y;
- if (recoil.active) recoil.velocity.y = -recoil.velocity.y;
+ if (recoil.active)
+ {
+ if (recoil.stun) recoil.velocity.y = -recoil.velocity.y * 0.3f;
+ else (recoil.active = false);
+ }
else computeFacingDirection();
}
void WitchEntity::collideMapBottom()
{
velocity.y = -velocity.y;
- if (recoil.active) recoil.velocity.y = -recoil.velocity.y;
+ if (recoil.active)
+ {
+ if (recoil.stun) recoil.velocity.y = -recoil.velocity.y * 0.3f;
+ else (recoil.active = false);
+ }
else computeFacingDirection();
}
void WitchEntity::collideWithEnemy(EnemyEntity* entity)
{
if (entity->getMovingStyle() == movWalking)
{
setVelocity(Vector2D(entity->getX(), entity->getY()).vectorTo(Vector2D(x, y), creatureSpeed ));
computeFacingDirection();
}
}
void WitchEntity::collideWithBolt(BoltEntity* boltEntity)
{
EnemyEntity::collideWithBolt(boltEntity);
}
void WitchEntity::fire()
{
if (witchType == WitchTypeNormal)
{
SoundManager::getInstance().playSound(SOUND_BLAST_FLOWER);
EnemyBoltEntity* bolt = new EnemyBoltEntity
(x, y + 10, ShotTypeStandard, 0, enemyType);
bolt->setMap(map, TILE_WIDTH, TILE_HEIGHT, 0, 0);
float flowerFireVelocity = EVIL_FLOWER_FIRE_VELOCITY;
if (specialState[SpecialStateIce].active) flowerFireVelocity *= 0.7f;
bolt->setVelocity(Vector2D(x, y).vectorNearlyTo(game().getPlayerPosition(), flowerFireVelocity, 1.0f ));
}
else
{
SoundManager::getInstance().playSound(SOUND_BLAST_FLOWER);
EnemyBoltEntity* bolt = new EnemyBoltEntity
(x, y + 10, ShotTypeBomb, 0, enemyType);
bolt->setMap(map, TILE_WIDTH, TILE_HEIGHT, 0, 0);
float flowerFireVelocity = EVIL_FLOWER_FIRE_VELOCITY * 0.9f;
if (specialState[SpecialStateIce].active) flowerFireVelocity *= 0.5f;
bolt->setVelocity(Vector2D(x, y).vectorNearlyTo(game().getPlayerPosition(), flowerFireVelocity, 1.0f ));
}
}
diff --git a/src/ZombieDarkEntity.cpp b/src/ZombieDarkEntity.cpp
index a127461..b6649eb 100644
--- a/src/ZombieDarkEntity.cpp
+++ b/src/ZombieDarkEntity.cpp
@@ -1,308 +1,328 @@
#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;
height = 80;
sprite.setOrigin(32.0f, 60.0f);
attackTimer = 2.0f;
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();
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;
}
}
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;
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);
}
else
SoundManager::getInstance().playSound(SOUND_ZOMBIE_00 + rand() % 2);
}
void ZombieDarkEntity::findNextRandomGoal()
{
currentTile = getCurrentTile();
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;
int newDir = rand() % 4;
if (newDir == 0)
{
if (backDirection != 4 && currentTile.x > 2 && (currentTile.y % 2 != 0))
{
currentDirection = 4;
targetTile = IntCoord(currentTile.x - 2, currentTile.y);
ok = true;
}
}
else if (newDir == 1)
{
if (backDirection != 6 && currentTile.x < MAP_WIDTH - 2 && (currentTile.y % 2 != 0))
{
currentDirection = 6;
targetTile = IntCoord(currentTile.x + 2, currentTile.y);
ok = true;
}
}
else if (newDir == 2)
{
if (backDirection != 8 && currentTile.y > 1 && (currentTile.x % 2 != 0))
{
currentDirection = 8;
targetTile = IntCoord(currentTile.x, currentTile.y - 2);
ok = true;
}
}
else
{
if (backDirection != 2 && currentTile.y < MAP_HEIGHT - 2 && (currentTile.x % 2 != 0))
{
currentDirection = 2;
targetTile = IntCoord(currentTile.x, currentTile.y + 2);
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;
}
void ZombieDarkEntity::collideWithBolt(BoltEntity* boltEntity)
{
EnemyEntity::collideWithBolt(boltEntity);
}
diff --git a/src/ZombieEntity.cpp b/src/ZombieEntity.cpp
index 1f15f79..764ed42 100644
--- a/src/ZombieEntity.cpp
+++ b/src/ZombieEntity.cpp
@@ -1,248 +1,248 @@
#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;
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;
+ 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;
+ 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;
+ 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;
+ 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();
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, Jun 12, 12:53 PM (3 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
70303
Default Alt Text
(20 KB)
Attached To
Mode
R78 witchblast
Attached
Detach File
Event Timeline