|
|
@ -14,7 +14,6 @@ import sig.engine.Point; |
|
|
|
import sig.map.Maps; |
|
|
|
import sig.map.Maps; |
|
|
|
import sig.objects.ConfigureControls; |
|
|
|
import sig.objects.ConfigureControls; |
|
|
|
import sig.objects.EditorRenderer; |
|
|
|
import sig.objects.EditorRenderer; |
|
|
|
import sig.objects.Erinoah; |
|
|
|
|
|
|
|
import sig.objects.LevelRenderer; |
|
|
|
import sig.objects.LevelRenderer; |
|
|
|
import sig.objects.Player; |
|
|
|
import sig.objects.Player; |
|
|
|
import sig.engine.Key; |
|
|
|
import sig.engine.Key; |
|
|
@ -25,18 +24,19 @@ import sig.engine.PaletteColor; |
|
|
|
import java.awt.Toolkit; |
|
|
|
import java.awt.Toolkit; |
|
|
|
import java.awt.event.KeyEvent; |
|
|
|
import java.awt.event.KeyEvent; |
|
|
|
|
|
|
|
|
|
|
|
public class RabiClone{ |
|
|
|
public class RabiClone { |
|
|
|
public static final String PROGRAM_NAME="RabiClone"; |
|
|
|
public static final String PROGRAM_NAME = "RabiClone"; |
|
|
|
|
|
|
|
public static final String BLANK = "\0"; |
|
|
|
|
|
|
|
|
|
|
|
public static int UPCOUNT=0; |
|
|
|
public static int UPCOUNT = 0; |
|
|
|
public static Panel p; |
|
|
|
public static Panel p; |
|
|
|
public static JFrame f; |
|
|
|
public static JFrame f; |
|
|
|
|
|
|
|
|
|
|
|
public static List<Object> OBJ = new ArrayList<Object>(); |
|
|
|
public static List<Object> OBJ = new ArrayList<Object>(); |
|
|
|
|
|
|
|
|
|
|
|
public static int BASE_WIDTH=512; |
|
|
|
public static int BASE_WIDTH = 512; |
|
|
|
public static int BASE_HEIGHT=288; |
|
|
|
public static int BASE_HEIGHT = 288; |
|
|
|
public static int SIZE_MULTIPLIER=1; |
|
|
|
public static int SIZE_MULTIPLIER = 1; |
|
|
|
public static Point MOUSE_POS; |
|
|
|
public static Point MOUSE_POS; |
|
|
|
|
|
|
|
|
|
|
|
public static PaletteColor BACKGROUND_COLOR = PaletteColor.DARK_ORCHID; |
|
|
|
public static PaletteColor BACKGROUND_COLOR = PaletteColor.DARK_ORCHID; |
|
|
@ -46,35 +46,35 @@ public class RabiClone{ |
|
|
|
public static Player player; |
|
|
|
public static Player player; |
|
|
|
|
|
|
|
|
|
|
|
public static Maps CURRENT_MAP = Maps.WORLD1; |
|
|
|
public static Maps CURRENT_MAP = Maps.WORLD1; |
|
|
|
public static Controller[] CONTROLLERS = new Controller[]{}; |
|
|
|
public static Controller[] CONTROLLERS = new Controller[] {}; |
|
|
|
|
|
|
|
|
|
|
|
public static long lastControllerScan = System.currentTimeMillis(); |
|
|
|
public static long lastControllerScan = System.currentTimeMillis(); |
|
|
|
|
|
|
|
|
|
|
|
static long lastUpdate=System.nanoTime(); |
|
|
|
static long lastUpdate = System.nanoTime(); |
|
|
|
final static long TARGET_FRAMETIME = 8333333l; |
|
|
|
final static long TARGET_FRAMETIME = 8333333l; |
|
|
|
static long lastReportedTime=System.currentTimeMillis(); |
|
|
|
static long lastReportedTime = System.currentTimeMillis(); |
|
|
|
|
|
|
|
public static long TIME = 0; |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
|
|
|
|
|
|
Key.InitializeKeyConversionMap(); |
|
|
|
Key.InitializeKeyConversionMap(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
f = new JFrame(PROGRAM_NAME); |
|
|
|
f = new JFrame(PROGRAM_NAME); |
|
|
|
f.setResizable(false); |
|
|
|
f.setResizable(false); |
|
|
|
f.setUndecorated(true); |
|
|
|
f.setUndecorated(true); |
|
|
|
f.setSize(BASE_WIDTH,BASE_HEIGHT); //1024x576 (64x64)
|
|
|
|
f.setSize(BASE_WIDTH, BASE_HEIGHT); // 1024x576 (64x64)
|
|
|
|
ChooseBestRatio(); |
|
|
|
ChooseBestRatio(); |
|
|
|
|
|
|
|
|
|
|
|
p = new Panel(f); |
|
|
|
p = new Panel(f); |
|
|
|
|
|
|
|
|
|
|
|
MOUSE_POS=p.mousePos; |
|
|
|
MOUSE_POS = p.mousePos; |
|
|
|
|
|
|
|
|
|
|
|
p.init(); |
|
|
|
p.init(); |
|
|
|
|
|
|
|
|
|
|
|
f.add(p); |
|
|
|
f.add(p); |
|
|
|
f.addKeyListener(p); |
|
|
|
f.addKeyListener(p); |
|
|
|
f.setLocation((int)((Toolkit.getDefaultToolkit().getScreenSize().getWidth()-f.getWidth())/2), (int)((Toolkit.getDefaultToolkit().getScreenSize().getHeight()-f.getHeight())/2)); |
|
|
|
f.setLocation((int) ((Toolkit.getDefaultToolkit().getScreenSize().getWidth() - f.getWidth()) / 2), |
|
|
|
|
|
|
|
(int) ((Toolkit.getDefaultToolkit().getScreenSize().getHeight() - f.getHeight()) / 2)); |
|
|
|
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
|
|
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
|
|
f.setVisible(true); |
|
|
|
f.setVisible(true); |
|
|
|
|
|
|
|
|
|
|
@ -87,13 +87,13 @@ public class RabiClone{ |
|
|
|
long dt = 0; |
|
|
|
long dt = 0; |
|
|
|
|
|
|
|
|
|
|
|
CONTROLLERS = ControllerEnvironment.getDefaultEnvironment().getControllers(); |
|
|
|
CONTROLLERS = ControllerEnvironment.getDefaultEnvironment().getControllers(); |
|
|
|
while (true) { |
|
|
|
|
|
|
|
dt += System.nanoTime()-lastGameTime; |
|
|
|
|
|
|
|
lastGameTime=System.nanoTime(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (true) { |
|
|
|
|
|
|
|
dt += System.nanoTime() - lastGameTime; |
|
|
|
|
|
|
|
lastGameTime = System.nanoTime(); |
|
|
|
|
|
|
|
|
|
|
|
while (dt>=(1/244d)*1000000000l) { |
|
|
|
while (dt >= (1 / 244d) * 1000000000l) { |
|
|
|
final double updateMult = 1/244d; |
|
|
|
final double updateMult = 1 / 244d; |
|
|
|
handleGameControllers(); |
|
|
|
handleGameControllers(); |
|
|
|
|
|
|
|
|
|
|
|
KeyBind.poll(); |
|
|
|
KeyBind.poll(); |
|
|
@ -101,7 +101,7 @@ public class RabiClone{ |
|
|
|
if (Key.isKeyHeld(KeyEvent.VK_F1)) { |
|
|
|
if (Key.isKeyHeld(KeyEvent.VK_F1)) { |
|
|
|
if (level_renderer instanceof EditorRenderer) { |
|
|
|
if (level_renderer instanceof EditorRenderer) { |
|
|
|
OBJ.remove(level_renderer); |
|
|
|
OBJ.remove(level_renderer); |
|
|
|
OBJ.add(level_renderer=new LevelRenderer(p)); |
|
|
|
OBJ.add(level_renderer = new LevelRenderer(p)); |
|
|
|
StartGame(); |
|
|
|
StartGame(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -109,73 +109,78 @@ public class RabiClone{ |
|
|
|
if (!(level_renderer instanceof EditorRenderer)) { |
|
|
|
if (!(level_renderer instanceof EditorRenderer)) { |
|
|
|
OBJ.clear(); |
|
|
|
OBJ.clear(); |
|
|
|
ResetGame(); |
|
|
|
ResetGame(); |
|
|
|
OBJ.add(level_renderer=new EditorRenderer(p)); |
|
|
|
OBJ.add(level_renderer = new EditorRenderer(p)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (Key.isKeyHeld(KeyEvent.VK_F3)) { |
|
|
|
if (Key.isKeyHeld(KeyEvent.VK_F3)) { |
|
|
|
OBJ.clear(); |
|
|
|
OBJ.clear(); |
|
|
|
ResetGame(); |
|
|
|
ResetGame(); |
|
|
|
OBJ.add(control_settings_menu=new ConfigureControls(p)); |
|
|
|
OBJ.add(control_settings_menu = new ConfigureControls(p)); |
|
|
|
} |
|
|
|
} |
|
|
|
if (Key.isKeyHeld(KeyEvent.VK_F5)&&System.currentTimeMillis()-lastControllerScan>5000) { |
|
|
|
if (Key.isKeyHeld(KeyEvent.VK_F5) && System.currentTimeMillis() - lastControllerScan > 5000) { |
|
|
|
CONTROLLERS=ControllerEnvironment.getDefaultEnvironment().rescanControllers(); |
|
|
|
CONTROLLERS = ControllerEnvironment.getDefaultEnvironment().rescanControllers(); |
|
|
|
System.out.println(Arrays.toString(CONTROLLERS)); |
|
|
|
System.out.println(Arrays.toString(CONTROLLERS)); |
|
|
|
lastControllerScan=System.currentTimeMillis(); |
|
|
|
lastControllerScan = System.currentTimeMillis(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (int i=0;i<OBJ.size();i++) { |
|
|
|
for (int i = 0; i < OBJ.size(); i++) { |
|
|
|
OBJ.get(i).update(updateMult); |
|
|
|
OBJ.get(i).update(updateMult); |
|
|
|
if (OBJ.get(i).isMarkedForDeletion()) { |
|
|
|
if (OBJ.get(i).isMarkedForDeletion()) { |
|
|
|
OBJ.remove(i--); |
|
|
|
OBJ.remove(i--); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
dt-=(1/244d)*1000000000l; |
|
|
|
dt -= (1 / 244d) * 1000000000l; |
|
|
|
|
|
|
|
TIME += (1 / 244d) * 1000000000l; |
|
|
|
|
|
|
|
// System.out.println(TIME);
|
|
|
|
} |
|
|
|
} |
|
|
|
if (dt<(1/244d)*1000000000l) { |
|
|
|
if (dt < (1 / 244d) * 1000000000l) { |
|
|
|
lastReportedTime=System.currentTimeMillis(); |
|
|
|
lastReportedTime = System.currentTimeMillis(); |
|
|
|
} else |
|
|
|
} else { |
|
|
|
if (System.currentTimeMillis()-lastReportedTime>5000) { |
|
|
|
if (System.currentTimeMillis() - lastReportedTime > 5000) { |
|
|
|
System.out.println("WARNING! Game is lagging behind! Frames Behind: "+(dt/((1/244d)*1000000000l))); |
|
|
|
System.out.println( |
|
|
|
lastReportedTime=System.currentTimeMillis(); |
|
|
|
"WARNING! Game is lagging behind! Frames Behind: " + (dt / ((1 / 244d) * 1000000000l))); |
|
|
|
|
|
|
|
lastReportedTime = System.currentTimeMillis(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
System.out.print(BLANK); //This is hackish. Removing this slows down the game by about 30%. The timer runs slower. ???
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void handleGameControllers() { |
|
|
|
private static void handleGameControllers() { |
|
|
|
for (int i=0;i<CONTROLLERS.length;i++) { |
|
|
|
for (int i = 0; i < CONTROLLERS.length; i++) { |
|
|
|
if (CONTROLLERS[i].getType()==Controller.Type.KEYBOARD||CONTROLLERS[i].getType()==Controller.Type.MOUSE) { |
|
|
|
if (CONTROLLERS[i].getType() == Controller.Type.KEYBOARD |
|
|
|
|
|
|
|
|| CONTROLLERS[i].getType() == Controller.Type.MOUSE) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!CONTROLLERS[i].poll()) { |
|
|
|
if (!CONTROLLERS[i].poll()) { |
|
|
|
Controller[] newArr = new Controller[CONTROLLERS.length-1]; |
|
|
|
Controller[] newArr = new Controller[CONTROLLERS.length - 1]; |
|
|
|
for (int j=0;j<CONTROLLERS.length;j++) { |
|
|
|
for (int j = 0; j < CONTROLLERS.length; j++) { |
|
|
|
if (j!=i) { |
|
|
|
if (j != i) { |
|
|
|
newArr[(j>i?j-1:j)]=CONTROLLERS[i]; |
|
|
|
newArr[(j > i ? j - 1 : j)] = CONTROLLERS[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
CONTROLLERS=newArr; |
|
|
|
CONTROLLERS = newArr; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void ResetGame() { |
|
|
|
private static void ResetGame() { |
|
|
|
player=null; |
|
|
|
player = null; |
|
|
|
level_renderer=null; |
|
|
|
level_renderer = null; |
|
|
|
control_settings_menu=null; |
|
|
|
control_settings_menu = null; |
|
|
|
//System.gc();
|
|
|
|
// System.gc();
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void StartGame() { |
|
|
|
private static void StartGame() { |
|
|
|
//System.gc();
|
|
|
|
// System.gc();
|
|
|
|
OBJ.add(player = new Player(p)); |
|
|
|
OBJ.add(player = new Player(p)); |
|
|
|
OBJ.add(new Erinoah(p)); |
|
|
|
//OBJ.add(new Erinoah(p));
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void ChooseBestRatio() { |
|
|
|
private static void ChooseBestRatio() { |
|
|
|
while (f.getWidth()*(SIZE_MULTIPLIER+1)<Toolkit.getDefaultToolkit().getScreenSize().getWidth()) { |
|
|
|
while (f.getWidth() * (SIZE_MULTIPLIER + 1) < Toolkit.getDefaultToolkit().getScreenSize().getWidth()) { |
|
|
|
SIZE_MULTIPLIER++; |
|
|
|
SIZE_MULTIPLIER++; |
|
|
|
} |
|
|
|
} |
|
|
|
f.setSize(f.getWidth()*SIZE_MULTIPLIER,(int)((f.getWidth()*SIZE_MULTIPLIER)/1.77777777778d)); |
|
|
|
f.setSize(f.getWidth() * SIZE_MULTIPLIER, (int) ((f.getWidth() * SIZE_MULTIPLIER) / 1.77777777778d)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|