Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F126082
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/BoltEntity.cpp b/src/BoltEntity.cpp
index b7d1e02..020788a 100644
--- a/src/BoltEntity.cpp
+++ b/src/BoltEntity.cpp
@@ -1,249 +1,260 @@
#include "BoltEntity.h"
#include "Constants.h"
#include "DungeonMap.h"
#include "WitchBlastGame.h"
#include "sfml_game/ImageManager.h"
#include "sfml_game/SoundManager.h"
BoltEntity::BoltEntity(float x, float y, float boltLifeTime, enumShotType boltType, int level)
: CollidingSpriteEntity (ImageManager::getImageManager()->getImage(IMAGE_BOLT), x, y, BOLT_WIDTH, BOLT_HEIGHT)
{
lifetime = boltLifeTime;
setDamages(INITIAL_BOLT_DAMAGES);
type = ENTITY_BOLT;
viscosity = INITIAL_BOLT_VISCOSITY;
this->level = level;
if (boltType == ShotTypeLightning) viscosity += LIGHTNING_VISCOSITY_INCREASE[level];
frame = 0;
setMap(game().getCurrentMap(), TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
this->boltType = boltType;
switch (boltType)
{
case ShotTypeStandard: frame = 0; break;
case ShotTypeIce: frame = 2; break;
case ShotTypeStone: frame = 4; break;
case ShotTypeLightning: frame = 5; break;
case ShotTypeIllusion: frame = 3; break;
}
testWallsCollision = false;
flying = false;
// avoid starting in wall
if (y > (OFFSET_Y + (MAP_HEIGHT - 1) * TILE_HEIGHT - 16))
this->y = OFFSET_Y + (MAP_HEIGHT - 1) * TILE_HEIGHT - 16;
}
int BoltEntity::getDamages()
{
return damages;
}
unsigned int BoltEntity::getLevel()
{
return level;
}
void BoltEntity::setDamages(int damages)
{
this->damages = damages;
if (damages <= 4) renderScale = 0.8f;
else if (damages <= 8) renderScale = 0.85f;
else if (damages <= 12) renderScale = 0.9f;
else if (damages <= 16) renderScale = 1.0f;
else if (damages <= 20) renderScale = 1.1f;
else if (damages <= 24) renderScale = 1.2f;
else if (damages <= 30) renderScale = 1.3f;
else renderScale = 1.4f;
sprite.scale(renderScale, renderScale);
}
enumShotType BoltEntity::getBoltType()
{
return boltType;
}
bool BoltEntity::isFlying()
{
return flying;
}
void BoltEntity::setFlying(bool flying)
{
this->flying = flying;
}
void BoltEntity::animate(float delay)
{
SpriteEntity* trace = new SpriteEntity(ImageManager::getImageManager()->getImage(IMAGE_BOLT), x, y, BOLT_WIDTH, BOLT_HEIGHT);
trace->setFading(true);
trace->setZ(y);
trace->setLifetime(0.2f);
trace->setShrinking(true, renderScale, renderScale);
trace->setType(16);
trace->setFrame(frame);
z = y + height;
testWallsCollision = true;
CollidingSpriteEntity::animate(delay);
testWallsCollision = false;
if ( (lifetime - age) < 0.2f)
{
if (age >= lifetime)
sprite.setColor(sf::Color(255, 255, 255, 0));
else
sprite.setColor(sf::Color(255, 255, 255, (sf::Uint8)((lifetime - age) / 0.2f * 255)));
}
if (((velocity.x)*(velocity.x) + (velocity.y)*(velocity.y)) < 1500.0f) isDying = true;
}
void BoltEntity::calculateBB()
{
int colSize = testWallsCollision ? 1 : 10;
boundingBox.left = x - colSize;
boundingBox.width = colSize * 2;
boundingBox.top = y - colSize;
boundingBox.height = colSize * 2;
}
void BoltEntity::collide()
{
isDying = true;
for (int i=0; i<5; i++)
{
Vector2D vel(40.0f + rand() % 50);
generateParticule(vel);
}
}
void BoltEntity::generateParticule(Vector2D vel)
{
SpriteEntity* trace = new SpriteEntity(ImageManager::getImageManager()->getImage(IMAGE_BOLT), x, y, BOLT_WIDTH, BOLT_HEIGHT);
trace->setFading(true);
trace->setZ(y);
trace->setLifetime(0.5f);
trace->setScale(0.3f, 0.3f);
trace->setVelocity(vel);
trace->setViscosity(0.97f);
trace->setType(16);
trace->setFrame(frame);
}
bool BoltEntity::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 (boltType != ShotTypeIllusion)
{
if (flying)
{
if ( dynamic_cast<DungeonMap*>(map)->isFlyable(xTile, yTile) == false ) return true;
}
else
{
if ( dynamic_cast<DungeonMap*>(map)->isShootable(xTile, yTile) == false ) return true;
}
}
}
return false;
}
+void BoltEntity::onDying()
+{
+ SoundManager::getSoundManager()->playSound(SOUND_WALL_IMPACT);
+ for (int i=0; i<5; i++)
+ {
+ Vector2D vel(100.0f + rand() % 150);
+ generateParticule(vel);
+ }
+ isDying = true;
+}
+
void BoltEntity::collideMapRight()
{
if (boltType == ShotTypeLightning)
{
velocity.x = -velocity.x;
}
else
{
velocity.x = 0.0f;
isDying = true;
SoundManager::getSoundManager()->playSound(SOUND_WALL_IMPACT);
for (int i=0; i<5; i++)
{
Vector2D vel(100.0f + rand() % 150);
if (vel.x > 0.0f) vel.x = - vel.x;
generateParticule(vel);
}
}
}
void BoltEntity::collideMapLeft()
{
if (boltType == ShotTypeLightning)
{
velocity.x = -velocity.x;
}
else
{
velocity.x = 0.0f;
isDying = true;
SoundManager::getSoundManager()->playSound(SOUND_WALL_IMPACT);
for (int i=0; i<5; i++)
{
Vector2D vel(100.0f + rand() % 150);
if (vel.x < 0.0f) vel.x = - vel.x;
generateParticule(vel);
}
}
}
void BoltEntity::collideMapTop()
{
if (boltType == ShotTypeLightning)
{
velocity.y = -velocity.y;
}
else
{
velocity.y = 0.0f;
isDying = true;
SoundManager::getSoundManager()->playSound(SOUND_WALL_IMPACT);
for (int i=0; i<5; i++)
{
Vector2D vel(100.0f + rand() % 150);
if (vel.y < 0.0f) vel.y = - vel.y;
generateParticule(vel);
}
}
}
void BoltEntity::collideMapBottom()
{
if (boltType == ShotTypeLightning)
{
velocity.y = -velocity.y;
}
else
{
velocity.y = 0.0f;
isDying = true;
SoundManager::getSoundManager()->playSound(SOUND_WALL_IMPACT);
for (int i=0; i<5; i++)
{
Vector2D vel(100.0f + rand() % 150);
if (vel.y > 0.0f) vel.y = - vel.y;
generateParticule(vel);
}
}
}
diff --git a/src/BoltEntity.h b/src/BoltEntity.h
index 3363010..197b25c 100644
--- a/src/BoltEntity.h
+++ b/src/BoltEntity.h
@@ -1,45 +1,47 @@
#ifndef BOLTENTITY_H
#define BOLTENTITY_H
#include "sfml_game/CollidingSpriteEntity.h"
#include "Constants.h"
/*! \class BoltEntity
* \brief bolt thrown by the player
*
* BoltEntity are the missile weapons thrown by the player.
* The can collide with an enemy (to hurt him) or with the walls.
*/
class BoltEntity : public CollidingSpriteEntity
{
public:
BoltEntity(float x, float y, float boltLifeTime, enumShotType boltType, int level);
virtual void animate(float delay);
void collide();
void generateParticule(Vector2D vel);
int getDamages();
unsigned int getLevel();
void setDamages(int damages);
enumShotType getBoltType();
bool isFlying();
void setFlying(bool flying);
protected:
virtual void calculateBB();
virtual void collideMapRight();
virtual void collideMapLeft();
virtual void collideMapTop();
virtual void collideMapBottom();
virtual bool collideWithMap(int direction);
+ virtual void onDying();
+
int damages;
float renderScale;
enumShotType boltType;
private:
bool testWallsCollision;
bool flying;
unsigned int level;
};
#endif // BOLTENTITY_H
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jun 11, 10:35 AM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68454
Default Alt Text
(7 KB)
Attached To
Mode
R78 witchblast
Attached
Detach File
Event Timeline