Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
94 KB
Referenced Files
None
Subscribers
None
diff --git a/src/BaseCreatureEntity.cpp b/src/BaseCreatureEntity.cpp
index d237927..45c2a17 100644
--- a/src/BaseCreatureEntity.cpp
+++ b/src/BaseCreatureEntity.cpp
@@ -1,105 +1,102 @@
#include "BaseCreatureEntity.h"
#include "sfml_game/ImageManager.h"
#include "Constants.h"
#include "WitchBlastGame.h"
-BaseCreatureEntity::BaseCreatureEntity(sf::Texture* image, float x = 0.0f, float y = 0.0f, int spriteWidth = -1, int spriteHeight = -1)
- : CollidingSpriteEntity (image, x, y, spriteWidth, spriteHeight)
+BaseCreatureEntity::BaseCreatureEntity(sf::Texture* image, WitchBlastGame* parent, float x = 0.0f, float y = 0.0f, int spriteWidth = -1, int spriteHeight = -1)
+ : CollidingSpriteEntity (image, x, y, spriteWidth, spriteHeight )
{
hurting = false;
shadowFrame = -1;
-}
-
-void BaseCreatureEntity::setParent(WitchBlastGame* parent)
-{
parentGame = parent;
+ setMap(parent->getCurrentMap(), TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
}
int BaseCreatureEntity::getHp()
{
return hp;
}
int BaseCreatureEntity::getHpMax()
{
return hpMax;
}
int BaseCreatureEntity::getHpDisplay()
{
return hpDisplay;
}
void BaseCreatureEntity::animate(float delay)
{
if (hpDisplay > hp) hpDisplay--;
else if (hpDisplay < hp) hpDisplay++;
z = y + height/2;
if (hurting)
{
hurtingDelay -= delay;
if (hurtingDelay > 0.0f)
{
int fadeColor = (sf::Uint8)((HURTING_DELAY - hurtingDelay) * 255);
sprite.setColor(sf::Color(255, fadeColor, fadeColor, 255 ));
}
else
{
hurting = false;
sprite.setColor(sf::Color(255, 255, 255, 255 ));
}
}
CollidingSpriteEntity::animate(delay);
}
void BaseCreatureEntity::render(sf::RenderWindow* app)
{
if (!isDying && shadowFrame > -1)
{
// shadow
sprite.setTextureRect(sf::IntRect(shadowFrame * width, 0, width, height));
app->draw(sprite);
}
CollidingSpriteEntity::render(app);
#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 BaseCreatureEntity::calculateBB()
{
}
bool BaseCreatureEntity::hurt(int damages)
{
hurting = true;
hurtingDelay = HURTING_DELAY;
hp -= damages;
if (hp <= 0)
{
hp = 0;
dying();
}
return true;
}
void BaseCreatureEntity::dying()
{
isDying = true;
}
diff --git a/src/BaseCreatureEntity.h b/src/BaseCreatureEntity.h
index 1f053e8..1169a71 100644
--- a/src/BaseCreatureEntity.h
+++ b/src/BaseCreatureEntity.h
@@ -1,36 +1,35 @@
#ifndef BASECREATUREENTITY_H
#define BASECREATUREENTITY_H
#include "sfml_game/CollidingSpriteEntity.h"
class WitchBlastGame;
class BaseCreatureEntity : public CollidingSpriteEntity
{
public:
- BaseCreatureEntity(sf::Texture* image, float x, float y, int spriteWidth, int spriteHeight);
+ BaseCreatureEntity(sf::Texture* image, WitchBlastGame* parent, float x, float y, int spriteWidth, int spriteHeight);
int getHp();
int getHpMax();
int getHpDisplay();
virtual void animate(float delay);
virtual void render(sf::RenderWindow* app);
virtual void calculateBB();
virtual bool hurt(int damages);
virtual void dying();
- void setParent(WitchBlastGame* parent);
enum enumBloodColor { bloodRed, bloodGreen};
protected:
int hp;
int hpMax;
int hpDisplay;
float creatureSpeed;
int shadowFrame;
bool hurting;
float hurtingDelay;
WitchBlastGame* parentGame;
enumBloodColor bloodColor;
private:
};
#endif // BASECREATUREENTITY_H
diff --git a/src/BatEntity.cpp b/src/BatEntity.cpp
index b9892cc..c4aff08 100644
--- a/src/BatEntity.cpp
+++ b/src/BatEntity.cpp
@@ -1,124 +1,124 @@
#include "BatEntity.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"
-BatEntity::BatEntity(float x, float y, GameMap* map)
- : EnnemyEntity (ImageManager::getImageManager()->getImage(IMAGE_BAT), x, y, map)
+BatEntity::BatEntity(float x, float y, WitchBlastGame* parent)
+ : EnnemyEntity (ImageManager::getImageManager()->getImage(IMAGE_BAT), parent, x, y)
{
creatureSpeed = BAT_SPEED;
velocity = Vector2D(creatureSpeed);
hp = BAT_HP;
meleeDamages = BAT_DAMAGES;
type = ENTITY_ENNEMY;
bloodColor = bloodRed;
changingDelay = -0.5f;
shadowFrame = 3;
}
void BatEntity::animate(float delay)
{
changingDelay -= delay;
if (changingDelay < 0.0f)
{
velocity = Vector2D(creatureSpeed);
changingDelay = 0.5f + (float)(rand() % 2500) / 1000.0f;
}
if (age < 0.0f)
frame = 1;
else
frame = ((int)(age * 5.0f)) % 2;
testSpriteCollisions();
EnnemyEntity::animate(delay);
}
void BatEntity::calculateBB()
{
boundingBox.left = (int)x - width / 2 + BAT_BB_LEFT;
boundingBox.width = width - BAT_BB_WIDTH_DIFF;
boundingBox.top = (int)y - height / 2 + BAT_BB_TOP;
boundingBox.height = height - BAT_BB_HEIGHT_DIFF;
}
void BatEntity::collideMapRight()
{
// if (x > OFFSET_X + MAP_WIDTH * TILE_WIDTH)
velocity.x = -velocity.x;
}
void BatEntity::collideMapLeft()
{
// if (x < OFFSET_X + MAP_WIDTH )
velocity.x = -velocity.x;
}
void BatEntity::collideMapTop()
{
// if (y > OFFSET_Y + MAP_HEIGHT * TILE_HEIGHT)
velocity.y = -velocity.y;
}
void BatEntity::collideMapBottom()
{
// if (y < OFFSET_Y + MAP_HEIGHT )
velocity.y = -velocity.y;
}
bool BatEntity::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 BatEntity::dying()
{
isDying = true;
SpriteEntity* deadBat = new SpriteEntity(ImageManager::getImageManager()->getImage(IMAGE_CORPSES), x, y, 64, 64);
deadBat->setZ(OFFSET_Y);
deadBat->setFrame(FRAME_CORPSE_BAT);
deadBat->setType(ENTITY_CORPSE);
for (int i = 0; i < 4; i++) parentGame->generateBlood(x, y, bloodColor);
drop();
SoundManager::getSoundManager()->playSound(SOUND_ENNEMY_DYING);
}
diff --git a/src/BatEntity.h b/src/BatEntity.h
index c671d33..5af1f61 100644
--- a/src/BatEntity.h
+++ b/src/BatEntity.h
@@ -1,25 +1,25 @@
#ifndef BATSPRITE_H
#define BATSPRITE_H
#include "EnnemyEntity.h"
class BatEntity : public EnnemyEntity
{
public:
- BatEntity(float x, float y, GameMap* map);
+ BatEntity(float x, float y, WitchBlastGame* parent);
virtual void animate(float delay);
virtual void calculateBB();
protected:
virtual bool collideWithMap(int direction);
virtual void collideMapRight();
virtual void collideMapLeft();
virtual void collideMapTop();
virtual void collideMapBottom();
virtual void dying();
private:
float changingDelay;
};
#endif // BATSPRITE_H
diff --git a/src/EnnemyEntity.cpp b/src/EnnemyEntity.cpp
index 8b37163..959aa4f 100644
--- a/src/EnnemyEntity.cpp
+++ b/src/EnnemyEntity.cpp
@@ -1,125 +1,124 @@
#include "EnnemyEntity.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 <iostream>
#include "WitchBlastGame.h"
-EnnemyEntity::EnnemyEntity(sf::Texture* image, float x, float y, GameMap* map)
- : BaseCreatureEntity (image, x, y, 64, 64)
+EnnemyEntity::EnnemyEntity(sf::Texture* image, WitchBlastGame* parent, float x, float y)
+ : BaseCreatureEntity (image, parent, x, y, 64, 64)
{
type = ENTITY_ENNEMY;
bloodColor = bloodRed;
- setMap(map, TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
z = y;
age = -0.001f * (rand()%800) - 0.4f;
}
void EnnemyEntity::animate(float delay)
{
if (canCollide()) testSpriteCollisions();
if (age > 0.0f)
BaseCreatureEntity::animate(delay);
else
age += delay;
}
void EnnemyEntity::calculateBB()
{
boundingBox.left = (int)x - width / 2;
boundingBox.width = width;
boundingBox.top = (int)y - height / 2;
boundingBox.height = height;
}
void EnnemyEntity::collideMapRight()
{
velocity.x = 0.0f;
}
void EnnemyEntity::collideMapLeft()
{
velocity.x = 0.0f;
}
void EnnemyEntity::collideMapTop()
{
velocity.y = 0.0f;
}
void EnnemyEntity::collideMapBottom()
{
velocity.y = 0.0f;
}
void EnnemyEntity::readCollidingEntity(CollidingSpriteEntity* entity)
{
if (collideWithEntity(entity) &&
(entity->getType() == ENTITY_PLAYER || entity->getType() == ENTITY_BOLT ))
{
PlayerEntity* playerEntity = dynamic_cast<PlayerEntity*>(entity);
BoltEntity* boltEntity = dynamic_cast<BoltEntity*>(entity);
if (playerEntity != NULL && !playerEntity->isDead())
{
if (playerEntity->hurt(meleeDamages))
{
float xs = (x + playerEntity->getX()) / 2;
float ys = (y + playerEntity->getY()) / 2;
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 if (boltEntity != NULL && !boltEntity->getDying() && boltEntity->getAge() > 0.05f)
{
boltEntity->collide();
hurt(boltEntity->getDamages());
parentGame->generateBlood(x, y, bloodColor);
SoundManager::getSoundManager()->playSound(SOUND_IMPACT);
float xs = (x + boltEntity->getX()) / 2;
float ys = (y + boltEntity->getY()) / 2;
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);
}
}
}
void EnnemyEntity::dying()
{
isDying = true;
SpriteEntity* deadRat = new SpriteEntity(ImageManager::getImageManager()->getImage(3), x, y, 64, 64);
//deadRat->setZ(y + height);
deadRat->setZ(OFFSET_Y);
deadRat->setFrame(2);
deadRat->setType(13);
}
void EnnemyEntity::drop()
{
if (rand() % 5 == 0)
{
ItemEntity* newItem = new ItemEntity(itemCopperCoin, x, y);
newItem->setMap(map, TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
newItem->setVelocity(Vector2D(100.0f + rand()% 250));
newItem->setViscosity(0.96f);
}
}
bool EnnemyEntity::canCollide()
{
return true;
}
diff --git a/src/EnnemyEntity.h b/src/EnnemyEntity.h
index 5cc8e7e..2e4a229 100644
--- a/src/EnnemyEntity.h
+++ b/src/EnnemyEntity.h
@@ -1,29 +1,29 @@
#ifndef ENNEMYPRITE_H
#define ENNEMYPRITE_H
#include "BaseCreatureEntity.h"
class EnnemyEntity : public BaseCreatureEntity
{
public:
- EnnemyEntity(sf::Texture* image, float x, float y, GameMap* map);
+ EnnemyEntity(sf::Texture* image, WitchBlastGame* parent, float x, float y);
virtual void animate(float delay);
virtual void calculateBB();
protected:
virtual void collideMapRight();
virtual void collideMapLeft();
virtual void collideMapTop();
virtual void collideMapBottom();
virtual void readCollidingEntity(CollidingSpriteEntity* entity);
virtual void dying();
virtual void drop();
virtual bool canCollide();
int meleeDamages;
private:
};
#endif // ENNEMYPRITE_H
diff --git a/src/EvilFlowerEntity.cpp b/src/EvilFlowerEntity.cpp
index 4e62357..470718b 100644
--- a/src/EvilFlowerEntity.cpp
+++ b/src/EvilFlowerEntity.cpp
@@ -1,106 +1,105 @@
#include "EvilFlowerEntity.h"
#include "BoltEntity.h"
#include "EnnemyBoltEntity.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 <math.h>
-EvilFlowerEntity::EvilFlowerEntity(float x, float y, GameMap* map, PlayerEntity* player)
- : EnnemyEntity (ImageManager::getImageManager()->getImage(IMAGE_FLOWER), x, y, map)
+EvilFlowerEntity::EvilFlowerEntity(float x, float y, WitchBlastGame* parent)
+ : EnnemyEntity (ImageManager::getImageManager()->getImage(IMAGE_FLOWER), parent, x, y)
{
hp = EVIL_FLOWER_HP;
meleeDamages = EVIL_FLOWER_MELEE_DAMAGES;
setSpin(50.0f);
frame = 0;
type = 23;
bloodColor = bloodGreen;
//shadowFrame = 2;
fireDelay = EVIL_FLOWER_FIRE_DELAY;
- this->player = player;
age = -1.0f + (rand() % 2500) * 0.001f;
}
void EvilFlowerEntity::animate(float delay)
{
if (fireDelay < 0.7f) setSpin(500.0f);
else if (fireDelay < 1.4f) setSpin(120.0f);
else setSpin(50.0f);
EnnemyEntity::animate(delay);
angle += spin * delay;
if (age > 0.0f)
{
fireDelay -= delay;
if (fireDelay <= 0.0f)
{
fireDelay = EVIL_FLOWER_FIRE_DELAY;
fire();
}
}
}
void EvilFlowerEntity::calculateBB()
{
boundingBox.left = (int)x - width / 2 + EVIL_FLOWER_BB_LEFT;
boundingBox.width = width - EVIL_FLOWER_BB_WIDTH_DIFF;
boundingBox.top = (int)y - height / 2 + EVIL_FLOWER_BB_TOP;
boundingBox.height = height - EVIL_FLOWER_BB_HEIGHT_DIFF;
}
void EvilFlowerEntity::dying()
{
isDying = true;
SpriteEntity* deadFlower = new SpriteEntity(ImageManager::getImageManager()->getImage(IMAGE_CORPSES), x, y, 64, 64);
deadFlower->setZ(OFFSET_Y);
deadFlower->setFrame(FRAME_CORPSE_FLOWER);
deadFlower->setType(ENTITY_CORPSE);
for (int i = 0; i < 4; i++) parentGame->generateBlood(x, y, bloodColor);
drop();
SoundManager::getSoundManager()->playSound(SOUND_ENNEMY_DYING);
}
void EvilFlowerEntity::fire()
{
SoundManager::getSoundManager()->playSound(SOUND_BLAST_FLOWER);
EnnemyBoltEntity* bolt = new EnnemyBoltEntity
(ImageManager::getImageManager()->getImage(IMAGE_BOLT), x, y + 10);
bolt->setFrame(1);
bolt->setMap(map, TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
bolt->setVelocity(Vector2D(200.0f, 0.0f));
- float tan = (player->getX() - x) / (player->getY() - y);
+ float tan = (parentGame->getPlayer()->getX() - x) / (parentGame->getPlayer()->getY() - y);
float angle = atan(tan);
- if (player->getY() > y)
+ if (parentGame->getPlayer()->getY() > y)
bolt->setVelocity(Vector2D(sin(angle) * EVIL_FLOWER_FIRE_VELOCITY,
cos(angle) * EVIL_FLOWER_FIRE_VELOCITY));
else
bolt->setVelocity(Vector2D(-sin(angle) * EVIL_FLOWER_FIRE_VELOCITY,
-cos(angle) * EVIL_FLOWER_FIRE_VELOCITY));
}
void EvilFlowerEntity::render(sf::RenderWindow* app)
{
sprite.setPosition(x, y);
float savedAngle = sprite.getRotation();
sprite.setRotation(0.0f);
// shadow
sprite.setTextureRect(sf::IntRect(width * 2, 0, width, height));
app->draw(sprite);
sprite.setTextureRect(sf::IntRect(width, 0, width, height));
app->draw(sprite);
sprite.setRotation(savedAngle);
EnnemyEntity::render(app);
}
diff --git a/src/EvilFlowerEntity.h b/src/EvilFlowerEntity.h
index d70e37c..1866561 100644
--- a/src/EvilFlowerEntity.h
+++ b/src/EvilFlowerEntity.h
@@ -1,22 +1,21 @@
#ifndef EVILFLOWER_H
#define EVILFLOWER_H
#include "EnnemyEntity.h"
#include "PlayerEntity.h"
class EvilFlowerEntity : public EnnemyEntity
{
public:
- EvilFlowerEntity(float x, float y, GameMap* map, PlayerEntity* player);
+ EvilFlowerEntity(float x, float y, WitchBlastGame* parent);
virtual void animate(float delay);
virtual void calculateBB();
virtual void render(sf::RenderWindow* app);
void fire();
protected:
virtual void dying();
private:
float fireDelay;
- PlayerEntity* player;
};
#endif // EVILFLOWER_H
diff --git a/src/GreenRatEntity.cpp b/src/GreenRatEntity.cpp
index 4f5be2a..a7cd6a5 100644
--- a/src/GreenRatEntity.cpp
+++ b/src/GreenRatEntity.cpp
@@ -1,100 +1,99 @@
#include "GreenRatEntity.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"
-GreenRatEntity::GreenRatEntity(float x, float y, GameMap* map, PlayerEntity* player)
- : EnnemyEntity (ImageManager::getImageManager()->getImage(IMAGE_RAT), x, y, map)
+GreenRatEntity::GreenRatEntity(float x, float y, WitchBlastGame* parent)
+ : EnnemyEntity (ImageManager::getImageManager()->getImage(IMAGE_RAT), parent, x, y)
{
imagesProLine = 4;
creatureSpeed = GREEN_RAT_SPEED;
velocity = Vector2D(creatureSpeed);
hp = GREEN_RAT_HP;
meleeDamages = GREEN_RAT_DAMAGES;
type = ENTITY_ENNEMY_INVOCATED;
bloodColor = bloodRed;
shadowFrame = 3;
timer = (rand() % 50) / 10.0f;
age = -GREEN_RAT_FADE;
frame = 4;
- this->player = player;
}
void GreenRatEntity::animate(float delay)
{
z = y + boundingBox.top + boundingBox.height;
if (age > 0.0f)
{
sprite.setColor(sf::Color(255,255,255,255));
frame = 4 + ((int)(age * 5.0f)) % 2;
timer = timer - delay;
if (timer <= 0.0f)
{
timer = (rand() % 50) / 10.0f;
- float tan = (player->getX() - x) / (player->getY() - y);
+ float tan = (parentGame->getPlayer()->getX() - x) / (parentGame->getPlayer()->getY() - y);
float angle = atan(tan);
- if (player->getY() > y)
+ if (parentGame->getPlayer()->getY() > y)
setVelocity(Vector2D(sin(angle) * RAT_SPEED,
cos(angle) * RAT_SPEED));
else
setVelocity(Vector2D(-sin(angle) * RAT_SPEED,
-cos(angle) * RAT_SPEED));
}
}
else
{
sprite.setColor(sf::Color(255,255,255,255 * (1.0 + age)));
}
EnnemyEntity::animate(delay);
}
void GreenRatEntity::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 GreenRatEntity::collideMapRight()
{
velocity.x = -velocity.x;
}
void GreenRatEntity::collideMapLeft()
{
velocity.x = -velocity.x;
}
void GreenRatEntity::collideMapTop()
{
velocity.y = -velocity.y;
}
void GreenRatEntity::collideMapBottom()
{
velocity.y = -velocity.y;
}
void GreenRatEntity::dying()
{
isDying = true;
SpriteEntity* deadRat = new SpriteEntity(ImageManager::getImageManager()->getImage(IMAGE_CORPSES), x, y, 64, 64);
deadRat->setZ(OFFSET_Y);
deadRat->setFrame(FRAME_CORPSE_GREEN_RAT);
deadRat->setType(ENTITY_CORPSE);
for (int i = 0; i < 4; i++) parentGame->generateBlood(x, y, bloodColor);
//drop();
SoundManager::getSoundManager()->playSound(SOUND_ENNEMY_DYING);
}
diff --git a/src/GreenRatEntity.h b/src/GreenRatEntity.h
index 572fd8f..0554544 100644
--- a/src/GreenRatEntity.h
+++ b/src/GreenRatEntity.h
@@ -1,26 +1,24 @@
#ifndef GREENRATSPRITE_H
#define GREENRATSPRITE_H
#include "EnnemyEntity.h"
#include "PlayerEntity.h"
class GreenRatEntity : public EnnemyEntity
{
public:
- GreenRatEntity(float x, float y, GameMap* map, PlayerEntity* player);
+ GreenRatEntity(float x, float y, WitchBlastGame* parent);
virtual void animate(float delay);
virtual void calculateBB();
protected:
virtual void collideMapRight();
virtual void collideMapLeft();
virtual void collideMapTop();
virtual void collideMapBottom();
- //virtual void readCollidingEntity(CollidingSpriteEntity* entity);
virtual void dying();
private:
float timer;
- PlayerEntity* player;
};
#endif // GREENRATSPRITE_H
diff --git a/src/KingRatEntity.cpp b/src/KingRatEntity.cpp
index 6086e2a..3988a00 100644
--- a/src/KingRatEntity.cpp
+++ b/src/KingRatEntity.cpp
@@ -1,351 +1,350 @@
#include "KingRatEntity.h"
#include "GreenRatEntity.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"
#include "StaticTextEntity.h"
#include <iostream>
-KingRatEntity::KingRatEntity(float x, float y, GameMap* map, PlayerEntity* player)
- : EnnemyEntity (ImageManager::getImageManager()->getImage(IMAGE_KING_RAT), x, y, map)
+KingRatEntity::KingRatEntity(float x, float y, WitchBlastGame* parent)
+ : EnnemyEntity (ImageManager::getImageManager()->getImage(IMAGE_KING_RAT), parent, x, y)
{
width = 128;
height = 128;
creatureSpeed = KING_RAT_SPEED;
velocity = Vector2D(creatureSpeed);
hp = KING_RAT_HP;
hpDisplay = hp;
hpMax = KING_RAT_HP;
meleeDamages = KING_RAT_DAMAGES;
type = ENTITY_ENNEMY_BOSS;
bloodColor = bloodRed;
shadowFrame = 4;
frame = 0;
sprite.setOrigin(64.0f, 64.0f);
- this->player = player;
state = 0;
timer = 2.0f + (rand() % 40) / 10.0f;
age = 0.0f;
berserkDelay = 1.0f + rand()%5 * 0.1f;
hasBeenBerserk = false;
}
void KingRatEntity::animate(float delay)
{
float timerMult = 1.0f;
if (hp <= hpMax / 4)
{
creatureSpeed = KING_RAT_SPEED * 1.4f;
timerMult = 0.7f;
}
else if (hp <= hpMax / 2)
{
creatureSpeed = KING_RAT_SPEED * 1.2f;
timerMult = 0.85f;
}
else
{
creatureSpeed = KING_RAT_SPEED;
}
if (state == 5)
{
velocity.x *= 0.965f;
velocity.y *= 0.965f;
}
else
{
if (velocity.x > 0.1f) sprite.setScale(-1.0f, 1.0f);
else if (velocity.x < -0.1f) sprite.setScale(1.0f, 1.0f);
}
timer -= delay;
if (timer <= 0.0f)
{
if (state == 0)
{
state = 1;
// generate rats
generateGreenRats();
SoundManager::getSoundManager()->playSound(SOUND_KING_RAT_1);
timer = 2.0f;
velocity.x = 0.0f;
velocity.y = 0.0f;
}
else if (state == 1) // generate rats
{
// to normal or berserk
if (hp < hpMax / 4 && !hasBeenBerserk)
{
hasBeenBerserk = true;
timer = 12.0f;
state = 6;
velocity = Vector2D(KING_RAT_BERSERK_SPEED);
SoundManager::getSoundManager()->playSound(SOUND_KING_RAT_2);
}
else
{
timer = 7.0f * timerMult;
velocity = Vector2D(creatureSpeed);
state = 2;
}
}
else if (state == 2) // normal -> rush
{
state = 3;
// angry
timer = 2.0f;
velocity.x = 0.0f;
velocity.y = 0.0f;
SoundManager::getSoundManager()->playSound(SOUND_KING_RAT_2);
}
else if (state == 3) // normal -> rush
{
state = 4;
// rush
timer = 12.0f;
- float tan = (player->getX() - x) / (player->getY() - y);
+ float tan = (parentGame->getPlayer()->getX() - x) / (parentGame->getPlayer()->getY() - y);
float angle = atan(tan);
- if (player->getY() > y)
+ if (parentGame->getPlayer()->getY() > y)
setVelocity(Vector2D(sin(angle) * KING_RAT_RUNNING_SPEED,
cos(angle) * KING_RAT_RUNNING_SPEED));
else
setVelocity(Vector2D(-sin(angle) * KING_RAT_RUNNING_SPEED,
-cos(angle) * KING_RAT_RUNNING_SPEED));
}
else if (state == 5) // wall impact
{
// to normal or berserk
if (hp < hpMax / 4 && !hasBeenBerserk)
{
hasBeenBerserk = true;
timer = 12.0f;
state = 6;
velocity = Vector2D(KING_RAT_BERSERK_SPEED);
SoundManager::getSoundManager()->playSound(SOUND_KING_RAT_2);
}
else
{
timer = 7.0f * timerMult;
velocity = Vector2D(creatureSpeed);
state = 0;
}
}
else if (state == 6)
{
timer = 7.0f * timerMult;
velocity = Vector2D(creatureSpeed);
state = 0;
}
}
if (state == 6)
{
berserkDelay -= delay;
if (berserkDelay <= 0.0f)
{
berserkDelay = 0.8f + (rand()%10) / 10.0f;
SoundManager::getSoundManager()->playSound(SOUND_KING_RAT_2);
- float tan = (player->getX() - x) / (player->getY() - y);
+ float tan = (parentGame->getPlayer()->getX() - x) / (parentGame->getPlayer()->getY() - y);
float angle = atan(tan);
- if (player->getY() > y)
+ if (parentGame->getPlayer()->getY() > y)
setVelocity(Vector2D(sin(angle) * KING_RAT_BERSERK_SPEED,
cos(angle) * KING_RAT_BERSERK_SPEED));
else
setVelocity(Vector2D(-sin(angle) * KING_RAT_BERSERK_SPEED,
-cos(angle) * KING_RAT_BERSERK_SPEED));
}
}
frame = 0;
if (state == 1)
frame = 3;
else if (state == 3 || state == 6)
{
frame = 3; //0;
int r = ((int)(age * 10.0f)) % 2;
if (r == 0)
sprite.setScale(-1.0f, 1.0f);
else
sprite.setScale(1.0f, 1.0f);
}
else if (state == 4)
{
int r = ((int)(age * 7.5f)) % 4;
if (r == 1) frame = 1;
else if (r == 3) frame = 2;
}
else if (state == 5)
{
frame = 0;
}
else
{
int r = ((int)(age * 5.0f)) % 4;
if (r == 1) frame = 1;
else if (r == 3) frame = 2;
}
EnnemyEntity::animate(delay);
}
bool KingRatEntity::hurt(int damages)
{
hurting = true;
hurtingDelay = HURTING_DELAY;
if (state == 6)
hp -= damages / 4;
else
hp -= damages;
if (hp <= 0)
{
hp = 0;
dying();
}
return true;
}
void KingRatEntity::calculateBB()
{
boundingBox.left = (int)x - width / 2 + 25;
boundingBox.width = width - 50;
boundingBox.top = (int)y - height / 2 + 25;
boundingBox.height = height - 35;
}
void KingRatEntity::afterWallCollide()
{
if (state == 4)
{
state = 5;
timer = 1.4f;
velocity.x *= 0.75f;
velocity.y *= 0.75f;
//velocity = Vector2D(creatureSpeed);
SoundManager::getSoundManager()->playSound(SOUND_BIG_WALL_IMPACT);
}
}
void KingRatEntity::collideMapRight()
{
velocity.x = -velocity.x;
afterWallCollide();
}
void KingRatEntity::collideMapLeft()
{
velocity.x = -velocity.x;
afterWallCollide();
}
void KingRatEntity::collideMapTop()
{
velocity.y = -velocity.y;
afterWallCollide();
}
void KingRatEntity::collideMapBottom()
{
velocity.y = -velocity.y;
afterWallCollide();
}
void KingRatEntity::dying()
{
isDying = true;
SpriteEntity* deadRat = new SpriteEntity(ImageManager::getImageManager()->getImage(IMAGE_CORPSES_BIG), x, y, 128, 128);
deadRat->setZ(OFFSET_Y);
deadRat->setFrame(FRAME_CORPSE_KING_RAT - FRAME_CORPSE_KING_RAT);
deadRat->setType(ENTITY_CORPSE);
for (int i = 0; i < 10; i++) parentGame->generateBlood(x, y, bloodColor);
SoundManager::getSoundManager()->playSound(SOUND_KING_RAT_DIE);
}
void KingRatEntity::generateGreenRats()
{
for (int i = 0; i < 5; i++)
{
float xr = x + -100 + rand() % 200;
float yr = y + -100 + rand() % 200;
if (xr > OFFSET_X + TILE_WIDTH * 1.5f && xr < OFFSET_X + TILE_WIDTH * (MAP_WIDTH - 2)
&& yr > OFFSET_Y + TILE_HEIGHT * 1.5f && yr < OFFSET_Y + TILE_HEIGHT * (MAP_HEIGHT - 2))
{
- new GreenRatEntity(xr, yr, map, player);
+ new GreenRatEntity(xr, yr, parentGame);
}
else
i--;
}
}
void KingRatEntity::render(sf::RenderWindow* app)
{
EnnemyEntity::render(app);
if (state == 6)
{
int r = ((int)(age *12.0f)) % 2;
if (r == 0)
sprite.setTextureRect(sf::IntRect(1 * width, 1 * height, width, height));
else
sprite.setTextureRect(sf::IntRect(2 * width, 1 * height, -width, height));
sprite.setPosition(x, y);
sprite.setColor(sf::Color(255, 255, 255, 190));
app->draw(sprite);
sprite.setColor(sf::Color(255, 255, 255, 255));
}
float l = hpDisplay * ((MAP_WIDTH - 1) * TILE_WIDTH) / KING_RAT_HP;
sf::RectangleShape rectangle(sf::Vector2f((MAP_WIDTH - 1) * TILE_WIDTH, 25));
rectangle.setFillColor(sf::Color(0, 0, 0,128));
rectangle.setPosition(sf::Vector2f(OFFSET_X + TILE_WIDTH / 2, OFFSET_Y + 25 + (MAP_HEIGHT - 1) * TILE_HEIGHT));
app->draw(rectangle);
rectangle.setSize(sf::Vector2f(l, 25));
rectangle.setFillColor(sf::Color(190, 20, 20));
rectangle.setPosition(sf::Vector2f(OFFSET_X + TILE_WIDTH / 2, OFFSET_Y + 25 + (MAP_HEIGHT - 1) * TILE_HEIGHT));
app->draw(rectangle);
StaticTextEntity::Write(app,
"Rat King",
18,
OFFSET_X + TILE_WIDTH / 2 + 10.0f,
OFFSET_Y + 25 + (MAP_HEIGHT - 1) * TILE_HEIGHT + 1.0f,
ALIGN_LEFT,
sf::Color(255, 255, 255));
}
diff --git a/src/KingRatEntity.h b/src/KingRatEntity.h
index ef84fd4..6960703 100644
--- a/src/KingRatEntity.h
+++ b/src/KingRatEntity.h
@@ -1,34 +1,33 @@
#ifndef KINGRATSPRITE_H
#define KINGRATSPRITE_H
#include "EnnemyEntity.h"
#include "PlayerEntity.h"
class KingRatEntity : public EnnemyEntity
{
public:
- KingRatEntity(float x, float y, GameMap* map, PlayerEntity* player);
+ KingRatEntity(float x, float y, WitchBlastGame* parent);
virtual void animate(float delay);
virtual void render(sf::RenderWindow* app);
virtual void calculateBB();
protected:
virtual void collideMapRight();
virtual void collideMapLeft();
virtual void collideMapTop();
virtual void collideMapBottom();
void afterWallCollide();
virtual bool hurt(int damages);
void generateGreenRats();
//virtual void readCollidingEntity(CollidingSpriteEntity* entity);
virtual void dying();
private:
float timer;
float berserkDelay;
int state;
bool hasBeenBerserk;
- PlayerEntity* player;
};
#endif // KINGRATSPRITE_H
diff --git a/src/PlayerEntity.cpp b/src/PlayerEntity.cpp
index 3a4f433..c0cabe2 100644
--- a/src/PlayerEntity.cpp
+++ b/src/PlayerEntity.cpp
@@ -1,575 +1,576 @@
#include "PlayerEntity.h"
#include "BoltEntity.h"
#include "EnnemyBoltEntity.h"
#include "ItemEntity.h"
#include "FairyEntity.h"
#include "sfml_game/ImageManager.h"
#include "sfml_game/SoundManager.h"
#include "Constants.h"
#include "WitchBlastGame.h"
#include <iostream>
-PlayerEntity::PlayerEntity(sf::Texture* image, float x = 0.0f, float y = 0.0f) : BaseCreatureEntity (image, x, y, 64, 96)
+PlayerEntity::PlayerEntity(sf::Texture* image, WitchBlastGame* parent, float x = 0.0f, float y = 0.0f)
+ : BaseCreatureEntity (image, parent, x, y, 64, 96)
{
currentFireDelay = -1.0f;
canFirePlayer = true;
type = ENTITY_PLAYER;
imagesProLine = 8;
playerStatus = playerStatusPlaying;
hp = INITIAL_PLAYER_HP;
hpDisplay = hp;
hpMax = INITIAL_PLAYER_HP;
gold = 0;
boltLifeTime = INITIAL_BOLT_LIFE;
bloodColor = bloodRed;
for (int i = 0; i < NUMBER_EQUIP_ITEMS; i++) equip[i] = false;
colliding = 0;
computePlayer();
// TEST
//equip[EQUIP_BOSS_KEY] = true;
}
void PlayerEntity::moveTo(float newX, float newY)
{
float dx = newX - x;
float dy = newY - y;
x = newX;
y = newY;
if (equip[EQUIP_FAIRY])
{
fairy->setX(fairy->getX() + dx);
fairy->setY(fairy->getY() + dy);
}
}
float PlayerEntity::getPercentFireDelay()
{
if (canFirePlayer) return 1.0f;
else return (1.0f - currentFireDelay / fireDelay);
}
int PlayerEntity::getColliding()
{
return colliding;
}
bool PlayerEntity::isDead()
{
return playerStatus==playerStatusDead;
}
void PlayerEntity::setEntering()
{
playerStatus = playerStatusEntering;
}
void PlayerEntity::pay(int price)
{
gold -= price;
if (gold < 0) gold = 0;
SoundManager::getSoundManager()->playSound(SOUND_PAY);
}
void PlayerEntity::animate(float delay)
{
// rate of fire
if (!canFirePlayer)
{
currentFireDelay -= delay;
canFirePlayer = (currentFireDelay <= 0.0f);
}
// acquisition animation
if (playerStatus == playerStatusAcquire)
{
acquireDelay -= delay;
if (acquireDelay <= 0.0f)
{
equip[acquiredItem] = true;
computePlayer();
playerStatus = playerStatusPlaying;
if (acquiredItem == (int)EQUIP_FAIRY)
{
fairy = new FairyEntity(x, y - 50.0f, this);
}
}
}
else if (playerStatus == playerStatusUnlocking)
{
acquireDelay -= delay;
if (acquireDelay <= 0.0f)
{
playerStatus = playerStatusPlaying;
}
}
//z = y;
if (playerStatus != playerStatusDead) testSpriteCollisions();
colliding = 0;
BaseCreatureEntity::animate(delay);
if (isMoving())
{
frame = ((int)(age * 5.0f)) % 4;
if (frame == 2) frame = 0;
if (frame == 3) frame = 2;
SoundManager::getSoundManager()->playSound(SOUND_STEP);
}
else if (playerStatus == playerStatusAcquire || playerStatus == playerStatusUnlocking)
frame = 3;
else if (playerStatus == playerStatusDead)
frame = 0;
else
frame = 0;
if (x < OFFSET_X)
parentGame->moveToOtherMap(4);
else if (x > OFFSET_X + MAP_WIDTH * TILE_WIDTH)
parentGame->moveToOtherMap(6);
else if (y < OFFSET_Y)
parentGame->moveToOtherMap(8);
else if (y > OFFSET_Y + MAP_HEIGHT * TILE_HEIGHT - 5)
parentGame->moveToOtherMap(2);
if (playerStatus == playerStatusEntering)
{
if (boundingBox.left > OFFSET_X + TILE_WIDTH
&& (boundingBox.left + boundingBox.width) < OFFSET_X + TILE_WIDTH * (MAP_WIDTH - 1)
&& boundingBox.top > OFFSET_Y + TILE_HEIGHT
&& (boundingBox.top + boundingBox.height) < OFFSET_Y + TILE_HEIGHT * (MAP_HEIGHT - 1))
{
playerStatus = playerStatusPlaying;
parentGame->closeDoors();
}
}
if (playerStatus == playerStatusDead)
{
z = OFFSET_Y - 2;
}
}
void PlayerEntity::render(sf::RenderWindow* app)
{
sprite.setPosition(x, y);
if (playerStatus == playerStatusDead)
{
// blood
sprite.setTextureRect(sf::IntRect(6 * width, 0, width, height));
app->draw(sprite);
// body
sprite.setTextureRect(sf::IntRect(3 * width, height, width, height));
app->draw(sprite);
// feet
sprite.setTextureRect(sf::IntRect(3 * width, 2 * height, width, height));
app->draw(sprite);
// hand
sprite.setTextureRect(sf::IntRect(3 * width, 3 * height, width, height));
app->draw(sprite);
}
else
{
// shadow
sprite.setTextureRect(sf::IntRect(7 * width, 0, width, height));
app->draw(sprite);
// body
sprite.setTextureRect(sf::IntRect(frame * width, height, width, height));
app->draw(sprite);
// belt
if (equip[EQUIP_LEATHER_BELT])
{
sprite.setTextureRect(sf::IntRect(frame * width, 6 *height, width, height));
app->draw(sprite);
}
// head
if (playerStatus != playerStatusAcquire && playerStatus != playerStatusUnlocking)
{
sprite.setTextureRect(sf::IntRect(0, 0, width, height));
app->draw(sprite);
// hat
if (equip[EQUIP_ENCHANTER_HAT])
{
sprite.setTextureRect(sf::IntRect(3 * width, 0, width, height));
app->draw(sprite);
}
}
// feet
if( equip[EQUIP_LEATHER_BOOTS])
sprite.setTextureRect(sf::IntRect((frame + 4) * width, 2 * height, width, height));
else
sprite.setTextureRect(sf::IntRect(frame * width, 2 * height, width, height));
app->draw(sprite);
// staff
if ( equip[EQUIP_MAHOGANY_STAFF])
sprite.setTextureRect(sf::IntRect((frame + 4) * width + 4, 4 * height, width, height));
else
sprite.setTextureRect(sf::IntRect(frame * width + 4, 4 * height, width, height));
app->draw(sprite);
// snake
if (equip[EQUIP_BLOOD_SNAKE])
{
sprite.setTextureRect(sf::IntRect(frame * width + 4, 7 *height, width, height));
app->draw(sprite);
}
// hands
if( equip[EQUIP_VIBRATION_GLOVES])
sprite.setTextureRect(sf::IntRect((frame + 4) * width, 3 * height, width, height));
else
sprite.setTextureRect(sf::IntRect(frame * width, 3 * height, width, height));
app->draw(sprite);
// head
if (playerStatus == playerStatusAcquire || playerStatus == playerStatusUnlocking)
{
sprite.setTextureRect(sf::IntRect(width, 0, width, height));
app->draw(sprite);
// hat
if (equip[EQUIP_ENCHANTER_HAT])
{
sprite.setTextureRect(sf::IntRect(3 * width, 0, width, height));
app->draw(sprite);
}
// staff
//sprite.setTextureRect(sf::IntRect(width * 1, 4 * height, width, height));
//app->draw(sprite);
if ( equip[EQUIP_MAHOGANY_STAFF])
sprite.setTextureRect(sf::IntRect(5 * width + 4, 4 * height, width, height));
else
sprite.setTextureRect(sf::IntRect(width + 4, 4 * height, width, height));
app->draw(sprite);
// snake
if (equip[EQUIP_BLOOD_SNAKE])
{
sprite.setTextureRect(sf::IntRect(1 * width, 7 *height, width, height));
app->draw(sprite);
}
}
// necklace
if (equip[EQUIP_CONCENTRATION_AMULET])
{
sprite.setTextureRect(sf::IntRect(frame * width, 5 * height, width, height));
app->draw(sprite);
sprite.setColor(sf::Color(255,255,255, (1.0f + sin(age * 5.0f)) * 100));
sprite.setTextureRect(sf::IntRect(5 * width, 0, width, height));
app->draw(sprite);
sprite.setColor(sf::Color(255,255,255,255));
}
}
}
void PlayerEntity::calculateBB()
{
boundingBox.left = (int)x - width / 2;
boundingBox.width = width;
boundingBox.top = (int)y - height / 2;
boundingBox.height = height;
float fPrez = 10.0f;
boundingBox.left += fPrez;
boundingBox.width -= (fPrez + fPrez);
boundingBox.top += 52.0f;
boundingBox.height = boundingBox.width - 10.0f;
}
void PlayerEntity::readCollidingEntity(CollidingSpriteEntity* entity)
{
EnnemyBoltEntity* boltEntity = dynamic_cast<EnnemyBoltEntity*>(entity);
if (collideWithEntity(entity))
{
if (boltEntity != NULL && !boltEntity->getDying())
{
boltEntity->collide();
hurt(boltEntity->getDamages());
parentGame->generateBlood(x, y, bloodColor);
}
}
}
void PlayerEntity::move(int direction)
{
if (playerStatus == playerStatusPlaying)
{
float speedx = 0.0f, speedy = 0.0f;
if (direction == 1 || direction == 4 || direction == 7)
speedx = - creatureSpeed;
else if (direction == 3 || direction == 6 || direction == 9)
speedx = creatureSpeed;
if (direction == 1 || direction == 2 || direction == 3)
speedy = creatureSpeed;
else if (direction == 7 || direction == 8 || direction == 9)
speedy = - creatureSpeed;
setVelocity(Vector2D(speedx, speedy));
}
}
bool PlayerEntity::isMoving()
{
if (velocity.x < -1.0f || velocity.x > 1.0f) return true;
if (velocity.y < -1.0f || velocity.y > 1.0f) return true;
return false;
}
bool PlayerEntity::isEquiped(int eq)
{
return equip[eq];
}
void PlayerEntity::generateBolt(float velx, float vely)
{
BoltEntity* bolt = new BoltEntity(ImageManager::getImageManager()->getImage(1), x, y + 20, boltLifeTime);
bolt->setMap(map, TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
bolt->setDamages(fireDamages);
bolt->setVelocity(Vector2D(velx, vely));
}
void PlayerEntity::fire(int direction)
{
if (equip[EQUIP_FAIRY] && playerStatus != playerStatusDead)
fairy->fire(direction, map);
if (canFirePlayer && playerStatus != playerStatusDead)
{
SoundManager::getSoundManager()->playSound(SOUND_BLAST_STANDARD);
if (equip[EQUIP_BOOK_DUAL])
{
float shoot_angle = 0.2f;
if ((direction == 4 && velocity.x < -1.0f) || (direction == 6 && velocity.x > 1.0f)
|| (direction == 8 && velocity.y < -1.0f) || (direction == 2 && velocity.y > 1.0f))
shoot_angle = 0.1f;
else if ((direction == 6 && velocity.x < -1.0f) || (direction == 4 && velocity.x > 1.0f)
|| (direction == 2 && velocity.y < -1.0f) || (direction == 8 && velocity.y > 1.0f))
shoot_angle = 0.35f;
if (equip[EQUIP_VIBRATION_GLOVES]) shoot_angle += (1000 - rand() % 2000) * 0.0001f;
switch(direction)
{
case 4: generateBolt(-fireVelocity * cos(shoot_angle), fireVelocity * sin(shoot_angle));
generateBolt(-fireVelocity * cos(shoot_angle), - fireVelocity * sin(shoot_angle));break;
case 6: generateBolt(fireVelocity * cos(shoot_angle), fireVelocity * sin(shoot_angle));
generateBolt(fireVelocity * cos(shoot_angle), - fireVelocity * sin(shoot_angle));break;
case 8: generateBolt(fireVelocity * sin(shoot_angle), -fireVelocity * cos(shoot_angle));
generateBolt(-fireVelocity * sin(shoot_angle), - fireVelocity * cos(shoot_angle));break;
case 2: generateBolt(fireVelocity * sin(shoot_angle), fireVelocity * cos(shoot_angle));
generateBolt(-fireVelocity * sin(shoot_angle), fireVelocity * cos(shoot_angle));break;
}
}
else
{
if (equip[EQUIP_VIBRATION_GLOVES])
{
float shoot_angle = (1000 - rand() % 2000) * 0.0001f;
switch(direction)
{
case 4: generateBolt(-fireVelocity * cos(shoot_angle), fireVelocity * sin(shoot_angle)); break;
case 6: generateBolt(fireVelocity * cos(shoot_angle), fireVelocity * sin(shoot_angle)); break;
case 8: generateBolt(fireVelocity * sin(shoot_angle), -fireVelocity * cos(shoot_angle)); break;
case 2: generateBolt(fireVelocity * sin(shoot_angle), fireVelocity * cos(shoot_angle)); break;
}
}
else
{
switch(direction)
{
case 4: generateBolt(-fireVelocity, 0.0f); break;
case 6: generateBolt(fireVelocity, 0.0f); break;
case 8: generateBolt(0.0f, -fireVelocity); break;
case 2: generateBolt(0.0f, fireVelocity); break;
}
}
}
canFirePlayer = false;
currentFireDelay = fireDelay;
}
}
bool PlayerEntity::canFire()
{
return canFirePlayer;
}
bool PlayerEntity::canMove()
{
return (playerStatus == playerStatusPlaying);
}
bool PlayerEntity::hurt(int damages)
{
if (!hurting)
{
SoundManager::getSoundManager()->playSound(SOUND_PLAYER_HIT);
BaseCreatureEntity::hurt(damages);
parentGame->generateBlood(x, y, bloodColor);
parentGame->generateBlood(x, y, bloodColor);
return true;
}
return false;
}
void PlayerEntity::loseItem(enumItemType itemType, bool isEquip)
{
CollidingSpriteEntity* itemSprite
= new CollidingSpriteEntity(ImageManager::getImageManager()->getImage(isEquip ? IMAGE_ITEMS_EQUIP : IMAGE_ITEMS), x, y, 32, 32);
itemSprite->setMap(map, TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
itemSprite->setZ(OFFSET_Y - 1);
itemSprite->setFrame(itemType);
itemSprite->setType(ENTITY_BLOOD);
itemSprite->setVelocity(Vector2D(rand()%450));
itemSprite->setViscosity(0.95f);
itemSprite->setSpin( (rand() % 700) - 350.0f);
}
void PlayerEntity::dying()
{
playerStatus = playerStatusDead;
hp = 0;
SoundManager::getSoundManager()->playSound(SOUND_PLAYER_DIE);
setVelocity(Vector2D(0.0f, 0.0f));
int i;
for (i = 0; i < gold; i++) loseItem(itemCopperCoin, false);
for (i = 0; i < NUMBER_EQUIP_ITEMS; i++)
if (equip[i]) loseItem(enumItemType(i), true);
for (i = 0; i < 8; i++) parentGame->generateBlood(x, y, bloodColor);
CollidingSpriteEntity* itemSprite
= new CollidingSpriteEntity(ImageManager::getImageManager()->getImage(IMAGE_PLAYER), x, y, 64, 64);
itemSprite->setMap(map, TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
itemSprite->setZ(OFFSET_Y - 1);
itemSprite->setImagesProLine(10);
itemSprite->setFrame(/*11*/1);
itemSprite->setType(ENTITY_BLOOD);
itemSprite->setVelocity(Vector2D(rand()%450));
itemSprite->setViscosity(0.95f);
itemSprite->setSpin( (rand() % 700) - 350.0f);
}
void PlayerEntity::acquireItem(enumItemType type)
{
if (type >= itemMagicianHat) acquireStance(type);
else switch (type)
{
case itemCopperCoin: gold++;
SoundManager::getSoundManager()->playSound(SOUND_COIN_PICK_UP);
break;
case itemSilverCoin: gold = gold + 5; break;
case itemGoldCoin: gold = gold + 10; break;
case itemHealth: hp += 15;
SoundManager::getSoundManager()->playSound(SOUND_DRINK);
if (hp > hpMax) hp = hpMax; break;
default: break;
}
}
void PlayerEntity::computePlayer()
{
float boltLifeTimeBonus = 1.0f;
float fireDelayBonus = 1.0f;
float creatureSpeedBonus = 1.0f;
float fireVelocityBonus = 1.0f;
float fireDamagesBonus = 1.0f;
if (equip[EQUIP_VIBRATION_GLOVES]) fireDelayBonus -= 0.10f;
if (equip[EQUIP_ENCHANTER_HAT]) fireDelayBonus -= 0.2f;
if (equip[EQUIP_LEATHER_BELT]) fireDelayBonus -= 0.15f;
if (equip[EQUIP_LEATHER_BOOTS]) creatureSpeedBonus += 0.25f;
if (equip[EQUIP_BOOK_DUAL]) fireDelayBonus += 0.6f;
if (equip[EQUIP_CONCENTRATION_AMULET]) boltLifeTimeBonus += 0.5f;
if (equip[EQUIP_MAHOGANY_STAFF])
{
fireVelocityBonus += 0.15f;
fireDamagesBonus += 0.5f;
}
if (equip[EQUIP_BLOOD_SNAKE]) fireDamagesBonus += 1.0f;
fireDelay = INITIAL_PLAYER_FIRE_DELAY * fireDelayBonus;
creatureSpeed = INITIAL_PLAYER_SPEED * creatureSpeedBonus;
fireVelocity = INITIAL_BOLT_VELOCITY * fireVelocityBonus;
fireDamages = INITIAL_BOLT_DAMAGES * fireDamagesBonus;
boltLifeTime = INITIAL_BOLT_LIFE * boltLifeTimeBonus;
}
void PlayerEntity::acquireStance(enumItemType type)
{
velocity.x = 0.0f;
velocity.y = 0.0f;
playerStatus = playerStatusAcquire;
acquireDelay = ACQUIRE_DELAY;
acquiredItem = (enumItemType)(type - itemMagicianHat);
SoundManager::getSoundManager()->playSound(SOUND_BONUS);
}
void PlayerEntity::collideMapRight()
{
colliding = 6;
}
void PlayerEntity::collideMapLeft()
{
colliding = 4;
}
void PlayerEntity::collideMapTop()
{
colliding = 8;
}
void PlayerEntity::collideMapBottom()
{
colliding = 2;
}
void PlayerEntity::useBossKey()
{
velocity.x = 0.0f;
velocity.y = 0.0f;
playerStatus = playerStatusUnlocking;
acquireDelay = UNLOCK_DELAY;
acquiredItem = (enumItemType)(type - itemMagicianHat);
SoundManager::getSoundManager()->playSound(SOUND_BONUS);
equip[EQUIP_BOSS_KEY] = false;
SpriteEntity* spriteItem = new SpriteEntity(
ImageManager::getImageManager()->getImage(IMAGE_ITEMS_EQUIP),
x, y - 60.0f, ITEM_WIDTH, ITEM_HEIGHT);
spriteItem->setFrame(EQUIP_BOSS_KEY);
spriteItem->setZ(z);
spriteItem->setLifetime(UNLOCK_DELAY);
}
diff --git a/src/PlayerEntity.h b/src/PlayerEntity.h
index e15aaab..14149c8 100644
--- a/src/PlayerEntity.h
+++ b/src/PlayerEntity.h
@@ -1,84 +1,78 @@
#ifndef PLAYERSPRITE_H
#define PLAYERSPRITE_H
#include "BaseCreatureEntity.h"
#include "ItemEntity.h"
#include "Constants.h"
class FairyEntity;
class PlayerEntity : public BaseCreatureEntity
{
public:
- PlayerEntity(sf::Texture* image, float x, float y);
+ PlayerEntity(sf::Texture* image, WitchBlastGame* parent, float x, float y);
virtual void animate(float delay);
virtual void render(sf::RenderWindow* app);
void moveTo(float newX, float newY);
virtual void calculateBB();
void move(int direction);
void fire(int direction);
bool canFire();
bool isMoving();
bool isEquiped(int eq);
void setEntering();
bool canMove();
virtual void dying();
virtual bool hurt(int damages); // return true if hurted
bool isDead();
float getPercentFireDelay();
void acquireItem(enumItemType type);
void loseItem(enumItemType itemType, bool isEquip);
void acquireStance(enumItemType type);
void useBossKey();
int getGold() {return gold; }
void pay(int price);
int getColliding();
enum playerStatusEnum
{
playerStatusPlaying,
playerStatusEntering,
playerStatusAcquire,
playerStatusUnlocking,
playerStatusDead
};
protected:
void computePlayer();
virtual void readCollidingEntity(CollidingSpriteEntity* entity);
void generateBolt(float velx, float vely);
virtual void collideMapRight();
virtual void collideMapLeft();
virtual void collideMapTop();
virtual void collideMapBottom();
private:
- //int hp;
- //int hpMax;
int fireDamages;
float fireVelocity;
float fireDelay;
float currentFireDelay;
float boltLifeTime;
int gold;
- // float hurtingDelay;
- // float currentHurtingDelay;
-
bool canFirePlayer;
- //float playerSpeed;
playerStatusEnum playerStatus;
float acquireDelay;
enumItemType acquiredItem;
bool equip[NUMBER_EQUIP_ITEMS];
int colliding;
FairyEntity* fairy;
};
#endif // PLAYERSPRITE_H
diff --git a/src/RatEntity.cpp b/src/RatEntity.cpp
index 2c3ed27..2ebeab9 100644
--- a/src/RatEntity.cpp
+++ b/src/RatEntity.cpp
@@ -1,71 +1,71 @@
#include "RatEntity.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"
-RatEntity::RatEntity(float x, float y, GameMap* map)
- : EnnemyEntity (ImageManager::getImageManager()->getImage(IMAGE_RAT), x, y, map)
+RatEntity::RatEntity(float x, float y, WitchBlastGame* parent)
+ : EnnemyEntity (ImageManager::getImageManager()->getImage(IMAGE_RAT), parent, x, y)
{
creatureSpeed = RAT_SPEED;
velocity = Vector2D(creatureSpeed);
hp = RAT_HP;
meleeDamages = RAT_DAMAGES;
type = ENTITY_ENNEMY;
bloodColor = bloodRed;
shadowFrame = 3;
}
void RatEntity::animate(float delay)
{
if (age > 0.0f)
frame = ((int)(age * 5.0f)) % 2;
EnnemyEntity::animate(delay);
}
void RatEntity::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 RatEntity::collideMapRight()
{
velocity.x = -velocity.x;
}
void RatEntity::collideMapLeft()
{
velocity.x = -velocity.x;
}
void RatEntity::collideMapTop()
{
velocity.y = -velocity.y;
}
void RatEntity::collideMapBottom()
{
velocity.y = -velocity.y;
}
void RatEntity::dying()
{
isDying = true;
SpriteEntity* deadRat = new SpriteEntity(ImageManager::getImageManager()->getImage(IMAGE_CORPSES), x, y, 64, 64);
deadRat->setZ(OFFSET_Y);
deadRat->setFrame(FRAME_CORPSE_RAT);
deadRat->setType(ENTITY_CORPSE);
for (int i = 0; i < 4; i++) parentGame->generateBlood(x, y, bloodColor);
drop();
SoundManager::getSoundManager()->playSound(SOUND_ENNEMY_DYING);
}
diff --git a/src/RatEntity.h b/src/RatEntity.h
index 592b4e5..bde1409 100644
--- a/src/RatEntity.h
+++ b/src/RatEntity.h
@@ -1,24 +1,23 @@
#ifndef RATSPRITE_H
#define RATSPRITE_H
#include "EnnemyEntity.h"
class RatEntity : public EnnemyEntity
{
public:
- RatEntity(float x, float y, GameMap* map);
+ RatEntity(float x, float y, WitchBlastGame* parent);
virtual void animate(float delay);
virtual void calculateBB();
protected:
virtual void collideMapRight();
virtual void collideMapLeft();
virtual void collideMapTop();
virtual void collideMapBottom();
- //virtual void readCollidingEntity(CollidingSpriteEntity* entity);
virtual void dying();
private:
};
#endif // RATSPRITE_H
diff --git a/src/SlimeEntity.cpp b/src/SlimeEntity.cpp
index 29cf2ea..346da57 100644
--- a/src/SlimeEntity.cpp
+++ b/src/SlimeEntity.cpp
@@ -1,232 +1,231 @@
#include "SlimeEntity.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"
-SlimeEntity::SlimeEntity(float x, float y, GameMap* map, PlayerEntity* player)
- : EnnemyEntity (ImageManager::getImageManager()->getImage(IMAGE_SLIME), x, y, map)
+SlimeEntity::SlimeEntity(float x, float y, WitchBlastGame* parent)
+ : EnnemyEntity (ImageManager::getImageManager()->getImage(IMAGE_SLIME), parent, x, y)
{
creatureSpeed = 0.0f;
velocity = Vector2D(0.0f, 0.0f);
hp = SLIME_HP;
meleeDamages = SLIME_DAMAGES;
- this->player = player;
type = ENTITY_ENNEMY;
bloodColor = bloodGreen;
jumpingDelay = 2.0f;
shadowFrame = 3;
isJumping = false;
h = 0.0f;
viscosity = 0.98f;
frame = 0;
jumpingDelay = 0.6f + 0.1f * (rand() % 20);
}
void SlimeEntity::animate(float delay)
{
if (isJumping)
{
hVelocity -= 700.0f * delay;
h += hVelocity * delay;
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);
}
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 -= delay;
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 = (player->getX() - x) / (player->getY() - y);
+ float tan = (parentGame->getPlayer()->getX() - x) / (parentGame->getPlayer()->getY() - y);
float angle = atan(tan);
- if (player->getY() > y)
+ if (parentGame->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::RenderWindow* 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, 0, 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;
}
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);
deadSlime->setFrame(FRAME_CORPSE_SLIME);
deadSlime->setType(ENTITY_CORPSE);
for (int i = 0; i < 4; i++) parentGame->generateBlood(x, y, bloodColor);
drop();
SoundManager::getSoundManager()->playSound(SOUND_ENNEMY_DYING);
}
bool SlimeEntity::canCollide()
{
return h <= 70.0f;
}
bool SlimeEntity::hurt(int damages)
{
hurting = true;
hurtingDelay = HURTING_DELAY;
hp -= damages;
if (hp <= 0)
{
hp = 0;
if (!isJumping)
dying();
}
return true;
}
diff --git a/src/SlimeEntity.h b/src/SlimeEntity.h
index f11dea7..4bc9c46 100644
--- a/src/SlimeEntity.h
+++ b/src/SlimeEntity.h
@@ -1,34 +1,33 @@
#ifndef SLIMESPRITE_H
#define SLIMESPRITE_H
#include "EnnemyEntity.h"
#include "PlayerEntity.h"
class SlimeEntity : public EnnemyEntity
{
public:
- SlimeEntity(float x, float y, GameMap* map, PlayerEntity* player);
+ SlimeEntity(float x, float y, WitchBlastGame* parent);
virtual void animate(float delay);
virtual void render(sf::RenderWindow* app);
virtual void calculateBB();
protected:
virtual bool collideWithMap(int direction);
virtual void collideMapRight();
virtual void collideMapLeft();
virtual void collideMapTop();
virtual void collideMapBottom();
virtual void dying();
virtual bool canCollide();
virtual bool hurt(int damages);
private:
float jumpingDelay;
float h;
float hVelocity;
bool isJumping;
bool isFirstJumping;
- PlayerEntity* player;
};
#endif // SLIMESPRITE_H
diff --git a/src/WitchBlastGame.cpp b/src/WitchBlastGame.cpp
index fb56f28..81ccfe2 100644
--- a/src/WitchBlastGame.cpp
+++ b/src/WitchBlastGame.cpp
@@ -1,918 +1,927 @@
#include "WitchBlastGame.h"
#include "sfml_game/SpriteEntity.h"
#include "sfml_game/TileMapEntity.h"
#include "DungeonMap.h"
#include "sfml_game/ImageManager.h"
#include "sfml_game/SoundManager.h"
#include "sfml_game/EntityManager.h"
#include "Constants.h"
#include "RatEntity.h"
#include "GreenRatEntity.h"
#include "KingRatEntity.h"
#include "BatEntity.h"
#include "SlimeEntity.h"
#include "ChestEntity.h"
#include "EvilFlowerEntity.h"
#include "ItemEntity.h"
#include "ArtefactDescriptionEntity.h"
#include "StaticTextEntity.h"
#include "PnjEntity.h"
#include "TextEntity.h"
#include <iostream>
#include <sstream>
WitchBlastGame::WitchBlastGame(): Game(SCREEN_WIDTH, SCREEN_HEIGHT)
{
app->setTitle(APP_NAME + " V" + APP_VERSION);
// loading resources
ImageManager::getImageManager()->addImage((char*)"media/sprite.png");
ImageManager::getImageManager()->addImage((char*)"media/bolt.png");
ImageManager::getImageManager()->addImage((char*)"media/tiles.png");
ImageManager::getImageManager()->addImage((char*)"media/rat.png");
ImageManager::getImageManager()->addImage((char*)"media/minimap.png");
ImageManager::getImageManager()->addImage((char*)"media/doors.png");
ImageManager::getImageManager()->addImage((char*)"media/items.png");
ImageManager::getImageManager()->addImage((char*)"media/items_equip.png");
ImageManager::getImageManager()->addImage((char*)"media/chest.png");
ImageManager::getImageManager()->addImage((char*)"media/bat.png");
ImageManager::getImageManager()->addImage((char*)"media/evil_flower.png");
ImageManager::getImageManager()->addImage((char*)"media/slime.png");
ImageManager::getImageManager()->addImage((char*)"media/king_rat.png");
ImageManager::getImageManager()->addImage((char*)"media/blood.png");
ImageManager::getImageManager()->addImage((char*)"media/corpses.png");
ImageManager::getImageManager()->addImage((char*)"media/corpses_big.png");
ImageManager::getImageManager()->addImage((char*)"media/star.png");
ImageManager::getImageManager()->addImage((char*)"media/star2.png");
ImageManager::getImageManager()->addImage((char*)"media/interface.png");
ImageManager::getImageManager()->addImage((char*)"media/pnj.png");
ImageManager::getImageManager()->addImage((char*)"media/fairy.png");
SoundManager::getSoundManager()->addSound((char*)"media/sound/step.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/blast00.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/blast01.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/door_closing.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/door_opening.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/chest_opening.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/impact.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/bonus.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/drink.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/player_hit.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/player_die.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/ennemy_dying.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/coin.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/pay.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/wall_impact.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/big_wall_impact.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/king_rat_cry_1.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/king_rat_cry_2.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/king_rat_die.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/slime_jump.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/slime_impact.ogg");
SoundManager::getSoundManager()->addSound((char*)"media/sound/slime_impact_weak.ogg");
if (font.loadFromFile("media/DejaVuSans-Bold.ttf"))
{
myText.setFont(font);
}
miniMap = NULL;
currentMap = NULL;
currentFloor = NULL;
specialState = SpecialStateNone;
}
WitchBlastGame::~WitchBlastGame()
{
//dtor
}
+DungeonMap* WitchBlastGame::getCurrentMap()
+{
+ return currentMap;
+}
+
+PlayerEntity* WitchBlastGame::getPlayer()
+{
+ return player;
+}
+
void WitchBlastGame::onUpdate()
{
float delta = getAbsolutTime() - lastTime;
lastTime = getAbsolutTime();
EntityManager::getEntityManager()->animate(delta);
if (specialState != SpecialStateNone)
{
timer -= delta;
if (timer <= 0.0f)
{
if (specialState == SpecialStateFadeOut)
startNewGame();
else
specialState = SpecialStateNone;
}
}
if (isPlayerAlive)
{
if (player->getHp() <= 0)
{
isPlayerAlive = false;
playMusic(MusicEnding);
}
}
}
void WitchBlastGame::startNewGame()
{
// cleaning all entities
EntityManager::getEntityManager()->clean();
// cleaning data
if (miniMap != NULL) delete (miniMap);
if (currentFloor != NULL) delete (currentFloor);
gameState = gameStateInit;
currentFloor = new GameFloor(1);
floorX = FLOOR_WIDTH / 2;
floorY = FLOOR_HEIGHT / 2;
miniMap = new GameMap(FLOOR_WIDTH, FLOOR_HEIGHT);
refreshMinimap();
// the interface
SpriteEntity* interface = new SpriteEntity(ImageManager::getImageManager()->getImage(IMAGE_INTERFACE));
interface->setZ(10000.0f);
interface->removeCenter();
interface->setType(0);
// key symbol on the interface
keySprite.setTexture(*ImageManager::getImageManager()->getImage(IMAGE_ITEMS_EQUIP));
keySprite.setTextureRect(sf::IntRect(ITEM_WIDTH * EQUIP_BOSS_KEY, 0, ITEM_WIDTH, ITEM_HEIGHT));
keySprite.setPosition(326, 616);
// minimap on the interface
TileMapEntity* miniMapEntity = new TileMapEntity(ImageManager::getImageManager()->getImage(4), miniMap, 16, 12, 10);
miniMapEntity->setX(400);
miniMapEntity->setY(607);
miniMapEntity->setZ(10001.0f);
// current map (tiles)
currentTileMap = new TileMapEntity(ImageManager::getImageManager()->getImage(IMAGE_TILES), currentMap, 64, 64, 10);
currentTileMap->setX(OFFSET_X);
currentTileMap->setY(OFFSET_Y);
// doors
doorEntity[0] = new DoorEntity(8);
doorEntity[1] = new DoorEntity(4);
doorEntity[2] = new DoorEntity(2);
doorEntity[3] = new DoorEntity(6);
// the player
player = new PlayerEntity(ImageManager::getImageManager()->getImage(0),
+ this,
OFFSET_X + (TILE_WIDTH * MAP_WIDTH * 0.5f),
OFFSET_Y + (TILE_HEIGHT * MAP_HEIGHT * 0.5f));
- player->setMap(currentMap, TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
- player->setParent(this);
isPlayerAlive = true;
// generate the map
refreshMap();
// first map is open
roomClosed = false;
// and the boss room is closed
bossRoomOpened = false;
// game time counter an state
lastTime = getAbsolutTime();
gameState = gameStatePlaying;
playMusic(MusicDonjon);
// fade in
specialState = SpecialStateFadeIn;
timer = FADE_IN_DELAY;
float x0 = OFFSET_X + MAP_WIDTH * 0.5f * TILE_WIDTH; // - TILE_WIDTH * 0.5f;
float y0 = OFFSET_Y + MAP_HEIGHT * 0.5f * TILE_HEIGHT + 40.0f; // - TILE_HEIGHT * 0.5f;
TextEntity* text = new TextEntity("Level 1", 30, x0, y0);
text->setAlignment(ALIGN_CENTER);
text->setLifetime(2.5f);
text->setWeight(-36.0f);
text->setZ(1000);
text->setColor(TextEntity::COLOR_FADING_WHITE);
}
void WitchBlastGame::startGame()
{
startNewGame();
// Start game loop
while (app->isOpen())
{
// Process events
sf::Event event;
while (app->pollEvent(event))
{
// Close window : exit
if (event.type == sf::Event::Closed)
app->close();
}
if (player->canMove()) player->setVelocity(Vector2D(0.0f, 0.0f));
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q) || sf::Keyboard::isKeyPressed(sf::Keyboard::A))
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z) || sf::Keyboard::isKeyPressed(sf::Keyboard::W))
player->move(7);
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
player->move(1);
else
player->move(4);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z) || sf::Keyboard::isKeyPressed(sf::Keyboard::W))
player->move(9);
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
player->move(3);
else
player->move(6);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z) || sf::Keyboard::isKeyPressed(sf::Keyboard::W))
{
player->move(8);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
{
player->move(2);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
player->fire(4);
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
player->fire(6);
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
player->fire(8);
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
player->fire(2);
if (player->isDead() && specialState == SpecialStateNone && sf::Keyboard::isKeyPressed(sf::Keyboard::Return))
{
specialState = SpecialStateFadeOut;
timer = FADE_OUT_DELAY;
}
onUpdate();
EntityManager::getEntityManager()->sortByZ();
onRender();
verifyDoorUnlocking();
if (roomClosed)
{
- if (GetEnnemyCount() == 0)
+ if (getEnnemyCount() == 0)
{
currentMap->setCleared(true);
openDoors();
}
}
}
quitGame();
}
void WitchBlastGame::createFloor()
{
}
void WitchBlastGame::closeDoors()
{
if (!currentMap->isCleared())
{
int i;
for(i = 0; i < MAP_WIDTH; i++)
{
if (currentMap->getTile(i, 0) < 4) currentMap->setTile(i, 0, MAP_DOOR);
if (currentMap->getTile(i, MAP_HEIGHT - 1) < 4) currentMap->setTile(i, MAP_HEIGHT - 1, MAP_DOOR);
}
for(i = 0; i < MAP_HEIGHT; i++)
{
if (currentMap->getTile(0, i) < 4) currentMap->setTile(0, i, MAP_DOOR);
if (currentMap->getTile(MAP_WIDTH - 1, i) < 4) currentMap->setTile(MAP_WIDTH - 1, i, MAP_DOOR);
}
roomClosed = true;
}
}
void WitchBlastGame::openDoors()
{
int i, j;
for(i = 0; i < MAP_WIDTH; i++)
for(j = 0; j < MAP_WIDTH; j++)
if (currentMap->getTile(i, j) == MAP_DOOR) currentMap->setTile(i, j, 0);
roomClosed = false;
SoundManager::getSoundManager()->playSound(SOUND_DOOR_OPENING);
if (currentMap->hasNeighbourUp() == 2 && !bossRoomOpened)
currentMap->setTile(MAP_WIDTH/2, 0, MAP_DOOR);
else
doorEntity[0]->openDoor();
if (currentMap->hasNeighbourLeft() == 2 && !bossRoomOpened)
currentMap->setTile(0, MAP_HEIGHT / 2, MAP_DOOR);
else
doorEntity[1]->openDoor();
if (currentMap->hasNeighbourDown() == 2 && !bossRoomOpened)
currentMap->setTile(MAP_WIDTH / 2, MAP_HEIGHT - 1, MAP_DOOR);
else
doorEntity[2]->openDoor();
if (currentMap->hasNeighbourRight() == 2 && !bossRoomOpened)
currentMap->setTile(MAP_WIDTH - 1, MAP_HEIGHT / 2, MAP_DOOR);
else
doorEntity[3]->openDoor();
}
-int WitchBlastGame::GetEnnemyCount()
+int WitchBlastGame::getEnnemyCount()
{
int n=0;
EntityManager::EntityList* entityList =EntityManager::getEntityManager()->getList();
EntityManager::EntityList::iterator it;
for (it = entityList->begin (); it != entityList->end ();)
{
GameEntity *e = *it;
it++;
if (e->getType() >= 20)
{
n++;
} // endif
} // end for
return n;
}
void WitchBlastGame::refreshMap()
{
// clean the sprites from old map
EntityManager::getEntityManager()->partialClean(10);
// if new map, it has to be randomized
bool generateMap = !(currentFloor->getMap(floorX, floorY)->isVisited());
currentMap = currentFloor->getAndVisitMap(floorX, floorY);
// load the map
currentTileMap->setMap(currentMap);
player->setMap(currentMap, TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
refreshMinimap();
if(generateMap)
this->generateMap();
else
{
if (currentMap->getRoomType() == roomTypeMerchant)
new PnjEntity(OFFSET_X + (MAP_WIDTH / 2) * TILE_WIDTH + TILE_WIDTH / 2,
OFFSET_Y + (MAP_HEIGHT / 2 - 2) * TILE_HEIGHT,
0);
}
// for testing purpose (new stuff)
if (player->getAge() <2.0f)
{
/*ItemEntity* book = new ItemEntity(ItemEntity::itemHealth, player->getX(), player->getY()- 180);
book->setMap(currentMap, TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
book->setMerchandise(true);*/
int bonusType = getRandomEquipItem(true);
ItemEntity* boots = new ItemEntity((enumItemType)(itemMagicianHat + bonusType), player->getX(), player->getY()+ 180);
boots->setMap(currentMap, TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
//ChestEntity* chest = new ChestEntity(player->getX() + 100, player->getY()+ 150, CHEST_FAIRY, false);
//chest->setMap(currentMap, TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
}
// check doors
doorEntity[0]->setVisible(currentMap->hasNeighbourUp() > 0);
if (currentMap->hasNeighbourUp() == 1) doorEntity[0]->setDoorType(0);
if (currentMap->hasNeighbourUp() == 2 || currentMap->getRoomType()==roomTypeBoss) doorEntity[0]->setDoorType(1);
if (currentMap->hasNeighbourUp() == 2 && !bossRoomOpened)
{
doorEntity[0]->setOpen(false);
currentMap->setTile(MAP_WIDTH/2, 0, MAP_DOOR);
}
else
doorEntity[0]->setOpen(true);
doorEntity[3]->setVisible(currentMap->hasNeighbourRight() > 0);
if (currentMap->hasNeighbourRight() == 1) doorEntity[3]->setDoorType(0);
if (currentMap->hasNeighbourRight() == 2 || currentMap->getRoomType()==roomTypeBoss) doorEntity[3]->setDoorType(1);
if (currentMap->hasNeighbourRight() == 2 && !bossRoomOpened)
{
doorEntity[3]->setOpen(false);
currentMap->setTile(MAP_WIDTH - 1, MAP_HEIGHT / 2, MAP_DOOR);
}
else
doorEntity[3]->setOpen(true);
doorEntity[2]->setVisible(currentMap->hasNeighbourDown() > 0);
if (currentMap->hasNeighbourDown() == 1) doorEntity[2]->setDoorType(0);
if (currentMap->hasNeighbourDown() == 2 || currentMap->getRoomType()==roomTypeBoss) doorEntity[2]->setDoorType(1);
if (currentMap->hasNeighbourDown() == 2 && !bossRoomOpened)
{
doorEntity[2]->setOpen(false);
currentMap->setTile(MAP_WIDTH/2, MAP_HEIGHT - 1, MAP_DOOR);
}
else
doorEntity[2]->setOpen(true);
doorEntity[1]->setVisible(currentMap->hasNeighbourLeft() > 0);
if (currentMap->hasNeighbourLeft() == 1) doorEntity[1]->setDoorType(0);
if (currentMap->hasNeighbourLeft() == 2 || currentMap->getRoomType()==roomTypeBoss) doorEntity[1]->setDoorType(1);
if (currentMap->hasNeighbourLeft() == 2 && !bossRoomOpened)
{
doorEntity[1]->setOpen(false);
currentMap->setTile(0, MAP_HEIGHT / 2, MAP_DOOR);
}
else
doorEntity[1]->setOpen(true);
}
void WitchBlastGame::refreshMinimap()
{
for (int j=0; j < FLOOR_HEIGHT; j++)
for (int i=0; i < FLOOR_WIDTH; i++)
{
int n = currentFloor->getRoom(i, j);
if (n > 0 && currentFloor->getMap(i, j)->isVisited())
miniMap->setTile(i, j, currentFloor->getRoom(i, j));
else if (n > 0 && currentFloor->getMap(i, j)->isKnown())
miniMap->setTile(i, j, 9);
else
miniMap->setTile(i, j, 0);
}
miniMap->setTile(floorX, floorY, 8);
}
void WitchBlastGame::checkEntering()
{
if (!currentMap->isCleared())
{
player->setEntering();
SoundManager::getSoundManager()->playSound(SOUND_DOOR_CLOSING);
for (int i=0; i<4; i++)
doorEntity[i]->closeDoor();
}
}
void WitchBlastGame::saveMapItems()
{
EntityManager::EntityList* entityList =EntityManager::getEntityManager()->getList();
EntityManager::EntityList::iterator it;
for (it = entityList->begin (); it != entityList->end ();)
{
GameEntity* e = *it;
it++;
ItemEntity* itemEntity = dynamic_cast<ItemEntity*>(e);
ChestEntity* chestEntity = dynamic_cast<ChestEntity*>(e);
if (itemEntity != NULL)
{
currentMap->addItem(itemEntity->getItemType(), itemEntity->getX(), itemEntity->getY(), itemEntity->getMerchandise());
} // endif
else if (chestEntity != NULL)
{
currentMap->addChest(chestEntity->getChestType(), chestEntity->getOpened(), chestEntity->getX(), chestEntity->getY());
} // endif
else
{
SpriteEntity* spriteEntity = dynamic_cast<SpriteEntity*>(e);
if (spriteEntity != NULL && (e->getType() == ENTITY_BLOOD || e->getType() == ENTITY_CORPSE ) )
{
int spriteFrame = spriteEntity->getFrame();
if (spriteEntity->getWidth() == 128) spriteFrame += FRAME_CORPSE_KING_RAT;
currentMap->addSprite(e->getType(), spriteFrame, e->getX(), e->getY(), spriteEntity->getScaleX());
}
}
} // end for
}
void WitchBlastGame::moveToOtherMap(int direction)
{
saveMapItems();
switch (direction)
{
case (4): floorX--; player->moveTo((OFFSET_X + MAP_WIDTH * TILE_WIDTH), player->getY()); player->move(4); break;
case (6): floorX++; player->moveTo(OFFSET_X, player->getY()); player->move(6); break;
case (8): floorY--; player->moveTo(player->getX(), OFFSET_Y + MAP_HEIGHT * TILE_HEIGHT - 10); player->move(8); break;
case (2): floorY++; player->moveTo(player->getX(), OFFSET_Y); break;
}
refreshMap();
checkEntering();
currentMap->restoreMapObjects();
}
void WitchBlastGame::onRender()
{
// clear the view
app->clear(sf::Color(32, 32, 32));
// render the game objects
EntityManager::getEntityManager()->render(app);
myText.setColor(sf::Color(255, 255, 255, 255));
myText.setCharacterSize(17);
myText.setString("WASD or ZQSD to move\nArrows to shoot");
myText.setPosition(650, 650);
app->draw(myText);
myText.setCharacterSize(18);
std::ostringstream oss;
oss << player->getGold();
myText.setString(oss.str());
myText.setPosition(690, 612);
app->draw(myText);
myText.setColor(sf::Color(0, 0, 0, 255));
myText.setCharacterSize(16);
myText.setString("Level 1");
myText.setPosition(410, 692);
app->draw(myText);
sf::RectangleShape rectangle(sf::Vector2f(200, 25));
// life
if (gameState == gameStatePlaying)
{
// life and mana
rectangle.setFillColor(sf::Color(190, 20, 20));
rectangle.setPosition(sf::Vector2f(90, 622));
rectangle.setSize(sf::Vector2f(200.0f * (float)(player->getHpDisplay()) / (float)(player->getHpMax()) , 25));
app->draw(rectangle);
rectangle.setFillColor(sf::Color(255, 190, 190));
rectangle.setPosition(sf::Vector2f(90, 625));
rectangle.setSize(sf::Vector2f(200.0f * (float)(player->getHpDisplay()) / (float)(player->getHpMax()) , 2));
app->draw(rectangle);
rectangle.setFillColor(sf::Color(20, 20, 190));
rectangle.setPosition(sf::Vector2f(90, 658));
rectangle.setSize(sf::Vector2f(200.0f * player->getPercentFireDelay() , 25));
app->draw(rectangle);
rectangle.setFillColor(sf::Color(190, 190, 255));
rectangle.setPosition(sf::Vector2f(90, 661));
rectangle.setSize(sf::Vector2f(200.0f * player->getPercentFireDelay() , 2));
app->draw(rectangle);
// drawing the key on the interface
if (player->isEquiped(EQUIP_BOSS_KEY)) app->draw(keySprite);
if (player->isDead())
{
float x0 = OFFSET_X + (MAP_WIDTH / 2) * TILE_WIDTH + TILE_WIDTH / 2;
int fade = 255 * (1.0f + cos(2.0f * getAbsolutTime())) * 0.5f;
myText.setColor(sf::Color(255, 255, 255, 255));
myText.setCharacterSize(25);
myText.setString("GAME OVER");
myText.setPosition(x0 - myText.getLocalBounds().width / 2, 400);
app->draw(myText);
myText.setColor(sf::Color(255, 255, 255, fade));
myText.setCharacterSize(20);
myText.setString("Press [ENTER] to play again !");
myText.setPosition(x0 - myText.getLocalBounds().width / 2, 440);
app->draw(myText);
}
else if (currentMap->getRoomType() == roomTypeExit)
{
float x0 = OFFSET_X + (MAP_WIDTH / 2) * TILE_WIDTH + TILE_WIDTH / 2;
myText.setColor(sf::Color(255, 255, 255, 255));
myText.setCharacterSize(25);
myText.setString("CONGRATULATIONS !\nYou've challenged this demo and\nmanaged to kill the boss !\nSee you soon for new adventures !");
myText.setPosition(x0 - myText.getLocalBounds().width / 2, 220);
app->draw(myText);
}
if (specialState == SpecialStateFadeIn)
{
// fade in
rectangle.setFillColor(sf::Color(0, 0, 0, 255 - ((FADE_IN_DELAY - timer) / FADE_IN_DELAY) * 255));
rectangle.setPosition(sf::Vector2f(OFFSET_X, OFFSET_Y));
rectangle.setSize(sf::Vector2f(MAP_WIDTH * TILE_WIDTH , MAP_HEIGHT * TILE_HEIGHT));
app->draw(rectangle);
}
else if (specialState == SpecialStateFadeOut)
{
// fade out
rectangle.setFillColor(sf::Color(0, 0, 0, ((FADE_IN_DELAY - timer) / FADE_IN_DELAY) * 255));
rectangle.setPosition(sf::Vector2f(OFFSET_X, OFFSET_Y));
rectangle.setSize(sf::Vector2f(MAP_WIDTH * TILE_WIDTH , MAP_HEIGHT * TILE_HEIGHT));
app->draw(rectangle);
}
}
app->display();
}
void WitchBlastGame::generateBlood(float x, float y, BaseCreatureEntity::enumBloodColor bloodColor)
{
SpriteEntity* blood = new SpriteEntity(ImageManager::getImageManager()->getImage(IMAGE_BLOOD), x, y, 16, 16, 6);
//deadRat->setZ(y + height);
blood->setZ(OFFSET_Y - 1);
int b0 = 0;
if (bloodColor == BaseCreatureEntity::bloodGreen) b0 += 6;
blood->setFrame(b0 + rand()%6);
blood->setType(ENTITY_BLOOD);
blood->setVelocity(Vector2D(rand()%250));
blood->setViscosity(0.95f);
float bloodScale = 1.0f + (rand() % 10) * 0.1f;
blood->setScale(bloodScale, bloodScale);
}
void WitchBlastGame::showArtefactDescription(enumItemType itemType)
{
new ArtefactDescriptionEntity(itemType, this); //, &font);
}
void WitchBlastGame::generateMap()
{
if (currentMap->getRoomType() == roomTypeStandard)
generateStandardMap();
else if (currentMap->getRoomType() == roomTypeBonus)
{
currentMap->setCleared(true);
Vector2D v = currentMap->generateBonusRoom();
int bonusType = getRandomEquipItem(false);
if (bonusType == EQUIP_FAIRY)
{
ChestEntity* chest = new ChestEntity(v.x, v.y, CHEST_FAIRY, false);
chest->setMap(currentMap, TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
}
else
{
ItemEntity* newItem
= new ItemEntity( (enumItemType)(itemMagicianHat + bonusType), v.x ,v.y);
newItem->setMap(currentMap, TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
}
}
else if (currentMap->getRoomType() == roomTypeKey)
{
Vector2D v = currentMap->generateKeyRoom();
ItemEntity* newItem
= new ItemEntity( (enumItemType)(itemBossKey), v.x ,v.y);
newItem->setMap(currentMap, TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
initMonsterArray();
int x0 = MAP_WIDTH / 2;
int y0 = MAP_HEIGHT / 2;
monsterArray[x0][y0] = true;
findPlaceMonsters(MONSTER_RAT, 5);
findPlaceMonsters(MONSTER_BAT, 5);
}
else if (currentMap->getRoomType() == roomTypeMerchant)
{
currentMap->generateMerchantRoom();
ItemEntity* item1 = new ItemEntity(
itemHealth,
OFFSET_X + (MAP_WIDTH / 2 - 2) * TILE_WIDTH + TILE_WIDTH / 2,
OFFSET_Y + (MAP_HEIGHT / 2) * TILE_HEIGHT);
item1->setMap(currentMap, TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
item1->setMerchandise(true);
int bonusType = getRandomEquipItem(true);
ItemEntity* item2 = new ItemEntity(
(enumItemType)(itemMagicianHat + bonusType),
OFFSET_X + (MAP_WIDTH / 2 + 2) * TILE_WIDTH + TILE_WIDTH / 2,
OFFSET_Y + (MAP_HEIGHT / 2) * TILE_HEIGHT);
item2->setMap(currentMap, TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
item2->setMerchandise(true);
new PnjEntity(OFFSET_X + (MAP_WIDTH / 2) * TILE_WIDTH + TILE_WIDTH / 2,
OFFSET_Y + (MAP_HEIGHT / 2 - 2) * TILE_HEIGHT,
0);
currentMap->setCleared(true);
}
else if (currentMap->getRoomType() == roomTypeBoss)
{
currentMap->generateRoom(0);
boss = new KingRatEntity(OFFSET_X + (MAP_WIDTH / 2 - 2) * TILE_WIDTH + TILE_WIDTH / 2,
OFFSET_Y + (MAP_HEIGHT / 2 - 2) * TILE_HEIGHT + TILE_HEIGHT / 2,
- currentMap, player);
+ this);
}
else if (currentMap->getRoomType() == roomTypeStarting)
{
currentMap->generateRoom(0);
currentMap->setCleared(true);
}
else if (currentMap->getRoomType() == roomTypeExit)
{
currentMap->generateRoom(0);
currentMap->setCleared(true);
}
else
currentMap->randomize(currentMap->getRoomType());
}
void WitchBlastGame::initMonsterArray()
{
for (int i = 0; i < MAP_WIDTH; i++)
for (int j = 0; j < MAP_HEIGHT; j++)
monsterArray[i][j] = false;
}
void WitchBlastGame::addMonster(monster_type_enum monsterType, float xm, float ym)
{
switch (monsterType)
{
- case MONSTER_RAT: new RatEntity(xm, ym - 2, currentMap); break;
- case MONSTER_BAT: new BatEntity(xm, ym, currentMap); break;
- case MONSTER_EVIL_FLOWER: new EvilFlowerEntity(xm, ym, currentMap, player); break;
- case MONSTER_SLIME: new SlimeEntity(xm, ym, currentMap, player); break;
+ case MONSTER_RAT: new RatEntity(xm, ym - 2, this); break;
+ case MONSTER_BAT: new BatEntity(xm, ym, this); break;
+ case MONSTER_EVIL_FLOWER: new EvilFlowerEntity(xm, ym, this); break;
+ case MONSTER_SLIME: new SlimeEntity(xm, ym, this); break;
- case MONSTER_KING_RAT: new KingRatEntity(xm, ym, currentMap, player); break;
+ case MONSTER_KING_RAT: new KingRatEntity(xm, ym, this); break;
}
}
void WitchBlastGame::findPlaceMonsters(monster_type_enum monsterType, int amount)
{
// find a suitable place
bool isMonsterFlying = monsterType == MONSTER_BAT;
bool bOk;
int xm, ym;
float xMonster, yMonster;
for (int index = 0; index < amount; index++)
{
bOk = false;
while (!bOk)
{
bOk = true;
xm = 1 +rand() % (MAP_WIDTH - 3);
ym = 1 +rand() % (MAP_HEIGHT - 3);
if (monsterArray[xm][ym])
{
bOk = false;
}
if (bOk && !isMonsterFlying && !currentMap->isWalkable(xm, ym))
{
bOk = false;
}
if (bOk)
{
xMonster = OFFSET_X + xm * TILE_WIDTH + TILE_WIDTH * 0.5f;
yMonster = OFFSET_Y + ym * TILE_HEIGHT+ TILE_HEIGHT * 0.5f;
float dist2 = (xMonster - player->getX())*(xMonster - player->getX()) + (yMonster - player->getY())*(yMonster - player->getY());
if ( dist2 < 75000.0f)
{
bOk = false;
}
else
{
addMonster(monsterType, xMonster, yMonster);
monsterArray[xm][ym] = true;
}
}
}
}
}
void WitchBlastGame::generateStandardMap()
{
initMonsterArray();
int random = rand() % 100;
if (random < 16)
{
currentMap->generateRoom(rand()%3);
findPlaceMonsters(MONSTER_RAT,4);
}
else if (random < 32)
{
currentMap->generateRoom(rand()%4);
findPlaceMonsters(MONSTER_BAT,4);
}
else if (random < 48)
{
currentMap->generateRoom(rand()%4);
findPlaceMonsters(MONSTER_EVIL_FLOWER,4);
}
else if (random < 64)
{
Vector2D v = currentMap->generateBonusRoom();
ChestEntity* chest = new ChestEntity(v.x, v.y, CHEST_BASIC, false);
chest->setMap(currentMap, TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
currentMap->setCleared(true);
}
else if (random < 80)
{
currentMap->generateRoom(rand()%3);
findPlaceMonsters(MONSTER_RAT,3);
findPlaceMonsters(MONSTER_BAT,3);
}
else
{
currentMap->generateRoom(rand()%3);
findPlaceMonsters(MONSTER_SLIME,8 + rand() % 5);
}
}
int WitchBlastGame::getRandomEquipItem(bool toSale = false)
{
std::vector<int> bonusSet;
int setSize = 0;
for (int i = 0; i < NUMBER_EQUIP_ITEMS; i++)
{
if (!player->isEquiped(i) && i != EQUIP_BOSS_KEY)
{
if (!toSale || i!= EQUIP_FAIRY)
{
bonusSet.push_back(i);
setSize++;
}
}
}
int bonusType = 0;
if (setSize > 0) bonusType = bonusSet[rand() % setSize];
return bonusType;
}
void WitchBlastGame::verifyDoorUnlocking()
{
int colliding = (player->getColliding());
if (colliding > 0 && currentMap->isCleared() && !bossRoomOpened && player->isEquiped(EQUIP_BOSS_KEY))
{
int xt = (player->getX() - OFFSET_X) / TILE_WIDTH;
int yt = (player->getY() - OFFSET_Y) / TILE_HEIGHT;
if (yt <= 1 && xt >= MAP_WIDTH / 2 - 1 && xt <= MAP_WIDTH / 2 + 1 && currentMap->hasNeighbourUp() == 2)
{
doorEntity[0]->openDoor();
currentMap->setTile(MAP_WIDTH / 2, 0, 0);
SoundManager::getSoundManager()->playSound(SOUND_DOOR_OPENING);
player->useBossKey();
bossRoomOpened = true;
}
if (yt >= MAP_HEIGHT - 2 && xt >= MAP_WIDTH / 2 - 1 &&xt <= MAP_WIDTH / 2 + 1 && currentMap->hasNeighbourDown() == 2)
{
doorEntity[2]->openDoor();
currentMap->setTile(MAP_WIDTH / 2, MAP_HEIGHT - 1, 0);
SoundManager::getSoundManager()->playSound(SOUND_DOOR_OPENING);
player->useBossKey();
bossRoomOpened = true;
}
if (xt <= 1 && yt >= MAP_HEIGHT / 2 - 1 && yt <= MAP_HEIGHT / 2 + 1 && currentMap->hasNeighbourLeft() == 2)
{
doorEntity[1]->openDoor();
currentMap->setTile(0, MAP_HEIGHT / 2, 0);
SoundManager::getSoundManager()->playSound(SOUND_DOOR_OPENING);
player->useBossKey();
bossRoomOpened = true;
}
if (xt >= MAP_WIDTH - 2 && yt >= MAP_HEIGHT / 2 - 1 && yt <= MAP_HEIGHT / 2 + 1 && currentMap->hasNeighbourRight() == 2)
{
doorEntity[3]->openDoor();
currentMap->setTile(MAP_WIDTH - 1, MAP_HEIGHT / 2, 0);
SoundManager::getSoundManager()->playSound(SOUND_DOOR_OPENING);
player->useBossKey();
bossRoomOpened = true;
}
}
}
void WitchBlastGame::playMusic(musicEnum musicChoice)
{
music.stop();
music.setLoop(true);
bool ok = false;
switch (musicChoice)
{
case MusicDonjon:
ok = music.openFromFile("media/sound/track00.ogg");
music.setVolume(75);
break;
case MusicEnding:
ok = music.openFromFile("media/sound/track_ending.ogg");
music.setVolume(35);
break;
}
if (ok)
music.play();
}
diff --git a/src/WitchBlastGame.h b/src/WitchBlastGame.h
index cf7650b..f296e16 100644
--- a/src/WitchBlastGame.h
+++ b/src/WitchBlastGame.h
@@ -1,94 +1,96 @@
#ifndef MAGICGAME_H
#define MAGICGAME_H
#include "sfml_game/Game.h"
#include "sfml_game/TileMapEntity.h"
#include "PlayerEntity.h"
#include "EnnemyEntity.h"
#include "DoorEntity.h"
#include "GameFloor.h"
class WitchBlastGame : public Game
{
public:
WitchBlastGame();
virtual ~WitchBlastGame();
virtual void startGame();
void moveToOtherMap(int direction);
void closeDoors();
void openDoors();
- int GetEnnemyCount();
+ int getEnnemyCount();
+ DungeonMap* getCurrentMap();
+ PlayerEntity* getPlayer();
void generateBlood(float x, float y, BaseCreatureEntity::enumBloodColor bloodColor);
void showArtefactDescription(enumItemType itemType);
void write(std::string test_str, int size, float x, float y);
protected:
virtual void onRender();
virtual void onUpdate();
private:
bool isFiring;
PlayerEntity* player;
EnnemyEntity* boss;
// the doors graphics
DoorEntity* doorEntity[4];
GameMap* miniMap;
DungeonMap* currentMap;
GameFloor* currentFloor;
sf::Font font;
sf::Text myText;
sf::Sprite keySprite;
sf::Music music;
TileMapEntity* currentTileMap;
int floorX, floorY;
enum musicEnum
{
MusicDonjon,
MusicEnding
};
enum specialStateEnum
{
SpecialStateNone,
SpecialStateFadeIn,
SpecialStateFadeOut
};
specialStateEnum specialState;
float timer;
void startNewGame();
void createFloor();
void refreshMap();
void refreshMinimap();
void generateMap();
void generateStandardMap();
void checkEntering();
void saveMapItems();
void initMonsterArray();
void addMonster(monster_type_enum monsterType, float xm, float ym);
void findPlaceMonsters(monster_type_enum monsterType, int amount);
int getRandomEquipItem(bool toSale);
void verifyDoorUnlocking();
void playMusic(musicEnum musicChoice);
bool roomClosed;
bool bossRoomOpened;
enum gameStateEnum { gameStateInit, gameStatePlaying};
gameStateEnum gameState;
// use to remember if a case has a monster in monster spawn
bool monsterArray[MAP_WIDTH][MAP_HEIGHT];
bool isPlayerAlive;
};
#endif // MAGICGAME_H

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jun 11, 11:43 AM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68842
Default Alt Text
(94 KB)

Event Timeline