Simplifying a code.
in
Programming Questions
•
4 months ago
Hi, I got this code about a car game. I am studing processing in uni and I have trouble understanding this code. Could someone explain to me what different aspects of thsi code do and swap inputs like s(), r() etc. so i would understand what they do. Also would be nice if possible to do the yellow part with IF commands.
PVector p=new
PVector(110,110,0);
float v=0;
boolean[] keys=new boolean[3];
void setup(){
size(220, 220);
smooth();
}
void draw()
{
background(0);
s();
r();
}
void keyPressed()
{
b(true);
}
void keyReleased()
{b(false);
}
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;
}
}
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;
}
void r(){
translate(p.x,p.y);
rotate(p.z);
noStroke();
fill(0);
rect(-10,-10,20,20);
stroke(0);
fill(225);
triangle(-8,-8,15,0,-8,8);
}
Thanks!
1