(using slick, if that matters)
The input comes in the form of an Input object that notes every key that is pressed.
I have a Player object that keeps track of each ( theres only 2 right now ) player’s stuff for example their character ( assume its like a space shooter game or something i guess )
The Player object is passed the Input object and tells the containing Character object ( contains the sprites and velocities etc ) how to move by calling a move method inside the Character object.
EX: in one update i pressed forward and right ( diagonally up right ) for player one. The input is passed to player 1 first, which now has to read that forward and right for player one are pressed and then tells the Character to move in that direction. My problem is, i have gigantic if statements to deal with the movements in the first place but, now with an additional player theres multiple sets of gigantic if statements since the player has no way to tell if the inputs are for player 1 or for player 2 without checking each one every time. Is there a speedy(as of yet im unsure of things related to speed and how things can tax the system but this game will require very precise movements and thus maximum framerates and update rates, and it is planned for there to be many objects on screen which means lots of intersections) yet clean way to deal with this?
private void movementInputHandler(Input input){
if (playerNumber == 1){
p1MovementInputHandler(input);
}
else {
p2MovementInputHandler(input);
}
}
private void p1MovementInputHandler(Input input){
if (input.isKeyDown(Param.P1_8))
{
if (input.isKeyDown(Param.P1_4)){
chara.move7();
I can elaborate more if needed
Of and if this seems like unnecessary nitpicking, i plan to have lots and lots of inputs
Move
NW, N, NE ( 7 8 9 )
W, E ( 4 6 )
SW, S, SE ( 1 2 3 )
Basic Action
Shoot 1 - defaulted to energy projectile (A)
Held shoot 1
rapid shoot 1 ? (AAA)
Shoot 2 - defaulted to ballistic projectile (B)
Held shoot 2
rapid shoot 2 ? (BBB)
Action X, held, rapid (X)
Action Y, held, rapid (Y)
Modifier
Dash modifier (D)
Melee modifier (M)
Special modifier (S)
Defensive modifier (?)
a complicated input could be moving in the NE direction while dashing, and turning that into a dashing melee attack ( 2 direction, dash modifier, melee modifier, shoot1 button)
(its meant to be played on controller since keyboards choke on this stuff, but one step at a time…)
I’m open to all kinds of suggestions, and a variety would be good ( unless theres a single best way to deal with this ). Maybe i should just keep all that if statement clutter and fold it away?
This is heavily influenced by a certain game, for those who notice