So, I'm making a racing game. I'll try to explain this as detailed as possible.
My main object is a car (The player controls the car). The car is facing RIGHT. The controls: Up Arrow = The car moves right, Down Arrow = The car moves left, Left Arrow = The car turns left 20 Degrees left, Right Arrow = The car turns 20 Degrees right. (I've set the rotation so that the car can only move 20 degrees).
I'll use the left key as an example
What I want it to do is: With 1 press of the Left Arrow Key, I want the car to (Turn left 20 Degrees, Move 5, Turn right 20 degrees). It's like switching lanes.
Recap : When I tap the left key ONCE (Not holding it down) I want the car to Turn left 20 Degrees, Move 5, Turn right 20 degrees. So the car would be higher than where it was before and a little bit forward.
https://imgur.com/gallery/cO1h2
Thank You
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
When you post a code, can you please insert your code in mine? I get confused sometimes.
/**
* Write a description of class NSX9 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class NSX9 extends Actor
{
/**
* Act - do whatever the NSX9 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (Greenfoot.isKeyDown("left") && getRotation() != 340)
{
turn (-5);
}
if (Greenfoot.isKeyDown("right") && getRotation() != 20)
{
turn(5);
}
if (Greenfoot.isKeyDown("up"))
{
move(5);
}
if (Greenfoot.isKeyDown("down"))
{
move(-5);
}
}
}
