Hey, im doing a school project and i chose to do a racing game, i have made a car with basic controls (turn left/right, move forwards/backwards) but i want to limit how much the car turns.
The car is facing right, i want it to turn left 45 degrees and right 45 degrees (im guessing the angle i havent tried it out yet). Also, please tell me how to change the angle incase i want to.
Please Help with this (Hopefully its danpost :) )
Thank You
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class NSX4 here. * * @author (your name) * @version (a version number or a date) */ public class NSX4 extends Actor { /** * Act - do whatever the NSX4 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" )) { turn(- 5 ); } if (Greenfoot.isKeyDown( "right" )) { turn( 5 ); } if (Greenfoot.isKeyDown( "up" )) { move( 5 ); } if (Greenfoot.isKeyDown( "down" )) { move(- 5 ); } } } |