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

2013/9/3

Darkness Background

1
2
dominicarrojado dominicarrojado

2013/9/3

#
How can I blind the player and focus the light only around the player? Also when I move the player the Light circle follows too.
JetLennit JetLennit

2013/9/3

#
Take a look at one of these http://www.greenfoot.org/scenarios/4794 http://www.greenfoot.org/scenarios/4794 http://www.greenfoot.org/scenarios/6521 http://www.greenfoot.org/scenarios/7134
dominicarrojado dominicarrojado

2013/9/3

#
Thanks!
danpost danpost

2013/9/3

#
Or this one: http://www.greenfoot.org/scenarios/5213 (my Spot Light Demo)
dominicarrojado dominicarrojado

2013/9/4

#
Danpost I like your spot light demo. But it is assigned to many rocks. Can you make that's only assigned to one? I kinda mess up your code when trying to code it for a single actor. Xd
danpost danpost

2013/9/4

#
My constructor had a loop that added several objects to the Panel object. You only need assign one object to the Panel object. Remove the 'for' loop that is used to assign multiple objects to the Panel object in the world constructor and specify the actor you want spot-lighted in the argument of the 'addPanel' call.
dominicarrojado dominicarrojado

2013/9/4

#
Object obj = getObjects(Rock.class) ; portal.addPortal((Actor) obj); I tried this one but gets an error on terminal
danpost danpost

2013/9/4

#
Try this:
Rock rock = new Rock();
addObject(rock, x, y); // put world coordinate values in for x and y
portal.addPortal(rock);
or from what you tried:
Object obj = getObjects(Rock.class).get(0);
portal.addPortal((Actor)obj);
dominicarrojado dominicarrojado

2013/9/4

#
java.lang.ArrayIndexOutOfBoundsException: 5 at Portal.addPortal(Portal.java:82) at BG.<init>(BG.java:29) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:525) at greenfoot.core.Simulation.newInstance(Simulation.java:581) at greenfoot.platforms.ide.WorldHandlerDelegateIDE$3.run(WorldHandlerDelegateIDE.java:409) at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:468) at greenfoot.core.Simulation.maybePause(Simulation.java:281) at greenfoot.core.Simulation.runContent(Simulation.java:212) at greenfoot.core.Simulation.run(Simulation.java:205)
dominicarrojado dominicarrojado

2013/9/4

#
Rock rock = new Rock(); addObject(rock, x, y); // put world coordinate values in for x and y portal.addPortal(rock); This one worked. Thanks :D
danpost danpost

2013/9/4

#
You will need to show what your world class code looks like now. Use the 'code' tag under the 'Post a reply' box to insert your code in the post.
dominicarrojado dominicarrojado

2013/9/4

#
Why is that when I put the portal to my game it doesn't work? no errors but setPaintOrder(Portal.class) seem to not work. No darkness at all.
dominicarrojado dominicarrojado

2013/9/4

