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

2019/12/19

Need Help Shooting "bullet" at hero!!!

LightningFast LightningFast

2019/12/19

#
here is my code so far, ive tried everything but still can't understand :( HELPP import greenfoot.*; import java.util.*; public class Bullet1 extends Actor { Hero he = new Hero(); List<Hero> h; public void act() { move(); } public void move() { h = getObjectsInRange(1200, Hero.class); //he = h<0> turnTowards(he.getX(), he.getY()); move(2); } }
danpost danpost

2019/12/19

#
Unless these bullets have a guidance system (or are smart bullets), the only thing they should do is move (and maybe remove themselves upon hitting the edge of the world). The enemy that shoots these bullets should set their rotation to be going toward the hero.
LightningFast LightningFast

2019/12/19

#
How would I do that? I mean how would I shoot bullets from enemy? With this code I was thinking of using setLocation or move but just needed help with detecting the hero actor... so yea a smart bullet i guess??
danpost danpost

2019/12/19

#
LightningFast wrote...
How would I do that? I mean how would I shoot bullets from enemy? With this code I was thinking of using setLocation or move but just needed help with detecting the hero actor... so yea a smart bullet i guess??
Maybe I assumed too much. Q1: In what class might I find "new Bullet1()"? Q2: Do you want your Bullet1 objects to turn AS they move across the screen?
LightningFast LightningFast

2019/12/20

#
danpost wrote...
LightningFast wrote...
How would I do that? I mean how would I shoot bullets from enemy? With this code I was thinking of using setLocation or move but just needed help with detecting the hero actor... so yea a smart bullet i guess??
Maybe I assumed too much. Q1: In what class might I find "new Bullet1()"? Q2: Do you want your Bullet1 objects to turn AS they move across the screen?
Q1: idk i kind of just have it as an acter right now, but i could just put it in the enemy class Q2: noo, i want it to detect the actor’s location and move towards it when the int spawn mod 60 == 0 (in the MyWorld). So basically multiple bullets are being shot at the hero and the main goal of the game is for the hero to avoid it go to certain location at the same time. Right now my main problem is shooting bullets at the hero :(
LightningFast LightningFast

2019/12/20

#
To be honest i think i might have made it wayyy too confusing with the arraylist but i was trying to use the logic from another one of my game... so basically you can ignore my use of arraylist
danpost danpost

2019/12/20

#
LightningFast wrote...
Q1: idk i kind of just have it as an acter right now, but i could just put it in the enemy class
Does not have to be an enemy class, especially if it is just the world shooting the bullets.
Q2: noo, i want it to detect the actor’s location and move towards it when the int spawn mod 60 == 0 (in the MyWorld). So basically multiple bullets are being shot at the hero and the main goal of the game is for the hero to avoid it go to certain location at the same time. Right now my main problem is shooting bullets at the hero :(
Show world class codes (entire class).
You need to login to post a reply.