Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F126537
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
54 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/ArtefactDescriptionEntity.cpp b/src/ArtefactDescriptionEntity.cpp
index b7e0b49..17585d7 100644
--- a/src/ArtefactDescriptionEntity.cpp
+++ b/src/ArtefactDescriptionEntity.cpp
@@ -1,111 +1,111 @@
#include "ArtefactDescriptionEntity.h"
#include "Constants.h"
#include "sfml_game/ImageManager.h"
#include "WitchBlastGame.h"
#include "StaticTextEntity.h"
ArtefactDescriptionEntity::ArtefactDescriptionEntity(ItemEntity::enumItemType itemType, WitchBlastGame* parent/*, sf::Font* my_font*/)
: SpriteEntity (ImageManager::getImageManager()->getImage(IMAGE_ITEMS_EQUIP), 0, 0, ITEM_WIDTH, ITEM_HEIGHT)
{
//font = my_font;
this->setLifetime(6.0f);
this->setFrame(itemType - ItemEntity::itemMagicianHat);
this->setType(9);
float x0 = OFFSET_X + MAP_WIDTH * TILE_WIDTH * 0.5f - ARTEFACT_RECT_WIDTH * 0.5f;
rectangle.setSize(sf::Vector2f(ARTEFACT_RECT_WIDTH, ARTEFACT_RECT_HEIGHT));
rectangle.setPosition(sf::Vector2f(x0, ARTEFACT_POS_Y));
rectangle.setFillColor(sf::Color(20, 20, 70, 180));
rectangleBorder.setSize(sf::Vector2f(ARTEFACT_RECT_WIDTH + ARTEFACT_BORDER * 2.0f,
ARTEFACT_RECT_HEIGHT + ARTEFACT_BORDER * 2.0f));
rectangleBorder.setPosition(sf::Vector2f(x0 - ARTEFACT_BORDER, ARTEFACT_POS_Y - ARTEFACT_BORDER));
rectangleBorder.setFillColor(sf::Color(255, 255, 255, 180));
this->parent = parent;
this->x = x0 + 50.0f;
this->y = 500.0f;
sprite.setScale(3.5f, 3.5f);
z = 5000.0f;
switch (itemType)
{
case (ItemEntity::itemMagicianHat):
artefactName = "Enchanter Hat"; artefactDescription = "Increases fire rate"; break;
case (ItemEntity::itemLeatherBoots):
artefactName = "Leather Boots"; artefactDescription = "Increases speed"; break;
case (ItemEntity::itemBookDualShots):
artefactName = "Spell : Dual Bolts"; artefactDescription = "Shoots two bolts"; break;
case (ItemEntity::itemConcentrationAmulet):
artefactName = "Concentration Amulet"; artefactDescription = "Increases fire range"; break;
case (ItemEntity::itemBossKey):
artefactName = "Boss Key"; artefactDescription = "Open the boss gate"; break;
case (ItemEntity::itemVibrationGloves):
artefactName = "Vibration Gloves"; artefactDescription = "Vibrations + slighty increases fire rate"; break;
case (ItemEntity::itemMahoganyStaff):
artefactName = "Mahogany Staff"; artefactDescription = "Increases bolt's speed and damages"; break;
case (ItemEntity::itemFairy):
artefactName = "Fairy"; artefactDescription = "Help you in the dungeon"; break;
default: break;
}
}
ArtefactDescriptionEntity::~ArtefactDescriptionEntity()
{
}
void ArtefactDescriptionEntity::animate(float delay)
{
if (age < ARTEFACT_ZOOM_TIME)
{
float perc = 1.0f - age / ARTEFACT_ZOOM_TIME;
sprite.setScale(3.5f + perc * 50.0f, 3.5f + perc * 50.0f);
}
else
{
sprite.setScale(3.5f, 3.5f);
}
SpriteEntity::animate(delay);
}
void ArtefactDescriptionEntity::render(sf::RenderWindow* app)
{
int nx = frame;
int ny = 0;
if (imagesProLine > 0)
{
nx = frame % imagesProLine;
ny = frame / imagesProLine;
}
sprite.setTextureRect(sf::IntRect(nx * width, ny * height, /*(nx + 1) **/ width, /*(ny + 1) */ height));
sprite.setPosition(x, y);
sprite.setRotation(angle);
if (isFading)
{
sprite.setColor(sf::Color(255, 255, 255, (sf::Uint8)(getFade() * 255)));
}
if (isShrinking)
{
sprite.setScale(getFade(), getFade());
}
app->draw(rectangleBorder);
app->draw(rectangle);
app->draw(sprite);
- StaticTextEntity::Write(app, artefactName, 22, 315.0f, ARTEFACT_POS_Y + 15.0f, ALIGN_LEFT);
- StaticTextEntity::Write(app, artefactDescription, 20, 315.0f, ARTEFACT_POS_Y + 55.0f, ALIGN_LEFT);
+ StaticTextEntity::Write(app, artefactName, 22, 315.0f, ARTEFACT_POS_Y + 15.0f, ALIGN_LEFT, sf::Color(255, 255, 255));
+ StaticTextEntity::Write(app, artefactDescription, 20, 315.0f, ARTEFACT_POS_Y + 55.0f, ALIGN_LEFT, sf::Color(255, 255, 255));
}
diff --git a/src/ItemEntity.cpp b/src/ItemEntity.cpp
index b0e059b..29ed841 100644
--- a/src/ItemEntity.cpp
+++ b/src/ItemEntity.cpp
@@ -1,157 +1,157 @@
#include "ItemEntity.h"
#include "sfml_game/ImageManager.h"
#include "sfml_game/SpriteEntity.h"
#include "Constants.h"
#include "MagnetEntity.h"
#include "WitchBlastGame.h"
#include "StaticTextEntity.h"
#include <iostream>
#include <sstream>
const int itemCost[12] =
{
1, // copper coin
5, // silver
20, // gold
8, // health
20, // hat
20, // boots
20, // dual
20, // amulet
100, // boss key
20, // gloves
20, // staff
30, // fairy
};
ItemEntity::ItemEntity(enumItemType itemType, float x, float y)
: CollidingSpriteEntity(ImageManager::getImageManager()->getImage(itemType >= itemMagicianHat ? IMAGE_ITEMS_EQUIP : IMAGE_ITEMS), x, y, ITEM_WIDTH, ITEM_HEIGHT)
{
type = TYPE_ITEM;
this->itemType = itemType;
frame = itemType;
if (itemType >= itemMagicianHat) frame = itemType - itemMagicianHat;
isMerchandise = false;
}
void ItemEntity::setMerchandise(bool isMerchandise)
{
this->isMerchandise = isMerchandise;
}
bool ItemEntity::getMerchandise()
{
return isMerchandise;
}
int ItemEntity::getPrice()
{
return (itemCost[(int)(itemType)]);
}
void ItemEntity::setParent(WitchBlastGame* parent)
{
parentGame = parent;
}
void ItemEntity::animate(float delay)
{
z = y + height;
CollidingSpriteEntity::animate(delay);
if (age > 0.7f) testSpriteCollisions();
}
void ItemEntity::render(sf::RenderWindow* app)
{
// shadow
sprite.setTextureRect(sf::IntRect(9 * width, height, width, height));
app->draw(sprite);
// price
if (isMerchandise)
{
std::ostringstream oss;
oss << getPrice() << " $";
- StaticTextEntity::Write(app, oss.str(), 16, x, y + 18.0f, ALIGN_CENTER);
+ StaticTextEntity::Write(app, oss.str(), 16, x, y + 18.0f, ALIGN_CENTER, sf::Color(255, 255, 255));
}
CollidingSpriteEntity::render(app);
}
void ItemEntity::calculateBB()
{
boundingBox.left = (int)x - width / 2;
boundingBox.width = width;
boundingBox.top = (int)y - height / 2;
boundingBox.height = height;
}
void ItemEntity::dying()
{
isDying = true;
}
void ItemEntity::readCollidingEntity(CollidingSpriteEntity* entity)
{
PlayerEntity* playerEntity = dynamic_cast<PlayerEntity*>(entity);
if (collideWithEntity(entity))
{
if (playerEntity != NULL && !playerEntity->isDead())
{
if (isMerchandise == false || playerEntity->getGold() >= getPrice())
{
playerEntity->acquireItem(itemType);
if (isMerchandise) playerEntity->pay(getPrice());
//isDying = true;
dying();
if (itemType >= itemMagicianHat)
{
parentGame->showArtefactDescription(itemType);
SpriteEntity* spriteItem = new SpriteEntity(
image,
playerEntity->getX(), playerEntity->getY() - 60.0f, ITEM_WIDTH, ITEM_HEIGHT);
spriteItem->setFrame(frame);
spriteItem->setZ(z);
spriteItem->setLifetime(ACQUIRE_DELAY);
SpriteEntity* spriteStar = new SpriteEntity(
ImageManager::getImageManager()->getImage(IMAGE_STAR),
playerEntity->getX(), playerEntity->getY() - 60.0f);
spriteStar->setScale(4.0f, 4.0f);
spriteStar->setZ(z-1.0f);
spriteStar->setLifetime(ACQUIRE_DELAY);
spriteStar->setSpin(50.0f);
}
else
new MagnetEntity(x, y, playerEntity, itemType);
}
}
}
}
void ItemEntity::collideMapRight()
{
velocity.x = -velocity.x * 0.66f;
}
void ItemEntity::collideMapLeft()
{
velocity.x = -velocity.x * 0.66f;
}
void ItemEntity::collideMapTop()
{
velocity.y = -velocity.y * 0.66f;
}
void ItemEntity::collideMapBottom()
{
velocity.y = -velocity.y * 0.66f;
}
diff --git a/src/KingRatEntity.cpp b/src/KingRatEntity.cpp
index 3611c21..667e725 100644
--- a/src/KingRatEntity.cpp
+++ b/src/KingRatEntity.cpp
@@ -1,345 +1,351 @@
#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)
{
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 = 21;
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 angle = atan(tan);
if (player->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 angle = atan(tan);
if (player->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;
}
testSpriteCollisions();
EnnemyEntity::animate(delay);
}
void KingRatEntity::hurt(int damages)
{
hurting = true;
hurtingDelay = HURTING_DELAY;
if (state == 6)
hp -= damages / 4;
else
hp -= damages;
if (hp <= 0)
{
hp = 0;
dying();
}
}
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(TYPE_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);
}
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);
+ 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/PnjEntity.cpp b/src/PnjEntity.cpp
index ee60f1c..d4a697d 100644
--- a/src/PnjEntity.cpp
+++ b/src/PnjEntity.cpp
@@ -1,101 +1,101 @@
#include "PnjEntity.h"
#include "Constants.h"
#include "StaticTextEntity.h"
#include "sfml_game/ImageManager.h"
PnjEntity::PnjEntity(float x, float y, int pnjType) : SpriteEntity (ImageManager::getImageManager()->getImage(IMAGE_PNJ), x, y, 64, 96)
{
this->x = x;
this->y = y;
x0 = x;
y0 = y;
pnjVelocity = 140.0f;
xGoal = x0 + 180.0f;
direction = 6;
velocity.x = pnjVelocity;
isSpeaking = false;
speechTimer = 2.5f + 0.1f * (rand() % 50);
headFrame = 2;
type = 17;
}
void PnjEntity::animate(float delay)
{
if (direction == 6 && x >= xGoal)
{
direction = 4;
velocity.x = -pnjVelocity;
xGoal = x0 - 180.0f;
}
else if (direction == 4 && x <= xGoal)
{
direction = 6;
velocity.x = pnjVelocity;
xGoal = x0 + 180.0f;
}
speechTimer -= delay;
if (speechTimer <= 0.0f)
{
if (isSpeaking)
{
isSpeaking = false;
speechTimer = 3.0f + 0.1f * (rand() % 65);
velocity.x = (direction == 6) ? pnjVelocity : -pnjVelocity;
}
else
{
isSpeaking = true;
speechTimer = 5.0f;
velocity.x = 0.0f;
int r = rand() % 3;
switch (r)
{
case 0: speech = "Best price in entire dungeon !"; break;
case 1: speech = "Welcome in deep deep stores !"; break;
case 2: speech = "Have look to our merchandise !"; break;
}
}
}
if (isSpeaking)
{
headFrame = 2 + (int)(4 * age) % 2;
}
else
{
frame = 0 + (int)(4 * age) % 2;
headFrame = 2;
}
z = y + height;
SpriteEntity::animate(delay);
}
void PnjEntity::render(sf::RenderWindow* app)
{
sprite.setPosition(x, y);
// shadow
sprite.setTextureRect(sf::IntRect(4 * width, 0, width, height));
app->draw(sprite);
// body
sprite.setTextureRect(sf::IntRect(frame * width, 0, width, height));
app->draw(sprite);
// head
sprite.setTextureRect(sf::IntRect(headFrame * width, 0, width, height));
app->draw(sprite);
if (isSpeaking)
{
- StaticTextEntity::Write(app, speech, 20, x0, y0 - 72.0f, ALIGN_CENTER);
+ StaticTextEntity::Write(app, speech, 20, x0, y0 - 72.0f, ALIGN_CENTER, sf::Color(255, 255, 255));
}
}
diff --git a/src/StaticTextEntity.cpp b/src/StaticTextEntity.cpp
index a4152be..d137177 100644
--- a/src/StaticTextEntity.cpp
+++ b/src/StaticTextEntity.cpp
@@ -1,38 +1,39 @@
#include "StaticTextEntity.h"
#include <iostream>
StaticTextEntity::StaticTextEntity()
{
//ctor
}
/*void StaticTextEntity::Write()
{
static sf::font font;
}*/
-void StaticTextEntity::Write(sf::RenderWindow* app, std::string str, int size, float x, float y, int align)
+void StaticTextEntity::Write(sf::RenderWindow* app, std::string str, int size, float x, float y, int align, sf::Color color)
{
static bool fontDefined = false;
static sf::Font statFont;
static sf::Text statText;
if (fontDefined == false)
{
fontDefined = true;
if (!statFont.loadFromFile("media/DejaVuSans-Bold.ttf"))
{
// erreur...
}
statText.setFont(statFont);
}
statText.setString(str);
statText.setCharacterSize(size);
+ statText.setColor(color);
if (align == ALIGN_CENTER)
statText.setPosition(x - statText.getLocalBounds().width / 2, y);
else
statText.setPosition(x, y);
app->draw(statText);
}
diff --git a/src/StaticTextEntity.h b/src/StaticTextEntity.h
index c6e4b1d..d130ab6 100644
--- a/src/StaticTextEntity.h
+++ b/src/StaticTextEntity.h
@@ -1,21 +1,21 @@
#ifndef STATICTEXTENTITY_H
#define STATICTEXTENTITY_H
#include <SFML/Graphics.hpp>
const int ALIGN_LEFT = 0;
const int ALIGN_RIGHT = 1;
const int ALIGN_CENTER = 2;
class StaticTextEntity
{
public:
- static void Write(sf::RenderWindow* app, std::string str, int size, float x, float y, int align);
+ static void Write(sf::RenderWindow* app, std::string str, int size, float x, float y, int align, sf::Color color);
protected:
private:
StaticTextEntity();
};
#endif // STATICTEXTENTITY_H
diff --git a/src/TextEntity.cpp b/src/TextEntity.cpp
new file mode 100644
index 0000000..3eaa97e
--- /dev/null
+++ b/src/TextEntity.cpp
@@ -0,0 +1,66 @@
+/** This file is part of Witch Blast.
+ *
+ * FreeTumble is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * FreeTumble is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FreeTumble. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sstream>
+#include <iostream>
+
+#include "TextEntity.h"
+#include "StaticTextEntity.h"
+
+TextEntity::TextEntity(std::string text, int size, float x, float y) : GameEntity(x, y)
+{
+ this->text = text;
+ this->size = size;
+ alignment = ALIGN_LEFT;
+ colorType = COLOR_WHITE;
+
+ color = sf::Color(255, 255, 255);
+}
+
+void TextEntity::render(sf::RenderWindow* app)
+{
+ // determine the color
+ StaticTextEntity::Write(app, text, size, x, y, alignment, color);
+}
+
+void TextEntity::animate(float delay)
+{
+ GameEntity::animate(delay);
+
+ // TODO : other colorType
+ if (colorType == COLOR_FADING_WHITE)
+ color = sf::Color(255, 255, 255, 255 * (lifetime - age) / lifetime );
+}
+
+
+void TextEntity::setText(std::string text)
+{
+ this->text = text;
+}
+
+void TextEntity::setColor(int colorType)
+{
+ // TODO : other colorType
+ this->colorType = colorType;
+
+ if (colorType == COLOR_WHITE || colorType == COLOR_FADING_WHITE)
+ color = sf::Color(255, 255, 255);
+}
+
+void TextEntity::setAlignment(int alignment)
+{
+ this->alignment = alignment;
+}
diff --git a/src/TextEntity.h b/src/TextEntity.h
new file mode 100644
index 0000000..e2035b0
--- /dev/null
+++ b/src/TextEntity.h
@@ -0,0 +1,52 @@
+/** This file is part of Witch Blast.
+ *
+ * FreeTumble is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * FreeTumble is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FreeTumble. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TEXTENTITY_H_INCLUDED
+#define TEXTENTITY_H_INCLUDED
+
+#include "sfml_game/GameEntity.h"
+
+// Basis class for text
+class TextEntity : public GameEntity
+{
+public:
+ TextEntity(std::string text, int size, float x = 0.0f, float y = 0.0f);
+
+ virtual void render(sf::RenderWindow* app);
+ virtual void animate(float delay);
+
+ virtual void setText(std::string text);
+
+ void setAlignment(int alignment);
+ void setColor(int colorType);
+ enum alignmentEnum { ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER };
+ enum colorTypeEnum { COLOR_WHITE,
+ COLOR_BLUE,
+ COLOR_RED,
+ COLOR_GREEN,
+ COLOR_FADING_WHITE,
+ COLOR_FADING_BLUE,
+ COLOR_BLINKING_WHITE };
+
+protected:
+ std::string text;
+ int size;
+ int alignment;
+ int colorType;
+ sf::Color color;
+};
+
+#endif // TEXTENTITY_H_INCLUDED
diff --git a/src/WitchBlastGame.cpp b/src/WitchBlastGame.cpp
index f4130b8..273c607 100644
--- a/src/WitchBlastGame.cpp
+++ b/src/WitchBlastGame.cpp
@@ -1,870 +1,881 @@
#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 "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/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");
music.openFromFile("media/sound/track00.ogg");
music.setVolume(75);
music.setLoop(true);
if (font.loadFromFile("media/DejaVuSans-Bold.ttf"))
{
myText.setFont(font);
}
miniMap = NULL;
currentMap = NULL;
currentFloor = NULL;
specialState = SpecialStateNone;
}
WitchBlastGame::~WitchBlastGame()
{
//dtor
}
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;
}
}
}
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),
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);
// 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;
music.play();
// 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)
{
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;
/*SoundManager::getSoundManager()->playSound(SOUND_DOOR_CLOSING);
for (int i=0; i<4; i++)
doorEntity[i]->closeDoor();*/
}
}
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 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((ItemEntity::enumItemType)(ItemEntity::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() == TYPE_BLOOD || e->getType() == TYPE_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(TYPE_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(ItemEntity::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( (ItemEntity::enumItemType)(ItemEntity::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( (ItemEntity::enumItemType)(ItemEntity::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(
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(
(ItemEntity::enumItemType)(ItemEntity::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);
}
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_KING_RAT: new KingRatEntity(xm, ym, currentMap, player); 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 < 20)
{
currentMap->generateRoom(rand()%3);
findPlaceMonsters(MONSTER_RAT,4);
}
else if (random < 40)
{
currentMap->generateRoom(rand()%4);
findPlaceMonsters(MONSTER_BAT,4);
}
else if (random < 60)
{
currentMap->generateRoom(rand()%4);
findPlaceMonsters(MONSTER_EVIL_FLOWER,4);
}
else if (random < 80)
{
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
{
currentMap->generateRoom(rand()%3);
findPlaceMonsters(MONSTER_RAT,3);
findPlaceMonsters(MONSTER_BAT,3);
}
}
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;
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jun 11, 11:53 AM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68905
Default Alt Text
(54 KB)
Attached To
Mode
R78 witchblast
Attached
Detach File
Event Timeline