This is the code but it will not lose health when laser eats ship
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Enemylaser here. * */ public class Enemylaser extends Mover { private int life; boolean fired; public Bar bar = new Bar("YourShip", "Health Points", 10, 10); /** * Act - do whatever the Enemylaser wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(20); eat(); life--; if (life == 0) { getWorld().removeObject(this); } ifAtWorldEdge(); if (fired==false) setRotation(Warship.rotation); if (fired==false) fired=true; } public void ifAtWorldEdge() { if (atWorldEdge()) { getWorld().removeObject(this); } } public void eat() { Actor Ship; Ship = getOneObjectAtOffset(0, 0, Ship.class); if (Ship != null) { World World; World = getWorld(); GameOver gameover = new GameOver(); //World.addObject(gameover, World.getWidth()/2, World.getHeight()/2); //World.removeObject(Ship); bar.add(-1); } } }