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

2012/12/9

Title screen won't run

HadAWay HadAWay

2012/12/9

#
I have a school project that is due by the end of the week where we have to make a game in Greenfoot with a lot of requirements (title screen, etc.). However, seemingly overnight, my titlescreen, which is supposed to continue when "enter" is pressed, stopped responding, (No Syntax Errors). I forgot what I added/changed to the code, and I spent the last two class periods to no avail trying to fix it and my teacher/fellow classmates refuse to help me. Here is the code under my "world", and sorry for the generally terrible coding ability.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
 * Write a description of class ThisWorld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class ThisWorld extends World
{

    playerCharacter spawn;
    zombie undead;
    titlescreen start;
    finalscreen end;
    winscreen win;
    int shootrate = 20;
    int shootcounter = 0; 
    int zombierate = 120;
    int zombiecounter = 0;
    int enemyshootrate = 20;
    int enemyshootcounter = 0;
    int possiblexspawnzones[] = new int[4];
    int possibleyspawnzones[] = new int[4];
    static int totalnumberofzombies;
    static int maxnumberofzombies = 1;
    static boolean gameover = false; 
    int movecount = 0;
    int xzone;
    int yzone; 
    int i;
    static boolean immediatelybecomesfalse = true;
    static boolean gamestart = false;
    static boolean survivalgame = false;
    static boolean timedgame = false; 
    long starttime;
    long currenttime;
    long timeremaining;
    static long timescore;
    
    public ThisWorld() 
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1); 
        
       start = new titlescreen();
        addObject(start, 300, 200);
        
        
    }
    public void act() 
    {
        if (!gamestart) {
        gameprep();
        }
        
        if (Greenfoot.isKeyDown("enter") || survivalgame) {
            gamestart = true;
            survivalgame = true;
            gamemechanics();
            
        }
        if (Greenfoot.isKeyDown("shift") || timedgame) {
            gamestart = true;
            timedgame = true;
            timedgame();
            gamemechanics();
            
            if (timeremaining % 10000 == 0) {
                undead = new zombie();
                addObject(undead, 100, 200);
            }
            if (timeremaining > 60000) {
                endoftimedgame();
            }
        }
        
    }
    public void gamemechanics() {
        if (immediatelybecomesfalse) 
        {
            starting();
            immediatelybecomesfalse = false;
            
        }
        else if (playerCharacter.trueattheend) 
        {
            immediatelybecomesfalse = false;
            playerCharacter.trueattheend = false;
            i = 100;
            starting();
            thegameisover();
            System.out.println("Basic Movement has run");
        }
        else if (!immediatelybecomesfalse) {
            if (!gameover) {
                checkshotrate(); 
                System.out.println("zombies are spawning");
                }
            if (totalnumberofzombies < maxnumberofzombies) {
                spawnzombies();
                System.out.println("People are shooting");
                }
        }
    }
    public void checkshotrate() {
            
        if (!gameover) 
        {
            if (shootcounter == 0) {
                shoot();
            }
            else if (shootcounter < shootrate) { 
                shootcounter = shootcounter+1;
            }
            else if (shootcounter == shootrate) {
                shootcounter = 0; 
            }
        
    }
    }
    
    public void shoot()
    {
        if (Greenfoot.isKeyDown("space")) {
                addObject(new bullet(), spawn.getX(), spawn.getY());
                shootcounter = shootcounter+1;
                i = i+1;
           }
        else {
                shootcounter = 0;
            }
    }

    public void spawnzombies() 
    {
        if (!gameover) {
            if (zombiecounter == 0) {
                zombiespawner();
            }
        
            else if (zombiecounter < shootrate) {
                zombiecounter = zombiecounter+1;
            }
            else if (zombiecounter == zombierate) {
                zombiecounter = 0; 
            }
            else { 
                zombiecounter = 0;}
        }
        
    }
    public void zombiespawner() 
    {
        getspawnlocation();

        if (xzone - playerCharacter.playerx > 100 || yzone - playerCharacter.playery > 100)
        {
            addObject(undead, xzone, yzone);
            zombiecounter = zombiecounter+1;
            totalnumberofzombies = totalnumberofzombies+1;
        }
        else {
            getspawnlocation();
        }
        
    }
    
    public void getspawnlocation() 
    {
         possiblexspawnzones[0] = 50;
         possiblexspawnzones[1] = 225;
         possiblexspawnzones[2] = 375;
         possiblexspawnzones[3] = 550;
         possibleyspawnzones[0] = 50;
         possibleyspawnzones[1] = 150;
         possibleyspawnzones[2] = 250;
         possibleyspawnzones[3] = 350;
         
        undead = new zombie();
        
        xzone = possiblexspawnzones[Greenfoot.getRandomNumber(4)];
        yzone = possibleyspawnzones[Greenfoot.getRandomNumber(4)];
        
    }
    public void starting() 
    {
        if (gamestart) {

            start = new titlescreen();
            removeObject(start);
            
            spawn = new playerCharacter(); 
            addObject(spawn, 300, 200); 
        
            undead = new zombie();
            addObject(undead, 100, 200);
            
            
            totalnumberofzombies = totalnumberofzombies+1;

        }
      }
    
    public void thegameisover()
    {
        if (survivalgame) {
            if (maxnumberofzombies-1 < 100) {
                finalscreen end = new finalscreen();
                addObject(end, 300, 200);
                
            }
            else {
                winscreen win = new winscreen();
                addObject(win, 300, 200);
            }
        }
        else if (timedgame) {
            if (timeremaining < 60000) {
                timescore += timeremaining;
                finalscreen end = new finalscreen();
                addObject(end, 300, 200);}
        }
    
    }
    public void timedgame() {
        currenttime = System.currentTimeMillis();
        timeremaining = currenttime-starttime;
    }
    public void gameprep() {
            int i = 0;
        List everything = getObjects(null);
        removeObjects(everything);
        
        start = new titlescreen();
        addObject(start, 300, 200);
        
        starttime = System.currentTimeMillis();
    }
    public void endoftimedgame() {
        
        winscreen win = new winscreen();
        addObject(win, 300, 200);
        
        timescore += timeremaining;
    }
    }
    
HadAWay HadAWay

2012/12/9

#
Sorry for the misleading title, the titlescreen won't respond
danpost danpost

2012/12/9

#
Look closely at lines 190 and 191. Ask yourself, "What will be happening here?"; "Will this do what I need it to do?". By the way, 'removeObject' will not 'error' if the object is not in the world.
You need to login to post a reply.