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

2016/8/29

Healthbar problem

1
2
Dudimus Dudimus

2016/8/29

#
I've found a way how my Chased/my character would get damaged by his ammo/fire which is his own subclass. The problem is, when he first hits it, the healthbar decreases normally. But the second time he hits it, the healthbar decreases rapidly, what code do I need to add or edit? Here is the code for the Character:
import greenfoot.*;
import java.awt.Color;

/**
 * Class Chased (subclass of Actor): a user-controlled object with a mouse-controlled gun
 */
public class Chased extends Actor
{
    boolean touchingZ = false;
    boolean touchingZ2 = false;
    private int rotation;
    boolean touchingFire = false;
    Gun gun = new Gun(); // the gun for this actor
    Chaser chaser = new Chaser();
    Runner runner = new Runner();
    int timer;
    int bullet=10;
    
   
    /**
     * creates image for actor
     */
    public Chased()
    {
        // the image for this actor
        GreenfootImage image = new GreenfootImage(50, 50);
        image.fillOval(0, 0, 50, 50);
        image.setColor(Color.green);
        image.fillOval(7, 7, 36, 36);
        setImage(image);
    }
    
    /**
     * adds the gun for this actor into the world
     *
     * @param world the world this actor was added into
     */
    public void addedToWorld(World world)
    {
        world.addObject(gun, getX(), getY()); // add the gun belonging to this actor into the world
    }
    

      /**
     * move user-controlled actor and its gun; also, check for game over
     */
    public void act()
    {
        // user-controlled movement
        int dx = 0, dy = 0;
        if (Greenfoot.isKeyDown("a")) dx--;
        if (Greenfoot.isKeyDown("d")) dx++;
        if (Greenfoot.isKeyDown("w")) dy--;
        if (Greenfoot.isKeyDown("s")) dy++;
        setLocation(getX()+1*dx, getY()+1*dy);
        // limit to world bounds
        if (getX() < 25) setLocation(25, getY());
        if (getY() < 25) setLocation(getX(), 25);
        if (getX() > getWorld().getWidth()-25) setLocation(getWorld().getWidth()-25, getY());
        if (getY() > getWorld().getHeight()-25) setLocation(getX(), getWorld().getHeight()-25);
        // position gun
        gun.setLocation(getX(), getY());
        // check game over
            
         Actor chaser = getOneIntersectingObject(Chaser.class);
         
       if (chaser != null)
      
                {
            World world = getWorld();
                    Welt welt = (Welt)world; 
               
                    HealthBar healthbar = welt.getHealthBar();
                    Numberz numberz = welt.getNumberz();
                    if(touchingZ == false)
                    {
                        healthbar.loseHealth();
                        
                        touchingZ = true;
                       
                        if(healthbar.health <=0)
                        {
                         world.removeObjects(world.getObjects(null));
                         Greenfoot.setWorld(new Stats(((Welt)world).score));
                        }
                        
                        
                    }
        }else{
                    touchingZ = false;
                }
                
       Actor runner = getOneIntersectingObject(Runner.class);
         
       if (runner != null)
      
                {
            World world = getWorld();
                    Welt welt = (Welt)world; 
               
                    HealthBar healthbar = welt.getHealthBar();
                    Numberz numberz = welt.getNumberz();
                    if(touchingZ2 == false)
                    {
                        healthbar.loseHealth();
                        
                        touchingZ2 = true;
                       
                        if(healthbar.health <=0)
                        {
                         world.removeObjects(world.getObjects(null));
                         Greenfoot.setWorld(new Stats(((Welt)world).score));
                        }
                        
                        
                    }
        }else{
                    touchingZ2 = false;
                }
    }
    
     
   
    /**
     * Class: Gun (subclass of Actor -- inner class of Chased): the gun for this actor
     */
    private class Gun extends Actor
    {
        /**
         * creates image for actor
         */
        public Gun()
        {
            // the image for this actor
            GreenfootImage image = new GreenfootImage("Picture1.png");
           
            setImage(image);
        }
         
    public boolean Munition(){
        if(bullet>0){
            return true;
        }
        else{
            return false;
        }
    }

    private boolean mouseclick;
    /**
         * responds to mouse movement and mouse button clicks
         */
        public void act()
        {
            // turn towards mouse when mouse moves
            if (Greenfoot.mouseMoved(null) || Greenfoot.mouseDragged(null))
            {
                MouseInfo mouse = Greenfoot.getMouseInfo();
                if (mouse != null) turnTowards(mouse.getX(), mouse.getY());
            }
            // detect mouse clicks to fire shot   
           
            World world = getWorld();
                    Welt welt = (Welt)world;

                    AmmoBar ammobar = welt.getAmmoBar();
                   
            if(!mouseclick && (Greenfoot.mouseClicked(null)))
            {
                
             
                    if(Munition()==true){
                    mouseclick=true;
                    getWorld().addObject(new Shot(), getX(), getY());
                    bullet--;
                    ammobar.loseAmmo();
                    if (bullet ==0){
                        timer = 2000;
                    }
                
                }
            }
            if(mouseclick&& !Greenfoot.isKeyDown("space"))
            {
                mouseclick=false;
            }
           
             if (timer > 0){
                    timer--;
                    if (timer==0){
                        bullet+=10;
                        
                    }
                }
            
        }

       
       
       /**
         * Class Shot (subclass of QActor -- inner class of Chased.Gun): the shots from this gun
         */
        private class Shot extends QActor
        {
            /**
             * sets bounds fields and creates the image for this actor
             */
            public Shot()
            {
                setBoundedAction(QActor.REMOVE, 5); // set bounds fields
                // create image for this actor
                GreenfootImage image = new GreenfootImage("FIRE.png");
                
                setImage(image);

            }
            
            /**
             * initializes rotation and position of actor
             *
             * @param world the world this actor was added into
             */
            public void addedToWorld(World world)
            {
              
                setRotation(Gun.this.getRotation()); // set rotation (to that of gun)
                move(7000); // set position (at end of gun)
                rotation = getRotation();
                setRotation(0);
            }
            
            /**
             * moves actor and checks for removal of actor
             */
            public void act()
            {
                
                setVX(0);
                setVY(0);
                addForce(0, getRotation()*QVAL);
                move(); // moving (equivalent to 'move(5)' for a non-QActor)
                 World world = getWorld();
                    Welt welt = (Welt)world;
                     Numberz numberz = welt.getNumberz();
                      HealthBar healthbar = welt.getHealthBar();
                        Actor chased = getOneIntersectingObject(Chased.class);
                    if (hits(Chaser.class) || atWorldEdge()) 
                {
                    getWorld().removeObject(this); // removing
                    numberz.loseNum();
                   
                }else if (hits(Runner.class) || atWorldEdge()) 
                {
                    numberz.addNum();
                    getWorld().removeObject(this); // removing
                    numberz.loseNum();
                   
                } else if (chased != null){
                   if(touchingFire == false)
                    {
                        healthbar.loseHealth();
                        
                        touchingFire = true;
                       
                        if(healthbar.health <=0)
                        {
                         world.removeObjects(world.getObjects(null));
                         Greenfoot.setWorld(new Stats(((Welt)world).score));
                        }
                        
                        
                    }
                }else{
                    touchingFire = false;
                }
                
            }
            
            
                  /**
             * internal method to detect object collision; returns true if collision detected, else false
             *
             * @param cls the class of object to check for collision with
             * @return a flag indicating whether an object of given class was detected or not
             */
            private boolean hits(Class cls)
            {
                // get intersecting object and return result
                Actor clsActor = getOneIntersectingObject(cls);
                if (clsActor != null)
                {
                    // remove intersector and bump score
                    getWorld().removeObject(clsActor);
                    
                    return true; 
                }
                return false;
            }
             
