I still do have a related question though. then I'm back on track.
right now my little creature is bouncing around the screen. and I've added some dampening so that in time it bounces less and less till it comes to a full stop.
however it's the full stop thing that isn't happening. it keeps bouncing on very low values after a while.
I know that I probably have to add an if statement
that says when "speedY" reaches a certain value speedY=0
the problem with this is that if I do that. it interferes with the code where I reverse the polarity of a number.
how should I best tackle this problem?
I've added the code here.
Code:float x;
float y;
float speedy=15;
float speedx=5;
float gravity=0.3;
float s=250;
float s2=250;
void setup (){
size(700,700);
x=width/2;
y=500;
frameRate(60);
}
void draw(){
background(255);
y=y+speedy;
x=x+speedx;
speedy=speedy+gravity;
if (y>600){
y=600;
speedy=speedy* -0.8;
s=280;
s2=210;
}
if (x>600){
x=600;
speedx=speedx* -0.8;
s2=270;
}
if (x<0){
x=0;
speedx=speedx* -0.8;
}
speedy=constrain(speedy,-20,20);
speedx=constrain(speedx,-5,5);
s=s-1.5;
s2=s2+2;
s=constrain(s,250,280);
s2=constrain(s2,210,250);
//head
smooth();
strokeWeight(6);
stroke(0);
fill(255);
ellipseMode(CENTER);
ellipse(x,y,s,s2);
//wiskers
line(x-20,y+60,x+20,y+40);
line(x-20,y+40,x+20,y+60);
//eyes
strokeWeight(4);
stroke(70,150,50);
ellipseMode(CENTER);
fill(mouseX,mouseY,mouseX/5);
ellipse(x-40,y-30,30,30);
ellipseMode(CENTER);
fill(mouseX/3,mouseY*2,mouseX/5);
ellipse(x+40,y-30,30,30);
//ears
fill(20,40,50);
stroke(0);
triangle(x-90,y-50,x-130,y-140,x-55,y-85);
triangle(x+90,y-50,x+130,y-140,x+55,y-85);
}