Created
February 27, 2019 18:01
-
-
Save dinarname/a79affb2f7c8ecf5859f8d37a7ea4e9d to your computer and use it in GitHub Desktop.
pong
This file contains hidden or 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
int x, y; | |
int yDirection; | |
int xDirection; | |
int counter; | |
void setup() { | |
size(300, 400); | |
x = 100; | |
y = 10; | |
yDirection = 3; | |
xDirection = 3; | |
} | |
void draw() { | |
background(#F2F0AE); | |
fill(0); | |
stroke(#4CE82A); | |
strokeWeight(5); | |
ellipse(x, y, 20, 20); | |
y = y + yDirection; | |
x = x + xDirection; | |
// Условия для отражения от стен и потолка | |
if (y < 0) { | |
yDirection = yDirection * (-1); | |
} | |
if (x > 300 || x < 0) { | |
xDirection *= - 1; | |
} | |
fill(#1946B4); | |
noStroke(); | |
rect(mouseX, 350, 50, 10); | |
//Условие для отражения от площадки | |
if (x > mouseX && x < mouseX + 50) { | |
if (y >= 350 && y <= 360) { | |
yDirection = yDirection * (-1); | |
counter += 1; | |
} | |
} | |
if (y > 400) { | |
textSize(25); | |
textAlign(CENTER); | |
text("Шарик улетел", 150, 200); | |
yDirection = 0; | |
xDirection = 0; | |
} | |
text(counter, 250, 50); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment