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

2013/5/21

Just one question

Gzuzfrk Gzuzfrk

2013/5/21

#
How do I make it to where when I shoot that my bullet can only go so far until it dissappears?
Gzuzfrk Gzuzfrk

2013/5/21

#
Haha one more also I have a scrolling screen and I wanted to know how I can make it where the speed of the scroll get faster every 30sec how do I do that?
JetLennit JetLennit

2013/5/21

#
1. How far? 2.Could you show the code that you have thus far?
Gzuzfrk Gzuzfrk

2013/5/21

#
yah private final int DURATION = 20; private int firing; those are my variables if (firing != 0) firing--; if (Greenfoot.isKeyDown("space") && firing == 0) { shoot(); firing = DURATION; } my shot code And heres my firballcode
 private GreenfootImage Fire1 = new GreenfootImage("Fire1.png");
    private GreenfootImage Fire2 = new GreenfootImage("Fire2.png");
    private GreenfootImage Fire3 = new GreenfootImage("Fire3.png");
    
    private int frame = 1;
    private double animationCounter = 1;
    /**
     * Act - do whatever the FireBall wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move(5);
       fireBallHit();
       if(animationCounter % 4 == 0)
        animateFire();
        
        animationCounter++;// Add your action code here.
    }    
    public void fireBallHit()
    {
        Actor b = getOneIntersectingObject(Alien.class);
        if(b != null)
        {
            getWorld().removeObject(b);
            getWorld().removeObject(this);
        }
    }
    public void animateFire()
    {
        if(frame == 1)
        {
            setImage(Fire1);
            
        }
        else if(frame == 2)
        {
            setImage(Fire2);
           
        }
        else if(frame == 3)
        {
            setImage(Fire3);
            frame = 1;
            return;
            
        }
        
        frame ++;
        
        
    }
}
danpost danpost

2013/5/21

#
A timer is what you need. The following would be to limit the range of the bullet
private int fizzleTimer';

private void fizzle()
{
    fizzleTimer++;
    if (fizzleTimer == /* some number */) getWorld().removeObject(this);
}
As far as the scrolling issue, you should probably post the world class code that is related to it.
You need to login to post a reply.