            /**
             * internal method that returns a flag indicating world edge encroachment
             *
             * @return a flag indicating whether the actor has encroached on a world edge or not
             */
            private boolean atWorldEdge()
            {
                // return state of encroachment on world edge
                return getX() <= 0 || getY() <= 0 ||
                    getX() >= getWorld().getWidth()-1 ||
                    getY() >= getWorld().getHeight()-1;
            }
        }
    }
}
Here is the code for the Healthbar:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Write a description of class HealthBar here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class HealthBar extends Actor
{
    int health = 80;
    int hbw = 80;
    int hbh = 15;
    int pixelsPerHealthPoint = (int)hbw/health;
    /**
     * Act - do whatever the HealthBar wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public HealthBar()
    {
        update();
    }
    public void act() 
    {
        update();
    }    
    public void update()
    {
     setImage(new GreenfootImage(hbw+2, hbh +2));   
     GreenfootImage myImage = getImage();
     myImage.setColor(Color.WHITE);
     myImage.drawRect(0,0,hbw+1,hbh+1);
     myImage.setColor(Color.RED);
     myImage.fillRect(1,1,health*pixelsPerHealthPoint, hbh);
    }   
    public void loseHealth()
    {
        health--;
    }
    public void fireloseHealth()
    {
        health=-2;
    }
}
danpost danpost

2016/8/29

#
Dudimus wrote...
I've found a way how my Chased/my character would get damaged by his ammo/fire which is his own subclass.
They are not subclasses -- they are inner classes. Objects of inner classes belong to an object of their outer class (any Chased object can "own" any number of Gun objects).
The problem is, when he first hits it, the healthbar decreases normally. But the second time he hits it, the healthbar decreases rapidly, what code do I need to add or edit?
It is not immediately evident why you are getting this behavior. Try putting 'private' in front of all your boolean fields (lines 9, 10 an 12 of the Chased class). If any errors occur, report back as to what you got. Some things I have noticed: (1) in the Chased class, you declare two fields, one for a new Runner object and one for a new Chased object (lines 14 and 15). There is no reason for a Chased object to create either of these type objects. Remove lines 14 and 15. (2) in the Chased class, lines 74 and 102 are getting a Numberz object from the Welt class; yet in neither case are you doing anything with this object. Removes those two lines. (3) the image of the HealthBar object is being updated with a new image every act cycle (see the act method at lines 23 through 26 of the HealthBar class). This is waste of cpu time as the value of the bar will not be changing each and every act cycle. Remove the act method and add a call to 'updateImage' after changing the value of the bar (lins 38 and 42). (4) Couple things about the HealthBar class code: (a) it is not the responsibility of the HealthBar to change its value differently depending on what damage is taken by (fire or chaser or runner). In other words, the fireloseHealth method does not belong. Either call 'loseHealth' twice when fire does damage or add a method to alter the bar value by any amount; (b) the construction of the HealthBar image will work as long as you do not alter the maximum health or length of the bar. You will run into issues if these values were changed (for examples, if length of bar was decreased without decreasing the maximum bar value, no value will show on the bar; and if the maximum value was decreased to, say, 50 (in this case), then a full health value will not show a complete bar due to rounding of 'pixelsPerHealthPoint' (see line 14 of the HealthBar class).
Dudimus Dudimus

2016/8/30

#
I did the things you've said, so my code's cleaner now. But the problem is still there (actually the problem is that whenever I have one fire, even if I hit it multiple times, the healthbar decreases health by one. But when I click again and hit the second one, then my healthbar decreases rapidly). What should I do?
Dudimus Dudimus

2016/8/30

#
I did the things you've said, so my code's cleaner now. But the problem is still there (actually the problem is that whenever I have one fire, even if I hit it multiple times, the healthbar decreases health by one. But when I click again and hit the second one, then my healthbar decreases rapidly). What should I do?
danpost danpost

2016/8/30

#
Dudimus wrote...
I did the things you've said, so my code's cleaner now. But the problem is still there (actually the problem is that whenever I have one fire, even if I hit it multiple times, the healthbar decreases health by one. But when I click again and hit the second one, then my healthbar decreases rapidly). What should I do?
I believe the problem is caused by the fact that line 83 is checking for the state of the "space" key when you are using mouse clicks to fire a shot.
Dudimus Dudimus

2016/8/30

#
Surprisingly, when I put the the private Boolean touchingFire variable inside private class Shot, it works perfectly! Thank you. But I have another problem, how can I make your Zombies stay in the world? When I go far they wander off then they're gone. Is it possible to make them always follow me and not wander anymore? Also, I made them not touch go on top of the character with a code inserted in the class. The problem though is that they just stay in front of the character and the healthbar only increases with the first zombie touching "Chased."What can I do to make them always follow "Chased" and decrease the healthbar even after the first zombies contact(if that's possible)? Here's one zombie class:
import greenfoot.*;

public class Chaser extends QActor
{
    int dr = 0; // the current turn rate
   private boolean touchingZ3 = false;
    public Chaser()
    {
        setBoundedAction(Welt.actionType, Welt.actionDistance); // set bound fields
        // create image for this actor
        GreenfootImage image = new GreenfootImage("Z1.png");
        setImage(image);
    }

    /**
     * turn and move actor
     */
    public void act()
    {
        int dx = 0, dy = 0; // the differences in locational coordinates
        int rate = 0; // the rate of turn and speed
    
        Actor chased = Welt.chased;
        if (chased != null && chased.getWorld() != null)
        { // set variable values
             if(getOneObjectInFront(Chased.class)==null){
            dx = getX()-chased.getX();
            dy = getY()-chased.getY();
            rate = 400-(int)Math.abs(dx)-(int)Math.abs(dy);}
        }
        if (rate > 100 )
        { // chase
            // the next code line does what is described in the following commented lines
               // determine shortest turn direction to face chased
            // int angleDiff = getRotation()-(int)(Math.atan2(dy, dx)*180/Math.PI); // range: -359 to 359
            // int anglet = (angleDiff+360+180)%360-180; // range: -180 to 179 (sign is turn direction)
               // turn and move
            // turn(16*rate*(int)Math.signum(anglet)); 
             if(getOneObjectInFront(Chased.class)==null){turn(16*rate*(int)Math.signum((getRotation()-(int)(Math.atan2(dy, dx)*180/Math.PI)+540)%360-180));
            move(rate/8, getQR()); }
        }else 
        { // wander
            // vary turn rate
             if(getOneObjectInFront(Chased.class)==null){dr += 2-Greenfoot.getRandomNumber(5)-(int)Math.signum(dr);
            // limit turn rate to between 40 q-rotation units left and right
            if (dr < -40) dr = -20;
            if (dr > 40) dr = 20;
            // turn and move
            turn(dr);
            move(10);}
        }
    }
    
     /**
             * internal method that returns a flag indicating world edge encroachment
             *
             * @return a flag indicating whether the actor has encroached on a world edge or not
             */
            private boolean atWorldEdge()
            {
                // return state of encroachment on world edge
                return getX() <= 0 || getY() <= 0 ||
                    getX() >= getWorld().getWidth()-1 ||
                    getY() >= getWorld().getHeight()-1;
            }
    
    
        public Actor getOneObjectInFront(Class a)
       {
        GreenfootImage myImage=getImage();
        int distanceToFront=myImage.getWidth()/2;
        int xOffset = (int)Math.ceil(distanceToFront*Math.cos(Math.toRadians(getRotation())));
        int yOffset = (int)Math.ceil(distanceToFront*Math.sin(Math.toRadians(getRotation())));
        return(getOneObjectAtOffset(xOffset, yOffset, a));
        }
}
Dudimus Dudimus

