Skip to content

Commit da21cb8

Browse files
committed
Some basic game controls
1 parent 52c1c61 commit da21cb8

File tree

16 files changed

+122
-151
lines changed

16 files changed

+122
-151
lines changed

Game/Editor/roomdesigner.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ RoomDesigner::RoomDesigner()
3333

3434
for(int i = 0; i < DesignerMode::ModeCount; i++ )
3535
{
36-
designermodes[i]->Init( this, workingroom, textfont );
36+
designermodes[i]->Init( this, workingroom, workingroomindex, textfont );
3737
}
3838
designermode = DesignerMode::PanelMode;
3939

@@ -99,7 +99,7 @@ void RoomDesigner::EventOccurred(Event *e)
9999
AddLogText("Mode change to { Enemy }");
100100
break;
101101
}
102-
designermodes[designermode]->Init( this, workingroom, textfont );
102+
designermodes[designermode]->Init( this, workingroom, workingroomindex, textfont );
103103
return;
104104
case ALLEGRO_KEY_F4:
105105
workingroomindex = GameResources::GameWorld->Rooms.size() - 1;
@@ -129,7 +129,7 @@ void RoomDesigner::EventOccurred(Event *e)
129129
*/
130130
for(int i = 0; i < DesignerMode::ModeCount; i++ )
131131
{
132-
designermodes[i]->Init( this, workingroom, textfont );
132+
designermodes[i]->Init( this, workingroom, workingroomindex, textfont );
133133
}
134134
AddLogText( "Room " + Strings::FromNumber( workingroomindex ) );
135135
}
@@ -142,7 +142,7 @@ void RoomDesigner::EventOccurred(Event *e)
142142
workingroom->ResetRoomTime();
143143
for(int i = 0; i < DesignerMode::ModeCount; i++ )
144144
{
145-
designermodes[i]->Init( this, workingroom, textfont );
145+
designermodes[i]->Init( this, workingroom, workingroomindex, textfont );
146146
}
147147
AddLogText( "Room " + Strings::FromNumber( workingroomindex ) );
148148
}

Game/Editor/roomdesigner_mode.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
#include "roomdesigner_mode.h"
33
#include "roomdesigner.h"
44

5-
void RoomDesignerModule::Init(RoomDesigner* Designer, Room* Working, ALLEGRO_FONT* Font)
5+
void RoomDesignerModule::Init(RoomDesigner* Designer, Room* Working, int WorkingRoomIndex, ALLEGRO_FONT* Font)
66
{
7+
workingroomindex = WorkingRoomIndex;
78
workingroom = Working;
89
designer = Designer;
910
textfont = Font;

Game/Editor/roomdesigner_mode.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ class RoomDesignerModule
1515
{
1616

1717
protected:
18+
int workingroomindex;
1819
Room* workingroom;
1920
RoomDesigner* designer;
2021
ALLEGRO_FONT* textfont;
2122

2223
public:
23-
virtual void Init(RoomDesigner* Designer, Room* Working, ALLEGRO_FONT* Font);
24+
virtual void Init(RoomDesigner* Designer, Room* Working, int WorkingRoomIndex, ALLEGRO_FONT* Font);
2425
void AddLogText(std::string Text);
2526

2627
virtual void OnEvent(Event* e) = 0;

Game/Editor/roomdesigner_zone.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ RoomDesignerZone::RoomDesignerZone()
1818
Mode = ZONEMODE_ZONESELECT;
1919
}
2020

21-
void RoomDesignerZone::Init(RoomDesigner* Designer, Room* Working, ALLEGRO_FONT* Font)
21+
void RoomDesignerZone::Init(RoomDesigner* Designer, Room* Working, int WorkingRoomIndex, ALLEGRO_FONT* Font)
2222
{
23-
RoomDesignerModule::Init( Designer, Working, Font );
23+
RoomDesignerModule::Init( Designer, Working, WorkingRoomIndex, Font );
2424
CursorX = 120;
2525
CursorY = 72;
2626
CursorMove = 0;
@@ -88,8 +88,8 @@ void RoomDesignerZone::OnEvent(Event *e)
8888
zonepoint_activeindex = z->Area->Points->count - 1;
8989
}
9090
Vector2* v = (Vector2*)z->Area->Points->ItemAt( zonepoint_activeindex );
91-
CursorX = v->X;
92-
CursorY = v->Y;
91+
CursorX = v->X + 40;
92+
CursorY = v->Y + 28;
9393
} else {
9494
zonepoint_activeindex = 0;
9595
}
@@ -119,8 +119,8 @@ void RoomDesignerZone::OnEvent(Event *e)
119119
zonepoint_activeindex = 0;
120120
}
121121
Vector2* v = (Vector2*)z->Area->Points->ItemAt( zonepoint_activeindex );
122-
CursorX = v->X;
123-
CursorY = v->Y;
122+
CursorX = v->X + 40;
123+
CursorY = v->Y + 28;
124124
} else {
125125
zonepoint_activeindex = 0;
126126
}
@@ -151,7 +151,7 @@ void RoomDesignerZone::OnEvent(Event *e)
151151
switch( Mode )
152152
{
153153
case ZONEMODE_ZONESELECT:
154-
workingroom->Zones.push_back( new RoomZone( workingroom ) );
154+
workingroom->Zones.push_back( new RoomZone( workingroom, workingroomindex ) );
155155
zone_activeindex = workingroom->Zones.size() - 1;
156156
Mode = ZONEMODE_POINTSELECT;
157157
break;
@@ -298,8 +298,8 @@ void RoomDesignerZone::Update()
298298
if( z->Area->Points->count > 0 && z->Area->Points->count > zonepoint_activeindex && zonepoint_activeindex >= 0)
299299
{
300300
Vector2* v = (Vector2*)z->Area->Points->ItemAt( zonepoint_activeindex );
301-
v->X = CursorX;
302-
v->Y = CursorY;
301+
v->X = CursorX - 40;
302+
v->Y = CursorY - 28;
303303
}
304304
}
305305
}
@@ -325,8 +325,8 @@ void RoomDesignerZone::RenderRoom()
325325
int writeindex = 0;
326326
for( int vertindex = 0; vertindex < workingzone->Area->Points->count; vertindex++ )
327327
{
328-
verts[writeindex] = ((Vector2*)workingzone->Area->Points->ItemAt( vertindex ))->X;
329-
verts[writeindex + 1] = ((Vector2*)workingzone->Area->Points->ItemAt( vertindex ))->Y;
328+
verts[writeindex] = ((Vector2*)workingzone->Area->Points->ItemAt( vertindex ))->X + 40;
329+
verts[writeindex + 1] = ((Vector2*)workingzone->Area->Points->ItemAt( vertindex ))->Y + 28;
330330

331331
if( zoneindex == zone_activeindex && vertindex == zonepoint_activeindex && Mode == ZONEMODE_POINTMOVE )
332332
{

Game/Editor/roomdesigner_zone.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ class RoomDesignerZone : public RoomDesignerModule
2727

2828
RoomDesignerZone();
2929

30-
virtual void Init(RoomDesigner* Designer, Room* Working, ALLEGRO_FONT* Font);
30+
virtual void Init(RoomDesigner* Designer, Room* Working, int WorkingRoomIndex, ALLEGRO_FONT* Font);
3131

3232
virtual void OnEvent(Event* e);
3333
virtual void Update();
3434
virtual void RenderRoom();
3535
virtual void RenderOverlay();
3636

37-
};
37+
};

Game/Entities/combatant.cpp

Lines changed: 78 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,24 @@ Combatant::Combatant(Controller* Controls)
2323
weapon_current_index = 0;
2424
weapon_change_index = 0;
2525

26+
item_held_index = -1;
27+
2628
magicrampindex = 0;
2729
magicrampdelay = 0;
2830

2931
speed_delay = 0;
30-
Speed = 4;
32+
Speed = 5;
3133

3234
CurrentPower = COMBATANT_POWER;
3335
world_zone = nullptr;
34-
}
3536

