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

2020/3/8

Do not reply to this

1
2
Yoshi21137 Yoshi21137

2020/3/8

#
I only need this for the looks of the code
Yoshi21137 Yoshi21137

2020/3/8

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

/**
 * Write a description of class Knight here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Knight extends Players
{
    Main main = (Main)getWorld();
    int bulletSpeed = 100;  
    int hurtWait = 9;
    int hurtWait2 = 18;
    /**
     * Act - do whatever the Knight wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        Main main = (Main)getWorld();
        if (main.lives == 0)
        {
            main.removeObject(this);
        }
        looseHealth();
        checkKeys();
    }
    
    public void checkKeys()
    {
        if (getWorld() != null)
        {
            if (Greenfoot.isKeyDown("w"))
            {
                turn(-90);
                move(5);
                turn(90);
            }
            if (Greenfoot.isKeyDown("s"))
            {
                turn(90);
                move(5);
                turn(-90);
            }
            if (Greenfoot.isKeyDown("d"))
            {
                move(5);
            }
            if (Greenfoot.isKeyDown("a"))
            {
                move(-5);
            }
            if(Greenfoot.isKeyDown("enter") && getObjectsInRange(bulletSpeed, Bullet.class).isEmpty())
            {
                getWorld().addObject(new Bullet(), getX()+40, getY()+8);     
            }
        }
    }
    public void looseHealth()
    {
        if (getWorld() != null)
        {
            Main main = (Main)getWorld();
            if (isTouching(EnemyBullet.class))
            {
                hurtWait2 = hurtWait2-1;
                if (hurtWait2 == 0)
                {
                    main.lives = main.lives-1;
                    hurtWait2 = hurtWait2+14;
                }
            }
            if (canSee(GoblinShaman.class))
            {
                hurtWait = hurtWait-1;
                if (hurtWait == 0)
                {
                    main.lives = main.lives-1;
                    hurtWait = hurtWait+9;
                }
            }
            if (canSee(GoblinGuardBow.class))
            {
                hurtWait = hurtWait-1;
                if (hurtWait == 0)
                {
                    main.lives = main.lives-1;
                    hurtWait = hurtWait+9;
                }
            }
            if (canSee(GoblinGuardSpear.class))
            {
                hurtWait = hurtWait-1;
                if (hurtWait == 0)
                {
                    main.lives = main.lives-1;
                    hurtWait = hurtWait+9;
                }
            }
        }
    }
}
footpickle footpickle

2020/3/8

#
LOL i replied ha ha ha ha hello josh why havent u been at school
Yoshi21137 Yoshi21137

2020/3/8

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

/**
 * Write a description of class GoblinGuardBow here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class GoblinGuardBow extends Enemies
{
    /**
     * Act - do whatever the GoblinShaman wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move(-5);
        if (isAtEdge())
        {
            Main main = (Main)getWorld();
            main.removeObject(this);
        }
    }
}
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class GoblinGuardSpear here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class GoblinGuardSpear extends Enemies
{
    /**
     * Act - do whatever the GoblinGuardSpear wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move(-5);
        if (isAtEdge())
        {
            Main main = (Main)getWorld();
            main.removeObject(this);
        }
    }
}
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class GoblinShaman here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class GoblinShaman extends Enemies
{
    /**
     * Act - do whatever the GoblinShaman wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move(-5);
        if (isAtEdge())
        {
            Main main = (Main)getWorld();
            main.removeObject(this);
        }
    }
}
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class GoblinPriest here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class GoblinPriest extends Enemies
{
    int lives = 50;
    
    /**
     * Act - do whatever the GoblinPriest wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        Main main = (Main)getWorld();
        die();
        if (getWorld() != null)
        {
            int x=getX();
            int y=getY()-90;
            Actor health = (Actor)getWorld().getObjects(BossHealth.class).get(0);
            health.setLocation(x,y);
        }
        if (Greenfoot.getRandomNumber(5) < 1)
        {
            main.addObject(new EnemyBullet(), getX()-25, getY());
        }
    }
    
    
    
    public void die()
    {
        if (lives <= 0)
        {
            getWorld().removeObject(this);
        }
    }
}
Yoshi21137 Yoshi21137

2020/3/8

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

/**
 * Write a description of class Bullet here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Bullet extends Knight
{
    
    /**
     * Act - do whatever the Bullet wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move(5);
        kill();
        atWorldEdge();
        lowerHealth();
    }
    
    public void atWorldEdge()
    {
        if (getWorld() != null)
        {
            if (isAtEdge())
            {
                getWorld().removeObject(this);
            }
        }
    }
    
    public void kill()
    {
        if (getWorld() != null)
        {
            if (isAtEdge())
            {
                getWorld().removeObject(this);
            }
            else if (isTouching(GoblinShaman.class))
            {
                Main main = (Main)getWorld();
                removeTouching(GoblinShaman.class);
                main.kills = main.kills+10;
                getWorld().removeObject(this);
            }
            else if (isTouching(GoblinGuardBow.class))
            {
                Main main = (Main)getWorld();
                removeTouching(GoblinGuardBow.class);
                main.kills = main.kills+5;
                getWorld().removeObject(this);
            }
            else if (isTouching(GoblinGuardSpear.class))
            {
                Main main = (Main)getWorld();
                removeTouching(GoblinGuardSpear.class);
                main.kills = main.kills+1;
                getWorld().removeObject(this);
            }
        }
    }
    
    public void lowerHealth()
    {
        if(getWorld()!=null)
        {
            if (canSee(GoblinPriest.class))
            {
                ((BossHealth)getWorld().getObjects(BossHealth.class).get(0)).lives--;
                ((GoblinPriest)getWorld().getObjects(GoblinPriest.class).get(0)).lives--;
                getWorld().removeObject(this);
            }
        }
    }   
}
Yoshi21137 Yoshi21137

2020/3/8

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

/**
 * Write a description of class EnemyBullet here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class EnemyBullet extends Enemies
{
    int turnWait = 1;
    /**
     * Act - do whatever the EnemyBullet wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if (turnWait == 1)
        {
            setRotation(Greenfoot.getRandomNumber(360));
            turnWait = turnWait-1;
        }
        if (turnWait == 0)
        {
            move(-5);
            if (isAtEdge())
            {
                Main main = (Main)getWorld();
                main.removeObject(this);
            }
        }
    }
}
Yoshi21137 Yoshi21137

2020/3/8

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

/**
 * Write a description of class Title here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Title extends World
{

    /**
     * Constructor for objects of class Title.
     * 
     */
    public Title()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1000, 650, 1); 
        prepare();
    }
    
    public void act()
    {
        if (Greenfoot.mouseClicked(this))
        {
            Greenfoot.setWorld(new Main());
        }
    }
    
    private void prepare()
    {
        ClickToStart clickToStart = new ClickToStart();
        addObject(clickToStart, 500, 500);
    }
}
Yoshi21137 Yoshi21137

