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

2018/8/29

SpaceFighter_Skeleton.gfar

171828135 171828135

2018/8/29

#
this game contains of Aliens actors that need to move up and down.The problem i have is that i can't to make the shots fired from the middle center of the Aliens ship every 100 counts.
danpost danpost

2018/8/29

#
171828135 wrote...
this game contains of Aliens actors that need to move up and down.The problem i have is that i can't to make the shots fired from the middle center of the Aliens ship every 100 counts.
What code have you tried and where did you put it? Use code tags.
171828135 171828135

2018/8/29

#
int counter = 5; int direction = 0; int hits = 0; int score = 0; GreenfootImage img1; public Aliens() { img1 = new GreenfootImage("Ship.png"); setImage(img1); setRotation(90); } public void act() { // Add your action code here. shooting(); mover(); hits(); } public void shooting() { getWorld().addObject(new eBullet(),getX(), getY()); } public void mover() { if (direction==0) setLocation(getX(),getY()+5); else setLocation(getX(), getY()-5); if (isAtEdge()) { if (direction==0) direction=1; else direction=0; } } public void hits() { if(isTouching(pBullet.class)) { removeTouching(pBullet.class); } } } This is the code for Aliens that i have used but it's not working properly
danpost danpost

2018/8/29

#
Currently, you have a counter field and its value set to 5 (line 1), but its value is not changed or checked on. I presume the counter field is to be used for shooting; however 5 is not 100, which is the critical value you gave above. I would start the field at zero and increment it until 100 is reached, then add an eBullet object into the world and reset the field:
// field (line 1)
private int counter;

// in shooting method
counter = (counter+1)%100; // increments to AND resets to zero at 100
if (counter == 0) getWorld().addObject(new eBullet(), getX(), getY());
171828135 171828135

2018/8/29

#
it's not working
danpost danpost

2018/8/29

#
171828135 wrote...
it's not working
Show Aliens and eBullet class codes. Use code tags. Also, explain exactly what is not working (and what it is currently doing that you don't want).
171828135 171828135

2018/9/3

#
fine guys i got it it's working now thank you all for your support
171828135 171828135

2018/9/5

#
hy guys it's me again,can you please help to make my Asteroid to float
danpost danpost

2018/9/5

#
171828135 wrote...
hy guys it's me again,can you please help to make my Asteroid to float
You need to be more specific and show some attempted code. What do you mean by "float"? Would it be moving at all and, if so, how? (in detail)
You need to login to post a reply.