Skip to content

Commit e5a16bd

Browse files
committed
Add powerup spawning system for container and enemy
- Add powerup generator - Enemy now seldomly spawn powerups when dying - Containers (brazier or candle) have a small chance to spawn different COMMON powerup from its designated one - which also has to be another COMMON powerup (e.g. containers that hold RedMoneyBag (COMMON) have a chance to spawn SmallHeart (COMMON) instead. Containers that hold Cross powerup (RARE) ALWAYS spawn Cross powerup) - Powerup spawn chances: COMMON (~70% spawn chance) - RedMoneyBag - BlueMoneyBag - SmallHeart UNCOMMON (~25% spawn chance) - WhiteMoneyBag - AxeItem - BoomerangItem - DaggerItem - HolyWaterItem - LargeHeart RARE (~5% spawn chance) - FlashingMoneyBag - Cross - InvisibleJar - PorkChop - Stopwatch - DoubleShot - TripleShot - Fix simon bouncing back at wrong direction when get hit by enemies - Fix a bug where zombie occasionally spawned in the air in room 3 (great hall map) - Player must fall at least 2.5 tiles height to be able to do a superhero landing when hitting the ground - Copy asset folder to target directory in postbuild event
1 parent 5a52a32 commit e5a16bd

File tree

17 files changed

+250
-53
lines changed

17 files changed

+250
-53
lines changed

TROUBLESHOOTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ d3d9.lib;d3dx9.lib;dinput8.lib;dxguid.lib;dsound.lib;dxerr.lib;winmm.lib;%(Addit
4747
- Add this line in the Command Line
4848

4949
```
50-
XCOPY "$(ProjectDir)\lib\*.dll" "$(TargetDir)" /D /K /Y
50+
XCOPY "$(ProjectDir)lib\*.dll" "$(TargetDir)" /D /K /Y
5151
```
5252

5353
By default, Visual Studio only copy `*.dll` files in the `$(ProjectDir)`. If you put

src/GameCuaTao/Castlevania.vcxproj

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
<UseDebugLibraries>false</UseDebugLibraries>
3838
<PlatformToolset>v141</PlatformToolset>
3939
<WholeProgramOptimization>true</WholeProgramOptimization>
40-
<CharacterSet>MultiByte</CharacterSet>
40+
<CharacterSet>Unicode</CharacterSet>
41+
<IncludePath>Library\directx\Include;Library\freetype\Include;Library\fmt\Include;$(IncludePath)</IncludePath>
42+
<LibraryPath>Library\directx\Lib;Library\freetype\Lib;$(LibraryPath)</LibraryPath>
4143
</PropertyGroup>
4244
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
4345
<ConfigurationType>Application</ConfigurationType>
@@ -100,10 +102,11 @@
100102
</SubSystem>
101103
</Link>
102104
<PostBuildEvent>
103-
<Command>XCOPY "$(ProjectDir)\library\freetype\lib\freetype.dll" "$(TargetDir)" /D /K /Y</Command>
105+
<Command>XCOPY "$(ProjectDir)library\freetype\lib\freetype.dll" "$(TargetDir)" /D /K /Y
106+
XCOPY "$(ProjectDir)Castlevania\Content" "$(TargetDir)Castlevania\Content" /D /E /I /K /Y</Command>
104107
</PostBuildEvent>
105108
<PostBuildEvent>
106-
<Message>Copy DLLs to Target Directory</Message>
109+
<Message>Copy DLLs and asset files to Target Directory</Message>
107110
</PostBuildEvent>
108111
<PreBuildEvent>
109112
<!-- <Command>#$(ProjectDir)Deployment\cppclean.sh</Command> -->
@@ -135,11 +138,21 @@
135138
<FunctionLevelLinking>true</FunctionLevelLinking>
136139
<IntrinsicFunctions>true</IntrinsicFunctions>
137140
<SDLCheck>true</SDLCheck>
138-
<ConformanceMode>true</ConformanceMode>
141+
<!-- <ConformanceMode>true</ConformanceMode> -->
142+
<SDLCheck>true</SDLCheck>
143+
<ConformanceMode>false</ConformanceMode>
144+
<AdditionalIncludeDirectories>SDK Path\Include;.</AdditionalIncludeDirectories>
145+
<LanguageStandard>stdcpp17</LanguageStandard>
146+
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
147+
<ObjectFileName>$(IntDir)/%(RelativeDir)/</ObjectFileName>
139148
</ClCompile>
140149
<Link>
141150
<EnableCOMDATFolding>true</EnableCOMDATFolding>
142151
<OptimizeReferences>true</OptimizeReferences>
152+
<AdditionalDependencies>freetype.lib;d3d9.lib;d3dx9.lib;dinput8.lib;dxguid.lib;dsound.lib;dxerr.lib;winmm.lib;%(AdditionalDependencies);legacy_stdio_definitions.lib</AdditionalDependencies>
153+
<AdditionalLibraryDirectories>SDK Path\Include</AdditionalLibraryDirectories>
154+
<SubSystem>
155+
</SubSystem>
143156
</Link>
144157
</ItemDefinitionGroup>
145158
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -199,6 +212,7 @@
199212
<ClCompile Include="Castlevania\Models\Items\Door.cpp" />
200213
<ClCompile Include="Castlevania\Models\Items\DoorRenderingSystem.cpp" />
201214
<ClCompile Include="Castlevania\Models\Items\MoneyBag.cpp" />
215+
<ClCompile Include="Castlevania\Models\PowerupGenerator.cpp" />
202216
<ClCompile Include="Castlevania\Models\Systems\Rendering\ItemRenderingSystem.cpp" />
203217
<ClCompile Include="Castlevania\Models\Items\Powerup.cpp" />
204218
<ClCompile Include="Castlevania\Models\Items\PowerupResponseSystem.cpp" />
@@ -371,6 +385,7 @@
371385
<ClInclude Include="Castlevania\Models\IAttackable.h" />
372386
<ClInclude Include="Castlevania\Models\Items\MoneyBag.h" />
373387
<ClInclude Include="Castlevania\Models\Checkpoint.h" />
388+
<ClInclude Include="Castlevania\Models\PowerupGenerator.h" />
374389
<ClInclude Include="Castlevania\Models\Systems\Rendering\ItemRenderingSystem.h" />
375390
<ClInclude Include="Castlevania\Models\Items\PowerupResponseSystem.h" />
376391
<ClInclude Include="Castlevania\Models\Settings.h" />

src/GameCuaTao/Castlevania.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@
507507
<ClCompile Include="Castlevania\Models\Characters\Player\PlayerCollisionSystem.cpp">
508508
<Filter>Source Files</Filter>
509509
</ClCompile>
510+
<ClCompile Include="Castlevania\Models\PowerupGenerator.cpp">
511+
<Filter>Source Files</Filter>
512+
</ClCompile>
510513
</ItemGroup>
511514
<ItemGroup>
512515
<ClInclude Include="Library\pugixml.hpp">
@@ -1160,6 +1163,9 @@
11601163
<ClInclude Include="Castlevania\Models\Characters\Player\PlayerCollisionSystem.h">
11611164
<Filter>Header Files</Filter>
11621165
</ClInclude>
1166+
<ClInclude Include="Castlevania\Models\PowerupGenerator.h">
1167+
<Filter>Header Files</Filter>
1168+
</ClInclude>
11631169
</ItemGroup>
11641170
<ItemGroup>
11651171
<None Include="cpp.hint" />

src/GameCuaTao/Castlevania/Content/TiledMaps/Stage_01/Great_Hall.tmx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@
480480
</object>
481481
</objectgroup>
482482
<objectgroup color="#ff0000" id="5" name="Locations">
483-
<object id="9" name="Entrypoint1" type="Position" gid="185" x="64" y="320" width="60" height="66">
483+
<object id="9" name="Entrypoint" type="Position" gid="185" x="64" y="320" width="60" height="66">
484484
<properties>
485485
<property name="Facing" value="Right"/>
486486
</properties>
@@ -495,7 +495,7 @@
495495
<property name="Facing" value="Left"/>
496496
</properties>
497497
</object>
498-
<object id="120" name="Entrypoint" type="Position" gid="185" x="5050" y="310.83" width="60" height="66">
498+
<object id="120" name="Entrypoint2" type="Position" gid="185" x="5050" y="310.83" width="60" height="66">
499499
<properties>
500500
<property name="Facing" value="Right"/>
501501
</properties>
@@ -510,7 +510,7 @@
510510
<property name="Facing" value="Right"/>
511511
</properties>
512512
</object>
513-
<object id="125" name="Entrypoint2" type="Position" gid="185" x="2285" y="314" width="60" height="66">
513+
<object id="125" name="Entrypoint1" type="Position" gid="185" x="4220" y="124" width="60" height="66">
514514
<properties>
515515
<property name="Facing" value="Right"/>
516516
</properties>

src/GameCuaTao/Castlevania/Models/Characters/Enemies/Enemy.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "Enemy.h"
2+
#include "../../Items/Powerup.h"
23
#include "../../UpdateData.h"
34
#include "../../Settings.h"
5+
#include "../../../Utilities/CollisionGrid.h"
46

57
using namespace Castlevania;
68

@@ -38,6 +40,11 @@ int Enemy::GetExp()
3840
return exp;
3941
}
4042

