i'm making a racing game where four characters run from the left of the screen to the right. Four random number generators will run. The output of these generators must be stored as variables so that i can have four icons on screen change to show the appropriate number button to press. I must also have the player's "greenfoot.isKeyDown" change so that pressing the four buttons changes the players speed to a new value.
This is the code for my "Blankclass" it exists purely to hold the random number generator
This is the code for my player
I'm basically a beginner and thought something like this would be very easy to pull off. It's my college work so it's not like i can just drop it at this point. Thanks in advance.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Blankclass here. * * @author (your name) * @version (a version number or a date) */ public class Blankclass extends Actor { public float KeyOne = Greenfoot.getRandomNumber(9); public float KeyTwo = Greenfoot.getRandomNumber(9); public float KeyThree = Greenfoot.getRandomNumber(9); public float KeyFour = Greenfoot.getRandomNumber(9); /** * Act - do whatever the Blankclass wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { // Add your action code here. } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Player1 here. * * @author (your name) * @version (a version number or a date) */ public class Player1 extends Players { /** * Act - do whatever the Player1 wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public int Plyrspeed = 1; public void act() { move(Plyrspeed); setImage(gifImage.getCurrentImage()); if(isTouching(FinishLine.class)) { Plyrspeed = 0; } if(Greenfoot.isKeyDown(KeyOne)) { Plyrspeed = 2; } } GifImage gifImage = new GifImage("128.gif"); }