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

2015/8/1

Making things spawn in

Camyh15 Camyh15

2015/8/1

#
Hello, I want to make it so when I eat a balloon it then adds a skull. How do I do that? Here is my code so far:
import greenfoot.*;

/**
 * Write a description of class robot here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class robot extends Actor
{
    private int balloonEaten = 0;
    private Counter counter;
    private skull skull;
    
    public robot(Counter pointCounter)
    {
        counter = pointCounter;
    }
    
    public void act() 
    {   
        if (Greenfoot.isKeyDown("right"))
        move(5);
        if (Greenfoot.isKeyDown("left"))
        move(-5);
        if (Greenfoot.isKeyDown("space"))
        turn(17);
        setRotation(90);
        if (Greenfoot.isKeyDown("up"))
          { move(-5); }
        if (Greenfoot.isKeyDown("down"))
          { move(5); }
        setRotation(0);
        if (isAtEdge() )
        {
            turn(90);
         }
         Actor balloon = getOneIntersectingObject(balloon.class);
        if(balloon != null)
        {
            World myWorld = getWorld();
            balloonEaten++;
            counter.add(1);
            Greenfoot.playSound("balloon pop.mp3");
            myWorld.removeObject(balloon);
            if (counter.getValue() >= 9) {
                gameOver();
            }
            if (balloonEaten >= 10) {
            YouWin youwin = new YouWin();
            myWorld.addObject(youwin, myWorld.getWidth()/2, myWorld.getHeight()/2);
            }
        }
    }
        
    /**
     * We have won the game.
     */
    public void gameOver()
    {
        Greenfoot.playSound("superstition.wav");
        Greenfoot.stop();
    }
}
danpost danpost

2015/8/1

#
You are adding a 'YouWin' to the world in the class at lines 50 and 51. The code would be similar except for the actor being added and where you may want to add it into the world.
Camyh15 Camyh15

2015/8/2

#
Thanks, but it says, "constructor skull cannot be applied to given types; required:Counter; found:no arguments; reason:actual and formal arguments lists differ in length". What does this mean and how do you fix it?
danpost danpost

2015/8/2

#
It means that you do not have a constructor with the signature of how you are trying to call it. The fix depends on how you are calling it, how you need to call it and your skull class code. Show the code of the 'skull' class (you probably do not want to pass a Counter object to its constructor).
swacks swacks

2015/8/2

#
you could look at michoel kollings videos on making things spawn in i tried it and it worked
Camyh15 Camyh15

2015/8/3

#
Which video is it?
swacks swacks

2015/8/4

#
dont know exactly but if you search joy of code and watch the greenfoot channel a person by the name of micheol kolling will teach you how to code and teach you how to deal with your problem
davmac davmac

2015/8/4

#
Thanks, but it says, "constructor skull cannot be applied to given types; required:Counter; found:no arguments; reason:actual and formal arguments lists differ in length". What does this mean and how do you fix it?
It means the constructor for 'skull' requires a parameter of type Counter, and so whenever you construct a 'skull' you must supply a counter. However, you have a 'new skull' expression which doesn't supply the counter, which probably looks something like:
new skull()
Whereas it should look like:
new skull(counter)
(where 'counter' is a variable of type Counter, most likely containing a reference to an Counter instance).
Camyh15 Camyh15

2015/8/5

#
Thank you soooooooooo much!
You need to login to post a reply.