master
王宇洋 3 years ago
parent b00ee488f1
commit 2f4ebca336

@ -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.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -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<String, Texture> textures) {
super(origin, position, scale, textures);
}
public Bullet(Point4f origin, Point4f position, Vector4f scale, Vector4f rotation, HashMap<String, Texture> 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;
}
}

@ -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)) {

@ -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);
}

@ -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);
}

@ -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;
}

@ -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;
}

@ -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

Loading…
Cancel
Save