36-
Combatant::~Combatant()
37-
{
37+
ZoneClipping = false;
38+
UnlimitedPower = false;
39+
UnlimitedMagic = false;
3840
}
3941

40-
void Combatant::Load(ConfigFile* DataFile, std::string KeyPrefix)
41-
{
42-
43-
}
44-
45-
void Combatant::Save(ConfigFile* DataFile, std::string KeyPrefix)
42+
Combatant::~Combatant()
4643
{
47-
4844
}
4945

5046
void Combatant::Load(SQLiteDB* Database, int GameID, int RoomID)
@@ -382,23 +378,34 @@ Controller::ControllerStateFlags Combatant::GetSecondaryControllerState()
382378

383379
void Combatant::SetRoomZone(RoomZone* CurrentZone, bool IsWarped)
384380
{
381+
CurrentRoomID = CurrentZone->InRoomID;
385382
world_zone = CurrentZone;
386383
if( IsWarped )
387384
{
388385
world_z = CurrentZone->WorldZ;
389386
}
390387
// TODO: Run Enter Script
388+
389+
// Check for falling
391390
}
392391

393392
void Combatant::ProposeMove( int ScreenX, int ScreenY )
394393
{
395-
// if( ZoneClipping )
394+
if( ZoneClipping )
395+
{
396+
// Clipping
397+
this->ScreenX = ScreenX;
398+
this->ScreenY = ScreenY;
399+
return;
400+
}
396401

402+
// Check if we're in a valid place
397403
if( world_zone == nullptr )
398404
{
399405
return;
400406
}
401407

408+
// Can we locate the next zone?
402409
RoomZone* z = world_zone->InRoom->FindZoneForPoint( ScreenX, ScreenY );
403410
if( z != nullptr )
404411
{
@@ -407,17 +414,67 @@ void Combatant::ProposeMove( int ScreenX, int ScreenY )
407414
// Same zone
408415
this->ScreenX = ScreenX;
409416
this->ScreenY = ScreenY;
410-
} else if( ZoneClipping ) {
411-
// Clipping
412-
this->ScreenX = ScreenX;
413-
this->ScreenY = ScreenY;
414-
SetRoomZone( z, true );
415417
} else {
416418

417-
// TODO: Check valid to enter, then handle any conditions
418-
419-
420-
419+
bool allowMove = true;
420+
421+
// Can't magically walk up cliffs
422+
if( z->WorldZ > world_z )
423+
{
424+
allowMove = false;
425+
}
426+
427+
// Got to roll into here
428+
if( z->RollingZone && CurrentState != CombatantState::ROLLING )
429+
{
430+
allowMove = false;
431+
}
432+
433+
// Drowning time
434+
if( z->DrowningZone )
435+
{
436+
SetNewState( CombatantState::SINKING );
437+
}
438+
439+
if( z->WorldZ < world_z )
440+
{
441+
if( z->ClimbingZone )
442+
{
443+
// TODO: Handle climbing down
444+
allowMove = false;
445+
}
446+
}
447+
448+
if( z->TransportZone && (z->TransportRequiresItemHeld < 0 || z->TransportRequiresItemHeld == item_held_index) )
449+
{
450+
// TODO: Handle "animated" transports
451+
452+
Room* tr = GameResources::GameWorld->Rooms.at( z->TransportRoomID );
453+
RoomZone* tz = tr->FindZoneForPoint( z->TransportScreenX, z->TransportScreenY );
454+
this->ScreenX = z->TransportScreenX;
455+
this->ScreenY = z->TransportScreenY;
456+
if( z->TransportFacing != GameDirection::UNCHANGED )
457+
{
458+
CurrentDirection == z->TransportFacing;
459+
}
460+
if( z->TransportClearInput )
461+
{
462+
Controls->ClearState();
463+
}
464+
SetRoomZone( tz, true );
465+
allowMove = false;
466+
467+
}
468+
469+
// TODO: Check valid to enter, then handle any conditions
470+
471+
if( allowMove )
472+
{
473+
this->ScreenX = ScreenX;
474+
this->ScreenY = ScreenY;
475+
SetRoomZone( z, false );
476+
}
477+
421478
}
422479
}
423480
}

Game/Entities/combatant.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ class Combatant
3333
int weapon_current_index;
3434
int weapon_change_index;
3535

36+
int item_held_index;
37+
3638
int speed_delay;
37-
39+
3840

3941
int magicrampindex;
4042
int magicrampdelay;
@@ -61,6 +63,7 @@ class Combatant
6163
int ScreenX;
6264
int ScreenY;
6365
GameDirection::Direction CurrentDirection;
66+
int CurrentRoomID;
6467

6568
CombatantState::States CurrentState;
6669
int CurrentStateTime;
@@ -72,9 +75,6 @@ class Combatant
7275
Combatant(Controller* Controls);
7376
~Combatant();
7477

75-
void Load(ConfigFile* DataFile, std::string KeyPrefix);
76-
void Save(ConfigFile* DataFile, std::string KeyPrefix);
77-
7878
void Load(SQLiteDB* Database, int GameID, int RoomID);
7979
void Save(SQLiteDB* Database, int GameID, int RoomID);
8080

Game/Entities/panel.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,6 @@ bool Panel::SortingPredicate(const Panel* A, const Panel* B)
3030
return false;
3131
}
3232

33-
34-
void Panel::Load(ConfigFile* DataFile, std::string KeyPrefix)
35-
{
36-
ObjectGraphicIndex = DataFile->GetQuickIntegerValue( KeyPrefix, 0, ObjectGraphicIndex );
37-
for( int i = 0; i < 16; i++ )
38-
{
39-
ColourRemap[i] = DataFile->GetQuickIntegerValue( KeyPrefix, i + 1, ColourRemap[i] );
40-
}
41-
ScreenX = DataFile->GetQuickIntegerValue( KeyPrefix, 17, ScreenX );
42-
ScreenY = DataFile->GetQuickIntegerValue( KeyPrefix, 18, ScreenY );
43-
FlipHorizontal = DataFile->GetQuickBooleanValue( KeyPrefix, 19, FlipHorizontal );
44-
FlipVertical = DataFile->GetQuickBooleanValue( KeyPrefix, 20, FlipVertical );
45-
BackgroundAtY = DataFile->GetQuickIntegerValue( KeyPrefix, 21, BackgroundAtY );
46-
Visible = DataFile->GetQuickBooleanValue( KeyPrefix, 22, Visible );
47-
}
48-
49-
void Panel::Save(ConfigFile* DataFile, std::string KeyPrefix)
50-
{
51-
DataFile->SetIntegerValue( KeyPrefix, 0, ObjectGraphicIndex );
52-
for( int i = 0; i < 16; i++ )
53-
{
54-
DataFile->SetIntegerValue( KeyPrefix, i + 1, ColourRemap[i] );
55-
}
56-
DataFile->SetIntegerValue( KeyPrefix, 17, ScreenX );
57-
DataFile->SetIntegerValue( KeyPrefix, 18, ScreenY );
58-
DataFile->SetBooleanValue( KeyPrefix, 19, FlipHorizontal );
59-
DataFile->SetBooleanValue( KeyPrefix, 20, FlipVertical );
60-
DataFile->SetIntegerValue( KeyPrefix, 21, BackgroundAtY );
61-
DataFile->SetBooleanValue( KeyPrefix, 22, Visible );
62-
}
63-
6433
void Panel::Load(SQLiteDB* Database, int GameID, int RoomID, int PanelID)
6534
{
6635
std::string Query;

Game/Entities/panel.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ class Panel
2020

2121
static bool SortingPredicate(const Panel* A, const Panel* B);
2222

23-
void Load(ConfigFile* DataFile, std::string KeyPrefix);
24-
void Save(ConfigFile* DataFile, std::string KeyPrefix);
25-
2623
void Load(SQLiteDB* Database, int GameID, int RoomID, int PanelID);
2724
void Save(SQLiteDB* Database, int GameID, int RoomID, int PanelID);
2825

0 commit comments

Comments
 (0)