Skip to content

Commit

Permalink
Tweak subweapons collision handling, add weapon category in devtool
Browse files Browse the repository at this point in the history
- Make subweapons hit enemies easier by checking collision with sprite frame
  instead of bounding box (which is usually smaller)
- Refactor RangedWeapon: remove owner dependency
- Add ranged weapon type in devtool: Now you can throw weapons from mouse cursor's position
- Other misc cleanup
  • Loading branch information
NearHuscarl committed Dec 25, 2018
1 parent 1ba080f commit 8888f2f
Show file tree
Hide file tree
Showing 31 changed files with 158 additions and 237 deletions.
8 changes: 4 additions & 4 deletions src/GameCuaTao/Castlevania.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@
<ClCompile Include="Castlevania\Models\GameObject.cpp" />
<ClCompile Include="Castlevania\Models\Items\Door.cpp" />
<ClCompile Include="Castlevania\Models\Items\DoorRenderingSystem.cpp" />
<ClCompile Include="Castlevania\Models\Items\Fireball.cpp" />
<ClCompile Include="Castlevania\Models\Items\MoneyBag.cpp" />
<ClCompile Include="Castlevania\Models\Systems\Rendering\ItemRenderingSystem.cpp" />
<ClCompile Include="Castlevania\Models\Items\Powerup.cpp" />
Expand Down Expand Up @@ -222,8 +221,9 @@
<ClCompile Include="Castlevania\Models\Weapons\HolyWater.cpp" />
<ClCompile Include="Castlevania\Models\Weapons\HolyWaterRenderingSystem.cpp" />
<ClCompile Include="Castlevania\Models\Weapons\HolyWaterResponseSystem.cpp" />
<ClCompile Include="Castlevania\Models\Weapons\PoisonResponseSystem.cpp" />
<ClCompile Include="Castlevania\Models\Weapons\RangedWeapon.cpp" />
<ClCompile Include="Castlevania\Models\Weapons\WhipCollisionSystem.cpp" />
<ClCompile Include="Castlevania\Models\Weapons\WeaponCollisionSystem.cpp" />
<ClCompile Include="Castlevania\Models\Weapons\WhipFlashingRenderingSystem.cpp" />
<ClCompile Include="Castlevania\Models\Weapons\WhipRenderingSystem.cpp" />
<ClCompile Include="Castlevania\Models\Weapons\WeaponResponseSystem.cpp" />
Expand Down Expand Up @@ -354,7 +354,6 @@
<ClInclude Include="Castlevania\Models\IBoss.h" />
<ClInclude Include="Castlevania\Models\Items\Door.h" />
<ClInclude Include="Castlevania\Models\Items\DoorRenderingSystem.h" />
<ClInclude Include="Castlevania\Models\Items\Fireball.h" />
<ClInclude Include="Castlevania\Models\IAttackable.h" />
<ClInclude Include="Castlevania\Models\Items\MoneyBag.h" />
<ClInclude Include="Castlevania\Models\IThrowable.h" />
Expand Down Expand Up @@ -391,8 +390,9 @@
<ClInclude Include="Castlevania\Models\Weapons\HolyWater.h" />
<ClInclude Include="Castlevania\Models\Weapons\HolyWaterRenderingSystem.h" />
<ClInclude Include="Castlevania\Models\Weapons\HolyWaterResponseSystem.h" />
<ClInclude Include="Castlevania\Models\Weapons\PoisonResponseSystem.h" />
<ClInclude Include="Castlevania\Models\Weapons\RangedWeapon.h" />
<ClInclude Include="Castlevania\Models\Weapons\WhipCollisionSystem.h" />
<ClInclude Include="Castlevania\Models\Weapons\WeaponCollisionSystem.h" />
<ClInclude Include="Castlevania\Models\Weapons\WhipFlashingRenderingSystem.h" />
<ClInclude Include="Castlevania\Models\Weapons\WhipRenderingSystem.h" />
<ClInclude Include="Castlevania\Models\Weapons\WeaponResponseSystem.h" />
Expand Down
24 changes: 12 additions & 12 deletions src/GameCuaTao/Castlevania.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,9 @@
<ClCompile Include="Castlevania\Models\Characters\Enemies\FishmanControlSystem.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Castlevania\Models\Items\Fireball.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Castlevania\Models\Spawners\SpawnArea.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Castlevania\Models\Weapons\WhipCollisionSystem.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Castlevania\Models\Spawners\ZombieSpawnArea.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -477,6 +471,12 @@
<ClCompile Include="Castlevania\Models\Weapons\HolyWaterRenderingSystem.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Castlevania\Models\Weapons\PoisonResponseSystem.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Castlevania\Models\Weapons\WeaponCollisionSystem.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Library\pugixml.hpp">
Expand Down Expand Up @@ -950,9 +950,6 @@
<ClInclude Include="Castlevania\Models\IAttackable.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Castlevania\Models\Items\Fireball.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Castlevania\Models\Spawners\SpawnArea.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand All @@ -962,9 +959,6 @@
<ClInclude Include="Castlevania\Models\Spawners\ISpawner.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Castlevania\Models\Weapons\WhipCollisionSystem.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Castlevania\Models\Spawners\ZombieSpawnArea.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -1109,6 +1103,12 @@
<ClInclude Include="Castlevania\Models\Weapons\HolyWaterRenderingSystem.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Castlevania\Models\Weapons\PoisonResponseSystem.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Castlevania\Models\Weapons\WeaponCollisionSystem.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="cpp.hint" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

