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

Comments for Archerman

Return to Archerman

Green-FootGreen-Foot

2009/11/18

Hey I am downloading your source let me take a look at it and I'll see if I can help you out.
Green-FootGreen-Foot

2009/11/18

Hey I am downloading your source let me take a look at it and I'll see if I can help you out.
Green-FootGreen-Foot

2009/11/18

Hey I gave it a shot, I will work on it later. For some reason if you shoot from the right side it removes bullet, but if you shoot from the left side it removes the guard. Weird.
LilpowerdudeLilpowerdude

2009/11/18

to delete it you can use this code inside the class that checks for it to be gone (( <the name of the kind of world you have> ) getWorld()).removeObjects(getObjects( <what the arrow class is called> .class)); be sure to cast the getWorld() it should work if not, let me know
LilpowerdudeLilpowerdude

2009/11/18

Oh and if you want delay for the arrows, an easy way for beginners is to make 2 numbers one is equal to zero and the other the delay time then you can have the one equal to zero count up and everytime ur character makes a check if the key is down, let it also check if the number greater than zero is above the delay time so for example: int counter = 0; int delay = 20; act() { if(Greenfoot.isKeyDown("f") && counter > delay) { <attack code here> counter = 0; } counter++; }
kenshinakhkenshinakh

2009/11/18

You don't have to cast world to another one I think. getWorld().removeObjects(getWorld().getObjects(arrrow.class)); would be more correct? Just a guess. See if it compiles XD.
A new version of this scenario was uploaded on Wed Nov 18 03:50:07 UTC 2009
LilpowerdudeLilpowerdude

2009/11/18

ah okay just kidding sam kenshin is rite xD
SamSkinnerSamSkinner

2009/11/18

@Lilpowerdude, thanks for the delay code, worked perfectly and so simple. Awesome. :) The problem I am having with deleting the bullet is that I'm not sure what to do with the remove codes that I have. public void checkBullet(){ if(canSee(Bulletleft.class)||canSee(Bulletright.class)){ ((Archerworld)getWorld()).deleteGuard(this); ((Archerworld)getWorld()).deleteBullet(Bullet.class); } } That is what I have in the Guard1 class. public void deleteBullet(Actor actor){ removeObject(actor); } That is the method in the world. The problem is that the deleteBullet line in Guard1 doesn't know which bullet to delete. I got the bullets to delete when they touch the edges by simply putting: public void delete(){ if(getX()>=690||getX()<=10){ ((Archerworld)getWorld()).deleteBullet(this); } } That in the Bullet class.
A new version of this scenario was uploaded on Wed Nov 18 04:01:57 UTC 2009
kenshinakhkenshinakh

2009/11/18

public void checkBullet(){ if(canSee(Bulletleft.class)||canSee(Bulletright.class)) { ((Archerworld)getWorld()).deleteGuard(this); ((Archerworld)getWorld()).deleteBullet(getOneIntersectingObject(Bullet.class)); } } That will remove one bullet that is currently touching the object that calls that method.
SamSkinnerSamSkinner

2009/11/18

Urghh. Once bullet hit the guard it popped up with terminal error. Guard disappeared but bullet stayed and the error was saying stuff about:: The actor has not been inserted into the world so it has no location yet. You might want to look at the method addedToWorld on the actor class.
kenshinakhkenshinakh

2009/11/18

Ah that error. Well, to prevent that from happening, after removing the bullet, do return; to stop execution of that bullet so that way it won't try to act when it's already out of the world.
SamSkinnerSamSkinner

2009/11/18

public void deleteBullet(Actor actor){ removeObject(actor); return; } I changed it to that. Sadly it still happens. :(
kenshinakhkenshinakh

2009/11/18

Well, you have to stop that bullet from acting, so like, you need to either put the return in the bullet class at a point to stop it from acting, or add code that can stop bullet from accting. you could try: public void deleteBullet(Bullet bullet) { bullet.performRemove(); } bullet's performRemove() { isRemoved = true; //declare private boolean isRemoved; in the top, } and in the bulllet's act() { if (isRemoved){ getWorld().removeObject(this); return; // this will stop bullet's execution code when it is removed. } //the rest of bullet's act method. }
SamSkinnerSamSkinner

2009/11/18

kenshinakh, would you be able to download my source and try and figure that out, please? I can't understand where to put each thing and I just keep getting errors. :( I understand if you can't or don't want to, but if you can I'd very much appreciate it! :)) Thanks anyway.
MTKMTK

2009/11/18

How do you fire?
kenshinakhkenshinakh

2009/11/18

Okay so I compiled it, and it works now, but don't knwo how to send it to you, so I'll post the parts i changed here: in Gaurd1 public void checkBullet() { if(canSee(Bulletleft.class)||canSee(Bulletright.class)) { getAWorld().deleteBullet(getOneIntersectingObject(Bulletright.class)); getAWorld().deleteGuard(this); } } public Archerworld getAWorld() { return (Archerworld)getWorld(); } in archerworld public void deleteBullet(Actor actor) { removeObject(actor); }
kenshinakhkenshinakh

2009/11/18

All I did was change the order of act ( I just realized that the error was because guard1 is trying to act when it has been removed already). So all i did was tell the gaurd to remove itself once it is done with everything else.
A new version of this scenario was uploaded on Wed Nov 18 20:49:32 UTC 2009