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

2013/5/3

HELP ME PLEASE :)

SWAG SWAG

2013/5/3

#
My character currently can shoot, but I want him to shoot when he gets then gun. Can someone help create a code the will not allow my character to shoot until he touches the gun. I want the gun to disappear when we touches it and be able to continue to shoot. The gun wont be with him. Basically the gun enable him to shoot once he touches it once.
lightdlete3 lightdlete3

2013/5/3

#
no idea
RedManRocket RedManRocket

2013/5/4

#
Ok so a really simple way to do this is to make a boolean variable in the class the says gotGun or whatever you want it to be. And if you confused right now don't worry i will explain it in a moment. And you shoot with keys im assuming so to start off with the code heres where it will begin. this is below the class signature. public static boolean gotGun "or whatever you will call it" = false; then you will put the code for when you pick it up below the act method public void pickUpGun() //"or whatever you want to call it" { Gun is whatever the name of the gun is Gun gun = (Gun) getOneIntersectingObject(Gun.class); if(gun != null) { gotGun = true; getWorld().removeObject(gun); } } so what this does is, when you touch the gun it will remove it and make it so that you will be able to shoot once you have put that boolean variable gotGun into action so the way you do that is simple so this is your player class lets say you use space to fire so here is the keyPress method public void checkKeyPress() { if (Greenfoot.isKeyDown("space") && Gun.gotGun == true) { then insert your fire method here } } then put the checkKeyPress and pickUpGun method into your actMethod
You need to login to post a reply.