<Dictionary
Name="Fireball"
Speed="300.0"
ThrowSpeed_X="300.0"
ThrowSpeed_Y="0.0"
Attack="2">
</Dictionary>

Expand Down
10 changes: 5 additions & 5 deletions src/GameCuaTao/Castlevania/Content/Items/Holy_Water.atlas.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@

<Sprite ID="holy_water_flame_01">
<SpriteFrame Left="34" Top="0" Width="34" Height="30" />
<SpriteBoundary Left="45" Top="0" Width="12" Height="30" />
<SpriteBoundary Left="39" Top="0" Width="24" Height="30" />
</Sprite>

<Sprite ID="holy_water_flame_02">
<SpriteFrame Left="68" Top="0" Width="34" Height="30" />
<SpriteBoundary Left="79" Top="0" Width="12" Height="30" />
<SpriteBoundary Left="73" Top="0" Width="24" Height="30" />
</Sprite>

<Sprite ID="holy_water_flame_03">
<SpriteFrame Left="102" Top="0" Width="34" Height="30" />
<SpriteBoundary Left="113" Top="0" Width="12" Height="30" />
<SpriteBoundary Left="107" Top="0" Width="24" Height="30" />
</Sprite>

<Sprite ID="holy_water_flame_04">
<SpriteFrame Left="136" Top="0" Width="34" Height="30" />
<SpriteBoundary Left="147" Top="0" Width="12" Height="30" />
<SpriteBoundary Left="141" Top="0" Width="24" Height="30" />
</Sprite>

<Sprite ID="holy_water_flame_05">
<SpriteFrame Left="170" Top="0" Width="34" Height="30" />
<SpriteBoundary Left="181" Top="0" Width="12" Height="30" />
<SpriteBoundary Left="175" Top="0" Width="24" Height="30" />
</Sprite>
</Spritesheet>

Expand Down
15 changes: 5 additions & 10 deletions src/GameCuaTao/Castlevania/Models/Characters/Enemies/Fishman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ void Fishman::WalkLeft()
SetFishmanState(FishmanState::WALKING);
}

void Fishman::Shoot(std::unique_ptr<GameObject> fireball)
void Fishman::Shoot(std::unique_ptr<RangedWeapon> fireball)
{
this->fireball = std::move(fireball);
this->fireball->GetBody().Enabled(false);
this->fireball->SetVisibility(false);

velocity.x = 0.0f;
SetFishmanState(FishmanState::SHOOTING);
shootingTimer.Start();
Expand Down Expand Up @@ -106,14 +109,6 @@ void Fishman::ReleaseFireball()
fishmanRect.top + 6
};

fireball->SetPosition(position);

auto fireballSpeed = fireball->GetSpeed();

if (facing == Facing::Right)
fireball->SetVelocity_X(fireballSpeed);
else
fireball->SetVelocity_X(-fireballSpeed);

fireball->Throw(position);
collisionGrid->Add(std::move(fireball), CollisionObjectType::Entity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Direct2DGame/Utilities/Stopwatch.h"
#include "Enemy.h"
#include "../../Weapons/RangedWeapon.h"
#include "../../Factories/ObjectCollection.h"

namespace Castlevania
Expand All @@ -27,14 +28,14 @@ namespace Castlevania
void Launch();
void WalkRight();
void WalkLeft();
void Shoot(std::unique_ptr<GameObject> fireball);
void Shoot(std::unique_ptr<RangedWeapon> fireball);

private:
float launchSpeed;
FishmanState fishmanState;
Stopwatch shootingTimer;

std::unique_ptr<GameObject> fireball;
std::unique_ptr<RangedWeapon> fireball;

// Fishman animation stop updating when in falling state
void Freeze();
Expand Down
24 changes: 18 additions & 6 deletions src/GameCuaTao/Castlevania/Models/Characters/Enemies/GiantBat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ void GiantBat::Update(UpdateData &updateData)
case GiantBatState::SHOOTING:
if (shootingTimer.ElapsedMilliseconds() > SHOOTING_TIME)
{
if (fireball != nullptr)
collisionGrid->Add(std::move(fireball), CollisionObjectType::Entity);

ReleaseFireball();
Hover();
shootingTimer.Reset();
}
Expand Down Expand Up @@ -159,13 +157,18 @@ void GiantBat::Dive(Vector2 playerPosition)
DoDiveAttack();
}

void GiantBat::Shoot(std::unique_ptr<GameObject> fireball, Vector2 destination)
void GiantBat::Shoot(std::unique_ptr<RangedWeapon> fireball, Vector2 destination)
{
auto fireballPosition = GetOriginPosition();
auto direction = Vector2::Normalize(destination - fireballPosition);
auto fireballSpeed = fireball->GetSpeed();
auto fireballSpeed = fireball->GetThrowVelocity().x;

if (direction.x > 0)
fireball->SetFacing(Facing::Right);
else
fireball->SetFacing(Facing::Left);

fireball->SetVelocity(direction * fireballSpeed);
fireball->SetThrowVelocity(direction * fireballSpeed);
fireball->SetPosition(fireballPosition);

this->fireball = std::move(fireball);
Expand All @@ -191,3 +194,12 @@ void GiantBat::DoDiveAttack()
{
SetGiantBatState(GiantBatState::DIVING);
}

void GiantBat::ReleaseFireball()
{
if (fireball == nullptr)
return;

fireball->Throw(fireball->GetPosition());
collisionGrid->Add(std::move(fireball), CollisionObjectType::Entity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "Direct2DGame/Utilities/Stopwatch.h"
#include "Enemy.h"
#include "../../IBoss.h"
#include "../../Items/Fireball.h"
#include "../../Weapons/RangedWeapon.h"

namespace Castlevania
{
Expand Down Expand Up @@ -46,7 +46,7 @@ namespace Castlevania
void Hover();
void Fly(float distance);
void Dive(Vector2 playerPosition);
void Shoot(std::unique_ptr<GameObject> fireball, Vector2 destination);
void Shoot(std::unique_ptr<RangedWeapon> fireball, Vector2 destination);

private:
Vector2 playerPosition;
Expand All @@ -62,8 +62,9 @@ namespace Castlevania
void SetGiantBatState(GiantBatState state);
void Rise();
void DoDiveAttack();
void ReleaseFireball();

std::unique_ptr<GameObject> fireball;
std::unique_ptr<RangedWeapon> fireball;
Stopwatch shootingTimer;

friend class GiantBatMovementSystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void PantherCollisionSystem::Update(UpdateData &updateData)
}

// TODO: do we need to sort?
body.SetCollisionData(FilterCollision(results));
body.SetCollisionData(FilterCollisionResults(results));

// Check if player is inside active zone
if (!parent.IsActive())
Expand Down
21 changes: 9 additions & 12 deletions src/GameCuaTao/Castlevania/Models/Characters/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ void Player::Update(UpdateData &updateData)
{
GameObject::Update(updateData);
UpdateStates();
UpdateSubWeapons(updateData);

whip->Update(updateData);
}
Expand Down Expand Up @@ -169,15 +168,6 @@ void Player::UpdateStates()
}
}

void Player::UpdateSubWeapons(UpdateData &updateData)
{
if (subWeapon == nullptr)
return;

if (subWeapon->GetBody().Enabled()) // weapon is flying and active
collisionGrid->Add(std::move(subWeapon), CollisionObjectType::Entity);
}

void Player::OnAttackComplete()
{
switch (attackState)
Expand Down Expand Up @@ -365,7 +355,6 @@ void Player::Throw(std::unique_ptr<RangedWeapon> weapon)
return;

subWeapon = std::move(weapon);
subWeapon->SetOwner(this);
subWeapon->GetBody().Enabled(false);
subWeapon->SetVisibility(false);

Expand Down Expand Up @@ -439,7 +428,15 @@ void Player::DoThrow()
if (subWeapon == nullptr)
return;

subWeapon->Throw();
auto playerBbox = GetBoundingBox();
auto position = Vector2{
playerBbox.left,
playerBbox.top + 5
};

subWeapon->SetFacing(facing);
subWeapon->Throw(position);
collisionGrid->Add(std::move(subWeapon), CollisionObjectType::Entity);
}

void Player::Fall()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ namespace Castlevania
void Die();

void UpdateStates();
void UpdateSubWeapons(UpdateData &updateData);
void OnAttackComplete();
void OnHitStairEntry();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void PlayerResponseSystem::OnCollideWithVampireBat(CollisionResult &result)

void PlayerResponseSystem::OnCollideWithFireball(CollisionResult &result)
{
auto &object = dynamic_cast<Fireball&>(result.collidedObject);
auto &object = dynamic_cast<RangedWeapon&>(result.collidedObject);
auto hitDirection = GetPlayerHitDirection(object, result.direction);

parent.TakeDamage(object.GetAttack(), hitDirection);
Expand Down
Loading

0 comments on commit 8888f2f

Please sign in to comment.