Я пытался добавить gameStates несколько раз, я также смотрел другие свои коды и ссылался на множество других кодов, которые нашел в Интернете
var playerGoal = createSprite(200,28,100,20);
playerGoal.shapeColor = ("yellow");
var compGoal = createSprite(200,372,100,20);
compGoal.shapeColor=("yellow");
var striker = createSprite(200,200,10,10);
striker.shapeColor = "white";
var playerMallet = createSprite(200,50,50,10);
playerMallet.shapeColor = "black";
var computerMallet = createSprite(200,350,50,10);
computerMallet.shapeColor = "black";
var boundary1 = createSprite(200,145,400,5);
boundary1.shapeColor = "white";
var boundary2 = createSprite(200,250,400,5);
boundary2.shapeColor = "white";
var boundary3 = createSprite(200,385,400,5);
boundary3.shapeColor = "white";
var boundary4 = createSprite(200,15,400,5);
boundary4.shapeColor = "white";
var boundary5 = createSprite(10,200,5,400);
boundary5.shapeColor = "white";
var boundary6 = createSprite(390,200,5,400);
boundary6.shapeColor = "white";
var gameState = "serve";
var gameState = "end";
var compScore = 0;
var playerScore = 0;
function draw(){
background("green");
//gamestate serve
if(gameState === "serve"){
text("PRESS SPACE TO STRIKE",140,180);
textSize(50);
fill("black");
if(keyDown("left")){
playerMallet.x = playerMallet.x - 10;
}
if(keyDown("right")){
playerMallet.x = playerMallet.x + 10;
}
if(keyDown("up")){
if(playerMallet.y > 25)
{
playerMallet.y = playerMallet.y - 10;
}
if(keyDown("down")){
if(playerMallet.y<120)
{
playerMallet.y = playerMallet.y + 10;
}
}
}
}
text(compScore,20,230);
text(playerScore,20,180);
for (var b = 20; b < 400; b=b+20) {
line(0+b,200,10+b,200);
}
if (keyDown("space")) {
serve();
gameState = "play";
}
if(striker.isTouching(playerGoal) || striker.isTouching(compGoal)){
if(striker.isTouching(playerGoal)){
compScore = compScore +1;
fill("black");
reset();
}
if(keyDown("r") && gameState === "over"){
gameState = "serve";
compScore = 0;
playerScore = 0;
}
if(striker.isTouching(compGoal)){
playerScore = playerScore+1;
textSize(50);
fill("black");
reset();
}
gameState = "serve";
reset();
}
if(keyDown("left")){
playerMallet.velocityX = -5;
}
if(keyDown("right")){
playerMallet.velocityX = 5;
}
if(keyDown("up") && playerMallet.y > 25){
playerMallet.velocityY = -5;
}
if(keyDown("down") && playerMallet.y < 120){
playerMallet.velocityY = 5;
}
if (keyDown("space") && gameState === "serve") {
serve();
gameState = "play";
}
if(playerScore === 5 || compScore === 5){
text("GAME OVER",170,165);
text("PRESS 'R' TO RESTART", 140, 185);
textSize(50);
fill("black");
gameState = "over";
}
if(gameState === "over"){
reset();
}
if(keyDown("r") && gameState === "over"){
gameState = "serve";
compScore = 0;
playerScore = 0;
}
computerMallet.x = striker.x;
drawSprites();
}
function serve(){
striker.velocityX = 5;
striker.velocityY = 5;
}
function reset(){
striker.x = 200;
striker.y = 200;
striker.velocityX = 0;
striker.velocityY = 0;
playerMallet.x = 200;
playerMallet.y = 50;
playerMallet.velocityX = 0;
playerMallet.velocityY = 0;
}
Хотя я добавил the gameStates и использовал условное программирование, чтобы сообщить компьютеру, что делать, он показывает мне ошибки, я проверил свои предыдущие коды и спросил моего учителя, друзей и семью, он все еще не работает, когда не показывает никаких ошибок, нет разницы на выходе.