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.9;
//////////////////////////////////////////////////////////////////////////////////////
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, 20,20);
vy += gravetat;
posy += vy;
if(posy > height - 120){
vy *= bounce;
}
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;
}
else if (keyCode == DOWN) {
downPressed = false;
}
else if (keyCode == LEFT) {
leftPressed = false;
}
else if (keyCode == RIGHT) {
rightPressed = false;
}
}
Answers
First let's shorten your code a ton :
You can read on what a switch statement is here. It's basically a shortened if statement for cases such as these where the condition is just what a variable is.
As for jumping, I would appreciate a few more details. Do you want the ball to have the capability to jump at all times? Or just when it's in contact with the ground. If it's the latter, do you want the ball to lose its bounce height the more it bounces?
http://Studio.ProcessingTogether.com/sp/pad/export/ro.91tcpPtI9LrXp
[Edited: Remark: Sorry, I haven't seen the previous two posts]
in theory, to jump you say
vy=-12;
it's a high speed upwards (the jump) and the speed gets smaller by gravity