Compare commits
3 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
d8f7e71f79 | |
|
|
d2a8704ac9 | |
|
|
0bd51788cb |
|
|
@ -12,7 +12,7 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.*;
|
||||||
|
|
||||||
public class Engine extends Canvas {
|
public class Engine extends Canvas {
|
||||||
public static String gameFolder = null;
|
public static String gameFolder = null;
|
||||||
|
|
@ -20,11 +20,12 @@ public class Engine extends Canvas {
|
||||||
public static String startScene = null;
|
public static String startScene = null;
|
||||||
public static String name = null;
|
public static String name = null;
|
||||||
public static BufferStrategy bs = null;
|
public static BufferStrategy bs = null;
|
||||||
|
public static boolean running = true;
|
||||||
|
|
||||||
public Engine(String gameFolder) {
|
public Engine(String gameFolder) {
|
||||||
|
|
||||||
// setup the folder
|
// setup the folder
|
||||||
this.gameFolder = gameFolder;
|
Engine.gameFolder = gameFolder;
|
||||||
|
|
||||||
System.out.println("Engine started with folder " + gameFolder + " ...");
|
System.out.println("Engine started with folder " + gameFolder + " ...");
|
||||||
|
|
||||||
|
|
@ -57,7 +58,7 @@ public class Engine extends Canvas {
|
||||||
this.setPreferredSize(new Dimension(WIDTH, HEIGHT));
|
this.setPreferredSize(new Dimension(WIDTH, HEIGHT));
|
||||||
frame.pack();
|
frame.pack();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
this.requestFocus();
|
this.requestFocus();
|
||||||
this.addKeyListener(new Input());
|
this.addKeyListener(new Input());
|
||||||
this.addMouseMotionListener(new Input());
|
this.addMouseMotionListener(new Input());
|
||||||
|
|
@ -68,8 +69,7 @@ public class Engine extends Canvas {
|
||||||
|
|
||||||
Time.nanos = System.nanoTime();
|
Time.nanos = System.nanoTime();
|
||||||
|
|
||||||
|
while(running) {
|
||||||
while(true) {
|
|
||||||
|
|
||||||
Time.startTime = System.currentTimeMillis();
|
Time.startTime = System.currentTimeMillis();
|
||||||
if (System.currentTimeMillis() > Time.nextSecond) {
|
if (System.currentTimeMillis() > Time.nextSecond) {
|
||||||
|
|
@ -111,9 +111,8 @@ public class Engine extends Canvas {
|
||||||
|
|
||||||
private void loadConfig() throws Exception {
|
private void loadConfig() throws Exception {
|
||||||
|
|
||||||
File configFile = null;
|
|
||||||
try {
|
try {
|
||||||
configFile = new File(gameFolder + File.separatorChar + "build.config");
|
new File(gameFolder + File.separatorChar + "build.config");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new Exception("Configuration File not found");
|
throw new Exception("Configuration File not found");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ public class Input implements KeyListener, MouseListener, MouseMotionListener{
|
||||||
private static boolean[] keys = new boolean[512];
|
private static boolean[] keys = new boolean[512];
|
||||||
private static List<KeyListener> listeners = new ArrayList<KeyListener>();
|
private static List<KeyListener> listeners = new ArrayList<KeyListener>();
|
||||||
public static int mouseX, mouseY;
|
public static int mouseX, mouseY;
|
||||||
|
public static boolean mouse = false;
|
||||||
|
|
||||||
public static void addKeyListener(KeyListener listener) {
|
public static void addKeyListener(KeyListener listener) {
|
||||||
listeners.add(listener);
|
listeners.add(listener);
|
||||||
|
|
@ -61,14 +62,12 @@ public class Input implements KeyListener, MouseListener, MouseMotionListener{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
// TODO Auto-generated method stub
|
mouse = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
// TODO Auto-generated method stub
|
mouse = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -93,12 +93,15 @@ public class SceneManager {
|
||||||
int intValue;
|
int intValue;
|
||||||
try{
|
try{
|
||||||
intValue = Integer.parseInt(value);
|
intValue = Integer.parseInt(value);
|
||||||
}catch(Exception e) {
|
scopeObject.peek().getClass().getField(key).set(scopeObject.peek(), intValue);
|
||||||
|
}catch(NoSuchFieldException e) {
|
||||||
|
System.out.println(value + " isnt a property of " + ((DiveScript)scopeObject.peek()).name + "(" + scopeObject.peek() + ")");
|
||||||
|
continue;
|
||||||
|
}catch(NumberFormatException e) {
|
||||||
System.out.println(value + " is not an int");
|
System.out.println(value + " is not an int");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
scopeObject.peek().getClass().getField(key).set(scopeObject.peek(), intValue);
|
|
||||||
}else if(value.endsWith("F") || value.endsWith("f")) {
|
}else if(value.endsWith("F") || value.endsWith("f")) {
|
||||||
value = value.substring(0, value.length() - 1);
|
value = value.substring(0, value.length() - 1);
|
||||||
|
|
||||||
|
|
@ -137,7 +140,7 @@ public class SceneManager {
|
||||||
}
|
}
|
||||||
} catch( ClassNotFoundException e) {
|
} catch( ClassNotFoundException e) {
|
||||||
try {
|
try {
|
||||||
Object maybeComponent = Class.forName("diveengine2d." + componentClass).newInstance();
|
Object maybeComponent = Class.forName("diveengine2d.components." + componentClass).newInstance();
|
||||||
if(maybeComponent instanceof DiveScript) {
|
if(maybeComponent instanceof DiveScript) {
|
||||||
component = (DiveScript)maybeComponent;
|
component = (DiveScript)maybeComponent;
|
||||||
}else {
|
}else {
|
||||||
|
|
@ -168,7 +171,7 @@ public class SceneManager {
|
||||||
}
|
}
|
||||||
}catch(Exception e) {
|
}catch(Exception e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return entities;
|
return entities;
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ import java.awt.Graphics2D;
|
||||||
public class Tests {
|
public class Tests {
|
||||||
|
|
||||||
public static void run(Graphics2D g) {
|
public static void run(Graphics2D g) {
|
||||||
triangleTest(g);
|
//triangleTest(g);
|
||||||
coordinateTest(g);
|
//coordinateTest(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void coordinateTest(Graphics2D g) {
|
private static void coordinateTest(Graphics2D g) {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
package diveengine2d;
|
package diveengine2d.components;
|
||||||
|
|
||||||
|
import diveengine2d.DiveScript;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
package diveengine2d;
|
package diveengine2d.components;
|
||||||
|
|
||||||
|
import diveengine2d.DebugSettings;
|
||||||
|
import diveengine2d.DiveScript;
|
||||||
|
import diveengine2d.Time;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
package diveengine2d.components.ui;
|
||||||
|
|
||||||
|
import diveengine2d.DiveScript;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Marcus on 3/10/2016.
|
||||||
|
*/
|
||||||
|
public class Button extends DiveScript {
|
||||||
|
|
||||||
|
private static final int NONE = 0;
|
||||||
|
private static final int HOVER = 0;
|
||||||
|
private static final int DOWN = 0;
|
||||||
|
|
||||||
|
public String eventClass = null;
|
||||||
|
public String eventName = null;
|
||||||
|
private Method event;
|
||||||
|
private boolean linked = false;
|
||||||
|
private DiveScript eventListener;
|
||||||
|
private int state = NONE;
|
||||||
|
|
||||||
|
|
||||||
|
public void create() {
|
||||||
|
try {
|
||||||
|
Class<?> eventListenerClass = Class.forName(eventClass);
|
||||||
|
eventListener = entity.getComponent((Class<? extends DiveScript>)eventListenerClass);
|
||||||
|
event = eventListenerClass.getMethod(eventName);
|
||||||
|
linked = true;
|
||||||
|
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue