Created
February 22, 2021 16:07
-
-
Save janeoa/493bbbc5f01b81936397a73f04fa423a to your computer and use it in GitHub Desktop.
pong на одного игрока
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var wall = { | |
x : 400, | |
y : 400 | |
} | |
var player = { | |
x : 0, | |
y : 0, | |
width : 10, | |
height : 60 | |
} | |
var ball = { | |
x : 300, | |
y : 200, | |
width : 10, | |
height : 10, | |
vel : { | |
x : 5, | |
y : 5, | |
}, | |
} | |
function setup() { | |
createCanvas(400, 400); | |
} | |
function draw() { | |
background(220); | |
player.y = mouseY-player.height/2 | |
drawObj(player); | |
ballstep(); | |
drawObj(ball); | |
} | |
function drawObj(obj){ | |
rect(obj.x,obj.y,obj.width,obj.height) | |
} | |
function ballstep(){ | |
ball.x = ball.x + ball.vel.x; | |
ball.y = ball.y + ball.vel.y; | |
if(ball.x+10 > wall.x) ball.vel.x = -ball.vel.x | |
if(ball.y+10 > wall.y || ball.y < 10) ball.vel.y = -ball.vel.y | |
if (player.y+60 > ball.y && player.y < ball.y){ | |
print("отобьет"); | |
}else{ | |
print("гол"); | |
} | |
if(ball.x < 10){ | |
if (player.y+60 > ball.y && player.y-10 < ball.y){ | |
ball.vel.x = -ball.vel.x | |
mul = ball.vel.y/abs(ball.vel.y) | |
ball.vel.y = mul*random(5) | |
}else{ | |
print("Game over") | |
return | |
} | |
} | |
//print(ball.y) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment