-
Notifications
You must be signed in to change notification settings - Fork 6
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
1 parent
7db82c6
commit 5384b02
Showing
28 changed files
with
605 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* | ||
* Component | ||
* parent of all GameObject components | ||
* | ||
*/ | ||
|
||
package dev.jabo.kree; | ||
|
||
import java.awt.Graphics; | ||
|
||
public abstract class Component { | ||
|
||
protected GameObject gameObject; | ||
|
||
protected String name; | ||
|
||
public abstract void Update(); | ||
|
||
public abstract void Render(Graphics g); | ||
|
||
} |
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,15 @@ | ||
/* | ||
* | ||
* Debug Class is for debugging purposes | ||
* | ||
*/ | ||
|
||
package dev.jabo.kree; | ||
|
||
public class Debug { | ||
|
||
public static void Log(Object out) { | ||
System.out.println(out); | ||
} | ||
|
||
} |
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,115 @@ | ||
package dev.jabo.kree; | ||
|
||
import java.awt.Graphics; | ||
import java.awt.image.BufferStrategy; | ||
|
||
public class Game implements Runnable { | ||
|
||
private Thread thread; | ||
private boolean gameRunning; | ||
|
||
private Graphics g; | ||
private BufferStrategy bs; | ||
|
||
private Window window; | ||
|
||
public static Input INPUT = new Input(); | ||
|
||
public Game(Window window) { | ||
this.window = window; | ||
} | ||
|
||
public void Initialize() { | ||
window.getWindow().addKeyListener(INPUT); | ||
window.getCanvas().addMouseListener(INPUT); | ||
window.getCanvas().addMouseMotionListener(INPUT); | ||
} | ||
|
||
public void Update() { | ||
|
||
SceneManager.Update(); | ||
|
||
} | ||
|
||
public void Render() { | ||
|
||
bs = window.getCanvas().getBufferStrategy(); | ||
if(bs == null) { | ||
window.getCanvas().createBufferStrategy(3); | ||
return; | ||
} | ||
g = bs.getDrawGraphics(); | ||
g.clearRect(0, 0, window.getWindowWidth(), window.getWindowHeight()); | ||
// DRAW HERE | ||
|
||
SceneManager.Render(g); | ||
|
||
// END | ||
bs.show(); | ||
g.dispose(); | ||
|
||
} | ||
|
||
public synchronized void start() { | ||
if(gameRunning) | ||
return; | ||
gameRunning = true; | ||
thread = new Thread(this); | ||
thread.run(); | ||
} | ||
|
||
public synchronized void stop() { | ||
if(!gameRunning) | ||
return; | ||
gameRunning = false; | ||
try { | ||
thread.join(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
System.exit(0); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
|
||
Initialize(); | ||
|
||
// Handles the FPS | ||
int fps = 60; | ||
double timePerTick = 1000000000 / fps; | ||
double delta = 0; | ||
long now; | ||
long lastTime = System.nanoTime(); | ||
long timer = 0; | ||
int ticks = 0; | ||
|
||
while(gameRunning) { | ||
|
||
now = System.nanoTime(); | ||
delta += (now - lastTime) / timePerTick; | ||
timer += now - lastTime; | ||
lastTime = now; | ||
|
||
if(delta >= 1){ | ||
Update(); | ||
Render(); | ||
ticks++; | ||
delta--; | ||
} | ||
|
||
if(timer >= 1000000000){ | ||
System.out.println("FPS: " + ticks); | ||
ticks = 0; | ||
timer = 0; | ||
} | ||
|
||
} | ||
|
||
stop(); | ||
|
||
} | ||
|
||
|
||
} |
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,99 @@ | ||
package dev.jabo.kree; | ||
|
||
import java.awt.Graphics; | ||
|
||
public class GameObject { | ||
|
||
public Transform transform = new Transform(); | ||
|
||
public Component[] components = new Component[0]; | ||
|
||
public float id; | ||
public String name; | ||
|
||
private Scene parentScene; | ||
|
||
public GameObject(Scene parentScene, String name) { | ||
this.name = name; | ||
this.parentScene = parentScene; | ||
|
||
// Add to Scene GameObjects | ||
GameObject[] newGameObjectList = new GameObject[parentScene.gameObjects.length + 1]; | ||
for(int i = 0; i < parentScene.gameObjects.length; i++) { | ||
newGameObjectList[i] = parentScene.gameObjects[i]; | ||
} | ||
newGameObjectList[parentScene.gameObjects.length] = this; | ||
parentScene.gameObjects = newGameObjectList; | ||
// End | ||
|
||
this.id = (float) (Math.random() * 100); | ||
} | ||
|
||
public void Update() { | ||
for(int i = 0; i < components.length; i++) { | ||
components[i].Update(); | ||
} | ||
} | ||
|
||
public void Render(Graphics g) { | ||
for(int i = 0; i < components.length; i++) { | ||
components[i].Render(g); | ||
} | ||
} | ||
|
||
public Component GetComponent(String componentName) { | ||
for(int i = 0; i < components.length; i++) { | ||
if(components[i].name == componentName) { | ||
return components[i]; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public void AddComponent(Component component) { | ||
|
||
component.gameObject = this; | ||
|
||
// Add to GameObject's Component | ||
Component[] newComponentList = new Component[components.length + 1]; | ||
for(int i = 0; i < components.length; i++) { | ||
newComponentList[i] = components[i]; | ||
} | ||
newComponentList[components.length] = component; | ||
components = newComponentList; | ||
// End | ||
} | ||
|
||
// Set GameObject's position | ||
public void SetPosition(Vector2 position) { | ||
transform.position = position; | ||
} | ||
|
||
// Set GameObject's dimension | ||
public void SetScale(Vector2 scale) { | ||
transform.scale = scale; | ||
} | ||
|
||
public void Destroy() { | ||
for(int i = 0; i < parentScene.gameObjects.length; i++) { | ||
if(parentScene.gameObjects[i].id == this.id) { | ||
parentScene.gameObjects[i] = null; | ||
|
||
// Remove GameObject from Scene | ||
GameObject[] newGameObjectList = new GameObject[parentScene.gameObjects.length - 1]; | ||
int c = 0; | ||
for(int j = 0; j < parentScene.gameObjects.length; j++) { | ||
if(parentScene.gameObjects[j] != null) { | ||
newGameObjectList[c] = parentScene.gameObjects[j]; | ||
c++; | ||
} | ||
} | ||
parentScene.gameObjects = newGameObjectList; | ||
// End | ||
|
||
return; | ||
} | ||
} | ||
} | ||
|
||
} |
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,21 @@ | ||
package dev.jabo.kree; | ||
|
||
import java.awt.image.BufferedImage; | ||
import java.io.IOException; | ||
|
||
import javax.imageio.ImageIO; | ||
|
||
public class ImageLoader { | ||
|
||
public static BufferedImage LoadImage(String path) { | ||
|
||
try { | ||
return ImageIO.read(ImageLoader.class.getResource(path)); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
} |
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,75 @@ | ||
package dev.jabo.kree; | ||
|
||
import java.awt.event.KeyEvent; | ||
import java.awt.event.KeyListener; | ||
import java.awt.event.MouseEvent; | ||
import java.awt.event.MouseListener; | ||
import java.awt.event.MouseMotionListener; | ||
|
||
public class Input implements KeyListener, MouseMotionListener, MouseListener { | ||
|
||
public static boolean mouseClicked; | ||
public static int mouseX, mouseY; | ||
public static boolean[] keys = new boolean[256]; | ||
|
||
@Override | ||
public void keyPressed(KeyEvent arg0) { | ||
keys[arg0.getKeyCode()] = true; | ||
} | ||
|
||
@Override | ||
public void keyReleased(KeyEvent arg0) { | ||
keys[arg0.getKeyCode()] = false; | ||
} | ||
|
||
@Override | ||
public void keyTyped(KeyEvent arg0) { | ||
|
||
} | ||
|
||
@Override | ||
public void mouseClicked(MouseEvent arg0) { | ||
|
||
} | ||
|
||
@Override | ||
public void mouseEntered(MouseEvent arg0) { | ||
|
||
} | ||
|
||
@Override | ||
public void mouseExited(MouseEvent arg0) { | ||
|
||
} | ||
|
||
@Override | ||
public void mousePressed(MouseEvent arg0) { | ||
mouseClicked = true; | ||
} | ||
|
||
@Override | ||
public void mouseReleased(MouseEvent arg0) { | ||
mouseClicked = false; | ||
} | ||
|
||
@Override | ||
public void mouseDragged(MouseEvent arg0) { | ||
|
||
} | ||
|
||
@Override | ||
public void mouseMoved(MouseEvent arg0) { | ||
mouseX = arg0.getX(); | ||
mouseY = arg0.getY(); | ||
} | ||
|
||
public static Vector2 GetMouse() { | ||
return new Vector2(mouseX, mouseY); | ||
} | ||
|
||
public static boolean IsKeyPressed(int keyCode) { | ||
return keys[keyCode]; | ||
} | ||
|
||
|
||
} |
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,23 @@ | ||
package dev.jabo.kree; | ||
|
||
import java.awt.Graphics; | ||
|
||
public abstract class Scene { | ||
|
||
protected Game game; | ||
|
||
protected GameObject[] gameObjects = new GameObject[0]; | ||
|
||
public Scene(Game game) { | ||
this.game = game; | ||
} | ||
|
||
public abstract void Initialize(); | ||
|
||
public abstract void Update(); | ||
|
||
public abstract void Render(Graphics g); | ||
|
||
|
||
|
||
} |
Oops, something went wrong.