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.
Rock rock = new Rock(); addObject(rock, x, y); // put world coordinate values in for x and y portal.addPortal(rock);
Object obj = getObjects(Rock.class).get(0); portal.addPortal((Actor)obj);
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);
}
}
}
addObject(portal, width/2, height/2);