aboutsummaryrefslogtreecommitdiffstats
path: root/src/ru/olamedia/olacraft/weapon
diff options
context:
space:
mode:
Diffstat (limited to 'src/ru/olamedia/olacraft/weapon')
-rw-r--r--src/ru/olamedia/olacraft/weapon/Bullet.java51
-rw-r--r--src/ru/olamedia/olacraft/weapon/BulletScene.java35
-rw-r--r--src/ru/olamedia/olacraft/weapon/package-info.java8
3 files changed, 94 insertions, 0 deletions
diff --git a/src/ru/olamedia/olacraft/weapon/Bullet.java b/src/ru/olamedia/olacraft/weapon/Bullet.java
new file mode 100644
index 0000000..6292bf2
--- /dev/null
+++ b/src/ru/olamedia/olacraft/weapon/Bullet.java
@@ -0,0 +1,51 @@
+package ru.olamedia.olacraft.weapon;
+
+import javax.media.opengl.GL2;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.glu.GLU;
+import javax.media.opengl.glu.GLUquadric;
+import javax.vecmath.Point3f;
+import javax.vecmath.Vector3f;
+
+import org.ode4j.ode.DBody;
+
+public class Bullet {
+ public Point3f location = new Point3f();
+ public Vector3f velocity = new Vector3f();
+ public Vector3f acceleration = new Vector3f(0, -0.98f, 0);
+ public DBody body;
+ public float width = 0.05f;
+ public float height = 0.05f;
+ public float depth = 0.25f;
+ public boolean toRemove = false;
+ private static GLU glu = new GLU();
+
+ public void update(float deltams) {
+ // acceleration.set(velocity);
+ // acceleration.negate();
+ // acceleration.scale(0.1f);
+ // acceleration.y += -0.98f;
+ // velocity.x += acceleration.x * deltams;
+ // velocity.y += acceleration.y * deltams;
+ // velocity.z += acceleration.z * deltams;
+ // float step = deltams;
+ // location.x += velocity.x * deltams;
+ // location.y += velocity.y * deltams;
+ // location.z += velocity.z * deltams;
+ if (body.getPosition().get1() < 0 || body.getPosition().get1() > 100) {
+ // FIXME
+ toRemove = true;
+ }
+ }
+
+ public void render(GLAutoDrawable drawable) {
+ GL2 gl = drawable.getGL().getGL2();
+ gl.glPushMatrix();
+ gl.glTranslated(body.getPosition().get0(), body.getPosition().get1(), body.getPosition().get2());
+ GLUquadric bulletGeom = glu.gluNewQuadric();
+ glu.gluQuadricDrawStyle(bulletGeom, GLU.GLU_FILL);
+ glu.gluQuadricNormals(bulletGeom, GLU.GLU_SMOOTH);
+ glu.gluDisk(bulletGeom, 0.3, 0.4, 5, 5);
+ gl.glPopMatrix();
+ }
+}
diff --git a/src/ru/olamedia/olacraft/weapon/BulletScene.java b/src/ru/olamedia/olacraft/weapon/BulletScene.java
new file mode 100644
index 0000000..1e5ea05
--- /dev/null
+++ b/src/ru/olamedia/olacraft/weapon/BulletScene.java
@@ -0,0 +1,35 @@
+package ru.olamedia.olacraft.weapon;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.media.opengl.GLAutoDrawable;
+
+public class BulletScene {
+ private List<Bullet> bullets = new ArrayList<Bullet>();
+
+ public void add(Bullet b) {
+ bullets.add(b);
+ }
+
+ public int getCount(){
+ return bullets.size();
+ }
+
+ public void update(float deltas) {
+ for (int i = 0; i < bullets.size(); i++) {
+ Bullet b = bullets.get(i);
+ b.update(deltas);
+ if (b.toRemove) {
+ bullets.remove(b);
+ i--;
+ }
+ }
+ }
+
+ public void render(GLAutoDrawable drawable) {
+ for (Bullet b : bullets) {
+ b.render(drawable);
+ }
+ }
+}
diff --git a/src/ru/olamedia/olacraft/weapon/package-info.java b/src/ru/olamedia/olacraft/weapon/package-info.java
new file mode 100644
index 0000000..89ca87c
--- /dev/null
+++ b/src/ru/olamedia/olacraft/weapon/package-info.java
@@ -0,0 +1,8 @@
+/**
+ *
+ */
+/**
+ * @author olamedia
+ *
+ */
+package ru.olamedia.olacraft.weapon; \ No newline at end of file