Project as is
This commit is contained in:
commit
085ca8b7ee
15 changed files with 744 additions and 0 deletions
72
src/com/gnarly/game/Main.java
Executable file
72
src/com/gnarly/game/Main.java
Executable file
|
@ -0,0 +1,72 @@
|
|||
package com.gnarly.game;
|
||||
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
import com.gnarly.engine.GameObject;
|
||||
import com.gnarly.engine.Window;
|
||||
import com.gnarly.engine.graphics.ShaderLibrary;
|
||||
|
||||
public class Main {
|
||||
|
||||
Window window;
|
||||
ShaderLibrary shaders;
|
||||
boolean running = true;
|
||||
Map<String, GameObject> objects = new HashMap<>();
|
||||
GameObject block1;
|
||||
GameObject block2;
|
||||
public static Matrix4f projection;
|
||||
|
||||
public Main() {
|
||||
window = new Window(1000, 700, true);
|
||||
shaders = new ShaderLibrary();
|
||||
projection = new Matrix4f().ortho2D(-window.getWidth() / 2, window.getWidth() / 2, -window.getHeight() / 2, window.getHeight() / 2);
|
||||
run();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
objects.put("Stone Block", new GameObject("Stone Block", shaders.getDefault()));
|
||||
objects.put("Spring", new GameObject("Spring", shaders.getDefault(), 4, 2, true));
|
||||
block1 = objects.get("Stone Block").newInstanceOf(0.0f, 0.0f, 0.0f, 0.0f, 8.0f, 1.0f, 0.1f, false);
|
||||
while(running) {
|
||||
input();
|
||||
update(block1);
|
||||
render(block1);
|
||||
running = !window.shouldClose();
|
||||
}
|
||||
}
|
||||
|
||||
public void input() {
|
||||
float force = 0.05f;
|
||||
if(window.isKeyPressed(GLFW_KEY_D)) block1.addForce(0, force);
|
||||
if(window.isKeyPressed(GLFW_KEY_W)) block1.addForce(90, force);
|
||||
else if(window.isKeyPressed(GLFW_KEY_A)) block1.addForce(180, force);
|
||||
else if(window.isKeyPressed(GLFW_KEY_S)) block1.addForce(270, force);
|
||||
if(window.isKeyPressed(GLFW_KEY_RIGHT)) block2.addForce(0, force);
|
||||
if(window.isKeyPressed(GLFW_KEY_UP)) block2.addForce(90, force);
|
||||
else if(window.isKeyPressed(GLFW_KEY_LEFT)) block2.addForce(180, force);
|
||||
else if(window.isKeyPressed(GLFW_KEY_DOWN)) block2.addForce(270, force);
|
||||
if(window.isKeyPressed(GLFW_KEY_ESCAPE)) window.close();
|
||||
}
|
||||
|
||||
public void update(GameObject... gameObjects) {
|
||||
window.update();
|
||||
for (int i = 0; i < gameObjects.length; i++)
|
||||
gameObjects[i].update();
|
||||
}
|
||||
|
||||
public void render(GameObject... gameObjects) {
|
||||
window.clear();
|
||||
for (int i = 0; i < gameObjects.length; i++)
|
||||
gameObjects[i].render();
|
||||
window.swap();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Main();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue