I use a few variables within the player struct to define how it moves and the animation to use. A state machine is a very clean way to do it and once you have it set up adding things is cake.
Ben
[Icarus Independent | Jump Down The Rabbithole | Tombstone: Vendetta ]
How to separate game input from game logic?
quote:
Original post by GayleSaver
State machines are a good idea, but I would go further and implement properties (that''s right, "properties") for each object as in Dark/the unreleased Siege. I''m confident that at LG the "state machine" was simply the momentum/velocity/physics data. There was no "switch" statement. On each iteration of the loop, the physics system would calculate the time difference between the previous iteraiton and the current iteration, and then move objects accordingly. If you happened to hit a wall in that time period, I think the collision system would detect that because the loop that moves you one velocity unit would halt if you hit a wall, and post a collision on the event queue.
It''s quite funny, cos every post you make refers to Looking Glass, and how they did things, or whatever


I think that in 3D games, it is common to store the motion just as a direction and velocity. But some of the objects in the Dark Engine did have a ''state''. I know this wasn''t done using a switch statement (we have already discussed how ''objects'' in the Dark Engine are not objects in the code sense

So, Gaylesaver, I''d be interested to hear if you have any details on how this was accomplished

This how I do it. Not sure if this is the best way, but it works pretty well. I have a CInput class that wraps all of the DirectInput stuff. Then I have a CController class that owns a CInput object. However, CController is a singleton class and every object that needs input just gets a pointer to the CController class.
The disadvantage is that all of the input logic is not contained in one place.
The advantage is that all of the input logic is not contained in one place.
The disadvantage is that all of the input logic is not contained in one place.
The advantage is that all of the input logic is not contained in one place.

Well, I am no expert but this is what I do:
if(rightkeypressed)
MovePlayer(x, y)
and in MovePlayer(x, y):
currentx += x;
currenty += y;
So if I wanted to move 3 right.. I would say MovePlayer(3, 0);
Or, maybe 3 left? MovePlayer(-3, 0);
if(rightkeypressed)
MovePlayer(x, y)
and in MovePlayer(x, y):
currentx += x;
currenty += y;
So if I wanted to move 3 right.. I would say MovePlayer(3, 0);
Or, maybe 3 left? MovePlayer(-3, 0);
-AfroFire is Brin & Brin is AfroFire
I was thinking of having my input engine update a global list of controls, which could be associated with multiple keys or axis. Game objects could check the state of these controls from inside their Update() function. I don''t really know if this is a good solution, but I think it sounds fine. Has anyone else tried something like this? Any disadvantages to it?
"It tastes like burning..."
I must admit, I''m a rookie at this.
But just for fun and to stay on topic here''s
an idea: ( Spur of the moment stuff folks )
char velocity = 3;
If ( KEY_PRESSED )
MovePlayer( x + ( velocity | MOVE_LEFT_RIGHT ),
y + ( velocity | MOVE_UP_DOWN );
Where MOVE_LEFT_RIGHT and MOVE_UP_DOWN are signed characters
For a LEFT movement: MOVE_LEFT_RIGHT = 0x80
( turning on sign bit )
For a RIGHT movement: MOVE_LEFT_RIGHT = 0x00
So moving left would result in a negative number because
of the bit wise OR operation with the sign bit. Right
would just be 0x00 for no sign bit resulting in a positive
number. These flags would have to be turned on when the
key is fetched from the buffer. No multiple ifs.
But just for fun and to stay on topic here''s
an idea: ( Spur of the moment stuff folks )
char velocity = 3;
If ( KEY_PRESSED )
MovePlayer( x + ( velocity | MOVE_LEFT_RIGHT ),
y + ( velocity | MOVE_UP_DOWN );
Where MOVE_LEFT_RIGHT and MOVE_UP_DOWN are signed characters
For a LEFT movement: MOVE_LEFT_RIGHT = 0x80
( turning on sign bit )
For a RIGHT movement: MOVE_LEFT_RIGHT = 0x00
So moving left would result in a negative number because
of the bit wise OR operation with the sign bit. Right
would just be 0x00 for no sign bit resulting in a positive
number. These flags would have to be turned on when the
key is fetched from the buffer. No multiple ifs.
Adulthood is the vehicle for making you childhood dreams come true.
And that will save you, what, a nanosecond?
"It tastes like burning..."
If so, that would be
1, 000 picoseconds
1, 000, 000 femtoseconds
1, 000, 000, 000 attoseconds
That''s alot of atto seconds.
I can''t help myself, if I can devise quicker way
of doing things, I got to try it. I''d even do it
for an attosecond.
1, 000 picoseconds
1, 000, 000 femtoseconds
1, 000, 000, 000 attoseconds
That''s alot of atto seconds.
I can''t help myself, if I can devise quicker way
of doing things, I got to try it. I''d even do it
for an attosecond.
Adulthood is the vehicle for making you childhood dreams come true.
It''s called pseudo-code!!!
It doesn''t matter what you call it, the concept is the same..
btw there are no switch/case/if statements necessary..
here''s how:
enumerate all commands..
create array of function pointers..
link array elements to appropriate functions..
when processing a message/command, use the message(which is an enumeration)as an index into the array of function pointers..
that way you could have thousands of possible messages/commands/actions/events/ and NO checking to determine what type of message you are processing...simply offset into the array, and BAM!! control is instantly routed to the appropriate handler..
my GOD I can''t believe some people took that literally..it sounds like many assumptions were made based on the pseudo-code..if that''s the way YOU would have done it, fine, but please don''t assume that I would write my code in the same way..
"Like all good things, it starts with a monkey.."
It doesn''t matter what you call it, the concept is the same..
btw there are no switch/case/if statements necessary..
here''s how:
enumerate all commands..
create array of function pointers..
link array elements to appropriate functions..
when processing a message/command, use the message(which is an enumeration)as an index into the array of function pointers..
that way you could have thousands of possible messages/commands/actions/events/ and NO checking to determine what type of message you are processing...simply offset into the array, and BAM!! control is instantly routed to the appropriate handler..
my GOD I can''t believe some people took that literally..it sounds like many assumptions were made based on the pseudo-code..if that''s the way YOU would have done it, fine, but please don''t assume that I would write my code in the same way..
"Like all good things, it starts with a monkey.."
"Like all good things, it starts with a monkey.."
quote:
Original post by Arkon
hahahah what a supid idea!! - SendMessage
HELLLLLOOOOWWWWWWW you are programming a GAME not an application
one of the main goals in game is to do everything you can in the fastest way!
and using SendMessage and then switch or if statements to know what kind of message that was... is just f#@$king slow!
-----
or maybe i didn''t get your idea well,did i?
Arkon
[QSoft Systems]
a stupid idea?..what SHOULD I call the function?
I figured it''s for a game, not an application..is that not an appropriate pseudo-code function name?..what would be?..why?..
ah, the answer...everything must be done in the fastest possible way...so I guess I should have called the function "sm", that''s really the only improvement I can think of..that should save several keystrokes throughout the course of development..
switch or if statements?...what would you need them for?
"Like all good things, it starts with a monkey.."
"Like all good things, it starts with a monkey.."
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement