mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-04-28 15:57:59 +03:00
TR5 Moving Laser (#1598)
* First * First * Finished * Update CHANGELOG.md * Change default speed to 10 * SimplifyLogic * Revert "SimplifyLogic" This reverts commitbe0aeefaa4
. * Reapply "SimplifyLogic" This reverts commitc7b8e1442e
. * Add moving sound. * Add acceleration * Update tr5_movinglaser.cpp * Fix merge --------- Co-authored-by: Lwmte <3331699+Lwmte@users.noreply.github.com>
This commit is contained in:
parent
e0b50439b3
commit
9b119d03a2
7 changed files with 163 additions and 3 deletions
|
@ -27,9 +27,11 @@ TombEngine releases are located in this repository (alongside with Tomb Editor):
|
|||
- You must update your Lara object: https://github.com/TombEngine/Resources/raw/main/Wad2%20Objects/Lara/TEN_Lara.wad2
|
||||
* Added a particle based waterfall emitter object and associated sprite slots.
|
||||
- You must use this version: https://github.com/TombEngine/Resources/raw/refs/heads/main/Wad2%20Objects/Interactables/TEN_Waterfall_Emitter.wad2
|
||||
* Added TR4 statue plinth.
|
||||
* Added TR1 hammer.
|
||||
* Added TR1 Hammer.
|
||||
- You must use this version: <insert address here>
|
||||
* Added TR3 Moving Laser.
|
||||
- You must use this version: <insert address here>
|
||||
* Added TR4 Statue Plinth.
|
||||
|
||||
### Lua API changes
|
||||
|
||||
|
|
134
TombEngine/Objects/TR5/Trap/tr5_movinglaser.cpp
Normal file
134
TombEngine/Objects/TR5/Trap/tr5_movinglaser.cpp
Normal file
|
@ -0,0 +1,134 @@
|
|||
#include "framework.h"
|
||||
#include "Objects/TR5/Trap/tr5_movinglaser.h"
|
||||
|
||||
#include "Game/animation.h"
|
||||
#include "Game/collision/collide_item.h"
|
||||
#include "Game/collision/collide_room.h"
|
||||
#include "Game/collision/Point.h"
|
||||
#include "Game/collision/Sphere.h"
|
||||
#include "Game/control/control.h"
|
||||
#include "Game/effects/effects.h"
|
||||
#include "Game/effects/light.h"
|
||||
#include "Game/items.h"
|
||||
#include "Game/Lara/lara.h"
|
||||
#include "Sound/sound.h"
|
||||
#include "Math/Utils.h"
|
||||
#include "Specific/level.h"
|
||||
|
||||
using namespace TEN::Collision::Sphere;
|
||||
|
||||
namespace TEN::Entities::Traps
|
||||
{
|
||||
enum MovingLaserFlags
|
||||
{
|
||||
Speed,
|
||||
PauseCounter,
|
||||
Direction,
|
||||
DistanceTravelled,
|
||||
SpeedCalc
|
||||
};
|
||||
|
||||
constexpr auto MOVING_LASER_DAMAGE = 100;
|
||||
constexpr int PAUSE_FRAMES = 30;
|
||||
constexpr float MAX_SPEED_THRESHOLD = 0.9f;
|
||||
constexpr float MIN_SPEED = 1.0f;
|
||||
constexpr float ACCELERATION = 1.0f;
|
||||
|
||||
void InitializeMovingLaser(short itemNumber)
|
||||
{
|
||||
auto& item = g_Level.Items[itemNumber];
|
||||
item.ItemFlags[MovingLaserFlags::Direction] = 1;
|
||||
item.ItemFlags[MovingLaserFlags::Speed] = 10;
|
||||
item.Pose.Translate(item.Pose.Orientation, -CLICK(1)); // Offset by one click to make it dangerous at the edges of the block.
|
||||
}
|
||||
|
||||
void ControlMovingLaser(short itemNumber)
|
||||
{
|
||||
auto& item = g_Level.Items[itemNumber];
|
||||
|
||||
if (!TriggerActive(&item))
|
||||
return;
|
||||
|
||||
float moveDistance = (BLOCK(1) * item.TriggerFlags) + CLICK(2); // Use OCB to calculate the distance and add 2 clicks.
|
||||
|
||||
float distancePerFrame = ((float)(CLICK(1)) * item.ItemFlags[MovingLaserFlags::Speed]) / FPS; // Calculate distance per frame
|
||||
|
||||
item.Animation.ActiveState = 0;
|
||||
SpawnDynamicLight(item.Pose.Position.x, item.Pose.Position.y - 64, item.Pose.Position.z, (Random::GenerateInt() % 2) + 8, (Random::GenerateInt() % 4) + 24, Random::GenerateInt() % 4, Random::GenerateInt() % 2);
|
||||
item.MeshBits = -1 - (GetRandomControl() & 0x14); // To make lasers flicker
|
||||
|
||||
if (item.TriggerFlags == 0)
|
||||
{
|
||||
AnimateItem(&item);
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.ItemFlags[MovingLaserFlags::PauseCounter] > 0)
|
||||
{
|
||||
item.ItemFlags[MovingLaserFlags::PauseCounter]--;
|
||||
|
||||
if (item.ItemFlags[MovingLaserFlags::PauseCounter] == 0)
|
||||
{
|
||||
item.ItemFlags[MovingLaserFlags::Direction] *= -1;
|
||||
item.ItemFlags[MovingLaserFlags::DistanceTravelled] = 0;
|
||||
}
|
||||
|
||||
AnimateItem(&item);
|
||||
return;
|
||||
}
|
||||
|
||||
item.Pose.Translate(item.Pose.Orientation, (item.ItemFlags[MovingLaserFlags::Direction] * item.ItemFlags[MovingLaserFlags::SpeedCalc]));
|
||||
|
||||
item.ItemFlags[MovingLaserFlags::DistanceTravelled] += item.ItemFlags[MovingLaserFlags::SpeedCalc];
|
||||
|
||||
if (item.ItemFlags[DistanceTravelled] < (moveDistance -BLOCK(0.5f)))
|
||||
item.ItemFlags[SpeedCalc] = std::min(distancePerFrame, item.ItemFlags[MovingLaserFlags::SpeedCalc] + ACCELERATION);
|
||||
else
|
||||
item.ItemFlags[SpeedCalc] = std::max(MIN_SPEED, item.ItemFlags[MovingLaserFlags::SpeedCalc] - ACCELERATION);
|
||||
|
||||
|
||||
if (item.ItemFlags[MovingLaserFlags::DistanceTravelled] >= moveDistance)
|
||||
{
|
||||
item.ItemFlags[MovingLaserFlags::PauseCounter] = PAUSE_FRAMES;
|
||||
}
|
||||
|
||||
if (item.ItemFlags[MovingLaserFlags::PauseCounter] == 0)
|
||||
{
|
||||
SoundEffect(SFX_TR5_MOVING_LASER_LOOP, &item.Pose, SoundEnvironment::Always);
|
||||
}
|
||||
|
||||
// Update room if necessary.
|
||||
short new_room = item.RoomNumber;
|
||||
GetPointCollision(item).GetRoomNumber();
|
||||
if (new_room != item.RoomNumber)
|
||||
ItemNewRoom(itemNumber, new_room);
|
||||
|
||||
AnimateItem(&item);
|
||||
}
|
||||
|
||||
void CollideMovingLaser(short itemNumber, ItemInfo* playerItem, CollisionInfo* coll)
|
||||
{
|
||||
auto& item = g_Level.Items[itemNumber];
|
||||
|
||||
// Collide with objects.
|
||||
if (item.Status == ITEM_ACTIVE)
|
||||
{
|
||||
if (!TestBoundsCollide(&item, playerItem, coll->Setup.Radius))
|
||||
return;
|
||||
|
||||
HandleItemSphereCollision(item, *playerItem);
|
||||
}
|
||||
else if (item.Status != ITEM_INVISIBLE)
|
||||
{
|
||||
ObjectCollision(itemNumber, playerItem, coll);
|
||||
}
|
||||
|
||||
// Damage entity.
|
||||
if (TestBoundsCollide(&item, playerItem, coll->Setup.Radius))
|
||||
{
|
||||
DoDamage(playerItem, MOVING_LASER_DAMAGE);
|
||||
DoLotsOfBlood(playerItem->Pose.Position.x, playerItem->Pose.Position.y + CLICK(3), playerItem->Pose.Position.z, 4, playerItem->Pose.Orientation.y, playerItem->RoomNumber, 3);
|
||||
playerItem->TouchBits.ClearAll();
|
||||
}
|
||||
}
|
||||
}
|
11
TombEngine/Objects/TR5/Trap/tr5_movinglaser.h
Normal file
11
TombEngine/Objects/TR5/Trap/tr5_movinglaser.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
struct CollisionInfo;
|
||||
struct ItemInfo;
|
||||
|
||||
namespace TEN::Entities::Traps
|
||||
{
|
||||
void InitializeMovingLaser(short itemNumber);
|
||||
void ControlMovingLaser(short itemNumber);
|
||||
void CollideMovingLaser(short itemNumber, ItemInfo* item, CollisionInfo* coll);
|
||||
}
|
|
@ -65,6 +65,7 @@
|
|||
#include "Objects/TR5/Trap/tr5_ventilator.h"
|
||||
#include "Objects/TR5/Trap/tr5_romehammer.h"
|
||||
#include "Objects/TR5/Trap/tr5_fallingceiling.h"
|
||||
#include "Objects/TR5/Trap/tr5_movinglaser.h"
|
||||
#include "Objects/TR5/Trap/tr5_explosion.h"
|
||||
#include "Objects/TR5/Trap/tr5_wreckingball.h"
|
||||
|
||||
|
@ -963,6 +964,15 @@ static void StartTrap(ObjectInfo *obj)
|
|||
obj->drawRoutine = nullptr;
|
||||
obj->usingDrawAnimatingItem = false;
|
||||
}
|
||||
|
||||
obj = &Objects[ID_MOVING_LASER];
|
||||
if (obj->loaded)
|
||||
{
|
||||
obj->Initialize = InitializeMovingLaser;
|
||||
obj->control = ControlMovingLaser;
|
||||
obj->collision = CollideMovingLaser;
|
||||
obj->SetHitEffect(true);
|
||||
}
|
||||
}
|
||||
|
||||
static void StartSwitch(ObjectInfo *obj)
|
||||
|
|
|
@ -373,6 +373,7 @@ enum GAME_OBJECT_ID : short
|
|||
ID_ELECTRIC_BALL_IMPACT_POINT,
|
||||
ID_HAMMER_HANDLE,
|
||||
ID_HAMMER_HEAD,
|
||||
ID_MOVING_LASER,
|
||||
|
||||
ID_PUZZLE_ITEM1 = 500,
|
||||
ID_PUZZLE_ITEM2,
|
||||
|
|
|
@ -1163,7 +1163,7 @@ enum SOUND_EFFECTS
|
|||
SFX_TR1_SLAMDOOR_CLOSE = 1144,
|
||||
SFX_TR2_DRAGON_FALL = 1145,
|
||||
SFX_TR2_MARCO_BARTOLLI_TRANSFORM = 1146,
|
||||
|
||||
SFX_TR5_MOVING_LASER_LOOP = 1147,
|
||||
// TombEngine sounds
|
||||
|
||||
SFX_TEN_CUSTOM_FOOTSTEPS_1 = 1150,
|
||||
|
|
|
@ -786,6 +786,7 @@ if not exist "%ScriptsDir%\Strings.lua" xcopy /Y "$(SolutionDir)Scripts\Strings.
|
|||
<ClInclude Include="Objects\TR5\Switch\tr5_raisingcog.h" />
|
||||
<ClInclude Include="Objects\TR5\Trap\LaserBarrier.h" />
|
||||
<ClInclude Include="Objects\TR5\Trap\LaserBeam.h" />
|
||||
<ClInclude Include="Objects\TR5\Trap\tr5_movinglaser.h" />
|
||||
<ClInclude Include="Objects\TR5\Trap\tr5_explosion.h" />
|
||||
<ClInclude Include="Objects\TR5\Trap\tr5_fallingceiling.h" />
|
||||
<ClInclude Include="Objects\TR5\Trap\tr5_romehammer.h" />
|
||||
|
@ -1311,6 +1312,7 @@ if not exist "%ScriptsDir%\Strings.lua" xcopy /Y "$(SolutionDir)Scripts\Strings.
|
|||
<ClCompile Include="Objects\TR5\tr5_objects.cpp" />
|
||||
<ClCompile Include="Objects\TR5\Trap\LaserBarrier.cpp" />
|
||||
<ClCompile Include="Objects\TR5\Trap\LaserBeam.cpp" />
|
||||
<ClCompile Include="Objects\TR5\Trap\tr5_movinglaser.cpp" />
|
||||
<ClCompile Include="Objects\TR5\Trap\tr5_explosion.cpp" />
|
||||
<ClCompile Include="Objects\TR5\Trap\tr5_fallingceiling.cpp" />
|
||||
<ClCompile Include="Objects\TR5\Trap\tr5_romehammer.cpp" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue