Ok. So yes, there are multiple discussions already but I still cant find help for my excat problem.
I try to create a working score that changes. I tried it with showText but that stays and I want a changing Score without 442 Score Objects after the first Level. My project is programming Space Invaders.
Here is my Score Class code:
Yes, changeScore is empty. I need to change that.
My world Class:
No other Method refers to the Score class in the World class
My Alien Class:
If you need more information, just ask.
Hope you can help,
Raven
import java.awt.Font;
import greenfoot.*;
public class Score extends Actor
{
// instance variables - replace the example below with your own
private static int score = 0;
public static GreenfootImage display = new GreenfootImage(400,80);
private int pre = 0;
public Score(){
score = 0;
setImage(new GreenfootImage("space1.jpg"));
// display.setFont(new Font("Courier New", Font.PLAIN, 20));
// display.drawString(convert(),400,80);
display.drawString("Banana",400,80);
}
public void act(){
if(pre != score){
pre = score;
changeScore();
}
}
public static int getScore(){
return score;
}
public static void addToScore(int x){
score = score + x;
}
public static void resetScore(int x){
score = 0;
}
private static String convert(){
String scoreS = "Score: " + score;
return scoreS;
}
private void changeScore(){
return;
}
}
public ClassicWorld()
{
// Creation of the Classic Map
super(672, 720, 1);
removeObjects(getObjects(null)); // remove all existing objects
addObject(new Player(),336,670);
addObject(new LivesCounter(),450,40);
addObject(new LivesCounter(),500,40);
addObject(new house(), 350,640);
addObject(new Score(),400,80);
Score.addToScore(-1000);
setupClassic(800);
}public void act()
{
//die
if(getY()>600){
ClassicWorld World = getWorldOfType(ClassicWorld.class);
World.showText("Aliens reached Earth",336,400);
World.endGame();
return;
}
//move
if(isDead == false){
Actor bullet = getOneIntersectingObject(Bullet.class);
if (bullet != null) {
getWorld().removeObject(bullet);
isDead = true;
setImage(new GreenfootImage("AlienClassicDead.png"));
int points = 10 + type*10;
Score.addToScore(points); //SCORE!!!!!
deathTimer.mark();
}
if(time.millisElapsed() > speed){
move();
time.mark();
if(Greenfoot.getRandomNumber(180) == 1){
shoot();
}
}
}
else{
if(deathTimer.millisElapsed() < 400){
if(time.millisElapsed() > speed){
move();
time.mark();
}
}
else{
List alienlist = getWorld().getObjects(Alien.class);
aliencounter = alienlist.size();
aliencounter --;
if(aliencounter==0){
World w = getWorld();
if(0<=type&&type<=2){
ClassicWorld cw = getWorldOfType(ClassicWorld.class);
cw.reset("CW",level);
}
else{}
w.removeObject(this);
}
else{
getWorld().removeObject(this);
}
}
}
//--------TESTING----------//
}
