Processing Question (cant get keypressed to work)
in
Programming Questions
•
2 years ago
I am working on a school assignment now, i have tried to get my white fish to move when i press W/A/S/D key
and put the fist right in the middle, however, wont able to get it to work....
any comments will help!
Thanks
I have setup-ed different class for Fishp and PlayerFish.
- import processing.opengl.PGraphicsOpenGL;
- int amount = 10;
- Fishp[]fishs = new Fishp [amount];
- PlayerFish player = new PlayerFish();
- boolean up, down, right, left ;
- float speed = 0.8;
- void keyPressed(){
- if (key == 'w') up = true;
- if (key == 'a') left = true;
- if (key == 's') down = true;
- if (key == 'd') right = true;
- }//keypressed
- void keyReleased(){
- if (key == 'w') up = false;
- if (key == 'a') left = false;
- if (key == 's') down = false;
- if (key == 'd') right = false;
- }//keyReleased
- void setup(){
- size(1000,1000,OPENGL);
- smooth();
- for(int i=0; i<amount; i++)
- {
- fishs [i]=new Fishp();
- }
- }
- void draw()
- {
- background(255);
- fill(26,131,135);
- smooth();
- rect(0,0,1000,1000);
- if(up) player.addAcc( new PVector (0,-speed));
- if(down) player.addAcc( new PVector (0,speed));
- if(left) player.addAcc( new PVector (-speed,0));
- if(right) player.addAcc( new PVector (speed,0));
- player.update();
- player.boundary();
- player.drawMe();
- for (int i=0; i<amount; i++){
- fishs[i].update();
- fishs[i].boundary();
- fishs[i].drawMe();
- }
- }
1