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

2016/1/4

starting screen

shane727 shane727

2016/1/4

#
i have a game built and all but at the beginning i want the player to be able to choose which character to play as. I have 3 different characters so far. easy, medium, and hard. So how do I set it up where the player makes the choice of who to play as?
danpost danpost

2016/1/4

#
You could have a PlayerChoice class that is given (as a parameter for the constructor) the character it represents. When a PlayerChoice object is clicked on, it can create a new game world and set the player in that world appropriately. The PlayerChoice objects can either use the image of the character it represents for itself (if the different difficulties provide different images) or a String object (expressing the difficulty) or GreenfootImage object (an alternate image that somehow represents the difficulty) can be used (as a second parameter for the constructor).
shane727 shane727

2016/1/5

#
I have 3 characters made along with theyre assigned difficulties(easy lizard, medium ladybug, and hard bee). But in the world class what heading would i put for when the world adds characters? instead of act, would i need to make a return value?
Super_Hippo Super_Hippo

2016/1/5

#
(Please ignore that everything is green, that isn't my fault.)
public WorldName()
{
    super(/*... , ... , ... , ...*/);
    //create all objects independent from difficulty
}

/** choice: 0=easy, 1=medium, 2=hard */
public WorldName(final int choice)
{
    this();
    switch(choice)
    {
        case 0: addObject(new Lizard(), /*... , ... */); break;
        case 1: addObject(new Ladybug(), /*... , ... */); break;
        case 2: addObject(new Bee(), /*... , ... */); break;
    }
}
Then, when creating the world, use 'Greenfoot.setWorld(new WorldName(0));' for an easy game, 1 for medium and 2 for hard.
shane727 shane727

2016/1/5

#
So would i have to use the actual numbers(1,2,3)? Or am i able to connect those to actors i already have? I have actors made that just say EASY , MEDIUM, and HARD. Would i be able to hook the case's up to them?
danpost danpost

2016/1/5

#
shane727 wrote...
So would i have to use the actual numbers(1,2,3)? Or am i able to connect those to actors i already have? I have actors made that just say EASY , MEDIUM, and HARD. Would i be able to hook the case's up to them?
Show the code you have for one of the EASY, MEDIUM, or HARD actors and then show the code for the World subclass that adds them into the world.
shane727 shane727

2016/1/6

#
public class ladybug extends Actor
{
    int counter= 0;
    int SPEED=4;
    World myWorld = getWorld();
    int spot = Greenfoot.getRandomNumber(280);
    int spot2 = Greenfoot.getRandomNumber(180);
      int time1=7;
    /**
     * Act - do whatever the ladybug wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
       
        
        counter ++;
        if(counter ==SPEED)
        {move(3);
            counter=0;
        }
                
        if(Greenfoot.isKeyDown("right"))
        {
            turn(4);
        }  
        if(Greenfoot.isKeyDown("left"))
        {
            turn(-4);
        }

        

        Actor Apple;
        Apple = getOneObjectAtOffset(0,0, Apple.class);
        if (Apple!=null)
        {
            World myWorld = getWorld();
            startscreen startscreen = (startscreen) myWorld;
            counter counter = startscreen.getCounter();
            counter.addScore();
            myWorld. removeObject(Apple);
            easy easy = new easy();
            // getWorld(). addObject(new gameover(), (50), (182));
            myWorld.removeObject(easy);
            getWorld(). addObject (new Apple(), Greenfoot.getRandomNumber(280), Greenfoot. getRandomNumber(180));
            timerMinus  timerMinus= startscreen.getTimerMinus();
            timerMinus.addTime();
        }
}
This is the code for the MEDIUM actor so far.
danpost danpost

2016/1/6

#
You appear to have gameplay code in a class for an Actor that will reside in a 'startscreen' world. Maybe you did not understand how I suggested to set things up. First, I suggest that you have two type of World objects (two different subclasses of World) -- one for choosing the character (or difficulty) and one for gameplay. Then, one extra subclass of Actor to create the "buttons" (clickable actors) for choosing the character (or difficulty) in the 'startscreen' world. By having this extra Actor subclass, you can keep the actions for the different worlds separate; that is, actions for gameplay and actions for choosing a character..
shane727 shane727

2016/1/7

#
So have a world class that has all the actors and actually starts the game, and have a separate world that has code like "if( "1" is pressed) add this and this and change worlds?
danpost danpost

2016/1/8

#
shane727 wrote...
So have a world class that has all the actors and actually starts the game, and have a separate world that has code like "if( "1" is pressed) add this and this and change worlds?
Something like that.
You need to login to post a reply.