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

2015/10/15

images not changing

hoothoot hoothoot

2015/10/15

#
on both the a and s commands my images aren't changing. please help me figure out why.
import greenfoot.*;

/**
 * Write a description of class Gohan here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Gohan extends Mover
{
    /**
     * Act - do whatever the Gohan wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        ((Galaxy)getWorld()).gbar.setValue(health);
        checkKeypress ();
        reloadDelayCount++;
        dead();
    }
    
    
    public int health = 900000; //its over 9000 
    public int getHealth()
    {
        return health;
    }
     public void setHealth(int points) {
        health += points;  
    }
    
    
    private GreenfootImage image1;
    private GreenfootImage image2;
    private GreenfootImage image3;
    private GreenfootImage image4;
    private GreenfootImage image5;
    private GreenfootImage image6; 
    private GreenfootImage image7;
    private GreenfootImage image8;
    private GreenfootImage image9;
    public Gohan() 
    {
        image1 = new GreenfootImage("gohan.png"); 
        image2 = new GreenfootImage("gohanstep.png");
        image3 = new GreenfootImage("gohanstep2.png");
        image4 = new GreenfootImage("powerattack.png");
        image5 = new GreenfootImage("gohanpunch.png");
        image6 = new GreenfootImage("Gohankick1.png");
        image7 = new GreenfootImage("HealthBar.png");
        image8 = new GreenfootImage("Gpowerup.png");
        image9 = new GreenfootImage("Gpowerup2.png");
        setImage(image1); 
        reloadDelayCount = 0;
        gunReloadTime = 20;
        
    }
    
    
    public void sideToSide()
    {
                 if ( getImage() == image1 ) 
            {   setImage(image2);
            }
        
            else{ setImage(image1);
            }
            }
    
    public void stopMovement()
    {
                {}if( getImage()== image9){}
    }
    
    //ENDHITTING↓↓↓
        public void return1()
        {
                if ( getImage()== image3)
                     {setImage(image1);}
                if ( getImage()== image5)
                     {setImage(image1);}
                if ( getImage()== image6)
                     {setImage(image1);}
        }
        
    public void win()
    { 
        if ( getImage()== image8){
            setImage (image9);
        }else if ( getImage()== image9){
            setImage (image8);
        }
    }
    public void checkKeypress() 
    {
        //MOVEMENT CONTROLS↓↓↓
                if (Greenfoot.isKeyDown("left"))
                {
                    { stopMovement();
                        move (-40);
                        sideToSide();
                    }
                        }
                  
                
                if (Greenfoot.isKeyDown("right"))
                { stopMovement();
                  move (40);
                  sideToSide();
                            }
        
       
        //HITTING CONTROLS↓↓↓
            if (Greenfoot.isKeyDown("a"))
            {
                if (getImage() == image8 )
                 {stopMovement();}
                    else
                   
                       setImage(image5);
                       hitEnemy();
                       Greenfoot.playSound("Gpunch.wav");
                    
                    
                        }else{ return1();}
                    
                        
            if (Greenfoot.isKeyDown("s"))
            {   
                if (getImage() == image8 )
                 {stopMovement();}
                    else
                   
                       setImage(image3);
                       hitEnemy();
                       Greenfoot.playSound("Gpunch.wav");
                    
                }else{ return1();}
                    
            if (Greenfoot.isKeyDown("x"))
            {
                if (getImage() == image8 )
                 {}
                 else
                     setImage(image6);
                     hitEnemy();
                     Greenfoot.playSound("Gpunch.wav");
                 if (getImage() == image9 )
                 {}
                 else
                     setImage(image6);
                     hitEnemy();
                     Greenfoot.playSound("Gpunch.wav");
                        }
                    
                else return1();  
            
            
       
        //SHOOTING CONTROLS↓↓↓
                if (Greenfoot.isKeyDown("space"))
                {    stopMovement(); 
                        fire();
                    }
                }   
    
        private void dead() {
            if (health <=0)
            {
                Greenfoot.playSound("cellyelling.wav");  
                getWorld().removeObject(this);
            }
        }
        private void hitEnemy() {
        Cell cell = (Cell) getOneObjectAtOffset(0, 0, Cell.class);
        if (cell != null) {
                cell.setHealth(-1000);
                cell.move(30);
                       if (cell.health <=0)
                            {
                                setImage(image8);
                                win();
                                getWorld().removeObject(cell);
                                Greenfoot.playSound("gohanyelling.wav");
                        }
            } 
    }
    
    public int reloadDelayCount;
    public int gunReloadTime;
    public int shotsFired;
    /**
     * Set the time needed for re-loading the rocket's gun. The shorter this time is,
     * the faster the rocket can fire. The (initial) standard time is 20.
     */
    public void setGunReloadTime(int reloadTime)
    {
        gunReloadTime = reloadTime;
    }
    private void fire() 
        {
        
         if (reloadDelayCount >= gunReloadTime) {
                setImage(image1);
                move(-250);
                Bullet b = new Bullet(getMovement().copy(), getRotation());
                getWorld().addObject(b, getX(), getY());
                b.move();
                shotsFired++;
                reloadDelayCount = 0;   // time since last shot fired
                setHealth(+1000);
         }
    }
    
    }
it's under checkKeypress.
You need to login to post a reply.