Compare commits

..

No commits in common. "661fc6d2753b498467fc00ba7f8e21ab3f583338" and "280907902500e7a4cce41222e0b7338bf33ba06a" have entirely different histories.

7 changed files with 24 additions and 152 deletions

View File

@ -3,20 +3,17 @@ package com.danitheskunk.skunkworks;
import com.danitheskunk.skunkworks.gfx.Color; import com.danitheskunk.skunkworks.gfx.Color;
import com.danitheskunk.skunkworks.gfx.IRenderContext; import com.danitheskunk.skunkworks.gfx.IRenderContext;
import com.danitheskunk.skunkworks.gfx.font.IFont; import com.danitheskunk.skunkworks.gfx.font.IFont;
import com.danitheskunk.skunkworks.nodes.Node;
public abstract class BaseGame { public abstract class BaseGame {
protected Engine engine; protected Engine engine;
protected IWindow window; protected IWindow window;
protected IFont debugFont; protected IFont debugFont;
protected Node rootNode;
public BaseGame(Vec2i windowSize, String windowTitle) { public BaseGame(Vec2i windowSize, String windowTitle) {
this.engine = new Engine(); this.engine = new Engine();
this.window = engine.openWindow(windowSize, windowTitle); this.window = engine.openWindow(windowSize, windowTitle);
//todo: load from .jar //todo: load from .jar
this.debugFont = window.loadFontTileset("fonts/ega-8x14.png"); this.debugFont = window.loadFontTileset("fonts/ega-8x14.png");
this.rootNode = new Node();
init(); init();
} }
@ -26,8 +23,6 @@ public abstract class BaseGame {
//todo: frame rate control //todo: frame rate control
update(1000.0 / 60.0); update(1000.0 / 60.0);
var rc = window.renderStart(); var rc = window.renderStart();
renderPre(rc);
rootNode.render(rc);
render(rc); render(rc);
window.renderFinish(rc); window.renderFinish(rc);
} }
@ -37,12 +32,8 @@ public abstract class BaseGame {
} }
protected void renderPre(IRenderContext rc) {
}
protected void render(IRenderContext rc) { protected void render(IRenderContext rc) {
//rc.drawString(new Vec2i(8, 8), "Welcome to Skunkworks, please overide the render method to get started", debugFont, Color.LIGHT_GRAY); rc.drawString(new Vec2i(8, 8), "Welcome to Skunkworks, please overide the render method to get started", debugFont, Color.LIGHT_GRAY);
} }
protected void update(double delta) { protected void update(double delta) {

View File

@ -1,19 +0,0 @@
package com.danitheskunk.skunkworks;
import com.danitheskunk.skunkworks.nodes.NodeSprite;
public class TestNode extends BaseGame {
NodeSprite sprite;
public TestNode() {
super(new Vec2i(1280, 720), "Skunkworks");
sprite = new NodeSprite();
sprite.setTexture(window.loadTexture("demoassets/test.png"));
sprite.setPos(new Vec2f(100, 100));
rootNode.add(sprite);
}
public static void main(String[] args) {
new TestNode().run();
}
}

View File

@ -1,7 +1,6 @@
package com.danitheskunk.skunkworks; package com.danitheskunk.skunkworks;
public final class Vec2f { public final class Vec2f {
public final static Vec2f ZERO = new Vec2f(0, 0);
private final double x, y; private final double x, y;
//constructors //constructors
@ -10,6 +9,15 @@ public final class Vec2f {
this.y = y; this.y = y;
} }
//getters and setters
public double getX() {
return x;
}
public double getY() {
return y;
}
//static functions //static functions
public static Vec2f add(Vec2f a, Vec2f b) { public static Vec2f add(Vec2f a, Vec2f b) {
return new Vec2f(a.x + b.x, a.y + b.y); return new Vec2f(a.x + b.x, a.y + b.y);
@ -26,17 +34,4 @@ public final class Vec2f {
public static Vec2f div(Vec2f a, double b) { public static Vec2f div(Vec2f a, double b) {
return new Vec2f(a.x / b, a.y / b); return new Vec2f(a.x / b, a.y / b);
} }
//getters and setters
public double getX() {
return x;
}
public double getY() {
return y;
}
public Vec2i toVec2i() {
return new Vec2i((int) x, (int) y);
}
} }

View File

@ -2,9 +2,10 @@ package com.danitheskunk.skunkworks;
@SuppressWarnings("SpellCheckingInspection") @SuppressWarnings("SpellCheckingInspection")
public final class Vec2i { public final class Vec2i {
public final static Vec2i ZERO = new Vec2i(0, 0);
private final int x, y; private final int x, y;
public final static Vec2i ZERO = new Vec2i(0, 0);
//constructors //constructors
public Vec2i(int x, int y) { public Vec2i(int x, int y) {
@ -14,6 +15,16 @@ public final class Vec2i {
//getters and setters //getters and setters
public int getX() {
return x;
}
public int getY() {
return y;
}
//static functions
public static Vec2i add(Vec2i a, Vec2i b) { public static Vec2i add(Vec2i a, Vec2i b) {
return new Vec2i(a.x + b.x, a.y + b.y); return new Vec2i(a.x + b.x, a.y + b.y);
} }
@ -22,8 +33,6 @@ public final class Vec2i {
return new Vec2i(a.x + b.x + c.x, a.y + b.y + c.y); return new Vec2i(a.x + b.x + c.x, a.y + b.y + c.y);
} }
//static functions
public static Vec2i add(Vec2i a, Vec2i b, Vec2i c, Vec2i d) { public static Vec2i add(Vec2i a, Vec2i b, Vec2i c, Vec2i d) {
return new Vec2i(a.x + b.x + c.x + d.x, a.y + b.y + c.y + d.y); return new Vec2i(a.x + b.x + c.x + d.x, a.y + b.y + c.y + d.y);
} }
@ -35,7 +44,6 @@ public final class Vec2i {
public static Vec2i mul(Vec2i a, int b) { public static Vec2i mul(Vec2i a, int b) {
return new Vec2i(a.x * b, a.y * b); return new Vec2i(a.x * b, a.y * b);
} }
public static Vec2i mul(Vec2i a, Vec2i b) { public static Vec2i mul(Vec2i a, Vec2i b) {
return new Vec2i(a.x * b.x, a.y * b.y); return new Vec2i(a.x * b.x, a.y * b.y);
} }
@ -43,36 +51,19 @@ public final class Vec2i {
public static Vec2i div(Vec2i a, int b) { public static Vec2i div(Vec2i a, int b) {
return new Vec2i(a.x / b, a.y / b); return new Vec2i(a.x / b, a.y / b);
} }
public static Vec2i div(Vec2i a, Vec2i b) { public static Vec2i div(Vec2i a, Vec2i b) {
return new Vec2i(a.x / b.x, a.y / b.y); return new Vec2i(a.x / b.x, a.y / b.y);
} }
public static Vec2f divf(Vec2i a, double b) { public static Vec2f divf(Vec2i a, double b) {
return new Vec2f(a.x / b, a.y / b); return new Vec2f(a.x / b, a.y / b);
} }
public static Vec2f divf(Vec2i a, Vec2f b) { public static Vec2f divf(Vec2i a, Vec2f b) {
return new Vec2f(a.x / b.getX(), a.y / b.getY()); return new Vec2f(a.x / b.getX(), a.y / b.getY());
} }
public static Vec2f divf(Vec2i a, int b) { public static Vec2f divf(Vec2i a, int b) {
return new Vec2f(a.x / (double) b, a.y / (double) b); return new Vec2f(a.x / (double)b, a.y / (double)b);
} }
public static Vec2f divf(Vec2i a, Vec2i b) { public static Vec2f divf(Vec2i a, Vec2i b) {
return new Vec2f(a.x / (double) b.x, a.y / (double) b.y); return new Vec2f(a.x / (double)b.x, a.y / (double)b.y);
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public Vec2f toVec2f() {
return new Vec2f((double) x, (double) y);
} }
} }

View File

@ -1,59 +0,0 @@
package com.danitheskunk.skunkworks.nodes;
import com.danitheskunk.skunkworks.Vec2f;
import com.danitheskunk.skunkworks.gfx.IRenderContext;
import java.sql.Array;
import java.util.*;
//todo: figure out the whole translation position thingie
public class Node implements Iterable<Node> {
protected List<Node> children;
protected Node parent;
protected Vec2f pos;
public Node() {
children = new ArrayList<>();
parent = null;
pos = Vec2f.ZERO;
}
public Vec2f getPos() {
return pos;
}
public void setPos(Vec2f pos) {
this.pos = pos;
}
public void add(Node node) {
if(node.parent != null) {
throw new RuntimeException("Can't add node to two nodes");
}
node.parent = this;
children.add(node);
}
public void remove(Node node) {
node.parent = null;
children.remove(node);
}
public void render(IRenderContext rc) {
for(var child : this) {
child.render(rc);
}
}
public Vec2f getAbsolutePos() {
if(parent == null)
return pos;
return Vec2f.add(parent.getAbsolutePos(), pos);
}
@Override
public Iterator<Node> iterator() {
return children.iterator();
}
}

View File

@ -1,27 +0,0 @@
package com.danitheskunk.skunkworks.nodes;
import com.danitheskunk.skunkworks.Vec2f;
import com.danitheskunk.skunkworks.gfx.IRenderContext;
import com.danitheskunk.skunkworks.gfx.ITexture;
public class NodeSprite extends Node {
//todo: support animations
private ITexture texture;
public NodeSprite() {
texture = null;
}
public ITexture getTexture() {
return texture;
}
public void setTexture(ITexture texture) {
this.texture = texture;
}
@Override
public void render(IRenderContext rc) {
rc.drawTexture(getAbsolutePos().toVec2i(), texture);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB