Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
diff --git a/src/ChestEntity.cpp b/src/ChestEntity.cpp
index 4c2cf26..123d7ff 100644
--- a/src/ChestEntity.cpp
+++ b/src/ChestEntity.cpp
@@ -1,82 +1,83 @@
#include "ChestEntity.h"
#include "PlayerEntity.h"
#include "WitchBlastGame.h"
#include "sfml_game/ImageManager.h"
#include "sfml_game/SoundManager.h"
#include "sfml_game/SpriteEntity.h"
#include "Constants.h"
ChestEntity::ChestEntity(float x, float y, int chestType, bool isOpen)
: CollidingSpriteEntity(ImageManager::getImageManager()->getImage(IMAGE_CHEST), x, y, 48, 48)
{
type = ENTITY_CHEST;
imagesProLine = 2;
this->isOpen = isOpen;
this->chestType = chestType;
frame = chestType * 2 + (isOpen ? 1 : 0);
setMap(game().getCurrentMap(), TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
}
bool ChestEntity::getOpened()
{
return isOpen;
}
int ChestEntity::getChestType()
{
return chestType;
}
void ChestEntity::animate(float delay)
{
CollidingSpriteEntity::animate(delay);
if (!isOpen) testSpriteCollisions();
z = y + height/2;
}
void ChestEntity::calculateBB()
{
boundingBox.left = (int)x - width / 2;
boundingBox.width = width;
boundingBox.top = (int)y - height / 2;
boundingBox.height = height;
}
void ChestEntity::readCollidingEntity(CollidingSpriteEntity* entity)
{
PlayerEntity* playerEntity = dynamic_cast<PlayerEntity*>(entity);
if (collideWithEntity(entity))
{
if (!isOpen && playerEntity != NULL && !playerEntity->isDead())
{
open();
frame += 1;
}
}
}
void ChestEntity::open()
{
isOpen = true;
SoundManager::getSoundManager()->playSound(SOUND_CHEST_OPENING);
if (chestType == CHEST_BASIC)
{
- for (int i = 0; i < 5; i++)
+ int r = 2 + rand() % 6;
+ for (int i = 0; i < r; i++)
{
ItemEntity* newItem = new ItemEntity(ItemCopperCoin, x, y);
newItem->setVelocity(Vector2D(50.0f + rand()% 150));
newItem->setViscosity(0.96f);
}
}
else if (chestType == CHEST_FAIRY)
{
ItemEntity* newItem = new ItemEntity(ItemFairy, x, y);
newItem->setMap(map, TILE_WIDTH, TILE_HEIGHT, OFFSET_X, OFFSET_Y);
newItem->setVelocity(Vector2D(50.0f + rand()% 150));
newItem->setViscosity(0.96f);
}
}

File Metadata

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

Event Timeline