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

2018/4/10

Need bullets and enemy class...

IlikeThePrequels IlikeThePrequels

2018/4/10

#
I'm trying to make it where the bullets and enemies disappear both when the bullet hits them. Also, I'm trying to make it where the bullet shoots in the direction its facing. Lastly, I'm trying to make it where the enemy only shoots one bullet at a time. Here is my code for my bullet class and enemy class. import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class bullet here. * * @author (your name) * @version (a version number or a date) */ public class Stinger extends Actor { public void act() { move(5); checkCollision(); } public void checkCollision() { Actor bee2 = (Actor) getOneIntersectingObject(Bee2.class); if(bee2 != null) { getWorld().removeObject(bee2); getWorld().removeObject(this); } } } and enemy class import greenfoot.*; /** * Write a description of class Ladybug1 here. * * @author (your name) * @version (a version number or a date) */ public class Bee2 extends Actor { private int beehivesEaten; private int health; private GreenfootImage image3; private GreenfootImage image4; /** * Act - do whatever the Ladybug1 wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public Bee2() { beehivesEaten = 0; image3 = new GreenfootImage("bee.png"); image4 = new GreenfootImage("bee2.png"); setImage(image3); } public void act() { followBeehive(); lookForBeehive(); switchImage(); } public void followBeehive() { turnTowards(150,500); Actor beehive = (Actor) getOneIntersectingObject(Beehive.class); move(3); if(beehive !=null) { getWorld().removeObject(beehive); } } public void attackBeehive() { if(!getObjectsInRange(500, Beehive.class).isEmpty()) { Actor beehive=(Actor) getObjectsInRange(200, Beehive.class).get(0); if(beehive !=null) { followBeehive(); } } } private void lookForBeehive() { if (isTouching(Beehive.class)) { Greenfoot.playSound("munch.mp3"); removeTouching(Beehive.class); beehivesEaten = beehivesEaten + 1; } } public void switchImage() { if (getImage() == image3) { setImage(image4); } else { setImage(image3); } } } // References //www.youtube.com/watch?v=DoElE2f_QdM //www.youtube.com/watch?v=aiNg8ChsyUg //www.greenfoot.org/topics/60455/0
IlikeThePrequels IlikeThePrequels

2018/4/10

#
Could someone please respond?
nolttr21 nolttr21

2018/4/10

#
in the enemy class you could write,
1
2
3
4
5
6
if (isTouching(Stinger.class))
    {
           removeTouching(Stinger.class);
           getWorld().removeObject(this);
           return;
}
I am not sure how to do the other two things.
danpost danpost

2018/4/10

#
nolttr21 wrote...
in the enemy class you could write, << Code Omitted >> I am not sure how to do the other two things.
This seems to have already been taken care of in the Stinger class. Apparently the Bee2 claas instances are the enemies here.
danpost danpost

2018/4/10

#
IlikeThePrequels wrote...
I'm trying to make it where the bullet shoots in the direction its facing. Lastly, I'm trying to make it where the enemy only shoots one bullet at a time.
I do not see any code where a Stinger object (bullet) is created at all by any enemy (bee) or otherwise.
IlikeThePrequels IlikeThePrequels

2018/4/10

#
danpost wrote...
IlikeThePrequels wrote...
I'm trying to make it where the bullet shoots in the direction its facing. Lastly, I'm trying to make it where the enemy only shoots one bullet at a time.
I do not see any code where a Stinger object (bullet) is created at all by any enemy (bee) or otherwise.
Its in my bee class should I state my bee1 class code.
danpost danpost

2018/4/11

#
IlikeThePrequels wrote...
Its in my bee class should I state my bee1 class code.
Yes -- that is where the rotation of the stinger need to be set from as well as where the code can be modified so that the stingers are not streaming out.
You need to login to post a reply.