started implementing tweening system

This commit is contained in:
DaniTheSkunk 2022-10-11 21:23:34 +00:00
parent 66c05256e6
commit 91169a40b0
7 changed files with 74 additions and 2 deletions

View File

@ -26,6 +26,7 @@
<option name="PARENTHESES_EXPRESSION_LPAREN_WRAP" value="true" />
<option name="PARENTHESES_EXPRESSION_RPAREN_WRAP" value="true" />
<option name="BINARY_OPERATION_WRAP" value="5" />
<option name="WHILE_BRACE_FORCE" value="3" />
<option name="WRAP_LONG_LINES" value="true" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />

View File

@ -3,24 +3,32 @@ package com.danitheskunk.skunkworks;
import com.danitheskunk.skunkworks.gfx.IRenderContext;
import com.danitheskunk.skunkworks.gfx.font.IFont;
import com.danitheskunk.skunkworks.nodes.Node;
import com.danitheskunk.skunkworks.nodes.NodeRoot;
import org.lwjgl.glfw.GLFW;
public abstract class BaseGame {
protected Engine engine;
protected IWindow window;
protected IFont debugFont;
protected Node rootNode;
protected NodeRoot rootNode;
public BaseGame(Vec2i windowSize, String windowTitle) {
this.engine = new Engine();
this.window = engine.openWindow(windowSize, windowTitle);
//todo: load from .jar
this.debugFont = window.loadFontTileset("fonts/ega-8x14.png");
this.rootNode = new Node();
this.rootNode = new NodeRoot();
init();
}
public void run() {
double lastTime, currentTime, delta;
lastTime = GLFW.glfwGetTime();
while(!window.shouldClose()) {
currentTime = GLFW.glfwGetTime();
delta = currentTime - lastTime;
lastTime = currentTime;
window.tick();
//todo: frame rate control
update(1000.0 / 60.0);

View File

@ -0,0 +1,5 @@
package com.danitheskunk.skunkworks;
public enum Timestep {
FIXED, VARIABLE
}

View File

@ -0,0 +1,15 @@
package com.danitheskunk.skunkworks.nodes;
public abstract class BaseTween {
protected double progress;
public BaseTween() {
progress = 0;
}
public void setProgress(double progress) {
this.progress = progress;
}
protected abstract void apply();
}

View File

@ -20,6 +20,10 @@ public class Node implements Iterable<Node> {
pos = Vec2f.ZERO;
}
public Node getParent() {
return parent;
}
public Vec2f getPos() {
return pos;
}
@ -52,8 +56,31 @@ public class Node implements Iterable<Node> {
return Vec2f.add(parent.getAbsolutePos(), pos);
}
public Node getRoot() {
var node = this;
while(node.parent != null) {
node = node.parent;
}
return node;
}
@Override
public Iterator<Node> iterator() {
return children.iterator();
}
public class TweenPos extends BaseTween {
private final Vec2f start;
private final Vec2f end;
public TweenPos(Vec2f start, Vec2f end) {
this.start = start;
this.end = end;
}
@Override
protected void apply() {
pos = Vec2f.tween(start, end, progress);
}
}
}

View File

@ -0,0 +1,5 @@
package com.danitheskunk.skunkworks.nodes;
public class NodeRoot extends Node {
}

View File

@ -0,0 +1,11 @@
package com.danitheskunk.skunkworks.nodes;
import com.danitheskunk.skunkworks.Timestep;
public class Tweener {
private Timestep timestepMode;
public Tweener(Timestep timestepMode) {
this.timestepMode = timestepMode;
}
}