keyPressed problem
in
Programming Questions
•
10 months ago
Hi, I'm working on a very simple game and have a temporary character at the bottom that should move up and down when the UP and DOWN keys are pressed. For some reason the character will not move when the keys are pressed and I'm not sure why. Any suggestions?
float spdx, spdy;
float gravity;
float damping;
float xpos,ypos;
float px, py;
void setup(){
size(800,600);
background(200,200,255);
fill(100,255,100);
rect(0,500,800,100);
cloud(100,100);
cloud(300,200);
cloud(500,150);
cloud(550,100);
cloud(450,100);
cloud(450,300);
player(100,475);
}
void draw(){
if(keyPressed == true){
if(key == CODED){
if(keyCode == UP){
py = py + 25;
}
if(keyCode == DOWN){
py = py-25;
}
}
}
}
void cloud(float xpos, float ypos){
noStroke();
fill(255);
ellipse(xpos,ypos,40,40);
ellipse(xpos-20,ypos+15,40,40);
ellipse(xpos-15,ypos+15,40,40);
ellipse(xpos+25,ypos-15,40,40);
ellipse(xpos+40,ypos,100,40);
ellipse(xpos+45,ypos+30,40,40);
ellipse(xpos+10,ypos+30,40,40);
ellipse(xpos+60,ypos+20,40,40);
ellipse(xpos+80,ypos+20,65,40);
}
void player(float px, float py){
noStroke();
fill(255,255,0);
ellipse(px,py,50,50);
fill(0);
ellipse(px-10,py-10,5,5);
ellipse(px+10,py-10,5,5);
bezier(px-15,py+5,px-10,py+20,px+10,py+20,px+15,py+5);
}
1