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.*;
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());
}
}
}
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;
}
}
}
