Shooting java games




















Material; import javax. Node; import javax. PhysicalBody; import javax. PhysicalEnvironment; import javax. PositionInterpolator; import javax. Switch; import javax. Transform3D; import javax.

TransformGroup; import javax. View; import javax. ViewPlatform; import javax. VirtualUniverse; import javax. WakeupCriterion; import javax. WakeupOnCollisionEntry; import javax. WakeupOnElapsedTime; import javax. WakeupOr; import javax. Color3f; import javax. Matrix3d; import javax. Point3d; import javax. Vector3d; import javax. Vector3f; import com. Scene; import com. ObjectFile; import com. Box; import com.

Cylinder; import com. Ok so the code example. First the gameloop. Add the firedBullets for update in the gameloop. Every fired bullet gets moved on its direction vector. So the player should have a method fire. This creates the bullet with position of the player. The bullet gets the same direction as where the player is facing. And the bullet get added to the list so it will be updated every gameloop.

So the direction gets set once when the bullet is fired. Every game update the bullet is moved in this direction by the speed of the bullet. This logic can be used for everything that has to be moved in the game. For example if you want a bullet that changes direction in mid-air you would just change its direction in mid-air.

Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 6 years, 10 months ago. Active 6 years, 10 months ago. Viewed 17k times. I have pasted all my of code below 4 classes : package me. Color; import java. Dimension; import java. Graphics; import java. Image; import java. KeyEvent; import java. KeyListener; import java. BufferedImage; import java.

File; import java. IOException; import javax. ImageIO; import javax. JPanel; import me. Player; import me. Please check the code for any errors! This is my Main class: package me. Container; import java. WindowEvent; import java.

WindowListener; import javax. JFrame; import javax. ImageIO; import me. Thank you very much! Improve this question. Adam 1 1 gold badge 1 1 silver badge 12 12 bronze badges. Grim Reaper Grim Reaper 3 3 gold badges 6 6 silver badges 21 21 bronze badges. I see an over abundance use of static , I'd strongly encourage you to reduce it. A better choice might be to rely more on state models instead.

KeyListener is also questionable. The Key Bindings API would probably provide you with more reliable solution as well as one that is more configurable.



0コメント

  • 1000 / 1000