We are about to switch to a new forum software. Until then we have removed the registration on this forum.
boolean upPressed = false;
boolean downPressed = false;
boolean leftPressed = false;
boolean rightPressed = false;
//float cercleX = 50;
//float cercleY = 50;
float gravetat = 0.8;
float posx = 200;
float posy = 50;
float vy = 0;
float bounce = -0.1;
float rad = 25;
void setup() {
size (500, 500);
smooth();
noStroke();
}
void draw() {
frameRate (70);
background (255);
fill(0);
rect(0, 400, 500, 100);
fill(255, 0, 0);
ellipse(posx, posy, rad, rad);
vy += gravetat;
posy += vy;
if (posy > height - 120) {
vy *= bounce;
}
if (vy < 0 && posy > height -120) {
vy = 0;
gravetat = 0;
} else if (posy > height -120) {
vy = vy *-0.9;
}
if (upPressed) {
posy--;
}
if (downPressed) {
posy++;
}
if (leftPressed) {
posx--;
}
if (rightPressed) {
posx++;
}
}
void keyPressed() {
if (keyCode == UP) {
upPressed = true;
} else if (keyCode == DOWN) {
downPressed = true;
} else if (keyCode == LEFT) {
leftPressed = true;
} else if (keyCode == RIGHT) {
rightPressed = true;
}
}
void keyReleased() {
if (keyCode == UP) {
upPressed = false;
gravetat = 0.98;
bounce = 0.9;
posy = 300;
} else if (keyCode == DOWN) {
downPressed = false;
} else if (keyCode == LEFT) {
leftPressed = false;
} else if (keyCode == RIGHT) {
rightPressed = false;
}
}
Answers
https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text#latest