#
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 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;
    public int spawnWave2Quantity = 10;
    private final static int PISTOL_SPACING_EASY = 5000;
    private final static int SHOTGUN_SPACING_EASY = 4000;
    private final static int ASSAULT_SPACING_EASY = 3500;
    private final static int ENEMY_SPACING_EASY = 3000;
    private final static int ENEMY_SPACING_MEDIUM = 3000;
    private final static int ENEMY_SPACING_HARD = 2000;
    private final static int HEALTH_SPACING_EASY = 4000;
    private final int TIME_WHEN_THERE_ARE_NO_PISTOL =  333;
    private final int TIME_WHEN_THERE_ARE_NO_SHOTGUN =  533;
    private final int TIME_WHEN_THERE_ARE_NO_ASSAULT =  833;
    private final int TIME_WHEN_THERE_ARE_NO_HEALTH =  3000;
    private final int TIME_WHEN_THERE_ARE_NO_ENEMIES =  533;
    private final int PISTOL_SPACING;
    private final int SHOTGUN_SPACING;
    private final int ASSAULT_SPACING;
    private final int ENEMY_SPACING;
    private final int HEALTH_SPACING;
    private int gameTimer = 0;
    private final static int WORLD_WIDTH = 1150;
    private final static int WORLD_HEIGHT = 600;
    
    public Bar bar = new Bar("Player 1", "Health Points", heroLife, heroLifeMax);
    
    static int width = 1100; // 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(1100, 600, 1); 
        setPaintOrder(Portal.class);
        prepare();
        PISTOL_SPACING = PISTOL_SPACING_EASY;
        SHOTGUN_SPACING = SHOTGUN_SPACING_EASY;
        ASSAULT_SPACING = ASSAULT_SPACING_EASY;
        ENEMY_SPACING = ENEMY_SPACING_EASY;
        HEALTH_SPACING = HEALTH_SPACING_EASY;

    }

    /**
     * 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, 82, 300);
        portal.addPortal(this.hero); 
        
        this.pistol = new Pistol();
        addObject(this.pistol, 130, 310);

        this.minion = new Minion(this);
        addObject(this.minion, 1200, 50);

        this.minion2 = new Minion2(this);
        addObject(this.minion2, 1200, 150);

        this.minion3 = new Minion3(this);
        addObject(this.minion3, 1200, 250);

        this.minion = new Minion(this);
        addObject(this.minion, 1200, 350);

        this.minion2 = new Minion2(this);
        addObject(this.minion2, 1200, 450);

        this.minion3 = new Minion3(this);
        addObject(this.minion3, 1200, 550);

        
        Wall wall = new Wall();
        addObject(wall, 1000, 150);
        Wall wall2 = new Wall();
        addObject(wall2, 1000, 320);
        Wall wall3 = new Wall();
        addObject(wall3, 1000, 500);
        Wall wall4 = new Wall();
        addObject(wall4, 800, 150);
        Wall wall5 = new Wall();
        addObject(wall5, 800, 320);
        Wall wall6 = new Wall();
        addObject(wall6, 800, 500);
        Wall wall7 = new Wall();
        addObject(wall7, 600, 150);
        Wall wall8 = new Wall();
        addObject(wall8, 600, 320);
        Wall wall9 = new Wall();
        addObject(wall9, 600, 500);
        Wall wall10 = new Wall();
        addObject(wall10, 400, 150);
        Wall wall11 = new Wall();
        addObject(wall11, 400, 320);
        Wall wall12 = new Wall();
        addObject(wall12, 400, 500);
        Wall wall13 = new Wall();
        addObject(wall13, 200, 150);
        Wall wall14 = new Wall();
        addObject(wall14, 200, 320);
        Wall wall15 = new Wall();
        addObject(wall15, 200, 500);

        addObject(bar, 150, 40);
        addObject(pistolQuantity, 450, 39);
        addObject(shotgunQuantity, 550, 39);
        addObject(assaultQuantity, 650, 39);
        addObject(uziQuantity, 720, 39);
        addObject(zombieKillCounter, 900, 39);

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

        Uzi uzi = new Uzi();
        addObject(uzi, 172, 229);
    }
    
    public void generatePistol()
    {
        //do not generate any enemies in the intro sound to create suspense
        if (gameTimer < TIME_WHEN_THERE_ARE_NO_PISTOL) return; 

        if (gameTimer %  PISTOL_SPACING == 0)
        {
             Pistol pistol = new Pistol();
             addObject(pistol, Greenfoot.getRandomNumber(WORLD_WIDTH),Greenfoot.getRandomNumber(WORLD_HEIGHT));     
        }
        
    }
    public void generateShotgun()
    {
        //do not generate any enemies in the intro sound to create suspense
        if (gameTimer < TIME_WHEN_THERE_ARE_NO_SHOTGUN) return; 

        if (gameTimer %  SHOTGUN_SPACING == 0)
        {
             Shotgun shotgun = new Shotgun();
             addObject(shotgun, Greenfoot.getRandomNumber(WORLD_WIDTH),Greenfoot.getRandomNumber(WORLD_HEIGHT));     
        }
        
    }
    public void generateAssault()
    {
        //do not generate any enemies in the intro sound to create suspense
        if (gameTimer < TIME_WHEN_THERE_ARE_NO_ASSAULT) return; 

        if (gameTimer %  ASSAULT_SPACING == 0)
        {
             Assault assault = new Assault();
             addObject(assault, Greenfoot.getRandomNumber(WORLD_WIDTH),Greenfoot.getRandomNumber(WORLD_HEIGHT));     
        }
        
    }
    public void generateHealth()
    {
        if (gameTimer < TIME_WHEN_THERE_ARE_NO_HEALTH) return; 
        
        if (gameTimer %  HEALTH_SPACING == 0)
        {
             Health health = new Health();
             addObject(health, Greenfoot.getRandomNumber(WORLD_WIDTH),Greenfoot.getRandomNumber(WORLD_HEIGHT));    
        }
    }
    public void generateEnemiesWave2()
    {
        //do not generate any enemies in the intro sound to create suspense
        if  ((zombieKill > 20)&&(enemyLimit!=0))
        {
            
             if (gameTimer %  ENEMY_SPACING == 0)
             {
              this.minion = new Minion(this);
              addObject(this.minion, (WORLD_WIDTH)-1,Greenfoot.getRandomNumber(WORLD_HEIGHT));
              this.minion2 = new Minion2(this);
              addObject(this.minion2, (WORLD_WIDTH)-1,Greenfoot.getRandomNumber(WORLD_HEIGHT));
              this.minion3 = new Minion3(this);
              addObject(this.minion3, (WORLD_WIDTH)-1,Greenfoot.getRandomNumber(WORLD_HEIGHT));
              this.boss = new Boss(this);
              addObject(this.boss, (WORLD_WIDTH)-1,Greenfoot.getRandomNumber(WORLD_HEIGHT));
              enemyLimit-=3;
             Health health = new Health();
             addObject(health, Greenfoot.getRandomNumber(WORLD_WIDTH),Greenfoot.getRandomNumber(WORLD_HEIGHT)); 
             Assault assault = new Assault();
             addObject(assault, Greenfoot.getRandomNumber(WORLD_WIDTH),Greenfoot.getRandomNumber(WORLD_HEIGHT)); 
            }
        }
        if  ((zombieKill > 10)&&(enemyLimit!=0)&&(bossLimit!=0))
        {
            if (gameTimer %  5000 == 0)
             {
                 this.boss = new Boss(this);
              addObject(this.boss, (WORLD_WIDTH)-1,Greenfoot.getRandomNumber(WORLD_HEIGHT));
              bossLimit--;
            }
        }
    }
    public void generateEnemies()
    {
        //do not generate any enemies in the intro sound to create suspense
        if (gameTimer < TIME_WHEN_THERE_ARE_NO_ENEMIES) return; 
        
        if ((gameTimer %  ENEMY_SPACING == 0)&&(enemyLimit!=0))
        {
              this.minion = new Minion(this);
              addObject(this.minion, (WORLD_WIDTH)-1,Greenfoot.getRandomNumber(WORLD_HEIGHT));
              this.minion2 = new Minion2(this);
              addObject(this.minion2, (WORLD_WIDTH)-1,Greenfoot.getRandomNumber(WORLD_HEIGHT));
              this.minion3 = new Minion3(this);
              addObject(this.minion3, (WORLD_WIDTH)-1,Greenfoot.getRandomNumber(WORLD_HEIGHT));
              this.minion = new Minion(this);
              addObject(this.minion, (WORLD_WIDTH)-1,Greenfoot.getRandomNumber(WORLD_HEIGHT));
              this.minion2 = new Minion2(this);
              addObject(this.minion2, (WORLD_WIDTH)-1,Greenfoot.getRandomNumber(WORLD_HEIGHT));
              this.minion3 = new Minion3(this);
              addObject(this.minion3, (WORLD_WIDTH)-1,Greenfoot.getRandomNumber(WORLD_HEIGHT));
              enemyLimit-=6;
             
        }
        
    }
    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()
    {
        
        generatePistol();
        generateShotgun();
        generateAssault();
        generateHealth();
        generateEnemiesWave2();

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

}
danpost danpost

2013/9/4

#
You need to add the portal object into the world. Do this first in the prepare method:
addObject(portal, width/2, height/2);
dominicarrojado dominicarrojado

2013/9/4

#
Woops my bad. forgot to put addObject(portal, width / 2, height / 2); after setPaintOrder XD
There are more replies on the next page.
1
2