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

2012/3/13

Bullet problems

armoredarmada armoredarmada

2012/3/13

#
Hello this is again for my two player shooter. Everything is typed correct but the 2nd soldier wont shoot. The first soldier uses bullet under the subclass Mover. the second soldier uses bullet1 under subclass Mover1. Should I have both soldiers using bullet and Mover, or is there another solution?
danpost danpost

2012/3/13

#
You should only need one Mover (super) class. As far as bullet classes, you could use the same for both soldiers or use seperate classes for each soldier (since the action of the bullet is the same for either player, I would suggest you use only one bullet class (used by both soldiers); otherwise, you are just duplicating code, which in turn can get a bit confusing.
armoredarmada armoredarmada

2012/3/13

#
Ok in the actor classes, theres only ppl1 and ppl2 (my soldiers) the Mover, and the bullet which is the subclass of Mover, the soldiers' codes are the same besides controls. They both use the same code for shooting bullets, any other ideas?
danpost danpost

2012/3/13

#
If the soldiers are pretty much the same except for the keys (i assume one uses 'WASD' and the other 'ARROWS') you could use the same class for them also. Create a constructor that accepts either a boolean (true/false) or an int (1/-1) or really anything to distinguish the two, and set the value to an instance variable in the Soldier class. You can check its value to see which soldier is being acted on to determine good keypresses.
armoredarmada armoredarmada

2012/3/13

#
sorry but this is only my second day using this so I dont understand boolean or int. (please explain). I also have to use seperate bullet actors because ppl1 shoots a bullet designed to delete both soldiers, thus killing himself, so is it possible to use two bullet actors under one Mover actor?
danpost danpost

2012/3/13

#
Instead of explaining, I am going to direct you to someplace that you can get that information. The 'Oracle' or 'Java' site contains an extensive library of tutorials. I suggest you go to The Java Tutorials . The second section on the left, titled in red, you will see 'Trails Covering the Basics'. That would be the perfect place to start.
armoredarmada armoredarmada

2012/3/13

#
that answers my vocab problem, but not my shooter problem, if u do know, how would you have two players shoot bullets. Mine is set up so each soldier has thier own Mover and bullet.
danpost danpost

2012/3/13

#
Like I said, you can use the same Player class to instantiate both players. Act() will run on each player on each cycle. A bullet created from the Player class will come from the specific player that is being acted on. If need be, you can track the number of bullets remaining for each player also (all with the same code). This also means that the bullets can be created from the same Bullet class.
armoredarmada armoredarmada

2012/3/13

#
The bullets have to be in seperate classes so they dont remove the shooter, I literary went through the shooting codes of each shooter FIVE times, they are EXACTLY the same except for the bullet names and the key to execute the order. But I dont know why the second shooter "ppl2" wont shoot. I have the two bullet classes under Mover which is the script off this site to have any object thats a subclass of it to move in direction equal to the angle of it's shooter. I tried two bullets under one Mover and two bullets under two Movers. Anything else I can do?
danpost danpost

2012/3/13

#
Again, you only need ONE Bullet class under ONE Mover class. And why do they have a 'key to execute the order'? The player class should check for the keypresses and create the bullets and set their rotation, then have the world add them.
armoredarmada armoredarmada

2012/3/13

#
a "key to execute order" was the same as what you said, i just couldnt find the words. heres the ppl1 shooter code: if(";".equals(Greenfoot.getKey())) { bullet ball = new bullet(); getWorld().addObject(ball, getX(), getY()); ball.setRotation(getRotation()); And it is IMPOSSIBLE to use one bullet class because that bullet is programmed to remove any actor from the game on contact (ppl1 and ppl2). If theres another way to make it use only one bullet class then PLEASE tell me. I want to get this game done ASAP so I can show my friend at school. And after I graduate college, I want to be a video game designer so I would love to learn as much as I can.
You need to login to post a reply.