How do I make my car move using the pressing of keyboard directional arrows?
in
Programming Questions
•
2 years ago
Im making an attempt at trying to make a simple game. Im having trouble trying to figure out how it is i can make the car in the image move at the pressing of keyboard directional arrows. If anyone could please help me out it would be greatly appreciated. Thank you.
This is my code.
size(600,600);
background(255);
// Make one side of road
{
fill(29,180,48);
rectMode(CENTER);
rect(300,70, 600,150);
rect(300,520, 600, 150);
}
{
fill(0);
rectMode(CENTER);
rect(300,290,600,310);
}
//Make lane marks
{
fill(255);
stroke(255);
rectMode(CENTER);
rect(100,290,80,10);
}
{
fill(255);
stroke(255);
rectMode(CENTER);
rect(300,290,80,10);
}
{
fill(255);
stroke(255);
rectMode(CENTER);
rect(500,290,80,10);
}
// x location
int x = 220;
// y location
int y= 220;
// size
int thesize = 120;
// position of wheels relative to car
int offset = thesize/4;
//draw main car body
rectMode(CENTER) ;
stroke(255);
fill(175);
rect(x,y,thesize,thesize/2);
//Draw four wheels relative to center
fill(0);
rect(x-offset, y-offset, offset, offset/2);
rect(x+offset, y-offset, offset, offset/2);
rect(x-offset, y+offset, offset, offset/2);
rect(x+offset, y+offset, offset, offset/2);
This is my code.
size(600,600);
background(255);
// Make one side of road
{
fill(29,180,48);
rectMode(CENTER);
rect(300,70, 600,150);
rect(300,520, 600, 150);
}
{
fill(0);
rectMode(CENTER);
rect(300,290,600,310);
}
//Make lane marks
{
fill(255);
stroke(255);
rectMode(CENTER);
rect(100,290,80,10);
}
{
fill(255);
stroke(255);
rectMode(CENTER);
rect(300,290,80,10);
}
{
fill(255);
stroke(255);
rectMode(CENTER);
rect(500,290,80,10);
}
// x location
int x = 220;
// y location
int y= 220;
// size
int thesize = 120;
// position of wheels relative to car
int offset = thesize/4;
//draw main car body
rectMode(CENTER) ;
stroke(255);
fill(175);
rect(x,y,thesize,thesize/2);
//Draw four wheels relative to center
fill(0);
rect(x-offset, y-offset, offset, offset/2);
rect(x+offset, y-offset, offset, offset/2);
rect(x-offset, y+offset, offset, offset/2);
rect(x+offset, y+offset, offset, offset/2);
1