diff --git a/README.md b/README.md index 624765d..13fe810 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,8 @@ But in the video, I am using a Mac computer so the FPS might not very high... WASD to move. Space to jump. F to change the perspective. +Shift to go up +Enter to go down That's it. diff --git a/bin/Scene/Objects/Bullet.class b/bin/Scene/Objects/Bullet.class new file mode 100644 index 0000000..83afaa5 Binary files /dev/null and b/bin/Scene/Objects/Bullet.class differ diff --git a/bin/Scene/Objects/Player.class b/bin/Scene/Objects/Player.class index 9befcaa..deb487e 100644 Binary files a/bin/Scene/Objects/Player.class and b/bin/Scene/Objects/Player.class differ diff --git a/bin/Scene/Scene$1.class b/bin/Scene/Scene$1.class index 9ec413c..72ee031 100644 Binary files a/bin/Scene/Scene$1.class and b/bin/Scene/Scene$1.class differ diff --git a/bin/Scene/Scene$2.class b/bin/Scene/Scene$2.class index 5eee91c..1e54138 100644 Binary files a/bin/Scene/Scene$2.class and b/bin/Scene/Scene$2.class differ diff --git a/bin/Scene/Scene$3.class b/bin/Scene/Scene$3.class index 54f0736..b31f30c 100644 Binary files a/bin/Scene/Scene$3.class and b/bin/Scene/Scene$3.class differ diff --git a/bin/Scene/Scene$4.class b/bin/Scene/Scene$4.class index 711acd7..aefeee1 100644 Binary files a/bin/Scene/Scene$4.class and b/bin/Scene/Scene$4.class differ diff --git a/bin/Scene/Scene$5.class b/bin/Scene/Scene$5.class index 758975a..c16a241 100644 Binary files a/bin/Scene/Scene$5.class and b/bin/Scene/Scene$5.class differ diff --git a/bin/Scene/Scene.class b/bin/Scene/Scene.class index 8ab2ae1..e2633fb 100644 Binary files a/bin/Scene/Scene.class and b/bin/Scene/Scene.class differ diff --git a/bin/Scene/base/SceneManager.class b/bin/Scene/base/SceneManager.class index 80f48f4..7fc8005 100644 Binary files a/bin/Scene/base/SceneManager.class and b/bin/Scene/base/SceneManager.class differ diff --git a/bin/main/Camera.class b/bin/main/Camera.class index 8f8ce0f..123fde5 100644 Binary files a/bin/main/Camera.class and b/bin/main/Camera.class differ diff --git a/bin/main/Engine.class b/bin/main/Engine.class index 693afe0..4e9afc5 100644 Binary files a/bin/main/Engine.class and b/bin/main/Engine.class differ diff --git a/bin/main/Main$1.class b/bin/main/Main$1.class index 6f2a29e..db39181 100644 Binary files a/bin/main/Main$1.class and b/bin/main/Main$1.class differ diff --git a/bin/main/Main$2.class b/bin/main/Main$2.class index 2089e7e..ec60879 100644 Binary files a/bin/main/Main$2.class and b/bin/main/Main$2.class differ diff --git a/bin/main/Main$3.class b/bin/main/Main$3.class index a1a26ae..8c6e22e 100644 Binary files a/bin/main/Main$3.class and b/bin/main/Main$3.class differ diff --git a/bin/main/Main.class b/bin/main/Main.class index a4527a8..9a8cecd 100644 Binary files a/bin/main/Main.class and b/bin/main/Main.class differ diff --git a/src/Scene/Objects/Bullet.java b/src/Scene/Objects/Bullet.java new file mode 100644 index 0000000..c4c59a2 --- /dev/null +++ b/src/Scene/Objects/Bullet.java @@ -0,0 +1,82 @@ +package Scene.Objects; + +import Scene.base.SceneObject; +import base.GraphicsObjects.Point4f; +import base.GraphicsObjects.Vector4f; +import base.objects3D.DisplayListTexSphere; +import org.lwjgl.opengl.GL11; +import org.newdawn.slick.Color; +import org.newdawn.slick.opengl.Texture; + +import java.util.HashMap; + +import static org.lwjgl.opengl.GL11.GL_NEAREST; +import static org.lwjgl.opengl.GL11.GL_TEXTURE_MIN_FILTER; + +/** + * @Author: WangYuyang + * @Date: 2021/12/14-15:52 + * @Project: Assignment3 + * @Package: Scene.Objects + * @Description: + **/ +public class Bullet extends SceneObject { + DisplayListTexSphere sphere = new DisplayListTexSphere(1f, 16, 16, getTextures().get("wool_pink")); + private Vector4f direction = new Vector4f(); + private Integer drawCount = 0; + + public Bullet(Point4f origin, Point4f position, Vector4f scale) { + super(origin, position, scale); + } + + public Bullet(Point4f origin, Point4f position, Vector4f scale, HashMap textures) { + super(origin, position, scale, textures); + } + + public Bullet(Point4f origin, Point4f position, Vector4f scale, Vector4f rotation, HashMap textures) { + super(origin, position, scale, rotation, textures); + } + + @Override + public void draw(Integer delta) { + drawCount += 1; + move(direction.Normal()); + GL11.glTexParameteri( + GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, + GL11.GL_REPEAT); + GL11.glTexParameteri( + GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, + GL11.GL_REPEAT); + Color.white.bind(); +// Color.black.bind(); + //bind texture + getTextures().get("debug").bind(); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); +// oval.DrawOval(); + sphere.DrawTexSphere(); + + Color.white.bind(); + + } + + public DisplayListTexSphere getSphere() { + return sphere; + } + + public void setSphere(DisplayListTexSphere sphere) { + this.sphere = sphere; + } + + public Vector4f getDirection() { + return direction; + } + + public void setDirection(Vector4f direction) { + this.direction = direction; + } + + public Integer getDrawCount() { + return drawCount; + } +} diff --git a/src/Scene/Objects/Player.java b/src/Scene/Objects/Player.java index 050c897..bea917f 100644 --- a/src/Scene/Objects/Player.java +++ b/src/Scene/Objects/Player.java @@ -734,6 +734,9 @@ public class Player extends SceneObject { player.setAngle(angle); } if (Keyboard.isKeyDown(Keyboard.KEY_RETURN)) { + if (getPosition().y < 0) { + speedY = 0; + } move = move.PlusVector(new Vector4f(0, -speedY, 0, 0)); } if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) { diff --git a/src/Scene/Scene.java b/src/Scene/Scene.java index f0f96f0..91aa4a8 100644 --- a/src/Scene/Scene.java +++ b/src/Scene/Scene.java @@ -5,6 +5,10 @@ import Scene.base.*; import Scene.skybox.Skybox; import base.GraphicsObjects.Point4f; import base.GraphicsObjects.Vector4f; +import main.Camera; +import main.Engine; +import main.Main; +import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import org.lwjgl.util.vector.Vector3f; @@ -40,6 +44,7 @@ public class Scene { public static BunnyTestObject bunnyTestObject; public static NPC center; public static float bookRotate_Speed = 0.1f; + private static Integer bullet_counter = 0; // private static ParticleEmitter rightParticleEmitter = new ParticleEmitterBuilder() @@ -740,6 +745,25 @@ public class Scene { } public static void drawScene(SceneManager sceneManager, Integer delta) { + if (Mouse.isButtonDown(0) & bullet_counter <= 0) { + bullet_counter = 30; + Bullet bullet = new Bullet( + Scene.player.getOrigin(), + Scene.player.getPosition(), + new Vector4f(90, 90, 90, 0), + Engine.getTextures() + ); + bullet.setDirection(new Vector4f( + (float) Math.sin(Math.toRadians(180 - Camera.rotation.y)), + 0, + (float) Math.cos(Math.toRadians(180 - Camera.rotation.y)), + 0 + )); + sceneManager.addSceneObject(bullet); + } + if (bullet_counter > 0) { + bullet_counter--; + } sceneManager.drawAll(new IDrawListener() { @Override public void beforeEachDraw(SceneObject object) { @@ -749,6 +773,14 @@ public class Scene { @Override public void afterEachDraw(SceneObject object) { GL11.glPopMatrix(); + if (object instanceof Bullet) { + Bullet bullet = (Bullet) object; + if (!Main.harmless) + sceneManager.BulletHit(bullet); + if (bullet.getDrawCount() >= 300) { + sceneManager.remove(bullet); + } + } } }, delta); } diff --git a/src/Scene/base/SceneManager.java b/src/Scene/base/SceneManager.java index 3769672..0069328 100644 --- a/src/Scene/base/SceneManager.java +++ b/src/Scene/base/SceneManager.java @@ -1,5 +1,9 @@ package Scene.base; +import Scene.Objects.Bullet; +import Scene.Objects.Player; +import base.GraphicsObjects.Point4f; + import java.util.ArrayList; /** @@ -18,6 +22,22 @@ public class SceneManager { } } + public void remove(SceneObject sceneObject) { + sceneObjects.remove(sceneObject); + } + + public void BulletHit(Bullet bullet) { + for (int i = 0; i < sceneObjects.size(); i++) { +// System.out.println(sceneObjects.get(i).getWorldPosition().MinusPoint(new Point4f(bullet.getWorldPosition().x, bullet.getWorldPosition().y, bullet.getWorldPosition().z, 1)).length()); + if (sceneObjects.get(i).getWorldPosition().MinusPoint(new Point4f(bullet.getWorldPosition().x, bullet.getWorldPosition().y, bullet.getWorldPosition().z, 1)).length() < 100) { + if (!(sceneObjects.get(i) instanceof Bullet) && !(sceneObjects.get(i) instanceof Player)) { + sceneObjects.remove(i); + } + + } + } + } + public void addSceneObject(SceneObject sceneObject) { sceneObjects.add(sceneObject); } diff --git a/src/main/Camera.java b/src/main/Camera.java index ec49d3b..2e70a7f 100644 --- a/src/main/Camera.java +++ b/src/main/Camera.java @@ -149,7 +149,11 @@ public class Camera { if (Keyboard.isKeyDown(Keyboard.KEY_RETURN)) { - position.y -= speed; + if (position.y < 0) { + + } else { + position.y -= speed; + } } if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { position.y += speed; @@ -209,8 +213,8 @@ public class Camera { rotation.x = maxLookUp; } } - if (!Mouse.isButtonDown(0)) - Player.angle_target = 180 - (int) rotation.y; +// if (!Mouse.isButtonDown(0)) + Player.angle_target = 180 - (int) rotation.y; } diff --git a/src/main/Engine.java b/src/main/Engine.java index 1fb77ed..ffb3c22 100644 --- a/src/main/Engine.java +++ b/src/main/Engine.java @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.LinkedHashMap; import static main.Main.camera; +import static main.Main.harmless; import static main.ShaderLoader.loadShaders; import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.util.glu.GLU.gluPerspective; @@ -375,7 +376,7 @@ public class Engine { public void updateFPS() { if (getTime() - lastFPS > 1000) { - Display.setTitle("FPS: " + fps); + Display.setTitle("FPS: " + fps + " | " + "Harmless: " + harmless); fps = 0; lastFPS += 1000; } diff --git a/src/main/Main.java b/src/main/Main.java index 080af05..357a391 100644 --- a/src/main/Main.java +++ b/src/main/Main.java @@ -33,6 +33,7 @@ public class Main { public static SceneManager sceneManager = new SceneManager(); public static SceneManager backgroundManager = new SceneManager(); public static Camera camera = new Camera(); + public static Boolean harmless = true; private static boolean isBigScreen = false; private static Boolean setUpFinish = true; private static Boolean FPS_MODE = false; @@ -279,6 +280,13 @@ public class Main { setUpFinish = false; } + if (Keyboard.isKeyDown(Keyboard.KEY_L)) { + harmless = true; + } + if (Keyboard.isKeyDown(Keyboard.KEY_H)) { + harmless = false; + } + if (FPS_MODE) { camera.setCamera(new Vector4f( 0, -300, 0, 0