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

2015/6/16

Glitches

shannonf0126 shannonf0126

2015/6/16

#
My game works fine until it gets to level 2, and then after I collect the first coin, my code starts to glitch and my screen freezes. Can anyone help me out?
import greenfoot.*;
/**
 * @param none
    * @return none
 */
public class LevelTwo extends World
{ 
    int counter = 0;
    int score = 0;
    int scoreCount = 0;
    Scorev2 scoreObj = null;
    public LevelTwo()
    {    
        super(600, 600, 1, false); 
        
        Rocket plane = new Rocket();
        
        addObject (plane, 100, getHeight()/2);
        
        scoreObj = new Scorev2();
        scoreObj.Counting(0);
        
        addObject(scoreObj, 100, 100);
    }
    
    /**
     * @param none
    * @return none
     */
    public void act() 
    {
        counter++;
        
    if (counter %25 == 0 ) //increasing mod value decreases frequency
    {
        Rock stone = new Rock();
        addObject(stone, getWidth(), Greenfoot.getRandomNumber(580));
        counter = 0;
    }
        
        scoreCount++;
    if (scoreCount == 60) 
    { 
        Coin coin = new Coin();
        addObject(coin, getWidth(), Greenfoot.getRandomNumber(580));
        scoreCount = 0;
    }
    }
}
import greenfoot.*; import java.awt.Color; import java.awt.Font; public class Scorev2 extends Actor { int totalCount = 0; /** * @param none * @return none */ public Scorev2() { GreenfootImage gambar = new GreenfootImage(100, 60); setImage(gambar); } /** * @param none * @return score */ public void Counting (int score) // method Counting { totalCount += score; GreenfootImage gambar = getImage(); gambar.clear(); Font f = new Font("Adobe Devanagari", Font.PLAIN, 32); gambar.setFont(f); Color c = new Color(127, 127, 127, 127); gambar.setColor(c); gambar.fill(); gambar.setColor(Color.blue); gambar.drawString("" + totalCount, 30, 30); setImage(gambar); if(totalCount == 10) { Greenfoot.setWorld(new Menu()); } } }
azazeel azazeel

2015/6/16

#
what are the error messages ?
miningmanna miningmanna

2015/6/16

#
Is there code in the coin class?
danpost danpost

2015/6/16

#
What is the code you use for collecting a coin? Do you access a method or a field in a World subclass to register a coin being collected? Go through your actor class codes and search for "LevelOne". If you find it in any of them (like in that class of the object that collects the coins, maybe) and you have objects of that class in your LevelTwo world, that may be the location of your problem. You can still use those object in more than one world type; but, you must determine the type of world and cast the world properly before accessing the method or field.
You need to login to post a reply.