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

2015/3/25

Making game interesting

Ankit_Thapa Ankit_Thapa

2015/3/25

#
How can i make the end of my game attractive? Can I add some special effects?
fejfo fejfo

2015/3/25

#
what do u mean ? whit atracitve or special effects so for as I know I don't think so but you can take a look at the GreenfootImage package but you will have to program them your self
Ankit_Thapa Ankit_Thapa

2015/3/26

#
I mean to say if I can add some animations like fire crackers or the balloons flying over when the game is completed
Super_Hippo Super_Hippo

2015/3/26

#
Of course you can. Just add the objects to the world and program what they should do.
Ankit_Thapa Ankit_Thapa

2015/3/26

#
Can u provide me an example code for that one?
Super_Hippo Super_Hippo

2015/3/26

#
For balloons, you could add them like this:
final int w = getWorld().getWidth(), h=getWorld().getHeight();
for (int i=0; i<10; i++)
{
    getWorld().addObject(new Balloon(), Greenfoot.getRandomNumber(w), h+20);
}
This adds ten balloons at the bottom outside the world. To make this possible, you have to create the world with 'super(x,y,cellsize,false)'. This will make it possible for object to be outside the visible world. If you want to have this code in a world subclass, just remove all 'getWorld().' The Balloon code could look like this:
/**direction: 0=straight up, -1=going left, -2=going left (slower), 1=going right, 2=going right (slower)*/
private final int direction = -2+Greenfoot.getRandomNumber(5);
/**timer: controls when the balloon has to go to the side*/
private int timer = 0;

public Balloon()
{
    final int color = Greenfoot.getRandomNumber(4);
    switch (color)
    {
        case 0: setImage("BalloonRed.png"); break;
        case 1: setImage("BalloonYellow.png"); break;
        case 2: setImage("BalloonBlue.png"); break;
        case 3: setImage("BalloonGreen.png"); break;
    }
}

public void act()
{
    if (direction==0)
    {
        setLocation(getX(), getY()-1); //move straight up
    }
    else
    {
        int dx=0;
        timer++;
        if (timer>Math.abs(direction)*2)
        {
            if (direction>0) dx++;
            else dx--;
            timer=0;
        }
        setLocation(getX()+dx, getY()-1); //move up and to the side
    }
}
You need to login to post a reply.