Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
14 KB
Referenced Files
None
Subscribers
None
diff --git a/src/ImpEntity.cpp b/src/ImpEntity.cpp
index 5a2a9a0..3861110 100644
--- a/src/ImpEntity.cpp
+++ b/src/ImpEntity.cpp
@@ -1,241 +1,245 @@
#include "ImpEntity.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"
#include "EnnemyBoltEntity.h"
ImpEntity::ImpEntity(float x, float y, impTypeEnum impType)
: EnnemyEntity (ImageManager::getImageManager()->getImage(IMAGE_IMP), x, y)
{
// general
creatureSpeed = IMP_SPEED;
velocity = Vector2D(creatureSpeed);
hp = IMP_HP;
meleeDamages = IMP_MELEE_DAMAGES;
type = ENTITY_ENNEMY;
bloodColor = bloodRed;
changingDelay = 1.5f + (float)(rand() % 2500) / 1000.0f;
shadowFrame = 4;
movingStyle = movFlying;
imagesProLine = 5;
hurtingSound = SOUND_IMP_HURT;
agonizingSound = SOUND_IMP_DYING;
this->impType = impType;
state = 0;
// Imp-specific
if (impType == ImpTypeBlue)
{
dyingFrame = 8;
deathFrame = FRAME_CORPSE_IMP_BLUE;
resistance[ResistanceFrozen] = ResistanceImmune;
+ resistance[ResistanceIce] = ResistanceHigh;
+ resistance[ResistanceFire] = ResistanceLow;
}
- else
+ else // ImpTypeRed
{
dyingFrame = 3;
deathFrame = FRAME_CORPSE_IMP_RED;
+ resistance[ResistanceIce] = ResistanceLow;
+ resistance[ResistanceFire] = ResistanceHigh;
}
}
void ImpEntity::animate(float delay)
{
if (!isDying && !isAgonising)
{
if (age < 0.0f)
frame = 1;
else
{
changingDelay -= delay;
if (changingDelay < 0.0f)
{
if (state == 0) // flying -> pause
{
viscosity = 0.965f;
state = 1;
changingDelay = 0.5f;
}
else if (state == 1) // pause -> fire -> pause
{
changingDelay = 0.4f;
fire();
state = 2;
}
else if (state == 2) // pause -> teleport -> pause
{
teleport();
state = 3;
changingDelay = 0.4f;
}
else if (state == 3)
{
velocity = Vector2D(creatureSpeed);
changingDelay = 1.5f + (float)(rand() % 2500) / 1000.0f;
viscosity = 1.0f;
state = 0;
}
}
switch (((int)(age * 5.0f)) % 4)
{
case 0:
case 2: frame = 0; break;
case 1: frame = 1; break;
case 3: frame = 2; break;
}
}
if (impType == ImpTypeBlue) frame += 5;
}
EnnemyEntity::animate(delay);
}
void ImpEntity::calculateBB()
{
boundingBox.left = (int)x - width / 2 + IMP_BB_LEFT;
boundingBox.width = width - IMP_BB_WIDTH_DIFF;
boundingBox.top = (int)y - height / 2 + IMP_BB_TOP;
boundingBox.height = height - IMP_BB_HEIGHT_DIFF;
}
void ImpEntity::collideMapRight()
{
velocity.x = -velocity.x;
}
void ImpEntity::collideMapLeft()
{
velocity.x = -velocity.x;
}
void ImpEntity::collideMapTop()
{
velocity.y = -velocity.y;
}
void ImpEntity::collideMapBottom()
{
velocity.y = -velocity.y;
}
void ImpEntity::collideWithEnnemy(GameEntity* collidingEntity)
{
EnnemyEntity* entity = static_cast<EnnemyEntity*>(collidingEntity);
if (entity->getMovingStyle() == movFlying)
{
setVelocity(Vector2D(entity->getX(), entity->getY()).vectorTo(Vector2D(x, y), creatureSpeed ));
}
}
bool ImpEntity::hurt(int damages, enumShotType hurtingType, int level)
{
bool result = EnnemyEntity::hurt(damages, hurtingType, level);
if (!isDying && !isAgonising)
{
teleport();
state = 3;
changingDelay = 0.4f;
}
return result;
}
void ImpEntity::dying()
{
EnnemyEntity::dying();
h = 25.0f;
}
void ImpEntity::fire()
{
SoundManager::getSoundManager()->playSound(SOUND_BLAST_FLOWER);
EnnemyBoltEntity* bolt;
if (impType == ImpTypeBlue)
{
bolt = new EnnemyBoltEntity(x, y, ShotTypeIce, 0);
bolt->setDamages(5);
}
else
{
bolt = new EnnemyBoltEntity(x, y, ShotTypeFire, 0);
bolt->setDamages(8);
}
bolt->setFlying(true);
float fireVelocity = IMP_FIRE_VELOCITY;
if (specialState[SpecialStateIce].active) fireVelocity *= 0.5f;
bolt->setVelocity(Vector2D(x, y).vectorTo(game().getPlayerPosition(), fireVelocity ));
}
void ImpEntity::generateStar(sf::Color starColor)
{
SpriteEntity* spriteStar = new SpriteEntity(
ImageManager::getImageManager()->getImage(IMAGE_STAR_2),
x, y);
spriteStar->setScale(0.8f, 0.8f);
spriteStar->setZ(z-1.0f);
spriteStar->setLifetime(0.8f);
spriteStar->setSpin(-100 + rand()%200);
spriteStar->setVelocity(Vector2D(10 + rand()%40));
spriteStar->setWeight(-150);
spriteStar->setFading(true);
spriteStar->setColor(starColor);
}
void ImpEntity::teleport()
{
bool ok = false;
int xm, ym;
float xMonster, yMonster;
for(int i=0; i < 6; i++)
{
if (impType == ImpTypeBlue)
{
generateStar(sf::Color(50, 50, 255, 255));
generateStar(sf::Color(200, 200, 255, 255));
}
else
{
generateStar(sf::Color(255, 50, 50, 255));
generateStar(sf::Color(255, 200, 200, 255));
}
}
int counter = 50;
while (!ok && counter > 0)
{
counter--;
xm = 1 +rand() % (MAP_WIDTH - 3);
ym = 1 +rand() % (MAP_HEIGHT - 3);
xMonster = OFFSET_X + xm * TILE_WIDTH + TILE_WIDTH * 0.5f;
yMonster = OFFSET_Y + ym * TILE_HEIGHT+ TILE_HEIGHT * 0.5f;
ok = (game().getPlayerPosition().distance2(Vector2D(xMonster, yMonster)) > 40000);
}
x = xMonster;
y = yMonster;
for(int i=0; i < 6; i++)
{
if (impType == ImpTypeBlue)
{
generateStar(sf::Color(50, 50, 255, 255));
generateStar(sf::Color(200, 200, 255, 255));
}
else
{
generateStar(sf::Color(255, 50, 50, 255));
generateStar(sf::Color(255, 200, 200, 255));
}
}
}
diff --git a/src/SlimeEntity.cpp b/src/SlimeEntity.cpp
index 0469920..52c6ef6 100644
--- a/src/SlimeEntity.cpp
+++ b/src/SlimeEntity.cpp
@@ -1,296 +1,308 @@
#include "SlimeEntity.h"
#include "PlayerEntity.h"
#include "EnnemyBoltEntity.h"
#include "sfml_game/SpriteEntity.h"
#include "sfml_game/ImageManager.h"
#include "sfml_game/SoundManager.h"
#include "Constants.h"
#include "WitchBlastGame.h"
SlimeEntity::SlimeEntity(float x, float y, slimeTypeEnum slimeType, bool invocated)
: EnnemyEntity (ImageManager::getImageManager()->getImage(IMAGE_SLIME), x, y)
{
creatureSpeed = 0.0f;
velocity = Vector2D(0.0f, 0.0f);
hp = SLIME_HP;
meleeDamages = SLIME_DAMAGES;
this->slimeType = slimeType;
this->invocated = invocated;
if (invocated)
{
type = ENTITY_ENNEMY_INVOCATED;
jumpingDelay = 0.1f;
age = 0.0f;
}
else
{
type = ENTITY_ENNEMY;
jumpingDelay = 0.6f + 0.1f * (rand() % 20);
}
+ if (slimeType == SlimeTypeBlue)
+ {
+ resistance[ResistanceFrozen] = ResistanceImmune;
+ resistance[ResistanceIce] = ResistanceHigh;
+ resistance[ResistanceFire] = ResistanceLow;
+ }
+ else if (slimeType == SlimeTypeRed)
+ {
+ resistance[ResistanceIce] = ResistanceLow;
+ resistance[ResistanceFire] = ResistanceHigh;
+ }
+
bloodColor = bloodGreen;
frame = 0;
shadowFrame = 3;
imagesProLine = 4;
isJumping = false;
h = 0.0f;
viscosity = 0.98f;
}
void SlimeEntity::animate(float delay)
{
float slimeDelay = delay;
if (specialState[SpecialStateIce].active) slimeDelay = delay * specialState[SpecialStateIce].parameter;
if (isJumping)
{
hVelocity -= 700.0f * slimeDelay;
h += hVelocity * slimeDelay;
if (h <= 0.0f)
{
if (hp <= 0)
dying();
else
{
h = 0.0f;
if (isFirstJumping)
{
isFirstJumping = false;
hVelocity = 160.0f;
SoundManager::getSoundManager()->playSound(SOUND_SLIME_IMAPCT);
if (slimeType == SlimeTypeBlue || slimeType == SlimeTypeRed)
fire();
}
else
{
jumpingDelay = 0.4f + 0.1f * (rand() % 20);
isJumping = false;
SoundManager::getSoundManager()->playSound(SOUND_SLIME_IMAPCT_WEAK);
}
}
}
if (hVelocity > 0.0f) frame = 2;
else frame = 0;
}
else
{
jumpingDelay -= slimeDelay;
if (jumpingDelay < 0.0f)
{
SoundManager::getSoundManager()->playSound(SOUND_SLIME_JUMP);
hVelocity = 350.0f + rand() % 300;
isJumping = true;
isFirstJumping = true;
float randVel = 250.0f + rand() % 250;
if (rand() % 2 == 0)
{
float tan = (game().getPlayer()->getX() - x) / (game().getPlayer()->getY() - y);
float angle = atan(tan);
if (game().getPlayer()->getY() > y)
setVelocity(Vector2D(sin(angle) * randVel,
cos(angle) * randVel));
else
setVelocity(Vector2D(-sin(angle) * randVel,
-cos(angle) * randVel));
}
else
velocity = Vector2D(randVel);
}
else if (jumpingDelay < 0.25f)
frame = 1;
else frame = 0;
}
EnnemyEntity::animate(delay);
}
void SlimeEntity::render(sf::RenderTarget* app)
{
if (!isDying && shadowFrame > -1)
{
// shadow
sprite.setPosition(x, y);
sprite.setTextureRect(sf::IntRect(shadowFrame * width, 0, width, height));
app->draw(sprite);
}
sprite.setPosition(x, y - h);
sprite.setTextureRect(sf::IntRect(frame * width, slimeType * height, width, height));
app->draw(sprite);
#ifdef SHOW_BOUNDING_BOX
sf::Vertex line[] =
{
sf::Vertex(sf::Vector2f(boundingBox.left, boundingBox.top)),
sf::Vertex(sf::Vector2f(boundingBox.left + boundingBox.width, boundingBox.top)),
sf::Vertex(sf::Vector2f(boundingBox.left + boundingBox.width, boundingBox.top)),
sf::Vertex(sf::Vector2f(boundingBox.left + boundingBox.width, boundingBox.top + boundingBox.height)),
sf::Vertex(sf::Vector2f(boundingBox.left + boundingBox.width, boundingBox.top + boundingBox.height)),
sf::Vertex(sf::Vector2f(boundingBox.left, boundingBox.top + boundingBox.height)),
sf::Vertex(sf::Vector2f(boundingBox.left, boundingBox.top + boundingBox.height)),
sf::Vertex(sf::Vector2f(boundingBox.left, boundingBox.top))
};
app->draw(line, 8, sf::Lines);
#endif
}
void SlimeEntity::calculateBB()
{
boundingBox.left = (int)x - width / 2 + SLIME_BB_LEFT;
boundingBox.width = width - SLIME_BB_WIDTH_DIFF;
boundingBox.top = (int)y - height / 2 + SLIME_BB_TOP;
boundingBox.height = height - SLIME_BB_HEIGHT_DIFF;
}
void SlimeEntity::collideMapRight()
{
// if (x > OFFSET_X + MAP_WIDTH * TILE_WIDTH)
velocity.x = -velocity.x * 0.8f;
}
void SlimeEntity::collideMapLeft()
{
// if (x < OFFSET_X + MAP_WIDTH )
velocity.x = -velocity.x * 0.8f;
}
void SlimeEntity::collideMapTop()
{
// if (y > OFFSET_Y + MAP_HEIGHT * TILE_HEIGHT)
velocity.y = -velocity.y * 0.8f;
}
void SlimeEntity::collideMapBottom()
{
// if (y < OFFSET_Y + MAP_HEIGHT )
velocity.y = -velocity.y * 0.8f;
}
void SlimeEntity::collideWithEnnemy(GameEntity* collidingEntity)
{
if (recoil.active && recoil.stun) return;
EnnemyEntity* entity = static_cast<EnnemyEntity*>(collidingEntity);
if (entity->getMovingStyle() == movWalking)
{
Vector2D vel = Vector2D(entity->getX(), entity->getY()).vectorTo(Vector2D(x, y), 100.0f );
giveRecoil(false, vel, 0.3f);
computeFacingDirection();
}
}
bool SlimeEntity::collideWithMap(int direction)
{
calculateBB();
int xTile0 = (boundingBox.left - offsetX) / tileWidth;
int xTilef = (boundingBox.left + boundingBox.width - offsetX) / tileWidth;
int yTile0 = (boundingBox.top - offsetY) / tileHeight;
int yTilef = (boundingBox.top + boundingBox.height - offsetY) / tileHeight;
if (boundingBox.top < 0) yTile0 = -1;
for (int xTile = xTile0; xTile <= xTilef; xTile++)
for (int yTile = yTile0; yTile <= yTilef; yTile++)
{
if (xTile == 0 || xTile == MAP_WIDTH - 1 || yTile == 0 || yTile == MAP_HEIGHT - 1)
{
switch (direction)
{
case DIRECTION_LEFT:
if (map->isLeftBlocking(xTile, yTile)) return true;
break;
case DIRECTION_RIGHT:
if (map->isRightBlocking(xTile, yTile)) return true;
break;
case DIRECTION_TOP:
if (map->isUpBlocking(xTile, yTile)) return true;
break;
case DIRECTION_BOTTOM:
if (map->isDownBlocking(xTile, yTile)) return true;
break;
}
}
}
return false;
}
void SlimeEntity::dying()
{
isDying = true;
SpriteEntity* deadSlime = new SpriteEntity(ImageManager::getImageManager()->getImage(IMAGE_CORPSES), x, y, 64, 64);
deadSlime->setZ(OFFSET_Y);
switch (slimeType)
{
case SlimeTypeStandard: deadSlime->setFrame(FRAME_CORPSE_SLIME); break;
case SlimeTypeRed: deadSlime->setFrame(FRAME_CORPSE_SLIME_RED); break;
case SlimeTypeBlue: deadSlime->setFrame(FRAME_CORPSE_SLIME_BLUE); break;
}
deadSlime->setType(ENTITY_CORPSE);
for (int i = 0; i < 4; i++) game().generateBlood(x, y, bloodColor);
if (!invocated) drop();
SoundManager::getSoundManager()->playSound(SOUND_ENNEMY_DYING);
}
void SlimeEntity::prepareDying()
{
if (!isJumping)
dying();
}
bool SlimeEntity::canCollide()
{
return h <= 70.0f;
}
BaseCreatureEntity::enumMovingStyle SlimeEntity::getMovingStyle()
{
if (h <= 70.0f)
return movWalking;
else
return movFlying;
}
void SlimeEntity::fire()
{
for (int i = 0; i < 4; i++)
{
EnnemyBoltEntity* bolt;
if (slimeType == SlimeTypeBlue)
{
bolt = new EnnemyBoltEntity(x, y, ShotTypeIce, 0);
bolt->setDamages(5);
}
else if (slimeType == SlimeTypeRed)
{
bolt = new EnnemyBoltEntity(x, y, ShotTypeFire, 0);
bolt->setDamages(8);
}
else
return;
switch (i)
{
case 0: bolt->setVelocity(Vector2D(SLIME_FIRE_VELOCITY, 0)); break;
case 1: bolt->setVelocity(Vector2D(-SLIME_FIRE_VELOCITY, 0)); break;
case 2: bolt->setVelocity(Vector2D(0, SLIME_FIRE_VELOCITY)); break;
case 3: bolt->setVelocity(Vector2D(0, -SLIME_FIRE_VELOCITY)); break;
}
}
SoundManager::getSoundManager()->playSound(SOUND_BLAST_FLOWER);
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jun 11, 10:33 AM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68442
Default Alt Text
(14 KB)

Event Timeline