so I have a problem with getting the score to update in the background. It works fine otherwise to count and such but I dont know how to update it. Please and thank you!
this is the background, and Kunai is the class that counts the kills
The Kunai class in case you wanted to see it
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; /** * Write a description of class Floor here. * * @author (your name) * @version (a version number or a date) */ public class Floor extends World { public Bar bar = new Bar("Ninja", "Health Points", 20, 20); private int startEnenemies = 1; public int players; public Kunai kunai; private int Points = kunai.Kills; GreenfootImage bg = getBackground(); /** * Constructor for objects of class Floor. * */ public Floor() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(1200, 800, 1); bg.setColor(Color.BLACK); Score(); Killing(); addEnnemies(startEnenemies); addObject(new Ninja(),500,500); addObject(bar, 1000, 740); addObject(new Bat(), 520,450); } private void addEnnemies(int count) { for(int i = 0; i < count; i++) { int x = Greenfoot.getRandomNumber(getWidth()/2); int y = Greenfoot.getRandomNumber(getHeight()/2); addObject(new Ennemies(), x, y); } } public void act() { if (Greenfoot.getRandomNumber(200) == 0) { addObject (new Ennemies(), Greenfoot.getRandomNumber(600) + 20, Greenfoot.getRandomNumber(440) + 20); } { if (bar.getValue() == bar.getMinimumValue()) { if (getObjects(GameOver.class).isEmpty()) showGameOver(); return; } } } private void showGameOver() { addObject(new GameOver(), getWidth() / 2, getHeight() / 2); Greenfoot.stop(); } public int Score () { return Points; } public void Killing() { bg.drawString("Kills " + Points , 1050,100); } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Kunai here. * * @author (your name) * @version (a version number or a date) */ public class Kunai extends SmoothMover { /** The damage this bullet will deal */ private static final int damage = 50; public static int Kills; /** A bullet looses one life each act, and will disappear when life = 0 */ private int life = 40; public Kunai() { } public Kunai(Vector speed, int rotation) { super(speed); setRotation(rotation); addForce(new Vector(rotation, 15)); } /** * The bullet will damage asteroids if it hits them. */ public void act() { if(life <= 0) { getWorld().removeObject(this); } else { life--; move(); checkEnnemiesHit(); } } /** * Check whether we have hit an asteroid. */ private void checkEnnemiesHit() { Ennemies ennemies = (Ennemies) getOneIntersectingObject(Ennemies.class); if (ennemies != null){ getWorld().removeObject(this); ennemies.hit(damage); Kills = Kills + 1; System.out.println(Kills); } } }