This site requires JavaScript, please enable it in your browser!
Greenfoot back
Applez
Applez wrote ...

2018/5/10

Angles in Rotation Limit

Applez Applez

2018/5/10

#
Hi, I've made a speedometer in my car game and I've made code so that the needle stops at zero :
if (Greenfoot.isKeyDown("up") == false [code]&& getRotation() != 359)

        {
            turn(-1);
        }
But this means that i cant set a limit to the needle turning to the max speed (160). I tried
if (Greenfoot.isKeyDown("up") && getRotation() != 10)
        {
            turn(2);
        }
But that doesnt let the needle move far enough, anything less that 359 is in the blank area of the speedometer range (below zero). Please help thanks
Applez Applez

2018/5/10

#
I Also have another problem, I want cars to spawn randomly in my endless scrolling world so that my main car can dodge it, I dont know how to do this since its in a borderless world. Even if i can randomly spawn the cars, i need to make them move to the left :
move(-1);
So that all the cars keep going left and my main car goes right and dodges them, if my main car touches the other cars, how can i delete my main car (to make it look like it crashed)? Thanks
danpost danpost

2018/5/11

#
Applez wrote...
But that doesnt let the needle move far enough, anything less that 359 is in the blank area of the speedometer range (below zero).
Use '> 0' and '< 11' or higher.
Applez wrote...
if my main car touches the other cars, how can i delete my main car (to make it look like it crashed)?
if (isTouching(Car.class)) getWorld().removeObject(this);
Applez Applez

2018/5/11

#
Thanks, and how do I make cars randomly spawn?
danpost danpost

2018/5/11

#
Applez wrote...
Thanks, and how do I make cars randomly spawn?
Well, you probably do no want cars to spawn on each other, so using a random timer would probably be best. Something like this:
// add a timer field
private int spawnTimer;

// in action code
if (--spawnTimer < 0)
{
    getWorld().addObject(new Car(), << some x, some y >>);
    spawnTimer = 30+Greenfoot.getRandomNumber(150); // adjust values as needed
}
In line 8, the added value, 30, is the minimum delay time and the random part, 150 is the variable delay range beyond the initial 30.
You need to login to post a reply.