2020/3/8

#
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 Main extends World
{
    int spawnBoss = 0;
    int lives = 3;
    int kills = 0;
    int spawnS = 100;
    int spawnM = 125;
    int spawnL = 150;
    int spawn = 1;
    
    /**
     * Constructor for objects of class MyWorld.
     * 
     */
    public Main()
    {    
        super(1000, 650, 1); 
        prepare();
        showText(lives+"/3", 73, 42);
        showText(""+kills, 73, 66);
    }

    public void act()
    {
        if (spawn == 1)
        {
            newEnemy();
        }
        showText(""+kills, 73, 66);
        showText(lives+"/3", 73, 42);
        if (lives == 0)
        {
            addObject(new GameOver(), 500, 325);
            spawn = spawn+1;
            //Greenfoot.stop();
        }
        if (kills >= 200)
        {
            spawnBoss = spawnBoss+1;
        }
        if (spawnBoss == 1)  
        {
            addObject(new BossHealth(), 750, 235);
            addObject(new GoblinPriest(), 750, 325);
            spawnS = spawnS+25;
            spawnM = spawnM+25;
            spawnL = spawnL+25;
            spawnBoss = spawnBoss+1;
        }
    }

    /**
     * Prepare the world for the start of the program.
     * That is: create the initial objects and add them to the world.
     */
    private void prepare()
    {
        Knight knight = new Knight();
        addObject(knight, 250, 325);
        Score score = new Score();
        addObject(score,75,55);
    }
    
    private void createNewShaman()
    {
        GoblinShaman newGoblinShaman;
        newGoblinShaman = new GoblinShaman();
        
        int y = Greenfoot.getRandomNumber(650);
        
        addObject(newGoblinShaman, 1000, y);
    }
    
    private void createNewBow()
    {
        GoblinGuardBow newGoblinGuardBow;
        newGoblinGuardBow = new GoblinGuardBow();
        
        int y = Greenfoot.getRandomNumber(650);
        
        addObject(newGoblinGuardBow, 1000, y);
    }
    
    private void createNewSpear()
    {
        GoblinGuardSpear newGoblinGuardSpear;
        newGoblinGuardSpear = new GoblinGuardSpear();
        
        int y = Greenfoot.getRandomNumber(650);
        
        addObject(newGoblinGuardSpear, 1000, y);
    }
    
    public void newEnemy()
    {
        if ( Greenfoot.getRandomNumber(spawnS) < 1 )
        {
            createNewShaman();
        }
        if ( Greenfoot.getRandomNumber(spawnM) < 5 )
        {
            createNewBow();
        }
        if ( Greenfoot.getRandomNumber(spawnL) < 10 )
        {
            createNewSpear();
        }
    }
}
Yoshi21137 Yoshi21137

