Loading...
Logo
Processing Forum
Hi,

I am learning processing in school and I need to make a car game where:

the cars front and rear end are different.(can be just a triangle)
arrow key left turns the car left
arrow key right turns the car right
Shift key  accelerates
the car's front end is always towards the driving direction
there is always the force of friction applied to the car.

Replies(2)

Copy code
  1. PVector p=new PVector(110,110,0);float v=0;boolean[] keys=new boolean[3];
  2. void setup(){size(220, 220);smooth();}void draw(){background(0);s();r();}
  3. void keyPressed(){b(true);}void keyReleased(){b(false);}
  4. void b(boolean d){if(key==CODED){if(keyCode==LEFT)keys[0]=d;if(keyCode==RIGHT)keys[1]=d;if(keyCode==SHIFT)keys[2]=d;}}
  5. void s(){p.z+=(keys[0]?-.1:0)+(keys[1]?.1:0);v+=(keys[2]?.1:0);p.x=(p.x+width+v*cos(p.z))%width;p.y=(p.y+height+v*sin(p.z))%height;v*=.99;}
  6. void r(){translate(p.x,p.y);rotate(p.z);noStroke();fill(0,128,0); rect(-10,-10,20,20);stroke(0);noFill();triangle(-8,-8,7,0,-8,8);}