Hello, I recently finished looking at the tutorial for this matter, however it is still not yielding the results I need, I rlly need help with this. Here is the code.
Spawner (important code in act):
Zombies/Green:
MyWorld:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Spawner here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Spawner extends Actor
{
/**
* Act - do whatever the Spawner wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
World world=(MyWorld) getWorld();
public int zombies2kill = 5;
public int zombieskilled = 0;
public int zombies2spawn = 0;
private int delay = 0;
public void act()
{
if(delay > 0){
delay--;
}
if (zombieskilled == 1){
Green2 green2 = new Green2();
getWorld().addObject(green2,200,100);
}
if(delay == 0 && zombies2spawn <= zombies2kill) spawn();
}
private void spawn(){
int lr = Greenfoot.getRandomNumber(3);
if(lr==2){
Green2 green2 = new Green2();
getWorld().addObject(green2,580,380);
zombies2spawn++;
delay = 80;
}
if(lr==1){
Green green = new Green();
getWorld().addObject(green,0,380);
zombies2spawn++;
delay = 80;
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class green here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Green extends Actor
{
/**
* Act - do whatever the green wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(1);
if(isTouching(projectile_1.class)){
MyWorld world = (MyWorld) getWorld();
Spawner spawner = world.getSpawner();
spawner.zombieskilled++;
}
}
}
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
{
/**
* Constructor for objects of class MyWorld.
*
*/
private Spawner thespawner;
public MyWorld()
{
super(600, 400, 1);
spawnactor();
thespawner = new Spawner();
}
public Spawner getSpawner(){
return thespawner;
}
private void spawnactor(){
Play play = new Play();
addObject(play,300, 200);
}
}
