We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I'm new on the forum and I'm sorry if I somehow brake any rules. Anyway, I'm trying to make a simple game that i found on the p5js.org website and I'm just editing it a little bit. So you are a red ball and you can move a round on a canvas, now I want to make borders, like if you go all the way up you respawn, I managed to make those borders for the X axis, -X axis, Y axis, but I can't make it for the -Y if that's how I should say it. Here is my code:
var x = 30;
var y = 350;
var velicina = 50;
function setup() {
createCanvas(1366, 658);
background(100);
}
function draw() {
if (keyIsDown(LEFT_ARROW))
x-=10;
if (keyIsDown(RIGHT_ARROW))
x+=10;
if (keyIsDown(UP_ARROW))
y-=10;
if (keyIsDown(DOWN_ARROW))
y+=10;
clear();
fill(255, 0, 0);
ellipse(x, y, 50, 50);
if(x < 30) {
clear();
background(100);
ellipse(x, y, 50, 50);
x = 30;
y = 350;
}
if(x > 1340) {
clear();
background(100);
ellipse(x, y, 50, 50);
x = 30;
y = 350;
}
if(y < 30) {
clear();
background(100);
x = 30;
y = 350;
}
if(y > -150){
clear();
background(100);
x = 30;
y = 350;
}
It just doesn't work under Y -200 or Y 200. Please, try it yourself and see.
Thank you!
Answers
Line 54 is wrong
You want y>1200 or so here, not minus
Thank you so much Chrisir, it worked :D