This site requires JavaScript, please enable it in your browser!
Greenfoot back
Paswalt
Paswalt wrote ...

2016/12/15

Need help for a school project

Paswalt Paswalt

2016/12/15

#
Hello! I need to create a little game with Greenfoot 3 as a school project. I decided to make a top down (space) shooter. But I really have big problems with coding all the stuff. There are 2 mayor issues I have. The first one: I want to remove an enemy after 3 hits. So I made an if statement and after 3 hits this.getWorld().removeObject(this). So far so good. But I also want to remove the Enemy if he reaches the edge of the screen (at the bottom). So I also made an if statement for that. The problem is the enemys get removed when they reach the border but as soon as I destroy an enemy the game crashes. I can't post code at the moment because we don't use the "real java". We made a stride project and we use the simple version where you can drag and drop code and don't need {}; (I don't know the name I hope you get what I mean). If I find out how to copy the code like real java code I let you know! Maybe you have some solutions in mind!
Super_Hippo Super_Hippo

2016/12/16

#
This happens because if you shoot the enemy, it is removed from the world and after that, it tries to check its Y coordinate to see if it is at the bottom. This doesn't work because it is not in the world anymore.
1
2
if (getWorld() == null) return;
//check if it is at the bottom
Nosson1459 Nosson1459

2016/12/16

#
Paswalt wrote...
I can't post code at the moment because we don't use the "real java". We made a stride project and we use the simple version where you can drag and drop code and don't need {}; (I don't know the name I hope you get what I mean). If I find out how to copy the code like real java code I let you know! Maybe you have some solutions in mind!
You can make a copy of the class then convert it to java by right -clicking on it then pressing on "convert to java", the reason you have to make a copy is because (as it will say when you try) this action is irreversible (or something like that).
You need to login to post a reply.