Hello. This is a problem that I had for a long time now and I can't seem to solve this one after multiple hours.
I have a health int in "Link" and multiple heart classes which are being created in "MyWorld".
The Octorock (An Enemy) should when hitting / touching Link lower the health by 1 point and remove a heart.
Same goes with the Projectile class which is being shot by the Octorock it should also (when Link is hit) remove his health by 1 and remove 1 of his hearts.
With that problem I can't start up my "isGameOver" / setting it to true since my health never lowers.
I'll post the codes in here one by one.
This problem is ratherlarge complicated so I'd love to have some help!
This first one is setting the heart classes into my world. (the heartclasses are just empty (Heart1.class / Heart2.class)
public class MyWorld extends World { public int abstand = 120; GreenfootSound OverWorld = new GreenfootSound("Overworld.mp3"); /** * Constructor for objects of class MyWorld. * */ public MyWorld() { // Create a new world with 800x600 cells with a cell size of 1x1 pixels. super(800, 600, 1); setBackground(new GreenfootImage("background.png")); Link link = new Link(); addObject (link, 400, 300); Octorock Octo = new Octorock(); addObject (Octo, 100, 100); Octorock Octo2 = new Octorock(); addObject (Octo2, 400, 200); Octorock Octo3 = new Octorock(); addObject (Octo3, 600, 500); Heart5 Heart = new Heart5(); addObject (Heart, 770,30); Heart1 Heart1 = new Heart1(); addObject (Heart1, 750, 30); Heart2 Heart2 = new Heart2(); addObject (Heart2, 730, 30); Heart3 Heart3 = new Heart3(); addObject (Heart3, 710, 30); Heart4 Heart4 = new Heart4(); addObject (Heart4, 690, 30); for(int i=1;i<6;i++){ Wall Wall_i = new Wall(); addObject (Wall_i,737 - abstand, 537 - abstand); } Wall Wall_i = new Wall(); addObject (Wall_i, 737,537); //Bar UIBar = new Bar(); //addObject (UIBar,400,20); Life Life = new Life(); addObject (Life,732,15); OverWorld.play(); OverWorld.setVolume(25); setPaintOrder (Heart1.class,Heart2.class,Heart3.class,Heart4.class,Heart5.class, Life.class, Bar.class,Link.class, Wall.class,Tree.class); } }