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

2019/7/19

My images are larger than they are supposed to be. Also, using multidimensional arrays and for-loops to put actors into the world.

1
2
3
444Jam444 444Jam444

2019/7/28

#
Sorry for late reply. I've been busy.
danpost wrote...
You create objects in each part of the if-else-else... in your spawnPowerup method of the Powerups class; but, nothing is done with them.
I see... But problem is, addObject does not work in static methods. Any solutions? (Other than making the method non-static) I'm beginning to think that I should just make a simple randomiser... one that does not change the odds when something doesn't go the player's way... (In other words, I think I should give up on this complex randomiser. It's not a requirement and I'm making things more complicated than they have to be. Seems to be a habit of mine) Powerups
    public void spawnPowerup(int X, int Y){
         
        randChance = Greenfoot.getRandomNumber(100);
        if (randChance >= 0 && randChance < bombUpChance){
            getWorld().addObject(new BombUp(X, Y));
            
        }
        else if (randChance >= bombUpChance && randChance < explodeRadiusChance){
            getWorld().addObject(new ExplodeRadius(X, Y));
        }
        else if (randChance >= explodeRadiusChance && randChance < oneUpChance){
            getWorld().addObject(new OneUp(X, Y));
        }
        else if (randChance >= oneUpChance && randChance < skateChance){
            getWorld().addObject(new Skate(X, Y));
        }
    }
BreakBlock
        powerupChance = 6;
        BombExplode explosion = (BombExplode) getOneIntersectingObject(BombExplode.class);
        if (explosion != null){
            randChance = Greenfoot.getRandomNumber(powerupChance);
            if (randChance >= (powerupChance-1)){
                Powerups pUp = new Powerups();
                pUp.spawnPowerup(getX(), getY());
                
            }
            
             
            getWorld().removeObject(this);
        }
Super_Hippo Super_Hippo

2019/7/29

#
444Jam444 wrote...
I see... But problem is, addObject does not work in static methods. Any solutions? (Other than making the method non-static)
Easy, not really nice solution:
if (randChance >= (powerupChance-1))
{
    Powerups pUp = new Powerups();
    getWorld().addObject(pUp, getX(), getY());
    pUp.spawnPowerup(getX(), getY());
    getWorld().removeObject(pUp);
}
Better solution:
if (Greenfoot.getRandomNumber(6) == 0)
{
    randChance = Greenfoot.getRandomNumber(100);
    if (randChance < 30) getWorld().addObject(new BombUp(), getX(), getY());
    else if (randChance < 55) getWorld().addObject(new ExplodeRadius(), getX(), getY());
    else if (randChance < 65) getWorld().addObject(new OneUp(), getX(), getY());
    else getWorld().addObject(new Skate(), getX(), getY());
}
Even better solution
if (Greenfoot.getRandomNumber(6) == 0)
{
    randChance = Greenfoot.getRandomNumber(100);
    if (randChance < 30) getWorld().addObject(new Powerup(0), getX(), getY());
    else if (randChance < 55) getWorld().addObject(new Powerup(1), getX(), getY());
    else if (randChance < 65) getWorld().addObject(new Powerup(2), getX(), getY());
    else getWorld().addObject(new Powerup(3), getX(), getY());
}
(Which is the same as:
if (Greenfoot.getRandomNumber(6) == 0)
{
    randChance = Greenfoot.getRandomNumber(100);
    getWorld().addObject(new Powerup(randChance<30 ? 0 : randChance<55 ? 1 : randChance<65 ? 2 : 3), getX(), getY());
}
)
//Powerup class
private int type; public int getType() {return type}

public Powerup(int type)
{
    this.type = type;
}
//player checks collision with powerup
Powerup powerup = (Powerup) getOneIntersectingObject(Powerup.class);
if (powerup != null)
{
    switch (powerup.getType())
    {
        case 0: maxBomb++; break;
        case 1: explodeRadius++; break;
        case 2: lives++; break;
        case 3: moveSpeed -= 5; break; //bit weird that the variable is called “speed” but you decrease it to move faster
    }
    getWorld().removeObject(powerup);
}
444Jam444 444Jam444

2019/7/29

#
Thanks Super Hippo, but unfortunately I have simplified it and made it less complex than my previous versions (and it works now). Sorry to make you go through that effort. Hopefully I (or someone looking at this page) will use your code as reference in future. Thanks anyway. Appreciate the effort. My apologies.
444Jam444 444Jam444

2019/7/29

#
Super_Hippo wrote...
case 3: moveSpeed -= 5; break; //bit weird that the variable is called “speed” but you decrease it to move faster
Haha yeah, it's just because the player's movement is "delayCount += moveSpeed", so the lower the moveSpeed is, the less delay between movements there is, so the faster the player goes. It's just so that the player doesn't move out of sync with being centred in the cells. It's also because I used code from my previous project (frogger) as inspiration.
444Jam444 444Jam444

2019/7/29

#
public class BreakBlock extends Block
{
    public int powerupChance;
    
    
    
    private int randChance;
    
