Skip to content

Commit 84d3019

Browse files
committed
Falling and drowning
1 parent da21cb8 commit 84d3019

File tree

6 files changed

+84
-14
lines changed

6 files changed

+84
-14
lines changed

Game/Entities/combatant.cpp

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ Combatant::Combatant(Controller* Controls)
2525

2626
item_held_index = -1;
2727

28+
sinking_depth = 0;
29+
2830
magicrampindex = 0;
2931
magicrampdelay = 0;
3032

3133
speed_delay = 0;
32-
Speed = 5;
34+
Speed = 4;
3335

3436
CurrentPower = COMBATANT_POWER;
3537
world_zone = nullptr;
@@ -73,6 +75,7 @@ void Combatant::OnUpdate()
7375
weapon_change_on_stand = false;
7476
}
7577
SetNewState( curState->NextState );
78+
ProposeMove( ScreenX, ScreenY );
7679
}
7780

7881
if( (Controls->GetState() & Controller::WEAPON) == Controller::WEAPON )
@@ -258,7 +261,30 @@ void Combatant::OnUpdate()
258261

259262
}
260263

264+
if( CurrentState == CombatantState::FALLING )
265+
{
266+
if( world_z > world_zone->WorldZ )
267+
{
268+
world_z -= 4;
269+
ScreenY += 4;
270+
} else {
271+
world_z = world_zone->WorldZ;
272+
SetNewState( CombatantState::FALLING_LANDED );
273+
ProposeMove( ScreenX, ScreenY );
274+
}
275+
}
261276

277+
if( CurrentState == CombatantState::SINKING )
278+
{
279+
sinking_depth += 4;
280+
if( sinking_depth >= 42 )
281+
{
282+
// Check if transporting first
283+
SetNewState( CombatantState::DEAD );
284+
ScreenX = -60;
285+
return;
286+
}
287+
}
262288

263289
}
264290

@@ -291,10 +317,23 @@ void Combatant::OnRender()
291317
// Render
292318
if( shadowed )
293319
{
294-
SkinGraphic->DrawPartial( 0, 168, 32, 42, ScreenX - 16, ScreenY - 40, 0 );
320+
if( CurrentState == CombatantState::FALLING || CurrentState == CombatantState::LONGJUMP || CurrentState == CombatantState::SHORTJUMP )
321+
{
322+
SkinGraphic->DrawPartial( 0, 168, 32, 42, ScreenX - 16, ScreenY - 40 + world_z - world_zone->WorldZ, 0 );
323+
} else {
324+
SkinGraphic->DrawPartial( 0, 168, 32, 42, ScreenX - 16, ScreenY - 40, 0 );
325+
}
295326
}
296327

297-
SkinGraphic->DrawPartial( (framenumber % 13) * 32, (framenumber / 13) * 42, 32, 42, ScreenX - 16, ScreenY - 40 - zpos, flipflag );
328+
if( CurrentState == CombatantState::SINKING )
329+
{
330+
if( sinking_depth < 42 )
331+
{
332+
SkinGraphic->DrawPartial( (framenumber % 13) * 32, (framenumber / 13) * 42, 32, 42 - sinking_depth, ScreenX - 16, ScreenY - 40 - zpos + sinking_depth, flipflag );
333+
}
334+
} else {
335+
SkinGraphic->DrawPartial( (framenumber % 13) * 32, (framenumber / 13) * 42, 32, 42, ScreenX - 16, ScreenY - 40 - zpos, flipflag );
336+
}
298337
}
299338

300339
void Combatant::OnUpdateMagic()
@@ -341,6 +380,7 @@ void Combatant::SetNewState(CombatantState::States NewState)
341380

342381
CurrentState = NewState;
343382
CurrentStateTime = 0;
383+
sinking_depth = 0;
344384

345385
if( CombatantState::StateList[CurrentState]->LockControls )
346386
{
@@ -386,7 +426,11 @@ void Combatant::SetRoomZone(RoomZone* CurrentZone, bool IsWarped)
386426
}
387427
// TODO: Run Enter Script
388428

389-
// Check for falling
429+
if( world_z > CurrentZone->WorldZ && CurrentState != CombatantState::LONGJUMP && CurrentState != CombatantState::SHORTJUMP )
430+
{
431+
SetNewState( CombatantState::FALLING );
432+
return;
433+
}
390434
}
391435

392436
void Combatant::ProposeMove( int ScreenX, int ScreenY )
@@ -409,11 +453,25 @@ void Combatant::ProposeMove( int ScreenX, int ScreenY )
409453
RoomZone* z = world_zone->InRoom->FindZoneForPoint( ScreenX, ScreenY );
410454
if( z != nullptr )
411455
{
456+
// Drowning time
457+
if( z->DrowningZone && CurrentState != CombatantState::LONGJUMP && CurrentState != CombatantState::SHORTJUMP && z->WorldZ == world_z )
458+
{
459+
SetNewState( CombatantState::SINKING );
460+
return;
461+
}
462+
412463
if( z == world_zone )
413464
{
414465
// Same zone
415466
this->ScreenX = ScreenX;
416467
this->ScreenY = ScreenY;
468+
469+
// Check for falling
470+
if( world_z > z->WorldZ && CurrentState != CombatantState::LONGJUMP && CurrentState != CombatantState::SHORTJUMP )
471+
{
472+
SetNewState( CombatantState::FALLING );
473+
}
474+
417475
} else {
418476

419477
bool allowMove = true;
@@ -430,12 +488,6 @@ void Combatant::ProposeMove( int ScreenX, int ScreenY )
430488
allowMove = false;
431489
}
432490

433-
// Drowning time
434-
if( z->DrowningZone )
435-
{
436-
SetNewState( CombatantState::SINKING );
437-
}
438-
439491
if( z->WorldZ < world_z )
440492
{
441493
if( z->ClimbingZone )

Game/Entities/combatant.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Combatant
3737

3838
int speed_delay;
3939

40+
int sinking_depth;
4041

4142
int magicrampindex;
4243
int magicrampdelay;

Game/Entities/combatantstate.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,12 @@ void CombatantState::InitialiseCombatantStates()
173173
s->LockControls = true;
174174
s->NextState = States::STANDING;
175175
s->FrameNumbers.push_back( { 24, false, false, 0, false, false } );
176+
s->FrameNumbers.push_back( { 24, false, false, 0, false, false } );
176177
s->FrameNumbers.push_back( { 14, false, false, 0, true, false } );
178+
s->FrameNumbers.push_back( { 14, false, false, 0, false, false } );
177179
s->FrameNumbers.push_back( { 14, false, false, 0, true, false } );
180+
s->FrameNumbers.push_back( { 14, false, false, 0, false, false } );
181+
s->FrameNumbers.push_back( { 24, false, false, 0, false, false } );
178182
s->FrameNumbers.push_back( { 24, false, false, 0, false, false } );
179183
StateList.push_back(s);
180184

@@ -275,9 +279,9 @@ void CombatantState::InitialiseCombatantStates()
275279

276280
// States::SINKING
277281
s = new CombatantState();
278-
s->Loops = false;
282+
s->Loops = true;
279283
s->LockControls = true;
280-
s->NextState = States::STANDING;
284+
s->NextState = States::DEAD; // Usually dead, though sometimes not
281285
s->FrameNumbers.push_back( { 16, false, false, 0, false, false } );
282286
StateList.push_back(s);
283287

@@ -291,7 +295,7 @@ void CombatantState::InitialiseCombatantStates()
291295

292296
// States::FALLING_LANDED
293297
s = new CombatantState();
294-
s->Loops = true;
298+
s->Loops = false;
295299
s->LockControls = true;
296300
s->NextState = States::HITLOW;
297301
s->FrameNumbers.push_back( { 54, false, true, 0, false, false } );
@@ -303,6 +307,7 @@ void CombatantState::InitialiseCombatantStates()
303307
s->LockControls = true;
304308
s->NextState = States::STANDING;
305309
s->FrameNumbers.push_back( { 23, false, false, 0, false, false } );
310+
s->FrameNumbers.push_back( { 23, false, false, 0, false, false } );
306311
StateList.push_back(s);
307312

308313
// States::HITLOW
@@ -311,6 +316,7 @@ void CombatantState::InitialiseCombatantStates()
311316
s->LockControls = true;
312317
s->NextState = States::STANDING;
313318
s->FrameNumbers.push_back( { 54, false, false, 0, false, false } );
319+
s->FrameNumbers.push_back( { 54, false, false, 0, false, false } );
314320
StateList.push_back(s);
315321

316322
// States::DYING

Game/Entities/room.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ void Room::SetDefaults()
1313
RoomTime = 0;
1414
BackgroundColour = 13;
1515
Enemy = nullptr;
16+
FullyRendered = false;
1617
}
1718

1819
Room::~Room()
@@ -23,11 +24,13 @@ Room::~Room()
2324
void Room::ResetRoomTime()
2425
{
2526
RoomTime = 0;
27+
FullyRendered = false;
2628
}
2729

2830
void Room::OnEnter()
2931
{
3032
RoomTime = 0;
33+
FullyRendered = false;
3134
if( Script_OnCombatantEnter != "" )
3235
{
3336
GameResources::Scripting->ExecuteAsync( Script_OnCombatantEnter );
@@ -45,6 +48,12 @@ void Room::OnLeave()
4548
void Room::Update()
4649
{
4750
RoomTime++;
51+
52+
if( RoomTime >= FRAMEWORK->GetFramesPerSecond() )
53+
{
54+
FullyRendered = true;
55+
}
56+
4857
if( Script_OnUpdate != "" )
4958
{
5059
GameResources::Scripting->ExecuteAsync( Script_OnUpdate );
@@ -61,7 +70,7 @@ void Room::Render(int RenderOffsetX, int RenderOffsetY, int FromY, int ToY)
6170
int panelstodraw = Panels.size();
6271

6372
// Always 2 seconds to render a room
64-
if( RoomTime < FRAMEWORK->GetFramesPerSecond() )
73+
if( !FullyRendered )
6574
{
6675
float c = (float)RoomTime / (float)FRAMEWORK->GetFramesPerSecond(); // % through the build
6776
c *= Panels.size(); // Number of panels to draw at this percentage

Game/Entities/room.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Room
2222
std::string Script_OnCombatantLeave;
2323
std::string Script_OnUpdate;
2424

25+
bool FullyRendered;
26+
2527
Combatant* Enemy;
2628

2729
Room();

resources/jane4.db

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)