sam
2023-11-24 12:24:18 +01:00

View File

@@ -1,36 +1,46 @@
size = 50; size = 10;
posX = 500; radius = size/2;
posY = 300; cirX = 500
cirY = 300;
xmax = 1000;
ymax = 600;
speed = 3;
// the function setup() is called once when the page is loaded // the function setup() is called once when the page is loaded
function setup() { function setup() {
// create a canvas element and append it to the body // create a canvas element and append it to the body
createCanvas(1000, 600); createCanvas(xmax, ymax);
frameRate(120); frameRate(1200);
// disable the outline of shapes // disable the outline of shapes
noStroke(); noStroke();
} }
function keyPressed() { function keyPressed() {
if (keyIsDown(LEFT_ARROW)) { if (keyIsDown(LEFT_ARROW) && cirX > 0+radius) {
posX -= 5; cirX -= speed;
} }
if (keyIsDown(RIGHT_ARROW)) { if (keyIsDown(RIGHT_ARROW) && cirX < xmax-radius) {
posX += 5; cirX += speed;
} }
if (keyIsDown(UP_ARROW)) { if (keyIsDown(UP_ARROW) && cirY > 0+radius) {
posY -= 5; cirY -= speed;
} }
if (keyIsDown(DOWN_ARROW)) { if (keyIsDown(DOWN_ARROW) && cirY < ymax-radius) {
posY += 5; cirY += speed;
} }
} }
function collision() {
}
// the function draw() is called every frame // the function draw() is called every frame
function draw() { function draw() {
keyPressed(); keyPressed();
// clear the background with a transparent black color // clear the background with a transparent black color
background(0, 0, 0, 10); background(0, 0, 0, 100);
// draw a circle at the mouse position // draw a circle at the mouse position
circle(posX, posY, size); circle(constrain(cirX,0+radius,xmax-radius), constrain(cirY,0+radius,ymax-radius), size);
square(100,100,100,10);
} }