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

2013/9/6

Multi level problem

dominicarrojado dominicarrojado

2013/9/6

#
How can I set the world into the second level but want to preserve the state of my game character, If for example I stored some state (e.g. a score) in the instance variables of that actor, I want to make sure that I carry the actor object across without creating a new one in the second level.
Gevater_Tod4711 Gevater_Tod4711

2013/9/6

#
If you change the constructor of your second world class so that you can overgive the actor where the data is saved as a parameter you can have the same actor object in two different classes. Try it like this:
//in your level2 class;

public Level2(Actor actor) {
    super(600, 400, 1);//you should change this line to the worldsize you are using currenty. I just guessed some values;
    addObject(actor, 100, 100);//maybe some other coordinates; but this will add your actor to the new world;
}
Now you just need to change the setWorld method call. When you want to change the world from you actor (the one that is copied into the new world) you can do it like this:
Greenfoot.setWorld(new Level2(this));//if Level2 is not the correct name of your world class you'll have to change that;
If you want to call the setWorld method from another class you will have to do it this way:
Greenfoot.setWorld(new Level2(getWorld().getObjects(CopiedActor.class).get(0)));//instead of CopiedActor.class you have to use the right classname;

//if you use this code in a world subclass just leave out the 'getWorld().'
dominicarrojado dominicarrojado

2013/9/6

#
Okay thanks. Will try.
dominicarrojado dominicarrojado

2013/9/6

#
Constructor MyWorld2 in class MyWorld2 cannot be applied to given types.
dominicarrojado dominicarrojado

2013/9/6

#
I also need to get the current score, and other stuff like bullets? How can I transfer it to the level 2 without creating a new one or getting it back to zero?
danpost danpost

2013/9/6

#
Please show your level 1 world code from the beginning through the constructor and any methods the are called while the constructor is executing. It should give an idea of how you have things organized and better give an idea of how to transfer the information you need transferred.
dominicarrojado dominicarrojado

2013/9/6

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class MyWorld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class MyWorld extends World
{
    private Hero hero;
    private Minion minion;
    private Minion2 minion2;
    private Minion3 minion3;
    private NotRoamingMinion nrminion;
    private NotRoamingMinion2 nrminion2;
    private NotRoamingMinion3 nrminion3;
    //private Boss boss;
    private Pistol pistol;
    private CurrentGun currentgun;
    private Blood blood;
    PistolQuantity pistolQuantity = new PistolQuantity("Pistol: ");
    ShotgunQuantity shotgunQuantity = new ShotgunQuantity("Shotgun: ");
    AssaultQuantity assaultQuantity = new AssaultQuantity("Assault: ");
    UziQuantity uziQuantity = new UziQuantity("Uzi: ");
    ZombieKill zombieKillCounter = new ZombieKill("Kills: ");
    public int heroLifeMax = 100;
    public int heroLife = 100;
    public int bossQuantity = 1;
    public int enemyQuantity = 5;
    public int enemyLimit = 15;
    public int bossLimit = 2;
    public int zombieKill = 0;

   
    private int gameTimer = 0;
    private final static int WORLD_WIDTH = 1050;
    private final static int WORLD_HEIGHT = 600;
    
    public Bar bar = new Bar("Player 1", "Health Points", heroLife, heroLifeMax);
    
    static int width = 1050; // width of the world
    static int height = 600; // height of the world
    static int maxRocks = 5; // total number of rocks to create and keep portals for
    static int maxPortalActors = maxRocks; // sum number of portal objects
    Portal portal = new Portal();
    
   
    /**
     * Constructor for objects of class MyWorld.
     * 
     */
    
    public MyWorld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1050, 600, 1); 
        setPaintOrder(Bar.class,PistolQuantity.class,ShotgunQuantity.class,AssaultQuantity.class,UziQuantity.class,CurrentGun.class,ZombieKill.class,Portal.class,Wall.class,Pistol.class,Shotgun.class,Assault.class,Uzi.class);
        addObject(portal, width / 2, height / 2);
        prepare();
   

    }

    /**
     * Prepare the world for the start of the program. That is: create the initial
     * objects and add them to the world.
     */
    private void prepare()
    {
        this.hero = new Hero(this);
        addObject(this.hero, 25, 375);
        portal.addPortal(this.hero); 

        Key key = new Key();
        addObject(key, 25, 275);

        addObject(bar, 120, 25);
        addObject(pistolQuantity, 450, 24);
        addObject(shotgunQuantity, 550, 24);
        addObject(assaultQuantity, 650, 24);
        addObject(uziQuantity, 720, 24);
        addObject(zombieKillCounter, 900, 24);

        this.currentgun = new CurrentGun(this);
        addObject(this.currentgun, 760, 25);

        Wall wall = new Wall();
        addObject(wall, 25, 75);

        Wall wall2 = new Wall();
        addObject(wall2, 75, 75);

        Wall wall3 = new Wall();
        addObject(wall3, 125, 75);

        Wall wall4 = new Wall();
        addObject(wall4, 175, 75);

        Wall wall5 = new Wall();
        addObject(wall5, 225, 75);

        Wall wall6 = new Wall();
        addObject(wall6, 275, 75);

        Wall wall7 = new Wall();
        addObject(wall7, 325, 75);

        Wall wall8 = new Wall();
        addObject(wall8, 375, 75);

        Wall wall9 = new Wall();
        addObject(wall9, 425, 75);

        Wall wall10 = new Wall();
        addObject(wall10, 475, 75);

        Wall wall11 = new Wall();
        addObject(wall11, 525, 75);

        Wall wall12 = new Wall();
        addObject(wall12, 575, 75);

        Wall wall13 = new Wall();
        addObject(wall13, 625, 75);

        Wall wall14 = new Wall();
        addObject(wall14, 675, 75);

        Wall wall15 = new Wall();
        addObject(wall15, 725, 75);

        Wall wall16 = new Wall();
        addObject(wall16, 775, 75);

        Wall wall17 = new Wall();
        addObject(wall17, 825, 75);

        Wall wall18 = new Wall();
        addObject(wall18, 825, 25);

        Wall wall19 = new Wall();
        addObject(wall19, 875, 25);

        Wall wall20 = new Wall();
        addObject(wall20, 925, 25);

        Wall wall21 = new Wall();
        addObject(wall21, 975, 25);

        Wall wall22 = new Wall();
        addObject(wall22, 1025, 25);

        Wall wall24 = new Wall();
        addObject(wall24, 75, 125);

        Wall wall25 = new Wall();
        addObject(wall25, 225, 175);

        nrminion3 = new NotRoamingMinion3(this);
        addObject(nrminion3, 175, 175);

        Wall wall26 = new Wall();
        addObject(wall26, 25, 225);

        Wall wall27 = new Wall();
        addObject(wall27, 75, 225);

        Wall wall28 = new Wall();
        addObject(wall28, 125, 225);

        Wall wall29 = new Wall();
        addObject(wall29, 175, 225);

        Wall wall30 = new Wall();
        addObject(wall30, 225, 225);

        Wall wall31 = new Wall();
        addObject(wall31, 275, 225);

        Wall wall32 = new Wall();
        addObject(wall32, 325, 225);

        Wall wall33 = new Wall();
        addObject(wall33, 375, 225);

        Wall wall34 = new Wall();
        addObject(wall34, 425, 225);

        Wall wall35 = new Wall();
        addObject(wall35, 475, 225);

        Wall wall36 = new Wall();
        addObject(wall36, 525, 225);

        Wall wall37 = new Wall();
        addObject(wall37, 575, 225);

        Wall wall38 = new Wall();
        addObject(wall38, 625, 225);

        Wall wall39 = new Wall();
        addObject(wall39, 675, 225);

        Wall wall40 = new Wall();
        addObject(wall40, 175, 275);

        Wall wall41 = new Wall();
        addObject(wall41, 175, 325);

        Wall wall42 = new Wall();
        addObject(wall42, 175, 375);

        Wall wall43 = new Wall();
        addObject(wall43, 175, 425);

        Wall wall44 = new Wall();
        addObject(wall44, 175, 475);

        Wall wall45 = new Wall();
        addObject(wall45, 25, 325);

        Wall wall46 = new Wall();
        addObject(wall46, 125, 475);

        Wall wall47 = new Wall();
        addObject(wall47, 325, 325);

        Wall wall48 = new Wall();
        addObject(wall48, 325, 375);

        Wall wall49 = new Wall();
        addObject(wall49, 325, 425);

        Wall wall50 = new Wall();
        addObject(wall50, 225, 475);

        Wall wall51 = new Wall();
        addObject(wall51, 275, 475);

        Wall wall52 = new Wall();
        addObject(wall52, 325, 475);

        this.pistol = new Pistol();
        addObject(this.pistol, 325, 275);

        nrminion = new NotRoamingMinion(this);
        addObject(nrminion, 225, 425);

        nrminion = new NotRoamingMinion(this);
        addObject(nrminion, 275, 425);

        Key key2 = new Key();
        addObject(key2, 275, 425);

        Door door = new Door();
        addObject(door, 375, 475);

        Wall wall53 = new Wall();
        addObject(wall53, 425, 475);

        Wall wall54 = new Wall();
        addObject(wall54, 425, 525);

        Wall wall55 = new Wall();
        addObject(wall55, 425, 575);

        Wall wall56 = new Wall();
        addObject(wall56, 75, 325);

        SideDoor sidedoor = new SideDoor();
        addObject(sidedoor, 425, 425);

        Wall wall57 = new Wall();
        addObject(wall57, 425, 375);

        Wall wall58 = new Wall();
        addObject(wall58, 425, 325);

        Wall wall59 = new Wall();
        addObject(wall59, 425, 275);

        Wall wall60 = new Wall();
        addObject(wall60, 75, 375);

        Wall wall61 = new Wall();
        addObject(wall61, 75, 475);

        Wall wall62 = new Wall();
        addObject(wall62, 75, 525);

        Wall wall63 = new Wall();
        addObject(wall63, 175, 575);

        Wall wall64 = new Wall();
        addObject(wall64, 275, 525);

        Wall wall65 = new Wall();
        addObject(wall65, 375, 575);

        Wall wall66 = new Wall();
        addObject(wall66, 525, 325);

        Wall wall67 = new Wall();
        addObject(wall67, 575, 325);

        Wall wall68 = new Wall();
        addObject(wall68, 525, 425);

        Wall wall69 = new Wall();
        addObject(wall69, 575, 425);

        Wall wall70 = new Wall();
        addObject(wall70, 525, 525);

        Wall wall71 = new Wall();
        addObject(wall71, 575, 525);

        Wall wall72 = new Wall();
        addObject(wall72, 725, 325);

        Wall wall73 = new Wall();
        addObject(wall73, 775, 325);

        Wall wall74 = new Wall();
        addObject(wall74, 725, 425);

        Wall wall75 = new Wall();
        addObject(wall75, 775, 425);

        Wall wall76 = new Wall();
        addObject(wall76, 725, 525);

        Wall wall77 = new Wall();
        addObject(wall77, 775, 525);

        Wall wall78 = new Wall();
        addObject(wall78, 725, 225);

        Wall wall79 = new Wall();
        addObject(wall79, 775, 225);

        Shotgun shotgun = new Shotgun();
        addObject(shotgun, 525, 275);

        Wall wall80 = new Wall();
        addObject(wall80, 875, 225);

        Wall wall81 = new Wall();
        addObject(wall81, 875, 275);

        Wall wall82 = new Wall();
        addObject(wall82, 875, 325);

        Wall wall83 = new Wall();
        addObject(wall83, 875, 375);

        Wall wall84 = new Wall();
        addObject(wall84, 875, 425);

        Wall wall85 = new Wall();
        addObject(wall85, 875, 475);

        Wall wall86 = new Wall();
        addObject(wall86, 875, 525);

        Wall wall87 = new Wall();
        addObject(wall87, 925, 425);

        Wall wall88 = new Wall();
        addObject(wall88, 975, 525);

        Wall wall89 = new Wall();
        addObject(wall89, 975, 575);

        Health health = new Health();
        addObject(health, 875, 575);

        Key key3 = new Key();
        addObject(key3, 925, 575);

        this.minion = new Minion(this);
        addObject(this.minion, 725, 275);

        this.minion2 = new Minion2(this);
        addObject(this.minion2, 725, 375);

        this.minion3 = new Minion3(this);
        addObject(this.minion3, 725, 475);

        Door door2 = new Door();
        addObject(door2, 825, 225);

        Wall wall90 = new Wall();
        addObject(wall90, 975, 425);

        Wall wall91 = new Wall();
        addObject(wall91, 1025, 425);

        SideDoor2 sidedoor22 = new SideDoor2();
        addObject(sidedoor22, 975, 475);

        GrandKey grandkey = new GrandKey();
        addObject(grandkey, 1025, 575);

        Wall wall92 = new Wall();
        addObject(wall92, 375, 125);

        nrminion2 = new NotRoamingMinion2(this);
        addObject(nrminion2, 325, 125);

        Wall wall93 = new Wall();
        addObject(wall93, 525, 175);

        nrminion3 = new NotRoamingMinion3(this);
        addObject(nrminion3, 475, 175);

        Wall wall94 = new Wall();
        addObject(wall94, 675, 125);

        nrminion2 = new NotRoamingMinion2(this);
        addObject(nrminion2, 625, 125);

        Wall wall95 = new Wall();
        addObject(wall95, 775, 175);

        Wall wall96 = new Wall();
        addObject(wall96, 875, 175);

        Key key4 = new Key();
        addObject(key4, 25, 125);

        Assault assault = new Assault();
        addObject(assault, 25, 175);

        Wall wall97 = new Wall();
        addObject(wall97, 925, 125);

        Wall wall98 = new Wall();
        addObject(wall98, 925, 175);

        SideDoor sidedoor2 = new SideDoor();
        addObject(sidedoor2, 925, 75);

        this.minion = new Minion(this);
        addObject(this.minion, 975, 75);

        this.minion2 = new Minion2(this);
        addObject(this.minion2, 975, 125);

        this.minion3 = new Minion3(this);
        addObject(this.minion3, 975, 175);

        this.minion = new Minion(this);
        addObject(this.minion, 1025, 75);

        this.minion2 = new Minion2(this);
        addObject(this.minion2, 1025, 125);

        this.minion3 = new Minion3(this);
        addObject(this.minion3, 1025, 175);

        Wall wall99 = new Wall();
        addObject(wall99, 925, 225);

        Wall wall100 = new Wall();
        addObject(wall100, 975, 225);

        Wall wall101 = new Wall();
        addObject(wall101, 925, 325);

        Wall wall102 = new Wall();
        addObject(wall102, 975, 325);

        GrandDoor granddoor = new GrandDoor();
        addObject(granddoor, 954, 275);

        NextStage nextstage = new NextStage();
        addObject(nextstage, 925, 275);

        Key2 key22 = new Key2();
        addObject(key22, 925, 375);
        
        Health health2 = new Health();
        addObject(health2, 1025, 475);
        
        Uzi uzi = new Uzi();
        addObject(uzi, 1025, 525);
    }
    
    
    public void addBulletPistol()
    {
        pistolQuantity.add(50);
    }
    public void addBulletShotgun()
    {
        shotgunQuantity.add(25);
    }
    public void addBulletAssault()
    {
        assaultQuantity.add(15);
    }
    public void addBulletUzi()
    {
        uziQuantity.add(100);
    }
    public void subBulletPistol()
    {
        pistolQuantity.subtract(1);
    }
    public void subBulletShotgun()
    {
        shotgunQuantity.subtract(1);
    }
    public void subBulletAssault()
    {
        assaultQuantity.subtract(1);
    }
    public void subBulletUzi()
    {
        uziQuantity.subtract(1);
    }
    
    public void zombieKill()
    {
        zombieKillCounter.add(1);
    }
    
    public Hero getHero()
    {
        return this.hero;
    }
  
    public Minion getMinion()
    {
        return this.minion;
    }  
    public Minion2 getMinion2()
    {
        return this.minion2;
    }  
    public Minion3 getMinion3()
    {
        return this.minion3;
    }  
    /*
    public Boss getBoss()
    {
        return this.boss;
    }*/
    public Pistol getPistol()
    {
        return this.pistol;
    }
    public Bar getBar()
    {
        return this.bar;
    }
    public CurrentGun getCurrentGun()
    {
        return this.currentgun;
    }   
    public Blood blood()
    {
        return this.blood;
    }   
    public void act()
    {
        

        
        if (bar.getValue() == bar.getMinimumValue())
        {
            /*if (getObjects(GameOver.class).isEmpty()) showGameOver();
            return;*/
            removeObject(hero);
        }
       
    }
 
 

}
Gevater_Tod4711 Gevater_Tod4711

2013/9/6

#
All your variables in the world class are declared public so it would be the easyest way to change the constructor of the second level again. It then should look like this:
public MyWorld2(World world, Actor actor) {
    //here you can set the variables of your new world;
    //e.g. heroHealth = world.heroHealth;
    //...
    addObject(actor, 100, 100);
}
dominicarrojado wrote...
Constructor MyWorld2 in class MyWorld2 cannot be applied to given types.
To fix this problem you should post the code you use to create the new world (setWorld(...)).
danpost danpost

2013/9/6

#
If you added the 'get' and 'set' methods necessary for the transfers, then,
Level2 level2 = new Level2();
level2.setHero(getHero());
level2.getPistolQuantity().setValue(getPistolQuantity().getValue());
// etc.
Greenfoot.setLevel(level2);
dominicarrojado dominicarrojado

2013/9/6

#
but some of my variables are with the Actor class. (e.g. bullets..)
dominicarrojado dominicarrojado

2013/9/6

#
Where will I put that danpost?
Gevater_Tod4711 Gevater_Tod4711

2013/9/6

#
You should try to declare the variables in world or your hero class that are necessary in all levels. If you have some variables that you need in the next level your code will become very much and confusing. Or another method what would be possible for your bullets: declare the variables static. But this only works if the variable should have the same value for every bullet object. Otherwhise this method will not work. If you want to use static variables just declare the variables that you need as public static (or private static, ...). Then you can get the value of the variables using the classname + '.' + variable name (if it's public; otherwhise you need to declare a getter method but you can also reach this method with the classname ...).
danpost danpost

2013/9/6

#
dominicarrojado wrote...
but some of my variables are with the Actor class. (e.g. bullets..)
Show me where some of those are (need how declared, which class declared in and type of class). So I can give some valid examples.
dominicarrojado wrote...
Where will I put that danpost?
The code I last posted would go in the first world class; it can be either put in a method in the world class and called from wherever you detect that the world should change to level 2; or adjusted and placed at that detection place.
danpost danpost

2013/9/6

#
To make sure you understand, if you pass the actor that the variable is in, you are also passing the variable whose value remains intact (you are not creating a new actor with new initialized variables).
dominicarrojado dominicarrojado

2013/9/6

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Player here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Hero extends Actor
{
    public int powerup = 0;
    public int currentGun = 0;
    public int bullet1 = 0;
    public int bullet2 = 0;
    public int bullet3 = 0;
    public int bullet4 = 0;
    public int key = 0;
    public int key2 = 0;
    public int gkey = 0;
    private int fireDelay = 0;
    
    private MyWorld world;
    
    public static int currentX;
    public static int currentY;
    
    private static final GreenfootImage hero = new GreenfootImage("noweapon.png");
    private static final GreenfootImage hero1 = new GreenfootImage("holdpistol.png");
    private static final GreenfootImage hero2 = new GreenfootImage("holdshotgun.png");
    private static final GreenfootImage hero3 = new GreenfootImage("holdassault.png");
    private GreenfootImage hero4 = new GreenfootImage("holduzi.png");
    
    
    
    /**
     * Act - do whatever the Player wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public Hero(MyWorld world)
    {
        this.world = world;
    }
    public void act() 
    {
        move();
        attack();
        obtainKey();
        obtainKey2();
        obtainGrandKey();
        passDoor();
        passSideDoor();
        passSideDoor2();
        passGrandDoor();
        acquirePistol();
        acquireShotgun();
        acquireAssault();
        acquireUzi();
        changeImage();
        currentGun();
        changeImageIfNoBullet();
        processFireDelay();
        restoreHP();
        hit();
        checkAboveWalls();
        checkBelowWalls();
        checkRightWalls();
        checkLeftWalls();
        nextLevel();
        
        
        
        if (world.heroLife == 0)
        {
            getWorld().removeObject(this);
        }
        
       currentX = getX();
       currentY = getY();
    }
 
    
    public void move()
    {
    if(Greenfoot.isKeyDown("right"))
    {
        setRotation(0);
        move(2);
    }
    else if(Greenfoot.isKeyDown("up"))
    {
        setRotation(270);
        move(2);
    }
    else if(Greenfoot.isKeyDown("down"))
    {
        setRotation(90);
        move(2);
    }
    else if(Greenfoot.isKeyDown("left"))
    {
        setRotation(180);
        move(2);
    }
    
}
   public void attack()
   {
       if ("space".equals(Greenfoot.getKey())) 
    {
        if ((bullet1>0)&&(currentGun == 1)&&(fireDelay == 0))
        {
        pistol();
        bullet1--;
        ((MyWorld) getWorld()).subBulletPistol();
        }
        else if ((bullet2>0)&&(currentGun == 2)&&(fireDelay == 0))
        {
        shotgun();
        bullet2--;
        
        ((MyWorld) getWorld()).subBulletShotgun();
        }
        else if ((bullet3>0)&&(currentGun == 3)&&(fireDelay == 0))
        {
        assault();
        bullet3--;
        ((MyWorld) getWorld()).subBulletAssault();
        }
        else if (((currentGun == 1)&&(bullet1<=0))||
                ((currentGun == 2)&&(bullet2<=0))||
                ((currentGun == 3)&&(bullet3<=0)))
        {
            Greenfoot.playSound("empty.mp3");
        }
    }
    if (Greenfoot.isKeyDown("space"))
    {
        if ((bullet4>0)&&(currentGun == 4)&&(fireDelay == 0))
        {
        uzi();
        }
    }
   }
    
    public void changeImage()
    {
    if ((Greenfoot.isKeyDown("1"))&&(bullet1>0))
    {
        currentGun = 1;

    }
    else if ((Greenfoot.isKeyDown("2"))&&(bullet2>0))
    {
        currentGun = 2;

    }
    else if ((Greenfoot.isKeyDown("3"))&&(bullet3>0))
    {
        currentGun = 3;
 
    }
    else if ((Greenfoot.isKeyDown("4"))&&(bullet4>0))
    {
        currentGun = 4;
    }
   }

public void changeImageIfNoBullet()
{
    if ((bullet1<=0)&&(bullet2<=0)&&(bullet3<=0)&&(bullet4<=0))
    {
        currentGun = 0;
    }
      
}
public void currentGun()
{
    if (currentGun == 0) setImage(hero);
    else if (currentGun == 1) setImage(hero1);
    else if (currentGun == 2) setImage(hero2);
    else if (currentGun == 3) setImage(hero3);
    else if (currentGun == 4) setImage(hero4);
}




  
    public boolean checkBelowWalls()
    {
        int spriteHeight = getImage().getHeight();
        int yDistance = (int)(spriteHeight/2) + 5;
        
        Actor belowWall = getOneObjectAtOffset(0, yDistance, Wall.class);
        
        if (belowWall == null)
        {
            return false;
        }
        else
        {
            stopByBelowWall(belowWall);
            return true;
        }
    }
    
    public void stopByBelowWall(Actor belowWall)
    {
        int wallHeight = belowWall.getImage().getHeight();
        int newY = belowWall.getY() - (wallHeight + getImage().getHeight())/2;
        setLocation(getX(), newY-15);
    }
    
    public boolean checkAboveWalls()
    {
        int spriteHeight = getImage().getHeight();
        int yDistance = (int)(spriteHeight/-2) - 5;
        
        Actor aboveWall = getOneObjectAtOffset(0, yDistance, Wall.class);
        
        if (aboveWall == null)
        {
            return false;
        }
        else
        {
            stopByAboveWall(aboveWall);
            return true;
        }
    }
    
    public void stopByAboveWall(Actor aboveWall)
    {
        int wallHeight = aboveWall.getImage().getHeight();
        int newY = aboveWall.getY() - (wallHeight + getImage().getHeight())/-2;
        setLocation(getX(), newY+10);
    }
    
    
    public boolean checkRightWalls()
    {
        int spriteWidth = getImage().getWidth();
        int xDistance = (int)(spriteWidth/2);
        
        Actor rightWall = getOneObjectAtOffset(xDistance, 0, Wall.class);
        
        if(rightWall == null)
        {
            return false;
        }
        else
        {
            stopByRightWall(rightWall);
            return true;
        }
    }
    
    public void stopByRightWall(Actor rightWall)
    {
        int wallWidth = rightWall.getImage().getWidth();
        int newX = rightWall.getX() - (wallWidth + getImage().getWidth())/2;
        setLocation(newX - 5, getY());
    }
    
    public boolean checkLeftWalls()
    {
        int spriteWidth = getImage().getWidth();
        int xDistance = (int)(spriteWidth/-2);
        
        Actor leftWall = getOneObjectAtOffset(xDistance, 0, Wall.class);
        
        if(leftWall == null)
        {
            return false;
        }
        else
        {
            stopByLeftWall(leftWall);
            return true;
        }
    }
    public void stopByLeftWall(Actor leftWall)
    {
        int wallWidth = leftWall.getImage().getWidth();
        int newX = leftWall.getX() - (wallWidth + getImage().getWidth())/-2;
        setLocation(newX + 5, getY());
    }
    
  
    private void pistol()
    {
        if (fireDelay != 0) return;
        Fire fire = new Fire();  
        getWorld().addObject(fire, getX(), getY());    
        fire.setRotation(getRotation());
        fire.move(30);
        fireDelay = 30;
        Greenfoot.playSound("pistol.mp3");
    }
    private void shotgun()
    {
        if (fireDelay != 0) return;
        Fire2 fire2 = new Fire2();  
        getWorld().addObject(fire2, getX(), getY());    
        fire2.setRotation(getRotation());
        fire2.move(30);
        fireDelay = 70;
        Greenfoot.playSound("shotgun.mp3");
    }
    private void assault()
    {
        if (fireDelay != 0) return;
        Fire3 fire3 = new Fire3();  
        getWorld().addObject(fire3, getX(), getY());    
        fire3.setRotation(getRotation());
        fire3.move(30);
        fireDelay = 60;
        Greenfoot.playSound("assault.mp3");
    }
    private void uzi()
    {
        if (fireDelay != 0) return;
        Fire fire = new Fire();  
        getWorld().addObject(fire, getX(), getY());    
        fire.setRotation(getRotation());
        fire.move(30);
        ((MyWorld) getWorld()).subBulletUzi();
        bullet4--;
        fireDelay = 10;
        Greenfoot.playSound("uzi.mp3");
    }
   
    
    public void acquirePistol()
    {
        Actor pistol;
        pistol = getOneIntersectingObject(Pistol.class);
        if (pistol !=null)
        {
               setImage(hero1);
               currentGun = 1;
               Greenfoot.playSound("reload.mp3");
               bullet1 += 50;
               ((MyWorld) getWorld()).addBulletPistol();
        }
        getWorld().removeObject(pistol);
    }
    public void acquireShotgun()
    {
        Actor shotgun;
        shotgun = getOneIntersectingObject(Shotgun.class);
        if (shotgun !=null)
               {
               setImage(hero2);
               currentGun = 2;
               Greenfoot.playSound("reload.mp3");
               bullet2 += 25;
                ((MyWorld) getWorld()).addBulletShotgun();
               }
        getWorld().removeObject(shotgun);
    }
    public void acquireAssault()
    {
        Actor assault;
        assault = getOneIntersectingObject(Assault.class);
        if (assault !=null)
               {
               setImage(hero3);
               currentGun = 3;
               Greenfoot.playSound("reload.mp3");
               bullet3 += 15;
               ((MyWorld) getWorld()).addBulletAssault();
               }
        getWorld().removeObject(assault);
    }
    public void acquireUzi()
    {
        Actor uzi;
        uzi = getOneIntersectingObject(Uzi.class);
        if (uzi !=null)
               {
               setImage(hero4);
               currentGun = 4;
               Greenfoot.playSound("reload.mp3");
               bullet4 += 100;
               ((MyWorld) getWorld()).addBulletUzi();
               }
        getWorld().removeObject(uzi);
    }
    
    public void restoreHP()
    {
        Actor health;
        health = getOneIntersectingObject(Health.class);
        if (health != null)
        {
            MyWorld world = (MyWorld) getWorld();
            
            world.bar.add(25);
            getWorld().removeObject(health);
        }
    }
    private void processFireDelay()
    {
        if (fireDelay > 0)
        {
            fireDelay--;
        }
    }
        
    public void hit()
    {
        Actor fireb;
        
        fireb = getOneIntersectingObject(FireBoss.class);
           
        if (fireb !=null)
        {
            MyWorld world = (MyWorld) getWorld();
            
            world.bar.subtract(5);
            getWorld().removeObject(fireb);
        }
               
    }
    
    public void obtainKey()
    {
        Actor obtainkey;
        
        obtainkey = getOneIntersectingObject(Key.class);
           
        if (obtainkey !=null)
        {
            key++;
            getWorld().removeObject(obtainkey);
        }
               
    }
    
    public void obtainKey2()
    {
        Actor obtainkey2;
        
        obtainkey2 = getOneIntersectingObject(Key2.class);
           
        if (obtainkey2 !=null)
        {
            key2++;
            getWorld().removeObject(obtainkey2);
        }
               
    }
    
    public void obtainGrandKey()
    {
        Actor obtaingkey;
        
        obtaingkey = getOneIntersectingObject(GrandKey.class);
           
        if (obtaingkey!=null)
        {
            gkey++;
            getWorld().removeObject(obtaingkey);
        }
               
    }
    
    public void passDoor()
    {
        Actor door;
        
        door = getOneIntersectingObject(Door.class);
           
        if ((door !=null)&&(key == 1))
        {
            key--;
            getWorld().removeObject(door);
        }
        else if ((door !=null)&&(key == 0))
        {
        setLocation(currentX, currentY+5);
        }
               
    }
    
    public void passSideDoor()
    {
        Actor sdoor;
        
        sdoor = getOneIntersectingObject(SideDoor.class);
           
        if ((sdoor !=null)&&(key == 1))
        {
            key--;
            getWorld().removeObject(sdoor);
        }
        else if ((sdoor !=null)&&(key == 0))
        {
        setLocation(currentX-5, currentY);
        }
               
    }
    
    public void passSideDoor2()
    {
        Actor sdoor2;
        
        sdoor2 = getOneIntersectingObject(SideDoor2.class);
           
        if ((sdoor2 !=null)&&(key2 == 1))
        {
            key--;
            getWorld().removeObject(sdoor2);
        }
        else if ((sdoor2 !=null)&&(key2 == 0))
        {
        setLocation(currentX-5, currentY);
        }
               
    }
    
    public void passGrandDoor()
    {
        Actor gdoor;
        
        gdoor = getOneIntersectingObject(GrandDoor.class);
           
        if ((gdoor !=null)&&(gkey == 1))
        {
            gkey--;
            getWorld().removeObject(gdoor);
        }
        else if ((gdoor !=null)&&(gkey == 0))
        {
        setLocation(currentX+5, currentY);
        }
               
    }
    
    public void nextLevel()
    {
        Actor next;
        
        next = getOneIntersectingObject(NextStage.class);
        
        if (next!=null)
        {
            Greenfoot.setWorld(new MyWorld2());
        }
    
}
}
Here's my hero actor. I need those bullets for the next level.
You need to login to post a reply.