package detectiongame.dungen;
import engine.Entity;
import engine.GfxEngine;
import engine.Vec3f;
import engine.Light;
import engine.model.Material;
import engine.model.ObjModel;
import engine.model.OverlayMap;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import static org.lwjgl.opengl.GL11.*;
public class DunGen extends GfxEngine {
private Light light;
private Entity lightbulb;
private Vec3f lightbulb_offset;
private Clock clock;
private Entity skybox;
private WallGen walls;
private boolean drawMinimap = true;
private Runtime r = Runtime.getRuntime();
/*public static void main(String[] args ) {
System.out.println("program started");
DunGen game = new DunGen();
game.DISPLAY_WIDTH = 1280;
game.DISPLAY_HEIGHT = 800;
game.start();
} */
public void processKeyboard() {
float xrotrad,yrotrad,mul=appSpeed();
if(Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) == false) {
mul *= 0.2;
}
xrotrad = (float)Math.toRadians(this.camera.getRot().x);
yrotrad = (float)Math.toRadians(this.camera.getRot().y);
if(Keyboard.isKeyDown(Keyboard.KEY_W)) {
camera.move((float)Math.sin(yrotrad)*mul, -(float)Math.sin(xrotrad)*mul, -(float)Math.cos(yrotrad)*mul);
}
if(Keyboard.isKeyDown(Keyboard.KEY_S)) {
camera.move(-(float)Math.sin(yrotrad)*mul, (float)Math.sin(xrotrad)*mul, (float)Math.cos(yrotrad)*mul);
}
if(Keyboard.isKeyDown(Keyboard.KEY_A)) {
camera.move(-(float)Math.cos(yrotrad)*mul, 0f, -(float)Math.sin(yrotrad)*mul);
}
if(Keyboard.isKeyDown(Keyboard.KEY_D)) {
camera.move((float)Math.cos(yrotrad)*mul, 0f, (float)Math.sin(yrotrad)*mul);
}
if(Keyboard.isKeyDown(Keyboard.KEY_F)) {
}
if(Keyboard.isKeyDown(Keyboard.KEY_I)) {
this.lightbulb_offset.z -= mul;
}
if(Keyboard.isKeyDown(Keyboard.KEY_K)) {
this.lightbulb_offset.z += mul;
}
if(Keyboard.isKeyDown(Keyboard.KEY_J)) {
this.lightbulb_offset.x -= mul;
}
if(Keyboard.isKeyDown(Keyboard.KEY_L)) {
this.lightbulb_offset.x += mul;
}
if(Keyboard.isKeyDown(Keyboard.KEY_U)) {
this.lightbulb_offset.y -= mul;
}
if(Keyboard.isKeyDown(Keyboard.KEY_O)) {
this.lightbulb_offset.y += mul;
}
while( Keyboard.next() ){
int key = Keyboard.getEventKey();
boolean down = Keyboard.getEventKeyState();
boolean repeat = Keyboard.isRepeatEvent();
char c = Keyboard.getEventCharacter();
if(c == '1' && repeat == false) {
this.toggleWireframes();
}
else if(c == '2' && repeat == false) {
this.drawMinimap = (this.drawMinimap == true)?false:true;
}
else if(c == 'r' && repeat == false) {
reloadShaders();
}
else if(c == 'R' && repeat == false) {
reloadTextures();
}
else if(c == 'g' && repeat == false) {
}
else if(c == 'h' && repeat == false) {
}
if(Keyboard.getEventKeyState()){
if(key == Keyboard.KEY_LEFT){
this.walls.moveCurrentCell(-1, 0);
}
else if(key == Keyboard.KEY_RIGHT){
this.walls.moveCurrentCell(1, 0);
}
else if(key == Keyboard.KEY_UP){
this.walls.moveCurrentCell(0, -1);
}
else if(key == Keyboard.KEY_DOWN){
this.walls.moveCurrentCell(0, 1);
}
if(key == Keyboard.KEY_DELETE){
System.gc();
}
/*
if(key == Keyboard.KEY_END){
try {
for(int wx=0;wx<this.worldSize;wx++){
for(int wz=0;wz<this.worldSize;wz++){
this.world[wz][wx].saveToFile();
}}
} catch (FileNotFoundException ex) {
Logger.getLogger(DunGen.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(DunGen.class.getName()).log(Level.SEVERE, null, ex);
}
}
if(key == Keyboard.KEY_HOME){
try {
for(int wx=0;wx<this.worldSize;wx++){
for(int wz=0;wz<this.worldSize;wz++){
this.world[wz][wx].readFromFile();
}}
// this.world[7][7].free();
// this.world[7][7].rebuild();
} catch (FileNotFoundException ex) {
Logger.getLogger(DunGen.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(DunGen.class.getName()).log(Level.SEVERE, null, ex);
}
}
*/
}
}
}
public void processMouse() {
if(Mouse.isButtonDown(0)) {
if( Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) ||
Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
//camera.getPos().x -= (float)Mouse.getDX();
camera.move(-(float)Mouse.getDX()*2, -(float)Mouse.getDY()*2, 0f);
//camera.getPos().y -= (float)Mouse.getDY();
}
else if(Keyboard.isKeyDown(Keyboard.KEY_RCONTROL) ||
Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) {
//camera.getPos().x -= (float)Mouse.getDX();
camera.move(0f, -(float)Mouse.getDY()*2, -(float)Mouse.getDX()*2);
//camera.getPos().y -= (float)Mouse.getDY();
}else {
camera.getRot().x -= (float)Mouse.getDY()*0.5;
camera.getRot().x = Math.min(90.0f, camera.getRot().x);
camera.getRot().x = Math.max(-90.0f, camera.getRot().x);
camera.getRot().y += (float)Mouse.getDX()*0.5;
}
}
}
@Override
public void init() {
loadModel("tile_wall2_corner_0.obj").setDefaultMaterial(loadMaterial("tile_wall2.mat"));
loadModel("tile_wall2_corner_1.obj").setDefaultMaterial(loadMaterial("tile_wall2.mat"));
loadModel("tile_wall2_corner_2.obj").setDefaultMaterial(loadMaterial("tile_wall2.mat"));
loadModel("tile_wall2_pylon.obj").setDefaultMaterial(loadMaterial("tile_wall2.mat"));
this.clock = new Clock(500);
this.light = new Light(0);
skybox = new Entity();
skybox.setScale(30f);
skybox.setModel(loadModel("skybox.obj"));
this.lightbulb = new Entity();
this.lightbulb.setModel(loadModel("bulb.obj"));
this.lightbulb_offset = new Vec3f(0,0,0);
this.walls = new WallGen(32, 25, 100000);
//light.move(100f, 10f, 100f);
light.setPos((7+1)*250f,10f,(7+2.5f)*250-500);
//camera.setPos(new Vec3f((7+1)*250f-125,500f,(7+2.5f)*250));
camera.setPos(this.walls.getLightPos());
camera.move(0f, 3f, 2f);
camera.setRot(new Vec3f(15,0,0));
}
@Override
public void update() {
if(Display.isVisible()) {
this.processKeyboard();
this.processMouse();
}
this.skybox.setPos(this.camera.getPos());
this.lightbulb.setPos(this.light.getPos().x, this.light.getPos().y, this.light.getPos().z);
this.lightbulb.rotate(0, appSpeed(), 0);
this.walls.update();
}
@Override
public void drawEntities(){
//this.light.drawDebug();
glDisable(GL_DEPTH_TEST);
this.skybox.exist();
glEnable(GL_DEPTH_TEST);
//this.lightbulb.existDebug();
this.walls.exist();
this.lightbulb.exist();
/*
this.light.depthRender(this.camera.getPos(), new Vec3f(0,0,0));
this.walls.exist();
this.light.depthRenderEnd();
*/
}
@Override
public void drawOverlay(){
if(this.drawMinimap == true) {
this.walls.drawMinimap(this.camera.getRot());
}
//this.light.drawShadowDebug();
}
@Override
public void lights(){
light.setPos(this.walls.getLightPos().x+this.lightbulb_offset.x, this.walls.getLightPos().y+this.lightbulb_offset.y, this.walls.getLightPos().z+this.lightbulb_offset.z);
light.exist();
}
}