2020/3/8

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

/**
 * Write a description of class Win here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Win extends World
{
    private GifImage animation = new GifImage("FireworksL.gif");
    /**
     * Constructor for objects of class Win.
     * 
     */
    public Win()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1000, 650, 1); 
        //prepare();
    }
    
    public void act()
    {
        setBackground(animation.getCurrentImage());
    }
    
    private void prepare()
    {
        //YouWon youWon = new YouWon();
        //addObject(youWon, 250, 325);
    }
}
Yoshi21137 Yoshi21137

2020/3/8

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

/**
 * Write a description of class Actors here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Actors extends Actor
{
    /**
     * Act - do whatever the Actors 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.
    }
    
    /**
     * Return true if we can see an object of class 'clss' right where we are. 
     * False if there is no such object here.
     */
    public boolean canSee(Class clss)
    {
        Actor actor = getOneObjectAtOffset(0, 0, clss);
        return actor != null;        
    }

    
    /**
     * Try to eat an object of class 'clss'. This is only successful if there
     * is such an object where we currently are. Otherwise this method does
     * nothing.
     */
    public void eat(Class clss)
    {
        Actor actor = getOneObjectAtOffset(0, 0, clss);
        if(actor != null) {
            getWorld().removeObject(actor);
        }
    }
}
footpickle footpickle

2020/3/8

#
Josh why haven't you been at school lately? DO you hAvE coROnAvIRus?
footpickle footpickle

2020/3/8

#
@Yoshi21137
footpickle footpickle

2020/3/8

#
ok @mentions don't work that's good to know
Yoshi21137 Yoshi21137

2020/3/8

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

/**
 * Write a description of class BossHealth here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class BossHealth extends Actors
{
    int lives = 50;
    //int bossx= ((GoblinPriest)getWorld().getObjects(GoblinPriest.class).get(0)).bossx;

    //int bossy= ((GoblinPriest)getWorld().getObjects(GoblinPriest.class).get(0)).bossy;
    /**
     * Act - do whatever the BossHealth wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if (lives <= 0)
        {
            getWorld().removeObject(this);
        }
        takeDamage();
        
    }
    
    
    
    public void takeDamage()
    {
        if (lives == 45)
        {
            setImage("BossHealth9.png");
        }
        if (lives == 40)
        {
            setImage("BossHealth8.png");
        }
        if (lives == 35)
        {
            setImage("BossHealth7.png");
        }
        if (lives == 30)
        {
            setImage("BossHealth6.png");
        }
        if (lives == 25)
        {
            setImage("BossHealth5.png");
        }
        if (lives == 20)
        {
            setImage("BossHealth4.png");
        }
        if (lives == 15)
        {
            setImage("BossHealth3.png");
        }
        if (lives == 10)
        {
            setImage("BossHealth2.png");
        }
        if (lives == 5)
        {
            setImage("BossHealth1.png");
        }
        if (lives == 0)
        {
            setImage("BossHealth0.png");
        }
    }
}
Happycrusher764 Happycrusher764

2020/3/8

#
joSh As cOrOnA viRUs LMao
There are more replies on the next page.
1
2