Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F125833
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
7 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/BlackRatEntity.cpp b/src/BlackRatEntity.cpp
index 23ffcb5..c214982 100644
--- a/src/BlackRatEntity.cpp
+++ b/src/BlackRatEntity.cpp
@@ -1,248 +1,248 @@
#include "BlackRatEntity.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"
BlackRatEntity::BlackRatEntity(float x, float y, ratBlackTypeEnum ratType)
: EnemyEntity (ImageManager::getImageManager()->getImage(IMAGE_RAT), x, y),
currentTile(0, 0),
targetTile(0, 0)
{
this->ratType = ratType;
imagesProLine = 8;
if (ratType == RatBlackTypeNormal)
{
frame = 16;
dyingFrame = 22;
- deathFrame = FRAME_CORPSE_RAT;
+ deathFrame = FRAME_CORPSE_BLACK_RAT;
enemyType = EnemyTypeRatBlack;
hp = RAT_HP;
creatureSpeed = RAT_SPEED;
}
else //(ratType == RatBlackTypeHelmet)
{
frame = 32;
dyingFrame = 38;
deathFrame = FRAME_CORPSE_BLACK_RAT_HELMET;
enemyType = EnemyTypeRatBlackHelmet;
hp = RAT_HP_HELMET;
creatureSpeed = RAT_SPEED;
}
meleeDamages = BLACK_RAT_DAMAGES;
type = ENTITY_ENNEMY;
bloodColor = bloodRed;
shadowFrame = 7;
agonizingSound = SOUND_RAT_DYING;
currentDirection = 0;
findNextGoal();
}
void BlackRatEntity::animate(float delay)
{
if (age > 0.0f && !isAgonising)
{
// goal reached ?
if (currentDirection == 6 && x > (targetTile.x * TILE_WIDTH + TILE_WIDTH / 2 + OFFSET_X) ) findNextGoal();
else if (currentDirection == 4 && x < (targetTile.x * TILE_WIDTH + TILE_WIDTH / 2 + OFFSET_X) ) findNextGoal();
else if (currentDirection == 2 && y > (targetTile.y * TILE_HEIGHT + TILE_HEIGHT / 2 + OFFSET_Y - 5) ) findNextGoal();
else if (currentDirection == 8 && y < (targetTile.y * TILE_HEIGHT + TILE_HEIGHT / 2 + OFFSET_Y - 5) ) findNextGoal();
frame = 16 + ((int)(age * 5.0f)) % 2;
if (facingDirection == 4 || facingDirection == 6) frame += 2;
isMirroring = (facingDirection == 4 );
if (facingDirection == 8) frame += 4;
if (ratType == RatBlackTypeHelmet)
frame += 16;
}
EnemyEntity::animate(delay);
}
void BlackRatEntity::calculateBB()
{
boundingBox.left = (int)x - width / 2 + RAT_BB_LEFT;
boundingBox.width = width - RAT_BB_WIDTH_DIFF;
boundingBox.top = (int)y - height / 2 + RAT_BB_TOP;
boundingBox.height = height - RAT_BB_HEIGHT_DIFF;
}
void BlackRatEntity::collideMapRight()
{
findNextGoal();
}
void BlackRatEntity::collideMapLeft()
{
findNextGoal();
}
void BlackRatEntity::collideMapTop()
{
findNextGoal();
}
void BlackRatEntity::collideMapBottom()
{
findNextGoal();
}
void BlackRatEntity::collideWithEnnemy(GameEntity* collidingEntity)
{
EnemyEntity* entity = static_cast<EnemyEntity*>(collidingEntity);
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 = - BLACK_RAT_SPEED; velocity.y = 0.0f; break;
case 6: velocity.x = + BLACK_RAT_SPEED; velocity.y = 0.0f; break;
case 2: velocity.y = + BLACK_RAT_SPEED; velocity.x = 0.0f; break;
case 8: velocity.y = - BLACK_RAT_SPEED; velocity.x = 0.0f; break;
default: break;
}
facingDirection = currentDirection;
}
}
void BlackRatEntity::findNextGoal()
{
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 = - BLACK_RAT_SPEED; velocity.y = 0.0f; break;
case 6: velocity.x = + BLACK_RAT_SPEED; velocity.y = 0.0f; break;
case 2: velocity.y = + BLACK_RAT_SPEED; velocity.x = 0.0f; break;
case 8: velocity.y = - BLACK_RAT_SPEED; velocity.x = 0.0f; break;
default: break;
}
facingDirection = currentDirection;
}
void BlackRatEntity::collideWithBolt(BoltEntity* boltEntity)
{
if (ratType == RatBlackTypeHelmet && boltEntity->getBoltType() != ShotTypeIllusion)
{
int collisionDir = getCollisionDirection(boltEntity);
bool boltCollide = true;
switch (facingDirection)
{
case 4:
if (collisionDir == 7 || collisionDir == 4 || collisionDir == 1) boltCollide = false;
break;
case 2:
if (collisionDir == 1 || collisionDir == 2 || collisionDir == 3) boltCollide = false;
break;
case 6:
if (collisionDir == 9 || collisionDir == 6 || collisionDir == 3) boltCollide = false;
break;
case 8:
if (collisionDir == 7 || collisionDir == 8 || collisionDir == 9) boltCollide = false;
break;
}
if (boltCollide) EnemyEntity::collideWithBolt(boltEntity);
else
{
float xs = (x + boltEntity->getX()) / 2;
float ys = (y + boltEntity->getY()) / 2;
boltEntity->collide();
SpriteEntity* star = new SpriteEntity(ImageManager::getImageManager()->getImage(IMAGE_STAR_2), xs, ys);
star->setFading(true);
star->setZ(y+ 100);
star->setLifetime(0.7f);
star->setType(16);
star->setSpin(400.0f);
}
}
else EnemyEntity::collideWithBolt(boltEntity);
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jun 11, 9:50 AM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68209
Default Alt Text
(7 KB)
Attached To
Mode
R78 witchblast
Attached
Detach File
Event Timeline