added BaseGame

This commit is contained in:
DaniTheSkunk 2022-10-10 21:54:49 +00:00
parent b90784f744
commit 09362620e5
2 changed files with 80 additions and 68 deletions

111
Test.java
View File

@ -1,85 +1,60 @@
import com.danitheskunk.skunkworks.*; import com.danitheskunk.skunkworks.BaseGame;
import com.danitheskunk.skunkworks.Vec2i;
import com.danitheskunk.skunkworks.gfx.Color; import com.danitheskunk.skunkworks.gfx.Color;
import com.danitheskunk.skunkworks.gfx.IRenderContext;
import com.danitheskunk.skunkworks.gfx.vt.Terminal; import com.danitheskunk.skunkworks.gfx.vt.Terminal;
import java.nio.charset.StandardCharsets; public class Test extends BaseGame {
private Terminal term;
public class Test { public Test() {
public static void main(String[] args) { super(new Vec2i(1280, 720), "Skunkworks");
/*
var windows = Window.getAllVisible();
System.out.printf("%d Open Windows:\n", windows.size());
for(var window: windows) {
System.out.printf("%s -- %s -- %s\n", window.getTitle(), window.getClassName(), window.getExecutableName());
} }
windows.get(0).setBorder(true);
windows.get(0).setBorderRounded(false);
windows.get(0).move(new Recti(1280, 720, 2560, 1440));
windows.get(0).debugPrintStyles();
windows.get(0).debugPrintStylesEx();
Window.onKey();
Window.onNewWindow();
Window.messageLoop();
*/
var engine = new Engine(); public static void main(String[] args) {
var window = engine.openWindow(new Vec2i(1280, 720), "Skunkworks"); new Test().run();
var img = engine.loadImage("C:\\Users\\dani\\Videos\\Screenshot 2022-06-25 17-00-59.png"); }
var tex2 = window.loadTexture("C:\\art\\pixel stuff.png");
var tileset = window.loadTextureArray("C:\\stream\\coding\\rlc\\tilemap.png", new Vec2i(16, 16)); @Override
var font = window.loadFontTileset("EGA8x14.png"); protected void init() {
var fontThin = window.loadFontTileset("fonts\\thin-6x12.png"); var fontThin = window.loadFontTileset("fonts\\thin-6x12.png");
var fontThin2 = window.loadFontTileset("fonts\\thin-12x12.png"); var fontThin2 = window.loadFontTileset("fonts\\thin-12x12.png");
var font2 = window.loadFontTTF("fonts\\LiberationSans-Regular.ttf", 16 * 8.f); term = new Terminal(new Vec2i(80, 45), fontThin2, fontThin);
var font3 = window.loadFontTTF("fonts\\LiberationSans-Regular.ttf", 16);
var tex = window.loadTexture(img);
var slice = window.loadNineSlice("demoassets\\9slice-2.png");
var term = new Terminal(new Vec2i(80, 45), fontThin2, fontThin);
//window.setDebug(true);
term.setChar(new Vec2i(0, 0), 0xC9, Color.GREEN); var c1 = Color.GREEN;
term.setChar(new Vec2i(9, 9), 0xC9, Color.GREEN); var c2 = new Color(0, 128, 0);
term.setChar(new Vec2i(10, 10), 0xC9, Color.GREEN);
term.drawHalfString(new Vec2i(11, 11), "AHello world. This is a test.", Color.GREEN);
term.drawBoxDouble(new Recti(11, 12, 4, 4), Color.GREEN, Color.DARK_GRAY, true);
while(!window.shouldClose()) { term.drawHorizontalSingleLine(new Vec2i(0, 0), 20, c2);
window.tick(); term.drawHalfString(new Vec2i(6, 0), " Upgrades ");
var renderContext = window.renderStart();
/*renderContext.drawTextureRectangle(
new Recti(0, 0, 1280, 720),
tex,
false
);*/
//renderContext.drawTextureRectangle(
// new Recti(new Vec2i(200, 100), tex2.getSize()),
// tex2,
// true
//);
/*renderContext.drawTextureRectangle( term.drawHalfString(new Vec2i(0, 1), " a", c1);
new Recti(new Vec2i(400, 400), new Vec2i(160, 160)), term.drawHalfString(new Vec2i(1, 1), " - [", c2);
tileset.get(0x30), term.drawHalfString(new Vec2i(3, 1), " Upgraded Skeleton", c1);
true term.drawHalfString(new Vec2i(12, 1), " ]", c2);
);*/ term.drawHalfString(new Vec2i(16, 1), "10,000$", c1);
//byte[] str = {(byte)0xC9, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xCD, (byte)0xBB}; term.drawHalfString(new Vec2i(0, 2), " b", c1);
//renderContext.drawString(new Vec2i(36, 36), new String(str), fontThin2, new Color(0, 255, 0)); term.drawHalfString(new Vec2i(1, 2), " - [", c2);
//renderContext.drawString(new Vec2i(36, 36), "\u00c9\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00BB", fontThin2, new Color(0, 255, 0)); term.drawHalfString(new Vec2i(3, 2), " Upgraded Eyes", c1);
//renderContext.drawString(new Vec2i(36, 48), "\u00ba \u00ba", fontThin2, new Color(0, 255, 0)); term.drawHalfString(new Vec2i(10, 2), " ]", c2);
//renderContext.drawString(new Vec2i(36, 60), "\u00ba \u00ba", fontThin2, new Color(0, 255, 0)); term.drawHalfString(new Vec2i(16, 2), " 7,000$", c1);
//renderContext.drawString(new Vec2i(36, 72), "\u00c8\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00cd\u00BC", fontThin2, new Color(0, 255, 0));
//renderContext.drawString(new Vec2i(48, 48), "The quick brown fox jumps over the lazy dog", fontThin, new Color(0, 255, 0));
//renderContext.drawString(new Vec2i(48, 60), "Soft Kitty, Warm Kitty, Little Ball of Fur. Happy Kitty, Sleepy Kitty, Purr Purr Purr.", fontThin, new Color(0, 255, 0));
renderContext.drawTerminal(term); term.drawHalfString(new Vec2i(0, 3), " c", c1);
term.drawHalfString(new Vec2i(1, 3), " - [", c2);
term.drawHalfString(new Vec2i(3, 3), " Upgraded Senses", c1);
term.drawHalfString(new Vec2i(11, 3), " ]", c2);
term.drawHalfString(new Vec2i(16, 3), " 6,000$", c1);
//renderContext.drawNineSlice(slice, new Recti(100, 100, 75, 23)); term.drawHalfString(new Vec2i(0, 4), " d", c1);
//renderContext.drawString(new Vec2i(118, 117), "Meow", font3, new Color(0,0,0)); term.drawHalfString(new Vec2i(1, 4), " - [", c2);
//renderContext.drawString(new Vec2i(122, 105), "Meow", font, new Color(0,0,0)); term.drawHalfString(new Vec2i(3, 4), " Upgraded Legs", c1);
window.renderFinish(renderContext); term.drawHalfString(new Vec2i(10, 4), " ]", c2);
} term.drawHalfString(new Vec2i(16, 4), " 4,500$", c1);
} }
@Override
protected void render(IRenderContext rc) {
rc.drawTerminal(term);
}
} }

View File

@ -0,0 +1,37 @@
package com.danitheskunk.skunkworks;
import com.danitheskunk.skunkworks.gfx.IRenderContext;
public abstract class BaseGame {
protected Engine engine;
protected IWindow window;
public BaseGame(Vec2i windowSize, String windowTitle) {
this.engine = new Engine();
this.window = engine.openWindow(windowSize, windowTitle);
init();
}
public void run() {
while(!window.shouldClose()) {
window.tick();
//todo: frame rate control
update(1000.0 / 60.0);
var rc = window.renderStart();
render(rc);
window.renderFinish(rc);
}
}
protected void init() {
}
protected void render(IRenderContext rc) {
//todo: demo text?
}
protected void update(double delta) {
}
}