Key configurations
Hi!
I''m currently trying to make/making a simple platform game and I''m using DelphiX components. But I have encountered I problem I don''t know how to fix properly (yet)
The problem:
Two players can both select a character they want to play with. I currently have two characters and I have created classes for them like this:
TZero = class(TImageSprite)
procedure DoMove(MoveCount: Integer); override;
end;
the other class looks just like this.
To control characters I currently use this method (for checking out animations n stuff):
procedure TZero.DoMove(MoveCount: Integer);
begin
if isLeft in Form.DXInput.States then //blahblah
end;
but this way controls are fixed per character and not per player.
Also players won''t be able to select the same character.
What I want is controls fixed per player so player1 would have a set of controls and player2 would have a set of controls.
Does anyone know how to do this properly? I would appreciate any help here.
Thx,
S_O_S
I don''t know Delphi (I''m rather a C++ guy) but the idea should remain the same :
Declare a new class called Controler (or something like that) with abstract methods like left(), right(), etc... Then create two classes ControlerP1 and ControlerP2 which are derivated from the Controler class.
In your character class, put a pointer to a Controler object. When the game actually start just bind the good controler to the appropriate character.
Here''s a C++/java/pseudo sample code (hope it helps) :
Declare a new class called Controler (or something like that) with abstract methods like left(), right(), etc... Then create two classes ControlerP1 and ControlerP2 which are derivated from the Controler class.
In your character class, put a pointer to a Controler object. When the game actually start just bind the good controler to the appropriate character.
Here''s a C++/java/pseudo sample code (hope it helps) :
class Controler{ bool left() = 0; bool right() = 0; ...}class ControlP1 extends Controler{ bool left() { return (some key is down); } ...}class ControlP2 extends Controler{ bool left() { return (another key is down); } ...}class Character{ Controler * ctrl; void setControler( Controler * c) { ctrl = c; } void update() { if ( ctrl->left()) // moveLeft ... }}CharacterA charA;CharacterB charB;ControlP1 ctrlP1;ControlP2 ctrlP2;void startGame(){ if ( player 1 choose character A) { charA.setControler( &ctrlP1); charB.setControler( &ctrlP2); } else { charA.setControler( &ctrlP2); charB.setControler( &ctrlP1); }}
Ok let me get this straight. I make a class Controller with 2 descendants ControllerP1 and ControllerP2 and they have some boolean functions that per key return whether it is pressed. Different for each player (class). Ok I understand it so far. But then how do I actually bind those to my characters? This is where I don't entirely understand the code. (I really should learn C++). Well thx anyway
S_O_S
Edited by - Shadow_Of_Spawn on September 21, 2001 6:30:55 PM
S_O_S
Edited by - Shadow_Of_Spawn on September 21, 2001 6:30:55 PM
I would use a TIniFile.ReadSectionValues and a TStringList to load your bindings definitions, convert them all so that TStringList[] is the key value and the TStringList.Objects[] is the action associated with it. You can use TStringList.Objects[TStringList.IndexOf(Asc(Key))] to retrieve the action, provided IndexOf(Key) <> -1
-----------
-WarMage
...Fly Delphreek...
Edited by - WarMage on September 21, 2001 7:04:11 PM
-----------
-WarMage
...Fly Delphreek...
Edited by - WarMage on September 21, 2001 7:04:11 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement