1 svar
232 visningar
shodärja är nöjd med hjälpen
shodärja 74
Postad: 18 dec 2020 15:48

Mina andra två spelare funkar inte på koda.nu

Här är min kod:

<script src="https://koda.nu/simple.js">
var player1 = {x: 10, y: totalHeight/2-40};
var player2 = {x: totalWidth-20, y: totalHeight/2-40};
var player3 = {x: totalWidth/2, y: 10};
var player4 = {x: totalWidth/2, y: totalHeight-40};
var ball = {x: totalWidth/2-5, y: totalHeight/2-5, xSpeed: 3, ySpeed: 3};

function update()
{
fill("black");
rectangle(player1.x, player1.y, 10, 80, "red");
rectangle(player2.x, player2.y, 10, 80, "purple");
rectangle(player3.x, player3.y, 80, 10, "green");
rectangle(player4.x, player4.y, 80, 10, "white");
circle (ball.x, ball.y, 7, 10, "white");

if (ball.y > totalHeight-40 && ball.x > player4.x && ball.x < player4.x+80)
{ ball.ySpeed = -ball.ySpeed; }
else if (ball.y > totalHeight-40)
{text(50, 250, 20, "Vit missade");
stopUpdate();}

if (ball.x > totalWidth-30 && ball.y > player2.y && ball.y < player2.y+80)
{ ball.xSpeed = -ball.xSpeed; }
else if (ball.x > totalWidth-30)
{text(50, 250, 20, "Lila missade");
stopUpdate();}


if (ball. y < 30) {ball.ySpeed = -ball.ySpeed;}
if (ball.x < 30) {ball.xSpeed = -ball.xSpeed;}

if (keyboard.w) { player1.y -= 7; }
if (keyboard.s) { player1.y += 7; }
if (keyboard.up) { player2.y -= 7; }
if (keyboard.down) { player2.y += 7; }
if (keyboard.t) { player3.x -= 7; }
if (keyboard.g) { player3.x += 7; }
if (keyboard.o) { player4.x -= 7; }
if (keyboard.p) { player4.x += 7; }

ball.x += ball.xSpeed;
ball.y += ball.ySpeed;
}

</script>

Jag har försökt att få player 1 och 3 att spela som player 2 och 4 men det går inte.

shodärja 74
Postad: 18 dec 2020 15:53

Jag försöker få player 1 och 3 att också få ´missmeddelandet´.

Svara Avbryt
Close