43+
void Enemy::SetPowerupGenerator(std::unique_ptr<PowerupGenerator> powerupGenerator)
44+
{
45+
this->powerupGenerator = std::move(powerupGenerator);
46+
}
47+
4148
void Enemy::Update(UpdateData &updateData)
4249
{
4350
if (!updateData.isStopwatchActive)
@@ -68,4 +75,22 @@ void Enemy::Die()
6875
SetState(ObjectState::DYING);
6976
body.Enabled(false);
7077
Detach<IMovementSystem>();
78+
SpawnItem();
7179
}
80+
81+
void Enemy::SpawnItem()
82+
{
83+
if (powerupGenerator == nullptr)
84+
return;
85+
86+
auto item = powerupGenerator->Generate();
87+
88+
if (item == nullptr)
89+
return;
90+
91+
auto spawnedPosition = Vector2{ GetOriginPosition().x, position.y };
92+
93+
item->SetPosition(spawnedPosition);
94+
item->Spawn();
95+
collisionGrid->Add(std::move(item), CollisionObjectType::Entity);
96+
}

src/GameCuaTao/Castlevania/Models/Characters/Enemies/Enemy.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "../../GameObject.h"
44
#include "../../IAttackable.h"
55
#include "../../Health.h"
6+
#include "../../PowerupGenerator.h"
67

78
namespace Castlevania
89
{
@@ -17,6 +18,7 @@ namespace Castlevania
1718
void SetAttack(int value) override;
1819
void SetExp(int value);
1920
int GetExp();
21+
void SetPowerupGenerator(std::unique_ptr<PowerupGenerator> powerupGenerator);
2022

2123
virtual void Update(UpdateData &updateData) override;
2224
void TakeDamage(int damage);
@@ -26,5 +28,8 @@ namespace Castlevania
2628
Health health;
2729
int attack;
2830
int exp;
31+
std::unique_ptr<PowerupGenerator> powerupGenerator;
32+
33+
void SpawnItem();
2934
};
3035
}

src/GameCuaTao/Castlevania/Models/Characters/Player/Player.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ constexpr auto FLASHING_TIME = 900;
1515
constexpr auto UNTOUCHABLE_TIME = 2000;
1616
constexpr auto THROWING_COOLDOWN_TIME = 1000;
1717
constexpr auto INVISIBLE_TIME = 6000;
18+
constexpr auto LARGE_HEIGHT = 32 * 2.5f; // 2.5 tiles
1819

1920
// Simon bounce back's max height (when taking damage)
2021
constexpr auto BOUNCE_BACK_HEIGHT = 360.0f;
@@ -71,6 +72,7 @@ void Player::SetPosition(Checkpoint checkpoint)
7172
{
7273
position = checkpoint.position;
7374
SetFacing(checkpoint.facing);
75+
lastPlatformHeight = position.y + GetFrameRect().Height();
7476
}
7577

7678
void Player::SetSpeed(float speed)
@@ -464,6 +466,7 @@ bool Player::CanGoDownstairs()
464466

465467
void Player::IdleOnGround()
466468
{
469+
lastPlatformHeight = position.y + GetFrameRect().Height();
467470
SetMoveState(MoveState::IDLE);
468471
velocity.x = 0;
469472
}
@@ -486,6 +489,7 @@ void Player::DoThrow()
486489

487490
void Player::Fall()
488491
{
492+
velocity.x = 0.0f;
489493
moveState = MoveState::FALLING_HARD;
490494
}
491495

@@ -501,7 +505,8 @@ void Player::Land()
501505
return;
502506
}
503507

504-
if (velocity.y > 600.0f) // Falling down very fast, do a superhero landing
508+
// Falling down at great distance, do a superhero landing
509+
if (position.y + GetFrameRect().Height() - lastPlatformHeight >= LARGE_HEIGHT)
505510
{
506511
SetMoveState(MoveState::LANDING_HARD);
507512
velocity = Vector2::Zero();

src/GameCuaTao/Castlevania/Models/Characters/Player/Player.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,10 @@ namespace Castlevania
155155

156156
// Component-related flags
157157
NearbyObjects nearbyObjects;
158+
159+
// Need a reference to the height of the platform the player was standing before jumping
160+
// or falling from to calculate how high the player fall. this will determine how the player
161+
// would land later on
162+
float lastPlatformHeight;
158163
};
159164
}

src/GameCuaTao/Castlevania/Models/Characters/Player/PlayerRenderingSystem.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ void PlayerRenderingSystem::Receive(int message)
4545
break;
4646

4747
case UNTOUCHABLE_STARTED:
48+
case INVISIBLE_STARTED:
4849
drawUntouchableEffect = true;
4950
break;
5051

@@ -168,7 +169,7 @@ void PlayerRenderingSystem::UpdateInvisibleRendering()
168169
{
169170
auto invisibleElapsed = parent.invisibleTimer.ElapsedMilliseconds();
170171

171-
if (invisibleElapsed >= INVISIBLE_EFFECT_START && invisibleElapsed <= INVISIBLE_EFFECT_END)
172+
if (INVISIBLE_EFFECT_START <= invisibleElapsed && invisibleElapsed <= INVISIBLE_EFFECT_END)
172173
{
173174
if (!drawInvisibleEffect)
174175
{

src/GameCuaTao/Castlevania/Models/Characters/Player/PlayerResponseSystem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ Direction PlayerResponseSystem::GetPlayerHitDirection(GameObject &object, Direct
151151
case Direction::Top:
152152
case Direction::Bottom:
153153
if (parent.GetOriginPosition().x <= object.GetOriginPosition().x)
154-
hitDirection = Direction::Left;
155-
else
156154
hitDirection = Direction::Right;
155+
else
156+
hitDirection = Direction::Left;
157157
break;
158158
}
159159

@@ -197,7 +197,7 @@ void PlayerResponseSystem::OnCollideWithBoundary(CollisionResult &result, Respon
197197
{
198198
ClampDistance_Y(collisionData);
199199
parent.Land();
200-
200+
201201
if (parent.data.health.Value() <= 0)
202202
parent.Die();
203203
}

0 commit comments

Comments
 (0)