Skip to content

Commit

Permalink
Add cross powerup
Browse files Browse the repository at this point in the history
- Add cross powerup
  - Kill all enemy in viewport area continously. Lasts 0.75 seconds
- Crop bounding box background texture to a more resonable size
- Fix next map cutscene and reset cutscene background not drawing at all
  • Loading branch information
NearHuscarl committed Dec 26, 2018
1 parent 81b911a commit 776fa26
Show file tree
Hide file tree
Showing 18 changed files with 127 additions and 26 deletions.
2 changes: 2 additions & 0 deletions src/GameCuaTao/Castlevania.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@
<ClCompile Include="Castlevania\Models\Weapons\WeaponResponseSystem.cpp" />
<ClCompile Include="Castlevania\Effects\EffectFactory.cpp" />
<ClCompile Include="Castlevania\Scenes\Stages\BossFightCutscene.cpp" />
<ClCompile Include="Castlevania\Scenes\Stages\CrossCutscene.cpp" />
<ClCompile Include="Castlevania\Scenes\Stages\Cutscene.cpp" />
<ClCompile Include="Castlevania\Scenes\Stages\GoToCastleCutScene.cpp" />
<ClCompile Include="Castlevania\Scenes\Stages\ResetCutscene.cpp" />
Expand Down Expand Up @@ -402,6 +403,7 @@
<ClInclude Include="Castlevania\Scenes\GameOverScene.h" />
<ClInclude Include="Castlevania\Scenes\GameplayData.h" />
<ClInclude Include="Castlevania\Scenes\Stages\BossFightCutscene.h" />
<ClInclude Include="Castlevania\Scenes\Stages\CrossCutscene.h" />
<ClInclude Include="Castlevania\Scenes\Stages\GoToCastleCutScene.h" />
<ClInclude Include="Castlevania\Scenes\Stages\Cutscene.h" />
<ClInclude Include="Castlevania\Scenes\Stages\ResetCutscene.h" />
Expand Down
6 changes: 6 additions & 0 deletions src/GameCuaTao/Castlevania.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,9 @@
<ClCompile Include="Castlevania\Scenes\Stages\StopwatchCutscene.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Castlevania\Scenes\Stages\CrossCutscene.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Library\pugixml.hpp">
Expand Down Expand Up @@ -1115,6 +1118,9 @@
<ClInclude Include="Castlevania\Scenes\Stages\StopwatchCutscene.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Castlevania\Scenes\Stages\CrossCutscene.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="cpp.hint" />
Expand Down
Binary file modified src/GameCuaTao/Castlevania/Content/Backgrounds/BoundingBox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/GameCuaTao/Castlevania/Content/Hud/Background.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@
<object id="76" name="Door" type="Door" gid="77" x="4072" y="128" width="24" height="96"/>
<object id="119" name="Candle" type="Candle" gid="79" x="2998" y="34" width="16" height="32">
<properties>
<property name="Item" value="LargeHeart"/>
<property name="Item" value="Cross"/>
</properties>
</object>
</objectgroup>
Expand Down
2 changes: 0 additions & 2 deletions src/GameCuaTao/Castlevania/Hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ void Hud::Unregister<GameplayData>()
void Hud::LoadContent(ContentManager &content)
{
hudFont = content.Load<SpriteFont>("Fonts/MainFont.font.xml");
backgroundTexture = content.Load<Texture>("Hud/Background.png");
borderTexture = content.Load<Texture>("Hud/Border.png");
heartTexture = content.Load<Texture>("Hud/Heart.png");

Expand All @@ -104,7 +103,6 @@ void Hud::LoadContent(ContentManager &content)

void Hud::Draw(SpriteExtensions &spriteBatch)
{
spriteBatch.Draw(*backgroundTexture, Vector2::Zero(), Color::White(), false);
spriteBatch.Draw(*heartTexture, heartTexturePosition, Color::White(), false);
spriteBatch.Draw(*borderTexture, borderTexturePosition, Color::White(), false);

Expand Down
1 change: 0 additions & 1 deletion src/GameCuaTao/Castlevania/Hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ namespace Castlevania
int height;

std::shared_ptr<SpriteFont> hudFont;
std::shared_ptr<Texture> backgroundTexture;
std::shared_ptr<Texture> borderTexture;
std::shared_ptr<Texture> heartTexture;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ void PlayerResponseSystem::Update(UpdateData &updateData)
OnCollideWithMoneyBag(result);
break;

case ObjectId::AxeItem:
case ObjectId::DaggerItem:
case ObjectId::HolyWaterItem:
case ObjectId::Stopwatch:
OnCollideWithSubWeaponItem(result);
break;

case ObjectId::Cross:
OnCollideWithCross(result);
break;

case ObjectId::LargeHeart:
OnCollideWithHeart(result);
break;
Expand All @@ -90,13 +101,6 @@ void PlayerResponseSystem::Update(UpdateData &updateData)
OnCollideWithWhipPowerup(result);
break;

case ObjectId::AxeItem:
case ObjectId::DaggerItem:
case ObjectId::HolyWaterItem:
case ObjectId::Stopwatch:
OnCollideWithSubWeaponItem(result);
break;

case ObjectId::Door:
OnCollideWithDoor(result, responseResult);
break;
Expand Down Expand Up @@ -300,6 +304,23 @@ void PlayerResponseSystem::OnCollideWithMoneyBag(CollisionResult &result)
parent.data.score += moneyBag.GetMoney();
}

void PlayerResponseSystem::OnCollideWithSubWeaponItem(CollisionResult &result)
{
auto &subWeaponItem = dynamic_cast<GameObject&>(result.collidedObject);
auto itemId = subWeaponItem.GetId();

subWeaponItem.Destroy();
parent.SetSubWeapon(itemId);
}

void PlayerResponseSystem::OnCollideWithCross(CollisionResult &result)
{
auto &cross = dynamic_cast<GameObject&>(result.collidedObject);

parent.Notify(CROSS_POWERUP_ACTIVATED);
cross.Destroy();
}

void PlayerResponseSystem::OnCollideWithHeart(CollisionResult &result)
{
auto &largeHeart = dynamic_cast<GameObject&>(result.collidedObject);
Expand Down Expand Up @@ -348,15 +369,6 @@ void PlayerResponseSystem::OnCollideWithWhipPowerup(CollisionResult &result)
whipPowerup.Destroy();
}

void PlayerResponseSystem::OnCollideWithSubWeaponItem(CollisionResult &result)
{
auto &subWeaponItem = dynamic_cast<GameObject&>(result.collidedObject);
auto itemId = subWeaponItem.GetId();

subWeaponItem.Destroy();
parent.SetSubWeapon(itemId);
}

void PlayerResponseSystem::OnCollideWithDoor(CollisionResult &result, ResponseResult &responseResult)
{
auto &door = dynamic_cast<Door&>(result.collidedObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ namespace Castlevania
void OnCollideWithVampireBat(CollisionResult &result);
void OnCollideWithFireball(CollisionResult &result);
void OnCollideWithMoneyBag(CollisionResult &result);
void OnCollideWithSubWeaponItem(CollisionResult &result);
void OnCollideWithCross(CollisionResult &result);
void OnCollideWithHeart(CollisionResult &result);
void OnCollideWithSmallHeart(CollisionResult &result);
void OnCollideWithInvisibleJar(CollisionResult &result);
void OnCollideWithWhipPowerup(CollisionResult &result);
void OnCollideWithSubWeaponItem(CollisionResult &result);
void OnCollideWithDoor(CollisionResult &result, ResponseResult &responseResult);

void OnCollideWithStairUpTrigger(Trigger &trigger);
Expand Down
6 changes: 6 additions & 0 deletions src/GameCuaTao/Castlevania/Scenes/GameplayScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ void GameplayScene::LoadContent()
{
auto &content = sceneManager.GetContent();

auto &graphicsDevice = sceneManager.GetGraphicsDevice();
auto oldColorKey = graphicsDevice.GetColorKey();

graphicsDevice.SetColorKey(MAP_COLORKEY);
mapManager->LoadContent(content);
graphicsDevice.SetColorKey(oldColorKey);

hud->LoadContent(content);

NextStage(Map::GREAT_HALL); // TODO: change back to COURTYARD
Expand Down
49 changes: 49 additions & 0 deletions src/GameCuaTao/Castlevania/Scenes/Stages/CrossCutscene.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "CrossCutscene.h"
#include "Stage.h"
#include "StageEvent.h"
#include "../../Utilities/MapSettings.h"

using namespace Castlevania;

constexpr auto CROSS_TIME = 750; // in milliseconds

CrossCutscene::CrossCutscene(Stage &stage, ContentManager &content, CollisionGrid &grid) :
Cutscene{ stage },
grid{ grid }
{
auto backgroundTexture = content.Load<Texture>("Backgrounds/BoundingBox.png");
background = std::make_unique<Sprite>(backgroundTexture);

crossTimer.Start();
}

void CrossCutscene::Update(UpdateData &updateData)
{
grid.GetCellsFromBoundingBox(stage.GetCamera()->GetBounds(), [&](CollisionCell &cell, int col, int row)
{
auto &entities = cell.GetEntites();

for (auto &entity : entities)
{
auto enemy = dynamic_cast<Enemy*>(entity.get());

if (enemy != nullptr)
enemy->Die();
}
});

stage.UpdateGameplay(updateData);

if (crossTimer.ElapsedMilliseconds() >= CROSS_TIME)
{
stage.OnNotify(Subject::Empty(), CUTSCENE_ENDED);
isComplete = true;
}
}

void CrossCutscene::Draw(SpriteExtensions &spriteBatch)
{
background->SetColor(Stopwatch::Every(1) ? MAP_BLACK_COLOR : MAP_WHITE_COLOR);
spriteBatch.Draw(*background, Vector2::Zero(), false);
Cutscene::Draw(spriteBatch);
}
21 changes: 21 additions & 0 deletions src/GameCuaTao/Castlevania/Scenes/Stages/CrossCutscene.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include "Direct2DGame/Utilities/Stopwatch.h"
#include "Cutscene.h"

namespace Castlevania
{
class CrossCutscene : public Cutscene
{
public:
CrossCutscene(Stage &stage, ContentManager &content, CollisionGrid &grid);

void Update(UpdateData &updateData) override;
void Draw(SpriteExtensions &spriteBatch) override;

private:
std::unique_ptr<Sprite> background;
Stopwatch crossTimer;
CollisionGrid &grid;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ void NextMapCutscene::Update(UpdateData &updateData)

void NextMapCutscene::Draw(SpriteExtensions &spriteBatch)
{
spriteBatch.Draw(*cutsceneBackground, Vector2::Zero());
spriteBatch.Draw(*cutsceneBackground, Vector2::Zero(), false);
}
2 changes: 1 addition & 1 deletion src/GameCuaTao/Castlevania/Scenes/Stages/ResetCutscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void ResetCutscene::Update(UpdateData &updateData)

void ResetCutscene::Draw(SpriteExtensions &spriteBatch)
{
spriteBatch.Draw(*cutsceneBackground, Vector2::Zero());
spriteBatch.Draw(*cutsceneBackground, Vector2::Zero(), false);

if (isComplete)
stage.OnNotify(Subject::Empty(), RESET_STAGE_CUTSCENE_ENDED);
Expand Down
7 changes: 6 additions & 1 deletion src/GameCuaTao/Castlevania/Scenes/Stages/Stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "NextRoomCutscene.h"
#include "ResetCutscene.h"
#include "GoToCastleCutScene.h"
#include "CrossCutScene.h"
#include "StopwatchCutScene.h"
#include "../GameplayScene.h"
#include "../SceneManager.h"
Expand Down Expand Up @@ -345,6 +346,10 @@ void Stage::ProcessMessage(int message)
Reset();
break;

case CROSS_POWERUP_ACTIVATED:
SetCurrentCutscene(GameState::CROSS_CUTSCENE);
break;

case STOPWATCH_POWERUP_ACTIVATED:
SetCurrentCutscene(GameState::STOPWATCH_CUTSCENE);
break;
Expand Down Expand Up @@ -374,7 +379,7 @@ std::unique_ptr<Cutscene> Stage::ConstructCutscene(GameState gameState)
return std::make_unique<ResetCutscene>(*this, content);

case GameState::CROSS_CUTSCENE:
return std::make_unique<StopwatchCutscene>(*this);
return std::make_unique<CrossCutscene>(*this, content, *grid);

case GameState::STOPWATCH_CUTSCENE:
return std::make_unique<StopwatchCutscene>(*this);
Expand Down
2 changes: 0 additions & 2 deletions src/GameCuaTao/Castlevania/Scenes/Stages/StopwatchCutscene.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

#include "Direct2DGame/Utilities/Stopwatch.h"
#include "Cutscene.h"
#include "../../Models/Factories/ObjectFactory.h"

namespace Castlevania
{
class StopwatchCutscene : public Cutscene
{
public:
StopwatchCutscene(Stage &stage);

void Update(UpdateData &updateData) override;

private:
Expand Down
4 changes: 4 additions & 0 deletions src/GameCuaTao/Castlevania/Utilities/MapSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ namespace Castlevania
UNDERGROUND,
PLAYGROUND,
};

const auto MAP_BLACK_COLOR = Color{ 5, 5, 5, 255 };
const auto MAP_WHITE_COLOR = Color{ 188, 188, 188, 255 };
const auto MAP_COLORKEY = MAP_BLACK_COLOR;
}

0 comments on commit 776fa26

Please sign in to comment.