-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yelik
committed
May 10, 2014
1 parent
cc74e9c
commit 4c9bb76
Showing
82 changed files
with
2,171 additions
and
78 deletions.
There are no files selected for viewing
Binary file modified
BIN
+296 Bytes
(120%)
.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources
Binary file not shown.
2 changes: 1 addition & 1 deletion
2
.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+55 Bytes
(110%)
.metadata/.plugins/org.eclipse.jdt.core/externalLibsTimeStamps
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+1.6 KB
(110%)
.metadata/.plugins/org.eclipse.jdt.core/variablesAndContainers.dat
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>Cube</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.7 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
|
||
public class Array2D { | ||
int[] array; | ||
private int width; | ||
|
||
public Array2D(int width, int height) { | ||
this.width = width; | ||
array = new int[width * height]; | ||
} | ||
|
||
public boolean set(int x, int y, int value) { | ||
if (x < 0 || y < 0 || x >= getWidth() || y >= getHeight()) | ||
return false; | ||
array[y * getWidth() + x] = value; | ||
return true; | ||
} | ||
|
||
public int get(int x, int y) { | ||
if (y < 0 || x < 0 || y >= getHeight() || x >= getWidth()) | ||
return -1; | ||
return array[y * getWidth() + x]; | ||
} | ||
|
||
public int getI(int i) { | ||
if (i >= array.length || i < 0) | ||
return -1; | ||
return array[i]; | ||
} | ||
|
||
public boolean setI(int i, int value) { | ||
if (i >= array.length || i < 0) | ||
return false; | ||
array[i] = value; | ||
return true; | ||
} | ||
|
||
public int getWidth() { | ||
return width; | ||
} | ||
|
||
public int getHeight() { | ||
return array.length / getWidth(); | ||
} | ||
|
||
public int getLength() { | ||
return array.length; | ||
} | ||
|
||
public int[] getArray() { | ||
return array; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
|
||
import java.awt.event.KeyEvent; | ||
import java.awt.event.KeyListener; | ||
|
||
public class KeyReader implements KeyListener { | ||
private boolean[] keys; | ||
|
||
public KeyReader() { | ||
keys = new boolean[120]; | ||
} | ||
|
||
public boolean getUp() { | ||
return keys[KeyEvent.VK_UP]; | ||
} | ||
|
||
public boolean getDown() { | ||
return keys[KeyEvent.VK_DOWN]; | ||
} | ||
|
||
public boolean getLeft() { | ||
return keys[KeyEvent.VK_LEFT]; | ||
} | ||
|
||
public boolean getRight() { | ||
return keys[KeyEvent.VK_RIGHT]; | ||
} | ||
|
||
public boolean getSpace() { | ||
return keys[KeyEvent.VK_SPACE]; | ||
} | ||
|
||
@Override | ||
public void keyPressed(KeyEvent e) { | ||
keys[e.getKeyCode()] = true; | ||
} | ||
|
||
@Override | ||
public void keyReleased(KeyEvent e) { | ||
keys[e.getKeyCode()] = false; | ||
} | ||
|
||
@Override | ||
public void keyTyped(KeyEvent e) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import java.awt.Canvas; | ||
import java.awt.Cursor; | ||
import java.awt.Dimension; | ||
import java.awt.Graphics; | ||
import java.awt.Point; | ||
import java.awt.Toolkit; | ||
import java.awt.image.BufferStrategy; | ||
import java.awt.image.BufferedImage; | ||
import java.awt.image.DataBufferInt; | ||
|
||
import javax.swing.JFrame; | ||
|
||
import com.mrizen.cube.d2.Point2d; | ||
|
||
public class Main extends Canvas implements Runnable { | ||
private static final long serialVersionUID = 4648172894076113183L; | ||
|
||
private boolean running; | ||
private String title; | ||
private Screen screen; | ||
private BufferedImage image; | ||
private int[] pixels; | ||
private JFrame frame; | ||
private Thread thread; | ||
private double updatesPerSecond; | ||
private KeyReader keys; | ||
private MouseReader mouse; | ||
|
||
public Main(String title, int width, int height, double scale, double updatesPerSecond) { | ||
this.title = title; | ||
this.updatesPerSecond = updatesPerSecond; | ||
|
||
frame = new JFrame(); | ||
frame.setResizable(false); | ||
frame.setTitle(title); | ||
frame.add(this); | ||
setDimension(width, height, scale); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
frame.setLocationRelativeTo(null); | ||
frame.setVisible(true); | ||
|
||
screen = new Screen(width, height); | ||
|
||
keys = new KeyReader(); | ||
addKeyListener(keys); | ||
|
||
mouse = new MouseReader(scale); | ||
addMouseMotionListener(mouse); | ||
addMouseListener(mouse); | ||
|
||
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); | ||
pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData(); | ||
|
||
running = false; | ||
} | ||
|
||
public KeyReader getKeys() { | ||
return keys; | ||
} | ||
|
||
public MouseReader getMouse() { | ||
return mouse; | ||
} | ||
|
||
protected void setDimension(int width, int height, double scale) { | ||
setPreferredSize(new Dimension((int) (width * scale), (int) (height * scale))); | ||
frame.pack(); | ||
} | ||
|
||
protected void update() { | ||
|
||
} | ||
|
||
protected void render() { | ||
screen.drawLine2d(new Point2d(1, 1), new Point2d(1, 1), 0); | ||
} | ||
|
||
private void renderPrivate() { | ||
BufferStrategy bs = getBufferStrategy(); | ||
if (bs == null) { | ||
createBufferStrategy(3); | ||
return; | ||
} | ||
screen.clear(); | ||
render(); | ||
for (int i = 0; i < screen.getPixels().getLength(); i++) { | ||
pixels[i] = screen.getPixels().getI(i); | ||
} | ||
Graphics g = bs.getDrawGraphics(); | ||
g.drawImage(image, 0, 0, getWidth(), getHeight(), null); | ||
g.dispose(); | ||
bs.show(); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
long lastTime = System.nanoTime(); | ||
long timer = System.currentTimeMillis(); | ||
final double ns = 1000000000.0 / updatesPerSecond; | ||
double delta = 0; | ||
int frames = 0; | ||
int updates = 0; | ||
requestFocus(); | ||
while (running) { | ||
long now = System.nanoTime(); | ||
delta += (now - lastTime) / ns; | ||
lastTime = now; | ||
while (delta > 1) { | ||
update(); | ||
updates++; | ||
delta--; | ||
} | ||
renderPrivate(); | ||
frames++; | ||
if (System.currentTimeMillis() - timer > 1000) { | ||
timer += 1000; | ||
frame.setTitle(title + " | " + updates + " ups, " + frames + " fps"); | ||
updates = 0; | ||
frames = 0; | ||
} | ||
} | ||
} | ||
|
||
protected synchronized void start() { | ||
running = true; | ||
thread = new Thread(this, "Display"); | ||
thread.start(); | ||
} | ||
|
||
protected synchronized void stop() { | ||
running = false; | ||
try { | ||
thread.join(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
String title = "Test"; | ||
int width = 300; | ||
int height = width / 16 * 9; | ||
int scale = 6; | ||
double updatesPerSecond = 60; | ||
|
||
Main main = new Main(title, width, height, scale, updatesPerSecond); | ||
main.start(); | ||
} | ||
|
||
public Screen getScreen() { | ||
return screen; | ||
} | ||
|
||
protected void showCursor(boolean show) { | ||
BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB); | ||
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor"); | ||
frame.getContentPane().setCursor(blankCursor); | ||
} | ||
} |
Oops, something went wrong.