2016/8/30

#
*Chased is the character I'm referring to
danpost danpost

2016/8/30

#
Dudimus wrote...
Surprisingly, when I put the the private Boolean touchingFire variable inside private class Shot, it works perfectly!
Actually, that does not surprise me. Each shot should have it own state of touching, or not touching, the fire.
What can I do to make them always follow "Chased"
Lines 42 through 51 is the code to wander (not chase). So, remove those lines and lines 31, 32 and 41 (removing the restriction on following). Line 9 should have actual values for the actors of this class and not get it values from the Welt class (I only had my scenario get those values from the Welt class because I wanted to allow those values to be adjusted by the user in the demo).
Dudimus Dudimus

2016/8/31

#
Oh. I decided to make the world warped though. Is it possible to make my Fire bullet image a gif even though it's an inner class? I tried but it doesn't work.
import greenfoot.*;
import java.awt.Color;


/**
 * Class Chased (subclass of Actor): a user-controlled object with a mouse-controlled gun
 */
public class Chased extends Actor
{
    private boolean touchingZ = false;
    private boolean touchingZ2 = false;
    private boolean touchingZ3 = false;
    private int rotation;
    Gun gun = new Gun(); // the gun for this actor
 
    int timer;
    int bullet=10;
   
   
    /**
     * creates image for actor
     */
    public Chased()
    {
        // the image for this actor
        GreenfootImage image = new GreenfootImage(50, 50);
        image.fillOval(0, 0, 50, 50);
        image.setColor(Color.green);
        image.fillOval(7, 7, 36, 36);
        setImage(image);
    }
    
    /**
     * adds the gun for this actor into the world
     *
     * @param world the world this actor was added into
     */
    public void addedToWorld(World world)
    {
        world.addObject(gun, getX(), getY()); // add the gun belonging to this actor into the world
    }
    

      /**
     * move user-controlled actor and its gun; also, check for game over
     */
    public void act()
    {
       movement();  
         Actor chaser = getOneIntersectingObject(Chaser.class);
         
       if (chaser != null)
      
                {
            World world = getWorld();
                    Welt welt = (Welt)world; 
               
                    HealthBar healthbar = welt.getHealthBar();
                  
                    if(touchingZ == false)
                    {
                        move(10);
                        healthbar.loseHealth();
                        
                        touchingZ = true;
                       
                        if(healthbar.health <=0)
                        {
                         world.removeObjects(world.getObjects(null));
                         Greenfoot.setWorld(new Stats(((Welt)world).score));
                        }
                        
                        
                    }
        }else{
                    touchingZ = false;
                }
                
            
                
       Actor runner = getOneIntersectingObject(Runner.class);
         
       if (runner != null)
      
                {
            World world = getWorld();
                    Welt welt = (Welt)world; 
               
                    HealthBar healthbar = welt.getHealthBar();
                   
                    if(touchingZ2 == false)
                    {
                        healthbar.loseHealth();
                        
                        touchingZ2 = true;
                       
                        if(healthbar.health <=0)
                        {
                         world.removeObjects(world.getObjects(null));
                         Greenfoot.setWorld(new Stats(((Welt)world).score));
                        }
                        
                        
                    }
        }else{
                    touchingZ2 = false;
                }
                
       Actor bloater = getOneIntersectingObject(Bloater.class);
         
       if (bloater != null)
      
                {
            World world = getWorld();
                    Welt welt = (Welt)world; 
               
                    HealthBar healthbar = welt.getHealthBar();
                
                    if(touchingZ3 == false)
                    {
                        healthbar.loseHealth();
                        
                        touchingZ3 = true;
                       
                        if(healthbar.health <=0)
                        {
                         world.removeObjects(world.getObjects(null));
                         Greenfoot.setWorld(new Stats(((Welt)world).score));
                        }
                        
                        
                    }
        }else{
                    touchingZ3 = false;
                }
                
       
          
        }
        
    public void movement()
    {
        int dx = 0, dy = 0;
        if (Greenfoot.isKeyDown("a")) {
            if(getOneObjectInFront(Car.class)==null)
            dx--;
        }
        if (Greenfoot.isKeyDown("d")){ 
              if(getOneObjectInFront(Car.class)==null)
            dx++;
        }
        if (Greenfoot.isKeyDown("w")) {
              if(getOneObjectInFront(Car.class)==null)
            dy--;
        }
        if (Greenfoot.isKeyDown("s")) {
              if(getOneObjectInFront(Car.class)==null)
            dy++;
        }            
        setLocation(getX()+1*dx, getY()+1*dy);
        // limit to world bounds
        if (getX() < 25) setLocation(25, getY());
        if (getY() < 25) setLocation(getX(), 25);
        if (getX() > getWorld().getWidth()-25) setLocation(getWorld().getWidth()-25, getY());
        if (getY() > getWorld().getHeight()-25) setLocation(getX(), getWorld().getHeight()-25);
        // position gun
        gun.setLocation(getX(), getY());
         Actor chaser = getOneIntersectingObject(Chaser.class);
         
      
    }
     
    
        public Actor getOneObjectInFront(Class a)
       {
        GreenfootImage myImage=getImage();
        int distanceToFront=myImage.getWidth()/2;
        int xOffset = (int)Math.ceil(distanceToFront*Math.cos(Math.toRadians(getRotation())));
        int yOffset = (int)Math.ceil(distanceToFront*Math.sin(Math.toRadians(getRotation())));
        return(getOneObjectAtOffset(xOffset, yOffset, a));
        }
     
    /**
     * Class: Gun (subclass of Actor -- inner class of Chased): the gun for this actor
     */
    private class Gun extends Actor
    {
        /**
         * creates image for actor
         */
        public Gun()
        {
            // the image for this actor
            GreenfootImage image = new GreenfootImage("Picture1.png");
           
            setImage(image);
        }
         
    public boolean Munition(){
        if(bullet>0){
            return true;
        }
        else{
            return false;
        }
    }
    GifImage gifImage = new GifImage("57c3b88d56899519809115.gif");
    private boolean mouseclick;
    /**
         * responds to mouse movement and mouse button clicks
         */
        public void act()
        {
            // turn towards mouse when mouse moves
            if (Greenfoot.mouseMoved(null) || Greenfoot.mouseDragged(null))
            {
                MouseInfo mouse = Greenfoot.getMouseInfo();
                if (mouse != null) turnTowards(mouse.getX(), mouse.getY());
            }
            // detect mouse clicks to fire shot   
           
            World world = getWorld();
                    Welt welt = (Welt)world;

                    AmmoBar ammobar = welt.getAmmoBar();
                     
                   
            if(!mouseclick && (Greenfoot.mouseClicked(null)))
            {
                
             
                    if(Munition()==true){
                    mouseclick=true;
                    getWorld().addObject(new Shot(), getX(), getY());
                    bullet--;
                    ammobar.loseAmmo();
                    if (bullet ==0){
                        timer = 2000;
                    }
                
                }
            }
            if(mouseclick&& !Greenfoot.isKeyDown("space"))
            {
                mouseclick=false;
            }
           
             if (timer > 0){
                    timer--;
                    if (timer==0){
                        bullet+=10;
                        ammobar.addAmmo();
                    }
                }
                
        }
        
       
       
       /**
         * Class Shot (subclass of QActor -- inner class of Chased.Gun): the shots from this gun
         */
        private class Shot extends QActor
        {
            
            /**
             * sets bounds fields and creates the image for this actor
             */
            public Shot()
            {
                setBoundedAction(QActor.REMOVE, 5); // set bounds fields
                // create image for this actor
                setImage(gifImage.getCurrentImage());
                
            }
            
            /**
             * initializes rotation and position of actor
             *
             * @param world the world this actor was added into
             */
            public void addedToWorld(World world)
            {
              
                setRotation(Gun.this.getRotation()); // set rotation (to that of gun)
                move(7000); // set position (at end of gun)
                rotation = getRotation();
                setRotation(0);
            }
            
            /**
             * moves actor and checks for removal of actor
             */
            public void act()
            {
                
                setVX(0);
                setVY(0);
                addForce(0, getRotation()*QVAL);
                move(); // moving (equivalent to 'move(5)' for a non-QActor)
                 World world = getWorld();
                    Welt welt = (Welt)world;
                     Numberz numberz = welt.getNumberz();
                          
                if (hits(Chaser.class) || atWorldEdge()) 
                {
                    getWorld().removeObject(this); // removing
                    numberz.loseNum();
                   
                }else if (hits(Runner.class) || atWorldEdge()) 
                {
                    numberz.addNum();
                    getWorld().removeObject(this); // removing
                    numberz.loseNum();
                   
                }else if (hits(Bloater.class) || atWorldEdge()) 
                {
                    numberz.addNum();
                    getWorld().removeObject(this); // removing
                    numberz.loseNum();
                   
                } 
                
                
            }
                private boolean touchingFire = false;
                /**
             * internal method to detect object collision; returns true if collision detected, else false
             *
             * @param cls the class of object to check for collision with
             * @return a flag indicating whether an object of given class was detected or not
             */
            private boolean hits(Class cls)
            {
                // get intersecting object and return result
                
                 World world = getWorld();
                    Welt welt = (Welt)world;
 
                Actor chased = getOneIntersectingObject(Chased.class);
                if (chased != null){
                   HealthBar healthbar = welt.getHealthBar();
                    if(touchingFire == false)
                    {
                        
                        healthbar.loseHealth();
                        
                        touchingFire = true;
                        
                      
                        if(healthbar.health <=0)
                        {
                         world.removeObjects(world.getObjects(null));
                         Greenfoot.setWorld(new Stats(((Welt)world).score));
                        }
                        
                        
                    }
                }else{
          
                    touchingFire = false;
                 
                }
                Actor clsActor = getOneIntersectingObject(cls);
                if (clsActor != null)
                {
                    // remove intersector and bump score
                    getWorld().removeObject(clsActor);
                    
                    return true; 
                }
                return false;
                 
            }
             
            /**
             * internal method that returns a flag indicating world edge encroachment
             *
             * @return a flag indicating whether the actor has encroached on a world edge or not
             */
            private boolean atWorldEdge()
            {
                // return state of encroachment on world edge
                return getX() <= 0 || getY() <= 0 ||
                    getX() >= getWorld().getWidth()-1 ||
                    getY() >= getWorld().getHeight()-1;
            }
        }
    }
}
danpost danpost

2016/8/31

#
The GifImage object should probably be declared within the Shot class since each shot will track its own image (move line 207 to about 272). Line 273, in the constructor, only sets the initial image. You need to constantly check for updating the image using that same line of code within the act method.
Dudimus Dudimus

2016/8/31

#
So, how could I check for updates?
danpost danpost

2016/8/31

#
Dudimus wrote...
So, how could I check for updates?
danpost wrote...
using that same line of code within the act method.
That will have the system time constantly checked to have the image updated when necessary.
Dudimus Dudimus

2016/8/31

#
I tried putting the act code of the gun and the shot in public void update then I put update above the set image code and it still doesn't work. What should I do?
danpost danpost

2016/8/31

#
Dudimus wrote...
I tried putting the act code of the gun and the shot in public void update then I put update above the set image code and it still doesn't work. What should I do?
I said nothing about a 'public void update'. From the above code, just place a copy of line 273 in the act method of the Shot class (like line 296).
Dudimus Dudimus

2016/8/31

#
I did it but a red line appeared gifimage which says: cannot find symbol
There are more replies on the next page.
1
2