    /**
     * Act - do whatever the BreakBlock wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        powerupChance = 6;
        BombExplode explosion = (BombExplode) getOneIntersectingObject(BombExplode.class);
        if (explosion != null){
            randChance = Greenfoot.getRandomNumber(powerupChance);
            if (randChance >= (powerupChance-1)){
                getWorld().addObject(new Powerups(), getX(), getY());
         
            }
     
      
            getWorld().removeObject(this);
        }
        
    }    
}
public class Powerups extends Actor
{
    public int bombUpChance = 30;
    public int explodeRadiusChance = 55;
    public int oneUpChance = 65;
    public int skateChance = 100;
    public int randChance;
    //boolean activateOnce = false;
    
    
    /**
     * Act - do whatever the Powerups wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        spawnPowerup();
        //if (activateOnce == false){
        //    spawnPowerup();
        //    activateOnce = true;
        //}
    }    
    public void spawnPowerup(){
        
        randChance = Greenfoot.getRandomNumber(100);
        if (randChance >= 0 && randChance < bombUpChance){
            getWorld().addObject(new BombUp(), getX(), getY());
            getWorld().removeObject(this);
        }
        else if (randChance >= bombUpChance && randChance < explodeRadiusChance){
            getWorld().addObject(new ExplodeRadius(), getX(), getY());
            getWorld().removeObject(this);
        }
        else if (randChance >= explodeRadiusChance && randChance < oneUpChance){
            getWorld().addObject(new OneUp(), getX(), getY());
            getWorld().removeObject(this);
        }
        else if (randChance >= oneUpChance && randChance < skateChance){
            getWorld().addObject(new Skate(), getX(), getY());
            getWorld().removeObject(this);
        }
    }
}
444Jam444 444Jam444

2019/7/31

#
All my problems (that I can think of) have been fixed, apart from two one: - Creating a 2D array and spawning in actors into the world (randomly) using the array (danpost made a suggestion on this that I am yet to try) - Problems with a switch statement that refuses to change an actor’s image (could be a problem with the variable not changing, I am unsure) Edit: this 2nd problem has been fixed.
444Jam444 444Jam444

2019/8/4

#
I'm going to be honest here, I am getting quite annoyed at how Greenfoot can't seem to cope very well with loops. I created a for-loop (i=0, i < 35) and greenfoot crashed because of it. Seriously, something so simple should not be so much of a problem. Is anyone else having this problem? I keep noticing others using a for-loop inside a for-loop, but if I do that, Greenfoot crashes 101% of the time.
private void prepare()
    fillGrid(myGrid, Y);
//selector is equal to 20
public void fillGrid(String[][] grid, int ycoord){
        for (int i = 0; i < (grid[ycoord]).length;){
            if (grid[ycoord][i] == ""){
                int randInt = Greenfoot.getRandomNumber(selector);
                if (ycoord > 15 && selector > 17){
                    randInt = Greenfoot.getRandomNumber(selector)+20;
                    //increases the likelihood of key/door spawn.
                    //Otherwise, the likelihood of no endgoal spawn would be high.
                }
                
                
                if (randInt >= 18){
                    if (getObjects(Door.class).size() < 1){
                        grid[ycoord][i] = "DoorBlock";
                        addObject(new DoorBreakBlock(), (i*25+25/2), (ycoord*25+25/2));
                        selector--; //ensuring only 1 spawn
                    }
                    else{
                        grid[ycoord][i] = "KeyBlock";
                        addObject(new KeyBreakBlock(), (i*25+25/2), (ycoord*25+25/2));
                        selector--; //ensuring only 1 spawn
                    }
                }
                else if (randInt < 17 && randInt > 9){
                    grid[ycoord][i] = "Enemy";
                    addObject(new Enemy(), (i*25+25/2), (ycoord*25+25/2));
                }
                else if (randInt >= 0 && randInt < 10){
                    grid[ycoord][i] = "BreakBlock";
                    addObject(new BreakBlock(), (i*25+25/2), (ycoord*25+25/2));
                }
            }
            
        }
    }
danpost danpost

2019/8/4

#
Apparently, you do not know how to work with loops, yet (it is not Greenfoot that is at fault). Normally, you will have 3 parts to a standard for loop -- (1) the iterating variable with its initial value; (2) the condition for breaking out of the loop; and (3) what changes between each iteration of the loop (which is normally the change in value of the iterating variable; e.g. "i++"). You appear to be missing this last part, so your i value never increments in line 3 (it is forever 0, so you get stuck in your loop).
444Jam444 444Jam444

2019/8/5

#
danpost wrote...
your i value never increments in line 3 (it is forever 0, so you get stuck in your loop).
I remember hearing somewhere that the i++; was optional, and that, by default, if it was left blank then it would register it as i++ anyway. In some of my loops, there was no i++ included, and they still functioned as if i was increasing (they stopped at the correct amount). I'll have to mess around with this.
444Jam444 444Jam444

2019/8/5

#
So... both for (int i = 0; i < num;){} and for (int i = 0; i < num; i++){} are valid and working statements that do the same things, but if you would rather not have a forever-crashing greenfoot, use for (int i = 0; i < num; i++){}. Thanks danpost. Without you, I would have had a very frustrating time trying to figure out why greenfoot continuously crashed. And to be fair, I was not wrong, but my way was not optimal (whatsoever).
danpost danpost

2019/8/5

#
444Jam444 wrote...
I remember hearing somewhere that the i++; was optional, and that, by default, if it was left blank then it would register it as i++ anyway.
Yes -- it is optional; however, it will not still register as i++ (your source was mistaken -- nowhere is that mentioned in the documentation).
In some of my loops, there was no i++ included, and they still functioned as if i was increasing (they stopped at the correct amount). I'll have to mess around with this.
You may have had an:
i++;
within the code block itself (or something comparable).
444Jam444 444Jam444

2019/8/7

#
I see. Well, thanks for your help. My code is now complete, and fully functional. Couldn't have done it without your help, danpost. Super_Hippo, thanks for trying to help. I appreciate that.
444Jam444 444Jam444

2019/8/7

#
I wouldn't mind sharing all my code - but only after a couple more days, after this is due for a school assignment.
444Jam444 444Jam444

2019/8/8

#
Here is all my code. Thank you for your help.
444Jam444 444Jam444

2019/8/8

#
//World
import greenfoot.*;
public class MyWorld extends World
{
    Player player = new Player();
    SolidBlock sblock = new SolidBlock();
    
    public int powerupChance = 26;
    
    static int explodeRadius = 1;
    
    //score = ???
    //public void updateScore(newScore){
    //score = newScore
    //update score on screen or something idk, I will look up how to do this
    //}
    
    public int x = 1;
    public int y = 1;
    
    
    
    /**
     * Constructor for objects of class MyWorld.
     * 
     */
    public class MyWorld extends World
{
    Player player = new Player();
    SolidBlock sblock = new SolidBlock();
    
    
    public int score = 500;
    boolean scoreLoss = true;
    public int numOfEnemies;
    boolean powerupInWorld = false;
    public int numOfPowerups = 0;
    public int numOfBlocks;
    private int life = 3;
    //Setting a timer
    long startTime = System.currentTimeMillis();
    private int durationMillis;
    private int durationSecs;
    
    
    
    //World preparation variables
    public int x = 1;
    public int y = 1;
    public int numOfKeyBlock = 0;
    public int numOfDoorBlock = 0;
    public int maxNumOfEnemies = 35;
    
    public String[][] myGrid = new String[23][35];
    
    /**
     * Constructor for objects of class MyWorld.
     * 
     */
    public MyWorld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1000, 575, 1); 
        Player player = new Player();
        SolidBlock sblock = new SolidBlock();

        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()
    {
        addObject(player,(25/2),(25/2));
        addObject(new BreakBlock(), 50+25/2, 25/2);
        addObject(new BreakBlock(), 25/2, 50+25/2);
        initialiseGrid(myGrid);
        for (int i = 0; i < 250; i++){
            if (x > 34){
                y = y + 2;
                x = 1;
            }
            if (y > 22){
                i = 250;                
            }
            else{
                SolidBlock sblock = new SolidBlock();
                addObject(sblock, (x*25+(25/2)), (y*25+(25/2)));
                x = x + 2;
            }
        } 
        for (int i = 0; i < 10; i++){
            x = Greenfoot.getRandomNumber(35);
            y = Greenfoot.getRandomNumber(23);
            if (myGrid[y][x] == ""){
                if (getObjects(DoorBreakBlock.class).size() < 1){
                    myGrid[y][x] = "DoorBlock";
                    addObject(new DoorBreakBlock(), (x*25+25/2), (y*25+25/2));
                            
                }
                else{
                    myGrid[y][x] = "KeyBlock";
                    addObject(new KeyBreakBlock(), (x*25+25/2), (y*25+25/2));
                    i = 10;
                            
                }
            }
            else{
                i--;
            }
        }
        for (int i = 0; i < 35; i++){
            x = Greenfoot.getRandomNumber(35);
            y = Greenfoot.getRandomNumber(23);
            if (myGrid[y][x] == ""){
                if (getObjects(Enemy.class).size() < maxNumOfEnemies){
                    myGrid[y][x] = "Enemy";
                    addObject(new Enemy(), (x*25+25/2), (y*25+25/2));
                }
            }
            else{
                i--;
            }
        }
        for (int i = 0; i < 15; i++){
            x = Greenfoot.getRandomNumber(35);
            y = Greenfoot.getRandomNumber(23);
            if (myGrid[y][x] == ""){
                myGrid[y][x] = "space";
            }
            else{
                i--;
            }
        }
        for (int i = 0; i < 806; i++){
            x = i%35;
            y = i%23;
            if (myGrid[y][x] == ""){
                myGrid[y][x] = "BreakBlock";
                addObject(new BreakBlock(), (x*25+25/2), (y*25+25/2));
            }
        }

        
        setPaintOrder(BombExplodeG1.class, BombExplodeG2.class, Enemy.class, Player.class, Bomb.class, Key.class, Door.class);
        
        numOfEnemies = (getObjects(Enemy.class)).size();
        numOfBlocks = (getObjects(Block.class)).size();
        if (getObjects(DoorBreakBlock.class).size() < 1 || getObjects(KeyBreakBlock.class).size() < 1){
            System.out.println("ERROR: Game cannot be finished; Key/Door was unable to spawn. Please reset.");
        }
        if (getObjects(DoorBreakBlock.class).size() < 1 && getObjects(KeyBreakBlock.class).size() < 1){
            System.out.println("ERROR: Game cannot be finished; Key/Door was unable to spawn. Please reset.");
        }
    }
    
    public void act(){
        
        //Timer
        long currentTime = System.currentTimeMillis();
        durationMillis = (int)(currentTime - startTime);
        durationSecs = durationMillis / 1000;
        
        if ((getObjects(Player.class).size()) < 1 && durationSecs > 4){
            score -= 100;
            Greenfoot.stop();
            
        }
        else if (durationSecs < 10){
            showScore();
            
        }
        
        getScore();
        if (score <= 0){
            System.out.println("Out of score!");
            Greenfoot.stop();
        }
    }
    
    public static void main(String[][] args){
        
    }
    
    
    
    public void initialiseGrid(String[][] grid){
        //initialise basic layout of grid
        
        //please ignore the fact that I bruteforced this. Greenfoot was constantly crashing with loops (this was before danpost solved my looping problem)
        grid[0][0] = "Player";
        grid[0][1] = "space";
        grid[0][2] = "BreakBlock";
        grid[0][3] = "";
        grid[0][4] = "";
        grid[0][5] = "";
        grid[0][6] = "";
        grid[0][7] = "";
        grid[0][8] = "";
        grid[0][9] = "";
        grid[0][10] = "";
        grid[0][11] = "";
        grid[0][12] = "";
        grid[0][13] = "";
        grid[0][14] = "";
        grid[0][15] = "";
        grid[0][16] = "";
        grid[0][17] = "";
        grid[0][18] = "";
        grid[0][19] = "";
        grid[0][20] = "";
        grid[0][21] = "";
        grid[0][22] = "";
        grid[0][23] = "";
        grid[0][24] = "";
        grid[0][25] = "";
        grid[0][26] = "";
        grid[0][27] = "";
        grid[0][28] = "";
        grid[0][29] = "";
        grid[0][30] = "";
        grid[0][31] = "";
        grid[0][32] = "";
        grid[0][33] = "";
        grid[0][34] = "";
        
        grid[1][0] = "space";
        grid[1][1] = "SolidBlock";
        grid[1][2] = "";
        grid[1][3] = "SolidBlock";
        grid[1][4] = "";
        grid[1][5] = "SolidBlock";
        grid[1][6] = "";
        grid[1][7] = "SolidBlock";
        grid[1][8] = "";
        grid[1][9] = "SolidBlock";
        grid[1][10] = "";
        grid[1][11] = "SolidBlock";
        grid[1][12] = "";
        grid[1][13] = "SolidBlock";
        grid[1][14] = "";
        grid[1][15] = "SolidBlock";
        grid[1][16] = "";
        grid[1][17] = "SolidBlock";
        grid[1][18] = "";
        grid[1][19] = "SolidBlock";
        grid[1][20] = "";
        grid[1][21] = "SolidBlock";
        grid[1][22] = "";
        grid[1][23] = "SolidBlock";
        grid[1][24] = "";
        grid[1][25] = "SolidBlock";
        grid[1][26] = "";
        grid[1][27] = "SolidBlock";
        grid[1][28] = "";
        grid[1][29] = "SolidBlock";
        grid[1][30] = "";
        grid[1][31] = "SolidBlock";
        grid[1][32] = "";
        grid[1][33] = "SolidBlock";
        grid[1][34] = "";
        
        grid[2][0] = "BreakBlock";
        grid[2][1] = "";
        grid[2][2] = "";
        grid[2][3] = "";
        grid[2][4] = "";
        grid[2][5] = "";
        grid[2][6] = "";
        grid[2][7] = "";
        grid[2][8] = "";
        grid[2][9] = "";
        grid[2][10] = "";
        grid[2][11] = "";
        grid[2][12] = "";
        grid[2][13] = "";
        grid[2][14] = "";
        grid[2][15] = "";
        grid[2][16] = "";
        grid[2][17] = "";
        grid[2][18] = "";
        grid[2][19] = "";
        grid[2][20] = "";
        grid[2][21] = "";
        grid[2][22] = "";
        grid[2][23] = "";
        grid[2][24] = "";
        grid[2][25] = "";
        grid[2][26] = "";
        grid[2][27] = "";
        grid[2][28] = "";
        grid[2][29] = "";
        grid[2][30] = "";
        grid[2][31] = "";
        grid[2][32] = "";
        grid[2][33] = "";
        grid[2][34] = "";
        
        grid[3][0] = "";
        grid[3][1] = "SolidBlock";
        grid[3][2] = "";
        grid[3][3] = "SolidBlock";
        grid[3][4] = "";
        grid[3][5] = "SolidBlock";
        grid[3][6] = "";
        grid[3][7] = "SolidBlock";
        grid[3][8] = "";
        grid[3][9] = "SolidBlock";
        grid[3][10] = "";
        grid[3][11] = "SolidBlock";
        grid[3][12] = "";
        grid[3][13] = "SolidBlock";
        grid[3][14] = "";
        grid[3][15] = "SolidBlock";
        grid[3][16] = "";
        grid[3][17] = "SolidBlock";
        grid[3][18] = "";
        grid[3][19] = "SolidBlock";
        grid[3][20] = "";
        grid[3][21] = "SolidBlock";
        grid[3][22] = "";
        grid[3][23] = "SolidBlock";
        grid[3][24] = "";
        grid[3][25] = "SolidBlock";
        grid[3][26] = "";
        grid[3][27] = "SolidBlock";
        grid[3][28] = "";
        grid[3][29] = "SolidBlock";
        grid[3][30] = "";
        grid[3][31] = "SolidBlock";
        grid[3][32] = "";
        grid[3][33] = "SolidBlock";
        grid[3][34] = "";
        
        grid[4][0] = "";
        grid[4][1] = "";
        grid[4][2] = "";
        grid[4][3] = "";
        grid[4][4] = "";
        grid[4][5] = "";
        grid[4][6] = "";
        grid[4][7] = "";
        grid[4][8] = "";
        grid[4][9] = "";
        grid[4][10] = "";
        grid[4][11] = "";
        grid[4][12] = "";
        grid[4][13] = "";
        grid[4][14] = "";
        grid[4][15] = "";
        grid[4][16] = "";
        grid[4][17] = "";
        grid[4][18] = "";
        grid[4][19] = "";
        grid[4][20] = "";
        grid[4][21] = "";
        grid[4][22] = "";
        grid[4][23] = "";
        grid[4][24] = "";
        grid[4][25] = "";
        grid[4][26] = "";
        grid[4][27] = "";
        grid[4][28] = "";
        grid[4][29] = "";
        grid[4][30] = "";
        grid[4][31] = "";
        grid[4][32] = "";
        grid[4][33] = "";
        grid[4][34] = "";
        
        grid[5][0] = "";
        grid[5][1] = "SolidBlock";
        grid[5][2] = "";
        grid[5][3] = "SolidBlock";
        grid[5][4] = "";
        grid[5][5] = "SolidBlock";
        grid[5][6] = "";
        grid[5][7] = "SolidBlock";
        grid[5][8] = "";
        grid[5][9] = "SolidBlock";
        grid[5][10] = "";
        grid[5][11] = "SolidBlock";
        grid[5][12] = "";
        grid[5][13] = "SolidBlock";
        grid[5][14] = "";
        grid[5][15] = "SolidBlock";
        grid[5][16] = "";
        grid[5][17] = "SolidBlock";
        grid[5][18] = "";
        grid[5][19] = "SolidBlock";
        grid[5][20] = "";
        grid[5][21] = "SolidBlock";
        grid[5][22] = "";
        grid[5][23] = "SolidBlock";
        grid[5][24] = "";
        grid[5][25] = "SolidBlock";
        grid[5][26] = "";
        grid[5][27] = "SolidBlock";
        grid[5][28] = "";
        grid[5][29] = "SolidBlock";
        grid[5][30] = "";
        grid[5][31] = "SolidBlock";
        grid[5][32] = "";
        grid[5][33] = "SolidBlock";
        grid[5][34] = "";
        
        grid[6][0] = "";
        grid[6][1] = "";
        grid[6][2] = "";
        grid[6][3] = "";
        grid[6][4] = "";
        grid[6][5] = "";
        grid[6][6] = "";
        grid[6][7] = "";
        grid[6][8] = "";
        grid[6][9] = "";
        grid[6][10] = "";
        grid[6][11] = "";
        grid[6][12] = "";
        grid[6][13] = "";
        grid[6][14] = "";
        grid[6][15] = "";
        grid[6][16] = "";
        grid[6][17] = "";
        grid[6][18] = "";
        grid[6][19] = "";
        grid[6][20] = "";
        grid[6][21] = "";
        grid[6][22] = "";
        grid[6][23] = "";
        grid[6][24] = "";
        grid[6][25] = "";
        grid[6][26] = "";
        grid[6][27] = "";
        grid[6][28] = "";
        grid[6][29] = "";
        grid[6][30] = "";
        grid[6][31] = "";
        grid[6][32] = "";
        grid[6][33] = "";
        grid[6][34] = "";
        
        grid[7][0] = "";
        grid[7][1] = "SolidBlock";
        grid[7][2] = "";
        grid[7][3] = "SolidBlock";
        grid[7][4] = "";
        grid[7][5] = "SolidBlock";
        grid[7][6] = "";
        grid[7][7] = "SolidBlock";
        grid[7][8] = "";
        grid[7][9] = "SolidBlock";
        grid[7][10] = "";
        grid[7][11] = "SolidBlock";
        grid[7][12] = "";
        grid[7][13] = "SolidBlock";
        grid[7][14] = "";
        grid[7][15] = "SolidBlock";
        grid[7][16] = "";
        grid[7][17] = "SolidBlock";
        grid[7][18] = "";
        grid[7][19] = "SolidBlock";
        grid[7][20] = "";
        grid[7][21] = "SolidBlock";
        grid[7][22] = "";
        grid[7][23] = "SolidBlock";
        grid[7][24] = "";
        grid[7][25] = "SolidBlock";
        grid[7][26] = "";
        grid[7][27] = "SolidBlock";
        grid[7][28] = "";
        grid[7][29] = "SolidBlock";
        grid[7][30] = "";
        grid[7][31] = "SolidBlock";
        grid[7][32] = "";
        grid[7][33] = "SolidBlock";
        grid[7][34] = "";
        
        grid[8][0] = "";
        grid[8][1] = "";
        grid[8][2] = "";
        grid[8][3] = "";
        grid[8][4] = "";
        grid[8][5] = "";
        grid[8][6] = "";
        grid[8][7] = "";
        grid[8][8] = "";
        grid[8][9] = "";
        grid[8][10] = "";
        grid[8][11] = "";
        grid[8][12] = "";
        grid[8][13] = "";
        grid[8][14] = "";
        grid[8][15] = "";
        grid[8][16] = "";
        grid[8][17] = "";
        grid[8][18] = "";
        grid[8][19] = "";
        grid[8][20] = "";
        grid[8][21] = "";
        grid[8][22] = "";
        grid[8][23] = "";
        grid[8][24] = "";
        grid[8][25] = "";
        grid[8][26] = "";
        grid[8][27] = "";
        grid[8][28] = "";
        grid[8][29] = "";
        grid[8][30] = "";
        grid[8][31] = "";
        grid[8][32] = "";
        grid[8][33] = "";
        grid[8][34] = "";
        
        grid[9][0] = "";
        grid[9][1] = "SolidBlock";
        grid[9][2] = "";
        grid[9][3] = "SolidBlock";
        grid[9][4] = "";
        grid[9][5] = "SolidBlock";
        grid[9][6] = "";
        grid[9][7] = "SolidBlock";
        grid[9][8] = "";
        grid[9][9] = "SolidBlock";
        grid[9][10] = "";
        grid[9][11] = "SolidBlock";
        grid[9][12] = "";
        grid[9][13] = "SolidBlock";
        grid[9][14] = "";
        grid[9][15] = "SolidBlock";
        grid[9][16] = "";
        grid[9][17] = "SolidBlock";
        grid[9][18] = "";
        grid[9][19] = "SolidBlock";
        grid[9][20] = "";
        grid[9][21] = "SolidBlock";
        grid[9][22] = "";
        grid[9][23] = "SolidBlock";
        grid[9][24] = "";
        grid[9][25] = "SolidBlock";
        grid[9][26] = "";
        grid[9][27] = "SolidBlock";
        grid[9][28] = "";
        grid[9][29] = "SolidBlock";
        grid[9][30] = "";
        grid[9][31] = "SolidBlock";
        grid[9][32] = "";
        grid[9][33] = "SolidBlock";
        grid[9][34] = "";
        
        grid[10][0] = "";
        grid[10][1] = "";
        grid[10][2] = "";
        grid[10][3] = "";
        grid[10][4] = "";
        grid[10][5] = "";
        grid[10][6] = "";
        grid[10][7] = "";
        grid[10][8] = "";
        grid[10][9] = "";
        grid[10][10] = "";
        grid[10][11] = "";
        grid[10][12] = "";
        grid[10][13] = "";
        grid[10][14] = "";
        grid[10][15] = "";
        grid[10][16] = "";
        grid[10][17] = "";
        grid[10][18] = "";
        grid[10][19] = "";
        grid[10][20] = "";
        grid[10][21] = "";
        grid[10][22] = "";
        grid[10][23] = "";
        grid[10][24] = "";
        grid[10][25] = "";
        grid[10][26] = "";
        grid[10][27] = "";
        grid[10][28] = "";
        grid[10][29] = "";
        grid[10][30] = "";
        grid[10][31] = "";
        grid[10][32] = "";
        grid[10][33] = "";
        grid[10][34] = "";
        
        grid[11][0] = "";
        grid[11][1] = "SolidBlock";
        grid[11][2] = "";
        grid[11][3] = "SolidBlock";
        grid[11][4] = "";
        grid[11][5] = "SolidBlock";
        grid[11][6] = "";
        grid[11][7] = "SolidBlock";
        grid[11][8] = "";
        grid[11][9] = "SolidBlock";
        grid[11][10] = "";
        grid[11][11] = "SolidBlock";
        grid[11][12] = "";
        grid[11][13] = "SolidBlock";
        grid[11][14] = "";
        grid[11][15] = "SolidBlock";
        grid[11][16] = "";
        grid[11][17] = "SolidBlock";
        grid[11][18] = "";
        grid[11][19] = "SolidBlock";
        grid[11][20] = "";
        grid[11][21] = "SolidBlock";
        grid[11][22] = "";
        grid[11][23] = "SolidBlock";
        grid[11][24] = "";
        grid[11][25] = "SolidBlock";
        grid[11][26] = "";
        grid[11][27] = "SolidBlock";
        grid[11][28] = "";
        grid[11][29] = "SolidBlock";
        grid[11][30] = "";
        grid[11][31] = "SolidBlock";
        grid[11][32] = "";
        grid[11][33] = "SolidBlock";
        grid[11][34] = "";
        
        grid[12][0] = "";
        grid[12][1] = "";
        grid[12][2] = "";
        grid[12][3] = "";
        grid[12][4] = "";
        grid[12][5] = "";
        grid[12][6] = "";
        grid[12][7] = "";
        grid[12][8] = "";
        grid[12][9] = "";
        grid[12][10] = "";
        grid[12][11] = "";
        grid[12][12] = "";
        grid[12][13] = "";
        grid[12][14] = "";
        grid[12][15] = "";
        grid[12][16] = "";
        grid[12][17] = "";
        grid[12][18] = "";
        grid[12][19] = "";
        grid[12][20] = "";
        grid[12][21] = "";
        grid[12][22] = "";
        grid[12][23] = "";
        grid[12][24] = "";
        grid[12][25] = "";
        grid[12][26] = "";
        grid[12][27] = "";
        grid[12][28] = "";
        grid[12][29] = "";
        grid[12][30] = "";
        grid[12][31] = "";
        grid[12][32] = "";
        grid[12][33] = "";
        grid[12][34] = "";
        
        grid[13][0] = "";
        grid[13][1] = "SolidBlock";
        grid[13][2] = "";
        grid[13][3] = "SolidBlock";
        grid[13][4] = "";
        grid[13][5] = "SolidBlock";
        grid[13][6] = "";
        grid[13][7] = "SolidBlock";
        grid[13][8] = "";
        grid[13][9] = "SolidBlock";
        grid[13][10] = "";
        grid[13][11] = "SolidBlock";
        grid[13][12] = "";
        grid[13][13] = "SolidBlock";
        grid[13][14] = "";
        grid[13][15] = "SolidBlock";
        grid[13][16] = "";
        grid[13][17] = "SolidBlock";
        grid[13][18] = "";
        grid[13][19] = "SolidBlock";
        grid[13][20] = "";
        grid[13][21] = "SolidBlock";
        grid[13][22] = "";
        grid[13][23] = "SolidBlock";
        grid[13][24] = "";
        grid[13][25] = "SolidBlock";
        grid[13][26] = "";
        grid[13][27] = "SolidBlock";
        grid[13][28] = "";
        grid[13][29] = "SolidBlock";
        grid[13][30] = "";
        grid[13][31] = "SolidBlock";
        grid[13][32] = "";
        grid[13][33] = "SolidBlock";
        grid[13][34] = "";
        
        grid[14][0] = "";
        grid[14][1] = "";
        grid[14][2] = "";
        grid[14][3] = "";
        grid[14][4] = "";
        grid[14][5] = "";
        grid[14][6] = "";
        grid[14][7] = "";
        grid[14][8] = "";
        grid[14][9] = "";
        grid[14][10] = "";
        grid[14][11] = "";
        grid[14][12] = "";
        grid[14][13] = "";
        grid[14][14] = "";
        grid[14][15] = "";
        grid[14][16] = "";
        grid[14][17] = "";
        grid[14][18] = "";
        grid[14][19] = "";
        grid[14][20] = "";
        grid[14][21] = "";
        grid[14][22] = "";
        grid[14][23] = "";
        grid[14][24] = "";
        grid[14][25] = "";
        grid[14][26] = "";
        grid[14][27] = "";
        grid[14][28] = "";
        grid[14][29] = "";
        grid[14][30] = "";
        grid[14][31] = "";
        grid[14][32] = "";
        grid[14][33] = "";
        grid[14][34] = "";
        
        grid[15][0] = "";
        grid[15][1] = "SolidBlock";
        grid[15][2] = "";
        grid[15][3] = "SolidBlock";
        grid[15][4] = "";
        grid[15][5] = "SolidBlock";
        grid[15][6] = "";
        grid[15][7] = "SolidBlock";
        grid[15][8] = "";
        grid[15][9] = "SolidBlock";
        grid[15][10] = "";
        grid[15][11] = "SolidBlock";
        grid[15][12] = "";
        grid[15][13] = "SolidBlock";
        grid[15][14] = "";
        grid[15][15] = "SolidBlock";
        grid[15][16] = "";
        grid[15][17] = "SolidBlock";
        grid[15][18] = "";
        grid[15][19] = "SolidBlock";
        grid[15][20] = "";
        grid[15][21] = "SolidBlock";
        grid[15][22] = "";
        grid[15][23] = "SolidBlock";
        grid[15][24] = "";
        grid[15][25] = "SolidBlock";
        grid[15][26] = "";
        grid[15][27] = "SolidBlock";
        grid[15][28] = "";
        grid[15][29] = "SolidBlock";
        grid[15][30] = "";
        grid[15][31] = "SolidBlock";
        grid[15][32] = "";
        grid[15][33] = "SolidBlock";
        grid[15][34] = "";
        
        grid[16][0] = "";
        grid[16][1] = "";
        grid[16][2] = "";
        grid[16][3] = "";
        grid[16][4] = "";
        grid[16][5] = "";
        grid[16][6] = "";
        grid[16][7] = "";
        grid[16][8] = "";
        grid[16][9] = "";
        grid[16][10] = "";
        grid[16][11] = "";
        grid[16][12] = "";
        grid[16][13] = "";
        grid[16][14] = "";
        grid[16][15] = "";
        grid[16][16] = "";
        grid[16][17] = "";
        grid[16][18] = "";
        grid[16][19] = "";
        grid[16][20] = "";
        grid[16][21] = "";
        grid[16][22] = "";
        grid[16][23] = "";
        grid[16][24] = "";
        grid[16][25] = "";
        grid[16][26] = "";
        grid[16][27] = "";
        grid[16][28] = "";
        grid[16][29] = "";
        grid[16][30] = "";
        grid[16][31] = "";
        grid[16][32] = "";
        grid[16][33] = "";
        grid[16][34] = "";
        
        grid[17][0] = "";
        grid[17][1] = "SolidBlock";
        grid[17][2] = "";
        grid[17][3] = "SolidBlock";
        grid[17][4] = "";
        grid[17][5] = "SolidBlock";
        grid[17][6] = "";
        grid[17][7] = "SolidBlock";
        grid[17][8] = "";
        grid[17][9] = "SolidBlock";
        grid[17][10] = "";
        grid[17][11] = "SolidBlock";
        grid[17][12] = "";
        grid[17][13] = "SolidBlock";
        grid[17][14] = "";
        grid[17][15] = "SolidBlock";
        grid[17][16] = "";
        grid[17][17] = "SolidBlock";
        grid[17][18] = "";
        grid[17][19] = "SolidBlock";
        grid[17][20] = "";
        grid[17][21] = "SolidBlock";
        grid[17][22] = "";
        grid[17][23] = "SolidBlock";
        grid[17][24] = "";
        grid[17][25] = "SolidBlock";
        grid[17][26] = "";
        grid[17][27] = "SolidBlock";
        grid[17][28] = "";
        grid[17][29] = "SolidBlock";
        grid[17][30] = "";
        grid[17][31] = "SolidBlock";
        grid[17][32] = "";
        grid[17][33] = "SolidBlock";
        grid[17][34] = "";
        
        grid[18][0] = "";
        grid[18][1] = "";
        grid[18][2] = "";
        grid[18][3] = "";
        grid[18][4] = "";
        grid[18][5] = "";
        grid[18][6] = "";
        grid[18][7] = "";
        grid[18][8] = "";
        grid[18][9] = "";
        grid[18][10] = "";
        grid[18][11] = "";
        grid[18][12] = "";
        grid[18][13] = "";
        grid[18][14] = "";
        grid[18][15] = "";
        grid[18][16] = "";
        grid[18][17] = "";
        grid[18][18] = "";
        grid[18][19] = "";
        grid[18][20] = "";
        grid[18][21] = "";
        grid[18][22] = "";
        grid[18][23] = "";
        grid[18][24] = "";
        grid[18][25] = "";
        grid[18][26] = "";
        grid[18][27] = "";
        grid[18][28] = "";
        grid[18][29] = "";
        grid[18][30] = "";
        grid[18][31] = "";
        grid[18][32] = "";
        grid[18][33] = "";
        grid[18][34] = "";
        
        grid[19][0] = "";
        grid[19][1] = "SolidBlock";
        grid[19][2] = "";
        grid[19][3] = "SolidBlock";
        grid[19][4] = "";
        grid[19][5] = "SolidBlock";
        grid[19][6] = "";
        grid[19][7] = "SolidBlock";
        grid[19][8] = "";
        grid[19][9] = "SolidBlock";
        grid[19][10] = "";
        grid[19][11] = "SolidBlock";
        grid[19][12] = "";
        grid[19][13] = "SolidBlock";
        grid[19][14] = "";
        grid[19][15] = "SolidBlock";
        grid[19][16] = "";
        grid[19][17] = "SolidBlock";
        grid[19][18] = "";
        grid[19][19] = "SolidBlock";
        grid[19][20] = "";
        grid[19][21] = "SolidBlock";
        grid[19][22] = "";
        grid[19][23] = "SolidBlock";
        grid[19][24] = "";
        grid[19][25] = "SolidBlock";
        grid[19][26] = "";
        grid[19][27] = "SolidBlock";
        grid[19][28] = "";
        grid[19][29] = "SolidBlock";
        grid[19][30] = "";
        grid[19][31] = "SolidBlock";
        grid[19][32] = "";
        grid[19][33] = "SolidBlock";
        grid[19][34] = "";
        
        grid[20][0] = "";
        grid[20][1] = "";
        grid[20][2] = "";
        grid[20][3] = "";
        grid[20][4] = "";
        grid[20][5] = "";
        grid[20][6] = "";
        grid[20][7] = "";
        grid[20][8] = "";
        grid[20][9] = "";
        grid[20][10] = "";
        grid[20][11] = "";
        grid[20][12] = "";
        grid[20][13] = "";
        grid[20][14] = "";
        grid[20][15] = "";
        grid[20][16] = "";
        grid[20][17] = "";
        grid[20][18] = "";
        grid[20][19] = "";
        grid[20][20] = "";
        grid[20][21] = "";
        grid[20][22] = "";
        grid[20][23] = "";
        grid[20][24] = "";
        grid[20][25] = "";
        grid[20][26] = "";
        grid[20][27] = "";
        grid[20][28] = "";
        grid[20][29] = "";
        grid[20][30] = "";
        grid[20][31] = "";
        grid[20][32] = "";
        grid[20][33] = "";
        grid[20][34] = "";
        
        grid[21][0] = "";
        grid[21][1] = "SolidBlock";
        grid[21][2] = "";
        grid[21][3] = "SolidBlock";
        grid[21][4] = "";
        grid[21][5] = "SolidBlock";
        grid[21][6] = "";
        grid[21][7] = "SolidBlock";
        grid[21][8] = "";
        grid[21][9] = "SolidBlock";
        grid[21][10] = "";
        grid[21][11] = "SolidBlock";
        grid[21][12] = "";
        grid[21][13] = "SolidBlock";
        grid[21][14] = "";
        grid[21][15] = "SolidBlock";
        grid[21][16] = "";
        grid[21][17] = "SolidBlock";
        grid[21][18] = "";
        grid[21][19] = "SolidBlock";
        grid[21][20] = "";
        grid[21][21] = "SolidBlock";
        grid[21][22] = "";
        grid[21][23] = "SolidBlock";
        grid[21][24] = "";
        grid[21][25] = "SolidBlock";
        grid[21][26] = "";
        grid[21][27] = "SolidBlock";
        grid[21][28] = "";
        grid[21][29] = "SolidBlock";
        grid[21][30] = "";
        grid[21][31] = "SolidBlock";
        grid[21][32] = "";
        grid[21][33] = "SolidBlock";
        grid[21][34] = "";
        
        grid[22][0] = "";
        grid[22][1] = "";
        grid[22][2] = "";
        grid[22][3] = "";
        grid[22][4] = "";
        grid[22][5] = "";
        grid[22][6] = "";
        grid[22][7] = "";
        grid[22][8] = "";
        grid[22][9] = "";
        grid[22][10] = "";
        grid[22][11] = "";
        grid[22][12] = "";
        grid[22][13] = "";
        grid[22][14] = "";
        grid[22][15] = "";
        grid[22][16] = "";
        grid[22][17] = "";
        grid[22][18] = "";
        grid[22][19] = "";
        grid[22][20] = "";
        grid[22][21] = "";
        grid[22][22] = "";
        grid[22][23] = "";
        grid[22][24] = "";
        grid[22][25] = "";
        grid[22][26] = "";
        grid[22][27] = "";
        grid[22][28] = "";
        grid[22][29] = "";
        grid[22][30] = "";
        grid[22][31] = "";
        grid[22][32] = "";
        grid[22][33] = "";
        grid[22][34] = "";
        
        
        //note: this was the most tedious thing I've done in my entire life.
    }
    

    
    public void getScore(){
        
        if ((getObjects(Powerups.class)).size() > numOfPowerups){
            powerupInWorld = true;
            numOfPowerups = (getObjects(Powerups.class)).size();
        }
        if (powerupInWorld == true && ((getObjects(Powerups.class)).size()) < numOfPowerups){
            score += 50;
            showScore();
            numOfPowerups -= 1;
        }
        if (numOfPowerups == 0){
            powerupInWorld = false;
        }
        if (durationSecs%30 == 0 && durationSecs > 1){
            if (scoreLoss == true){
                score -= 10;
                scoreLoss = false;
            }
            showScore();
        }
        else{
            scoreLoss = true;
        }
        if ((getObjects(Enemy.class)).size() >= numOfEnemies){
            numOfEnemies = (getObjects(Enemy.class)).size();
        }
        if ((getObjects(Enemy.class)).size() < numOfEnemies){
            score += 100;
            showScore();
            numOfEnemies -= 1;
        }
        if ((getObjects(Block.class)).size() >= numOfBlocks){
            numOfBlocks = (getObjects(Block.class)).size();
        }
        if ((getObjects(Block.class)).size() < numOfBlocks){
            score += 10;
            showScore();
            numOfBlocks -= 1;
        }
        
    }
    
    public void showScore(){
        showText(("" + score + ""), (925+25/2), 125);
    }
    
    
    public void stopped(){
        System.out.println("Game Over!");
        System.out.println("Score: " + score);
    }
}


//Enemy
import greenfoot.*;
public class Enemy extends Actor
{
    private int delayCount = 25;
    public int moveSpeed;
    private int randMove;
    private String moveDir;
    
    GifImage myGif = new GifImage("Enemy.gif");
    /**
     * Act - do whatever the Enemy wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        playGif();
        BombExplodeG1 explosion1 = (BombExplodeG1) getOneIntersectingObject(BombExplodeG1.class);
        BombExplodeG2 explosion2 = (BombExplodeG2) getOneIntersectingObject(BombExplodeG2.class);
        if (explosion1 != null || explosion2 != null){
            getWorld().removeObject(this);
        }
        else if (explosion1 != null && explosion2 != null){
            getWorld().removeObject(this);
        }
        else{
            if (delayCount == 0){
                randMove = Greenfoot.getRandomNumber(4);
                moveSpeed = (Greenfoot.getRandomNumber(16) + 25);
                switch (randMove){
                    case 0:
                        moveDir = "up";
                        break;
                    case 1:
                        moveDir = "down";
                        break;
                    case 2:
                        moveDir = "right";
                        break;
                    case 3:
                        moveDir = "left";
                        break;
                    }   
                    if (moveDir == "up")
                    {
                        Block block = (Block) getOneObjectAtOffset(0, -25, Block.class);
                        Enemy enemy = (Enemy) getOneObjectAtOffset(0, -25, Enemy.class);
                 
                        if (block == null || enemy == null)
                        {
                            setLocation((getX()),(getY()-25));
                            
                            
                        }
                        if (isAtEdge()){
                            setLocation((getX()),(25/2));
                        }
                        delayCount = delayCount + moveSpeed;
                    }          
                    if (moveDir == "down")
                    {
                        Block block = (Block) getOneObjectAtOffset(0, 25, Block.class);
                        Enemy enemy = (Enemy) getOneObjectAtOffset(0, 25, Enemy.class);
                    
                        if (block == null || enemy != null)
                        {
                            setLocation((getX()),(getY()+25));
                            
                      
                        }
                        if (isAtEdge()){
                            setLocation((getX()),(575-(25/2)));
                        }
                        delayCount = delayCount + moveSpeed;
                    }
                    if (moveDir == "left")
                    {
                        Block block = (Block) getOneObjectAtOffset(-25, 0, Block.class);
                        Enemy enemy = (Enemy) getOneObjectAtOffset(-25, 0, Enemy.class);
                        if (block == null || enemy != null)
                        {
                            setLocation((getX()-25),(getY()));
                            
                       
                        }
                        if (isAtEdge()){
                            setLocation((getX()+(25/2)),(getY()));
                        }
                        delayCount = delayCount + moveSpeed;
                    }
                    if (moveDir == "right")
                    {   
                        Block block = (Block) getOneObjectAtOffset(25, 0, Block.class);
                        Enemy enemy = (Enemy) getOneObjectAtOffset(25, 0, Enemy.class);
                        if (block == null || enemy != null)
                        {
                            setLocation((getX()+25),(getY()));
                            
                           
                        }
                        
                        if (getX() >= 875){
                            setLocation((875-25/2),(getY()));
                        }
                        delayCount = delayCount + moveSpeed;
                    }
                }
        
            else{
                delayCount = moveDelay(delayCount);
            }
        }
    }
    public static int moveDelay(int delay)
    {
        delay--;
        return delay;
    }
    public void playGif(){
        setImage(myGif.getCurrentImage());
        
    }
}

//Block
import greenfoot.*;
public class Block extends Actor
{
    /**
     * Act - do whatever the Block wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
    }    
}

//BreakBlock
import greenfoot.*;
public class BreakBlock extends Block
{
    public int powerupChance;
    
    
    
    private int randChance;
    
    /**
     * Act - do whatever the BreakBlock wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        powerupChance = 6;
        BombExplode explosion = (BombExplode) getOneIntersectingObject(BombExplode.class);
        if (explosion != null){
            randChance = Greenfoot.getRandomNumber(powerupChance);
            if (randChance >= (powerupChance-1)){
                getWorld().addObject(new Powerups(), getX(), getY());
         
            }
     
      
            getWorld().removeObject(this);
        }
        
    }    
}

//DoorBreakBlock
import greenfoot.*;
public class DoorBreakBlock extends Block
{
    /**
     * Act - do whatever the DoorBreakBlock wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        BombExplode explosion = (BombExplode) getOneIntersectingObject(BombExplode.class);
        if (explosion != null){
            getWorld().addObject(new Door(), getX(), getY());
            getWorld().removeObject(this);
        }
    }    
}

//KeyBreakBlock
import greenfoot.*;
public class KeyBreakBlock extends Block
{
    
    /**
     * Act - do whatever the KeyBreakBlock wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        BombExplode explosion = (BombExplode) getOneIntersectingObject(BombExplode.class);
        if (explosion != null){
            getWorld().addObject(new Key(), getX(), getY());
            getWorld().removeObject(this);
        }
    }    
}

//SolidBlock
import greenfoot.*;
public class SolidBlock extends Block
{
    /**
     * Act - do whatever the DoorBreakBlock wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
    }    
}

//EndGoal
import greenfoot.*;
public class EndGoal extends Actor
{
    /**
     * Act - do whatever the EndGoal wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
    }    
}

//Door
import greenfoot.*;
public class Door extends EndGoal
{
    /**
     * Act - do whatever the Door wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        Player player = (Player) getOneIntersectingObject(Player.class);
        Bomb bomb = (Bomb) getOneIntersectingObject(Bomb.class);
        BombExplode explode = (BombExplode) getOneIntersectingObject(BombExplode.class);
        
    }    
}

//Key
import greenfoot.*;
public class Key extends EndGoal
{
    /**
     * Act - do whatever the Door wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        Player player = (Player) getOneIntersectingObject(Player.class);
        Bomb bomb = (Bomb) getOneIntersectingObject(Bomb.class);
        BombExplode explode = (BombExplode) getOneIntersectingObject(BombExplode.class);
        
    }    
}

//Large Key
import greenfoot.*;
public class LargeKey extends Key
{
    /**
     * Act - do whatever the LargeKey wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
    }    
}

//Powerups
import greenfoot.*;
public class Powerups extends Actor
{
    public int bombUpChance = 30;
    public int explodeRadiusChance = 55;
    public int oneUpChance = 65;
    public int skateChance = 100;
    public int randChance;
    //boolean activateOnce = false;
    
    
    /**
     * Act - do whatever the Powerups wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        spawnPowerup();
        //if (activateOnce == false){
        //    spawnPowerup();
        //    activateOnce = true;
        //}
    }    
    public void spawnPowerup(){
        
        randChance = Greenfoot.getRandomNumber(100);
        if (randChance >= 0 && randChance < bombUpChance){
            getWorld().addObject(new BombUp(), getX(), getY());
            getWorld().removeObject(this);
        }
        else if (randChance >= bombUpChance && randChance < explodeRadiusChance){
            getWorld().addObject(new ExplodeRadius(), getX(), getY());
            getWorld().removeObject(this);
        }
        else if (randChance >= explodeRadiusChance && randChance < oneUpChance){
            getWorld().addObject(new OneUp(), getX(), getY());
            getWorld().removeObject(this);
        }
        else if (randChance >= oneUpChance && randChance < skateChance){
            getWorld().addObject(new Skate(), getX(), getY());
            getWorld().removeObject(this);
        }
    }
}

//BombUp (Powerup)
import greenfoot.*;
public class BombUp extends Powerups
{
    
    /**
     * Act - do whatever the BombUp wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        
    }    
}

//ExplodeRadius (Powerup)
import greenfoot.*;
public class ExplodeRadius extends Powerups
{
    
    /**
     * Act - do whatever the BombUp wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        
    }    
}

//OneUp (Powerup)
import greenfoot.*;
public class OneUp extends Powerups
{
    
    /**
     * Act - do whatever the BombUp wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        
    }    
}

//Skate (Powerup)
import greenfoot.*;
public class Skate extends Powerups
{
    
    /**
     * Act - do whatever the BombUp wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        
    }    
}

//Player
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Player extends Actor
{
    
    //Setting a timer
    long startTime = System.currentTimeMillis();
    private int durationMillis;
    private int durationSecs;
    
    public int delayCount = 0;
    public int invincibility = 0;
    public int maxInvincibility = 0;
    public int enemyHitDelay = 0;
    
    public int bombCount;
    
    public String moveDir = "none";
    
    //powerup counter
    public int lives = 3;
    public int maxBomb = 1;
    public int explodeRadius = 0;
    public int moveSpeed = 45;
    
    public String stringLives;
    public String stringBombs;
    
    int i;
    
    boolean flash = false;
    
    GifImage walkingUp = new GifImage("Walk-up.gif");
    GifImage walkingLeft = new GifImage("walkingLeft.gif");
    GifImage walkingRight = new GifImage("walkingRight.gif");
    GifImage walkingDown = new GifImage("walkingDown.gif");
    GifImage flashing = new GifImage("flashing.gif");
    
    private GreenfootSound music = new GreenfootSound("Background music.mp3");
    private GreenfootSound bomb = new GreenfootSound("Bomb.wav");
    
    boolean hasKey = false;
    
    public String jokeAchievement;
    
    /**
     * Act - do whatever the Player wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        showLives();
        showBombs();
        if (lives > 0){
            playGif(moveDir);
            if (invincibility <= (maxInvincibility/2)){
                checkKeypress();
                if (delayCount > 0){
                    delayCount = moveDelay(delayCount);
                }
                if (invincibility > 0){
                    
                    invincibility = invincibilityDelay(invincibility);
                }
            }
            else{
                invincibility = invincibilityDelay(invincibility);
            }
            checkCollision();
            music.setVolume(25);
            music.playLoop();
            if (invincibility == 0){
                flash = false;
            }
            else{
                flash = true;
                moveDir = "flash";
            }
            
            //Timer
            long currentTime = System.currentTimeMillis();
            durationMillis = (int)(currentTime - startTime);
            durationSecs = durationMillis / 1000;
            
            if (durationSecs == 3600 && durationMillis%1000 == 0){
                
                jokeAchievement = "Time";
                jokeAchievements(jokeAchievement);
                
            }
            
        }
        else{
            getWorld().removeObject(this);
        }
    }    
    public void checkKeypress()
    {
        bombCount = (getWorld().getObjects(Bomb.class)).size();
        if (Greenfoot.isKeyDown("space") && bombCount < maxBomb){
            if (isTouching(Bomb.class) == false){
                getWorld().addObject(new Bomb(explodeRadius), getX(), getY());
                bomb.setVolume(20);
                for (i = 0; i < (getWorld().getObjects(Bomb.class)).size(); i++){
                    bomb.play();
                }
            }
        }
        if (delayCount == 0){
            
            if (Greenfoot.isKeyDown("left") == false){
                if (Greenfoot.isKeyDown("right") == false){
                    if (Greenfoot.isKeyDown("up"))
                    {
                        Block block = (Block) getOneObjectAtOffset(0, -25, Block.class);
                        if (flash == false){
                            moveDir = "up";
                        }
                        if (block == null)
                        {
                            setLocation((getX()),(getY()-25));
                            delayCount = delayCount + moveSpeed;
                            
                        }
                        if (isAtEdge()){
                            setLocation((getX()),(getY()+(25/2)));
                        }
                    }
                    
                    else if (Greenfoot.isKeyDown("down"))
                    {
                        Block block = (Block) getOneObjectAtOffset(0, 25, Block.class);
                        if (flash == false){
                            moveDir = "down";
                        }
                        if (block == null)
                        {
                            setLocation((getX()),(getY()+25));
                            delayCount = delayCount + moveSpeed;
                            
                        }
                        if (isAtEdge()){
                            setLocation((getX()),(getY()-(25/2)));
                        }
                    } 
                    else{
                        moveDir = "none";
                    }
                }
            }
                        
            if (Greenfoot.isKeyDown("up") == false){
                if (Greenfoot.isKeyDown("down") == false){
                    if (Greenfoot.isKeyDown("left"))
                    {
                        Block block = (Block) getOneObjectAtOffset(-25, 0, Block.class);
                        if (flash == false){
                            moveDir = "left";
                        }
                        if (block == null)
                        {
                            setLocation((getX()-25),(getY()));
                            delayCount = delayCount + moveSpeed;
                            
                        }
                        if (isAtEdge()){
                            setLocation((getX()+(25/2)),(getY()));
                        }
                    }
                    else if (Greenfoot.isKeyDown("right"))
                    {   
                        Block block = (Block) getOneObjectAtOffset(25, 0, Block.class);
                        if (flash == false){
                            moveDir = "right";
                        }
                        if (block == null)
                        {
                            setLocation((getX()+25),(getY()));
                            delayCount = delayCount + moveSpeed;
                            
                        }
                        
                        if (getX() >= 875){
                            setLocation((875-25/2),(getY()));
                        }
                    } 
                    else{
                        moveDir = "none";
                    }
                }
            }
            
        }
        else{
            delayCount = moveDelay(delayCount);
        }
    }
    public static int moveDelay(int delay)
    {
        delay--;
        return delay;
    }
    public static int invincibilityDelay(int invincibility)
    {
        invincibility--;
        return invincibility;
    }
    public static int hitDelay(int delay)
    {
        delay--;
        return delay;
    }
    
    public void checkCollision(){
        BombExplodeG1 explosion1 = (BombExplodeG1) getOneIntersectingObject(BombExplodeG1.class);
        BombExplodeG2 explosion2 = (BombExplodeG2) getOneIntersectingObject(BombExplodeG2.class);
        if (explosion1 != null || explosion2 != null){
            if (invincibility == 0){
                if (lives == 1){
                    jokeAchievement = "Bomb";
                    jokeAchievements(jokeAchievement);
                }
                lives = lives - 1;
                maxInvincibility = 100;
                invincibility = maxInvincibility;
                showLives();
                
            }
            
        }
        else if (explosion1 != null && explosion2 != null){
            if (invincibility == 0){
                if (lives == 1){
                    jokeAchievement = "Bomb";
                    jokeAchievements(jokeAchievement);
                }
                lives = lives - 1;
                maxInvincibility = 100;
                invincibility = maxInvincibility;
                showLives();
            }
        }
        Enemy enemy = (Enemy) getOneIntersectingObject(Enemy.class);
        if (enemy != null && enemyHitDelay == 0){
            if (invincibility == 0){
                if (lives == 1){
                    jokeAchievement = "Enemy";
                    jokeAchievements(jokeAchievement);
                }
                lives = lives - 1;
                maxInvincibility = 60;
                invincibility = maxInvincibility;
                enemyHitDelay = 120;
                showLives();
            }
            else{
                invincibility = invincibilityDelay(invincibility);
            }
        }
        else if (enemyHitDelay != 0){
            enemyHitDelay = hitDelay(enemyHitDelay);
        }
        
        BombUp bombup = (BombUp) getOneIntersectingObject(BombUp.class);
        ExplodeRadius explrad = (ExplodeRadius) getOneIntersectingObject(ExplodeRadius.class);
        OneUp oneup = (OneUp) getOneIntersectingObject(OneUp.class);
        Skate skate = (Skate) getOneIntersectingObject(Skate.class);
        Key key = (Key) getOneIntersectingObject(Key.class);
        Door door = (Door) getOneIntersectingObject(Door.class);
        
        if (bombup != null){
            maxBomb++;
            if (maxBomb == 25){
                jokeAchievement = "maxBomb";
                jokeAchievements(jokeAchievement);
            }
            showBombs();
            removeTouching(BombUp.class);
        }
        if (explrad != null){
            explodeRadius++;
            if (explodeRadius == 23){
                jokeAchievement = "Explosion";
                jokeAchievements(jokeAchievement);
            }
            removeTouching(ExplodeRadius.class);
        }
        if (oneup != null){
            lives++;
            if (lives == 25){
                jokeAchievement = "Life";
                jokeAchievements(jokeAchievement);
            }
            showLives();
            removeTouching(OneUp.class);
        }
        if (skate != null && moveSpeed > 0){
            moveSpeed = moveSpeed - 5;
            if (moveSpeed == 0){
                jokeAchievement = "Speed";
                jokeAchievements(jokeAchievement);
            }
            removeTouching(Skate.class);
        }
        if (key != null){
            hasKey = true;
            getWorld().addObject(new LargeKey(), (925+25/2), 515);
            removeTouching(Key.class);
        }
        if (hasKey == true){
            if (door != null){
                System.out.println("Congratulations! You won!");
                if ((getWorld().getObjects(Enemy.class)).size() < 1){
                    System.out.println("You slaughtered all the unarmed enemies! Congratulations, you monster.");
                }
                else{
                    System.out.println("There are enemies remaining! Coward."); 
                }
                Greenfoot.stop();
            }
        }
    }
    public void showLives(){
        stringLives = "" + lives + "";
        getWorld().showText(stringLives, (925+25/2), 250);
    }
    public void showBombs(){
        stringBombs = "" + maxBomb + "";
        getWorld().showText(stringBombs, (925+25/2), 425);
    }
    public void playGif(String moveDir){
        if (moveDir == "up"){
            setImage(walkingUp.getCurrentImage());
        }
        else if (moveDir == "down"){
            setImage(walkingDown.getCurrentImage());
        }
        else if (moveDir == "left"){
            setImage(walkingLeft.getCurrentImage());
        }
        else if (moveDir == "right"){
            setImage(walkingRight.getCurrentImage());
        }
        else if (moveDir == "flash"){
            setImage(flashing.getCurrentImage());
        }
        else{
            setImage("Player front.png");
        }
        
    }
    public void jokeAchievements(String string){
        System.out.println("ACHIEVEMENT UNLOCKED:");
        if (string == "Bomb"){
            System.out.println("Out with a bang");
        }
        if (string == "Speed"){
            System.out.println("2fast4u");
        }
        if (string == "Life"){
            System.out.println("Immortal");
        }
        if (string == "Explosion"){
            System.out.println("Unlimited POWER");
        }
        if (string == "Time"){
            System.out.println("Hour-long game");
        }
        if (string == "maxBomb"){
            System.out.println("Demolitions expert");
        }
        if (string == "Enemy"){
            System.out.println("Gently bashed to death by a sentient balloon");
        }
    }
    
}


//bomb
import greenfoot.*;
public class Bomb extends Actor
{
    //Setting the image so the gif plays when the game is run
    GifImage myGif = new GifImage("bomb-flash-recovered.gif");

    //Setting a timer so the explosion triggers after 5 secs (when the gif ends)
    long startTime = System.currentTimeMillis();
    
    public int explodeRadius;

    private int durationMillis;
    private int durationSecs;
    
    public Bomb(int explosionRadius){
        explodeRadius = explosionRadius;
    }
    public Bomb(){
    }
    /**
     * Act - do whatever the Bomb wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {

        //Timer
        long currentTime = System.currentTimeMillis();
        durationMillis = (int)(currentTime - startTime);
        durationSecs = durationMillis / 1000;

        if (durationSecs >= 5){
            System.out.println("Bomb" + explodeRadius);
            getWorld().addObject(new BombExplodeG1(explodeRadius), getX(), getY());
            getWorld().addObject(new BombExplodeG2(explodeRadius), getX(), getY());
            getWorld().removeObject(this);
        }
        else{
            playGif();
            
        }
    }
    public void playGif(){
        setImage(myGif.getCurrentImage());
        
    }
}

//BombExplode
import greenfoot.*;
public class BombExplode extends Actor
{
    //Setting a timer so the explosion disappears after 0.5 secs
    long startTime = System.currentTimeMillis();

    private int durationMillis;
    private int durationSecs;
    
    
    public void act() 
    {

        //Timer
        long currentTime = System.currentTimeMillis();
        durationMillis = (int)(currentTime - startTime);
        durationSecs = durationMillis / 1000;

        if (durationSecs >= 0.000001){
            getWorld().removeObject(this);
        }
        
    }
}



//BombExplodeG1
import greenfoot.*;
public class BombExplodeG1 extends BombExplode
{
    //Setting a timer so the explosion triggers after 5 secs (when the gif ends)
    long startTime = System.currentTimeMillis();

    private int durationMillis;
    private int durationSecs;
    
    public int explosionRadius;
    
    public BombExplodeG1(int explodeRadius){
        explosionRadius = explodeRadius;
    }
    public BombExplodeG1(){}
    
    //Player player = new Player();
    /**
     * Act - do whatever the Bomb wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        //explosionRadius = player.getExplosionRadius();
        //Timer
        long currentTime = System.currentTimeMillis();
        durationMillis = (int)(currentTime - startTime);
        durationSecs = durationMillis / 1000;
        
        if (explosionRadius <= 23){
            setImage("explosionG1 E" + explosionRadius + ".png");
            
        }
        else{
            setImage("explosionG1 E23.png");
        }
        
        if (durationSecs >= 0.05){
            System.out.println("Explosion" + explosionRadius);
            System.out.println("explosionG1 E" + explosionRadius + ".png");
            getWorld().removeObject(this);
        }
        
        
    }
}

//BombExplodeG2
import greenfoot.*;
public class BombExplodeG2 extends BombExplode
{
    //Setting a timer so the explosion triggers after 5 secs (when the gif ends)
    long startTime = System.currentTimeMillis();

    private int durationMillis;
    private int durationSecs;
    
    public int explosionRadius = 0;
    
    public BombExplodeG2(int explodeRadius){
        explosionRadius = explodeRadius;
    }
    public BombExplodeG2(){}
    
    //Player player = new Player();
    /**
     * Act - do whatever the Bomb wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        //explosionRadius = player.getExplosionRadius();
        
        //Timer
        long currentTime = System.currentTimeMillis();
        durationMillis = (int)(currentTime - startTime);
        durationSecs = durationMillis / 1000;
        
        if (explosionRadius <= 23){
            setImage("explosionG2 E" + explosionRadius + ".png");
        }
        else{
            setImage("explosionG2 E23.png");
        }
        
        if (durationSecs >= 0.000001){
            
            getWorld().removeObject(this);
        }
    }
}
There are more replies on the next page.
1
2
3