Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F126531
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
15 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/PlayerEntity.cpp b/src/PlayerEntity.cpp
index 8223871..8a90f4c 100644
--- a/src/PlayerEntity.cpp
+++ b/src/PlayerEntity.cpp
@@ -1,538 +1,537 @@
#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)
{
- fireDelay = INITIAL_PLAYER_FIRE_DELAY;
- fireVelocity = INITIAL_BOLT_VELOCITY;
currentFireDelay = -1.0f;
canFirePlayer = true;
type = 1;
- creatureSpeed = INITIAL_PLAYER_SPEED;
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_BLAST_STANDARD);
}
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);
// 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_MAHONAGY_STAFF])
sprite.setTextureRect(sf::IntRect(frame * width + 4, 4 * height, width, height));
else
sprite.setTextureRect(sf::IntRect(frame * width + 4, 4 * 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);
}
// 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);
}
void 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);
}
}
void PlayerEntity::loseItem(ItemEntity::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(TYPE_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(ItemEntity::itemCopperCoin, false);
for (i = 0; i < NUMBER_EQUIP_ITEMS; i++)
if (equip[i]) loseItem(ItemEntity::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(TYPE_BLOOD);
itemSprite->setVelocity(Vector2D(rand()%450));
itemSprite->setViscosity(0.95f);
itemSprite->setSpin( (rand() % 700) - 350.0f);
}
void PlayerEntity::acquireItem(ItemEntity::enumItemType type)
{
if (type >= ItemEntity::itemMagicianHat) acquireStance(type);
else switch (type)
{
case ItemEntity::itemCopperCoin: gold++;
SoundManager::getSoundManager()->playSound(SOUND_COIN_PICK_UP);
break;
case ItemEntity::itemSilverCoin: gold = gold + 5; break;
case ItemEntity::itemGoldCoin: gold = gold + 10; break;
case ItemEntity::itemHealth: hp += 15;
SoundManager::getSoundManager()->playSound(SOUND_DRINK);
if (hp > hpMax) hp = hpMax; break;
default: break;
}
}
void PlayerEntity::computePlayer()
{
fireDelay = INITIAL_PLAYER_FIRE_DELAY;
creatureSpeed = INITIAL_PLAYER_SPEED;
fireVelocity = INITIAL_BOLT_VELOCITY;
fireDamages = INITIAL_BOLT_DAMAGES;
if (equip[EQUIP_VIBRATION_GLOVES]) fireDelay *= 0.90f;
if (equip[EQUIP_ENCHANTER_HAT]) fireDelay *= 0.75f;
if (equip[EQUIP_LEATHER_BOOTS]) creatureSpeed += 50.0f;
if (equip[EQUIP_BOOK_DUAL]) fireDelay *= 1.6f;
if (equip[EQUIP_CONCENTRATION_AMULET]) boltLifeTime *= 1.5f;
if (equip[EQUIP_MAHONAGY_STAFF])
{
fireVelocity *= 1.15f;
fireDamages *= 1.5f;
}
}
void PlayerEntity::acquireStance(ItemEntity::enumItemType type)
{
velocity.x = 0.0f;
velocity.y = 0.0f;
playerStatus = playerStatusAcquire;
acquireDelay = ACQUIRE_DELAY;
acquiredItem = (ItemEntity::enumItemType)(type - ItemEntity::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 = (ItemEntity::enumItemType)(type - ItemEntity::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);
}
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
68899
Default Alt Text
(15 KB)
Attached To
Mode
R78 witchblast
Attached
Detach File
Event Timeline