this isnt so much an issue, but it does require just some guidance, help or just a finger that points me a good direction.

so ive been lovingly busy with a new version of my game FRONG and have really enjoyed working with HAXE/OPENFL. but the one thing ive only really worked on for ages in single player stuff. so my code right now is just STUPID big and over bloated to have the selection of 1 to 4 players playing. it works, but is just horribly large [thats what she said ;)]

so i have this in my main script, which is handling not so much everything since im splitting it all up into different classes. but this player choice is just large, too large for my liking, and i do know that it can be better, smaller and just downright looking more sexy than it is. there are too many doubles for my liking, but they arent crossing with each other luckily.

so this is my current player selection, along with the controls for the players. i think the keyUp/keyDown stuff can also be way better.

but if anyone could lend a helping word, id be more than happy to listen. if there is something that i could read up on, even better, if a video then i love you

the selection first is using the numbered keys to select players that are playing. which are tehn controlled by a QWERTY layout of keys

thanks to anyone who has a nice solution or guidance

```
private function keyDown(event:KeyboardEvent):Void {
//1 player
if (currentGameState == Paused && event.keyCode == 49) {
setGameState(Playing01);
} else if (event.keyCode == 87){
player01KeyUp = true;
} else if (event.keyCode == 83){
player01KeyDown = true;
}
//2 player
if (currentGameState == Paused && event.keyCode == 50) {
setGameState(Playing02);
} else if (event.keyCode == 87){
player01KeyUp = true;
} else if (event.keyCode == 83){
player01KeyDown = true;
} else if (event.keyCode == 82) {
player02KeyUp = true;
} else if (event.keyCode == 70) {
player02KeyDown = true;
}
//3 player
if (currentGameState == Paused && event.keyCode == 51) {
setGameState(Playing03);
} else if (event.keyCode == 87){
player01KeyUp = true;
} else if (event.keyCode == 83){
player01KeyDown = true;
} else if (event.keyCode == 82) {
player02KeyUp = true;
} else if (event.keyCode == 70) {
player02KeyDown = true;
} else if (event.keyCode == 89) {
player03KeyUp = true;
} else if (event.keyCode == 72) {
player03KeyDown = true;
}
//4 player
if (currentGameState == Paused && event.keyCode == 52) {
setGameState(Playing04);
} else if (event.keyCode == 87){
player01KeyUp = true;
} else if (event.keyCode == 83){
player01KeyDown = true;
} else if (event.keyCode == 82) {
player02KeyUp = true;
} else if (event.keyCode == 70) {
player02KeyDown = true;
} else if (event.keyCode == 89) {
player03KeyUp = true;
} else if (event.keyCode == 72) {
player03KeyDown = true;
} else if (event.keyCode == 73) {
player04KeyUp = true;
} else if (event.keyCode == 75) {
player04KeyDown = true;
}
}
private function keyUp(event:KeyboardEvent):Void {
//1 player
if (currentGameState == Paused && event.keyCode == 49) {
setGameState(Playing01);
} else if (event.keyCode == 87){
player01KeyUp = false;
} else if (event.keyCode == 83){
player01KeyDown = false;
}
//2 player
if (currentGameState == Paused && event.keyCode == 50) {
setGameState(Playing02);
} else if (event.keyCode == 87){
player01KeyUp = false;
} else if (event.keyCode == 83){
player01KeyDown = false;
} else if (event.keyCode == 82) {
player02KeyUp = false;
} else if (event.keyCode == 70) {
player02KeyDown = false;
}
//3 player
if (currentGameState == Paused && event.keyCode == 51) {
setGameState(Playing03);
} else if (event.keyCode == 87){
player01KeyUp = false;
} else if (event.keyCode == 83){
player01KeyDown = false;
} else if (event.keyCode == 82) {
player02KeyUp = false;
} else if (event.keyCode == 70) {
player02KeyDown = false;
} else if (event.keyCode == 89) {
player03KeyUp = false;
} else if (event.keyCode == 72) {
player03KeyDown = false;
}
//4 player
if (currentGameState == Paused && event.keyCode == 52) {
setGameState(Playing04);
} else if (event.keyCode == 87){
player01KeyUp = false;
} else if (event.keyCode == 83){
player01KeyDown = false;
} else if (event.keyCode == 82) {
player02KeyUp = false;
} else if (event.keyCode == 70) {
player02KeyDown = false;
} else if (event.keyCode == 89) {
player03KeyUp = false;
} else if (event.keyCode == 72) {
player03KeyDown = false;
} else if (event.keyCode == 73) {
player04KeyUp = false;
} else if (event.keyCode == 75) {
player04KeyDown = false;
}
}
private function everyFrame(event:Event):Void {
if (currentGameState == Playing01) {
// player 01
if (player01KeyUp) {
player01.y -= playerSpeed;
}
if (player01KeyDown) {
player01.y += playerSpeed;
}
if (player01.y < 5) player01.y = 5;
if (player01.y > 695) player01.y = 695;
// player 02
if (ball.x > 400 && ball.y > player02.y + 70) {
player02.y += playerSpeed;
}
if (ball.x > 400 && ball.y < player02.y + 30) {
player02.y -= playerSpeed;
}
if (player02.y < 5) player02.y = 5;
if (player02.y > 695) player02.y = 695;
// player03
if (ball.y < 300 && ball.x > player03.x + 70) {
player03.x += playerSpeed;
}
if (ball.y < 300 && ball.x < player03.x + 30) {
player03.x -= playerSpeed;
}
if (player03.x < 5) player03.x = 5;
if (player03.x > 695) player03.x = 695;
// player04
if (ball.y > 300 && ball.x > player04.x + 70) {
player04.x += playerSpeed;
}
if (ball.y > 300 && ball.x < player04.x + 30) {
player04.x -= playerSpeed;
}
if (player04.x < 5) player04.x = 5;
if (player04.x > 695) player04.x = 695;
ball.x += ballMovement.x;
ball.y += ballMovement.y;
//player01 bounce off
if (ballMovement.x < 0 && ball.x < 30 && ball.y >= player01.y && ball.y <= player01.y + 100) {
playerSound01.play();
bounceBall();
ball.x = 30;
}
//player02 bounce off
if (ballMovement.x > 0 && ball.x > 770 && ball.y >= player02.y && ball.y <= player02.y + 100) {
playerSound02.play();
bounceBall();
ball.x = 770;
}
//player03 bounce off
if (ballMovement.y < 0 && ball.y < 30 && ball.x >= player03.x && ball.x <= player03.x + 100) {
playerSound03.play();
bounceBall();
ball.y = 30;
}
//player04 bounce off
if (ballMovement.y > 0 && ball.y > 770 && ball.x >= player04.x && ball.x <= player04.x + 100) {
playerSound04.play();
bounceBall();
ball.y = 770;
}
if (ball.y < 5 || ball.y > 795) ballMovement.y *= -1;
if (ball.x > 795) {
winGame(Human01);
winGame(Human03);
winGame(Human04);
playerSoundScore02.play();
}
if (ball.x < 5) {
winGame(Human02);
winGame(Human03);
winGame(Human04);
playerSoundScore01.play();
}
if (ball.y > 795) {
winGame(Human01);
winGame(Human02);
winGame(Human03);
playerSoundScore04.play();
}
if (ball.y < 5) {
winGame(Human01);
winGame(Human02);
winGame(Human04);
playerSoundScore03.play();
}
}
if (currentGameState == Playing02) {
// player 01
if (player01KeyUp) {
player01.y -= playerSpeed;
}
if (player01KeyDown) {
player01.y += playerSpeed;
}
if (player01.y < 5) player01.y = 5;
if (player01.y > 695) player01.y = 695;
//newPlayer02 movement
if (player02KeyUp) {
player02.y -= playerSpeed;
}
if (player02KeyDown) {
player02.y += playerSpeed;
}
if (player02.y < 5) player02.y = 5;
if (player02.y > 695) player02.y = 695;
// player03
if (ball.y < 300 && ball.x > player03.x + 70) {
player03.x += playerSpeed;
}
if (ball.y < 300 && ball.x < player03.x + 30) {
player03.x -= playerSpeed;
}
if (player03.x < 5) player03.x = 5;
if (player03.x > 695) player03.x = 695;
// player04
if (ball.y > 300 && ball.x > player04.x + 70) {
player04.x += playerSpeed;
}
if (ball.y > 300 && ball.x < player04.x + 30) {
player04.x -= playerSpeed;
}
if (player04.x < 5) player04.x = 5;
if (player04.x > 695) player04.x = 695;
ball.x += ballMovement.x;
ball.y += ballMovement.y;
//player01 bounce off
if (ballMovement.x < 0 && ball.x < 30 && ball.y >= player01.y && ball.y <= player01.y + 100) {
playerSound01.play();
bounceBall();
ball.x = 30;
}
//player02 bounce off
if (ballMovement.x > 0 && ball.x > 770 && ball.y >= player02.y && ball.y <= player02.y + 100) {
playerSound02.play();
bounceBall();
ball.x = 770;
}
//player03 bounce off
if (ballMovement.y < 0 && ball.y < 30 && ball.x >= player03.x && ball.x <= player03.x + 100) {
playerSound03.play();
bounceBall();
ball.y = 30;
}
//player04 bounce off
if (ballMovement.y > 0 && ball.y > 770 && ball.x >= player04.x && ball.x <= player04.x + 100) {
playerSound04.play();
bounceBall();
ball.y = 770;
}
if (ball.y < 5 || ball.y > 795) ballMovement.y *= -1;
if (ball.x > 795) {
winGame(Human01);
winGame(Human03);
winGame(Human04);
playerSoundScore02.play();
}
if (ball.x < 5) {
winGame(Human02);
winGame(Human03);
winGame(Human04);
playerSoundScore01.play();
}
if (ball.y > 795) {
winGame(Human01);
winGame(Human02);
winGame(Human03);
playerSoundScore04.play();
}
if (ball.y < 5) {
winGame(Human01);
winGame(Human02);
winGame(Human04);
playerSoundScore03.play();
}
}
if (currentGameState == Playing03) {
// player 01
if (player01KeyUp) {
player01.y -= playerSpeed;
}
if (player01KeyDown) {
player01.y += playerSpeed;
}
if (player01.y < 5) player01.y = 5;
if (player01.y > 695) player01.y = 695;
//newPlayer02 movement
if (player02KeyUp) {
player02.y -= playerSpeed;
}
if (player02KeyDown) {
player02.y += playerSpeed;
}
if (player02.y < 5) player02.y = 5;
if (player02.y > 695) player02.y = 695;
//newPlayer03 movement
if (player03KeyUp) {
player03.x -= playerSpeed;
}
if (player03KeyDown) {
player03.x += playerSpeed;
}
if (player03.x < 5) player03.x = 5;
if (player03.x > 695) player03.x = 695;
// player04
if (ball.y > 300 && ball.x > player04.x + 70) {
player04.x += playerSpeed;
}
if (ball.y > 300 && ball.x < player04.x + 30) {
player04.x -= playerSpeed;
}
if (player04.x < 5) player04.x = 5;
if (player04.x > 695) player04.x = 695;
ball.x += ballMovement.x;
ball.y += ballMovement.y;
//player01 bounce off
if (ballMovement.x < 0 && ball.x < 30 && ball.y >= player01.y && ball.y <= player01.y + 100) {
playerSound01.play();
bounceBall();
ball.x = 30;
}
//player02 bounce off
if (ballMovement.x > 0 && ball.x > 770 && ball.y >= player02.y && ball.y <= player02.y + 100) {
playerSound02.play();
bounceBall();
ball.x = 770;
}
//player03 bounce off
if (ballMovement.y < 0 && ball.y < 30 && ball.x >= player03.x && ball.x <= player03.x + 100) {
playerSound03.play();
bounceBall();
ball.y = 30;
}
//player04 bounce off
if (ballMovement.y > 0 && ball.y > 770 && ball.x >= player04.x && ball.x <= player04.x + 100) {
playerSound04.play();
bounceBall();
ball.y = 770;
}
if (ball.y < 5 || ball.y > 795) ballMovement.y *= -1;
if (ball.x > 795) {
winGame(Human01);
winGame(Human03);
winGame(Human04);
playerSoundScore02.play();
}
if (ball.x < 5) {
winGame(Human02);
winGame(Human03);
winGame(Human04);
playerSoundScore01.play();
}
if (ball.y > 795) {
winGame(Human01);
winGame(Human02);
winGame(Human03);
playerSoundScore04.play();
}
if (ball.y < 5) {
winGame(Human01);
winGame(Human02);
winGame(Human04);
playerSoundScore03.play();
}
}
if (currentGameState == Playing04) {
// player 01
if (player01KeyUp) {
player01.y -= playerSpeed;
}
if (player01KeyDown) {
player01.y += playerSpeed;
}
if (player01.y < 5) player01.y = 5;
if (player01.y > 695) player01.y = 695;
//newPlayer02 movement
if (player02KeyUp) {
player02.y -= playerSpeed;
}
if (player02KeyDown) {
player02.y += playerSpeed;
}
if (player02.y < 5) player02.y = 5;
if (player02.y > 695) player02.y = 695;
//newPlayer03 movement
if (player03KeyUp) {
player02.x -= playerSpeed;
}
if (player03KeyDown) {
player03.x += playerSpeed;
}
if (player03.x < 5) player03.x = 5;
if (player03.x > 695) player03.x = 695;
//newPlayer04 movement
if (player04KeyUp) {
player04.x -= playerSpeed;
}
if (player04KeyDown) {
player04.x += playerSpeed;
}
if (player04.x < 5) player04.x = 5;
if (player04.x > 695) player04.x = 695;
ball.x += ballMovement.x;
ball.y += ballMovement.y;
//player01 bounce off
if (ballMovement.x < 0 && ball.x < 30 && ball.y >= player01.y && ball.y <= player01.y + 100) {
bounceBall();
playerSound01.play();
ball.x = 30;
}
//player02 bounce off
if (ballMovement.x > 0 && ball.x > 770 && ball.y >= player02.y && ball.y <= player02.y + 100) {
bounceBall();
playerSound02.play();
ball.x = 770;
}
//player03 bounce off
if (ballMovement.y < 0 && ball.y < 30 && ball.x >= player03.x && ball.x <= player03.x + 100) {
bounceBall();
playerSound03.play();
ball.y = 30;
}
//player04 bounce off
if (ballMovement.y > 0 && ball.y > 770 && ball.x >= player04.x && ball.x <= player04.x + 100) {
bounceBall();
playerSound04.play();
ball.y = 770;
}
if (ball.y < 5 || ball.y > 795) ballMovement.y *= -1;
if (ball.x > 795) {
winGame(Human01);
winGame(Human03);
winGame(Human04);
playerSoundScore02.play();
}
if (ball.x < 5) {
winGame(Human02);
winGame(Human03);
winGame(Human04);
playerSoundScore01.play();
}
if (ball.y > 795) {
winGame(Human01);
winGame(Human02);
winGame(Human03);
playerSoundScore04.play();
}
if (ball.y < 5) {
winGame(Human01);
winGame(Human02);
winGame(Human04);
playerSoundScore03.play();
}
}
```