buffer starts n stuff
parent
70b234f156
commit
394fcd6a45
|
|
@ -67,10 +67,12 @@ public class Engine extends Canvas {
|
|||
while(true) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
updateScene();
|
||||
repaint();
|
||||
Graphics2D g = (Graphics2D)bs.getDrawGraphics();
|
||||
render(g);
|
||||
bs.show();
|
||||
int elapsed = (int)(System.currentTimeMillis() - startTime);
|
||||
try{
|
||||
Thread.sleep(16 - elapsed);
|
||||
Thread.sleep(17 - elapsed);
|
||||
}catch(Exception e) {
|
||||
|
||||
}
|
||||
|
|
@ -142,17 +144,6 @@ public class Engine extends Canvas {
|
|||
|
||||
}
|
||||
|
||||
public void update(Graphics g) {
|
||||
Graphics2D g2 = null;
|
||||
try {
|
||||
g2 = (Graphics2D) bs.getDrawGraphics();
|
||||
render(g2);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
bs.show();
|
||||
}
|
||||
|
||||
private void render(Graphics2D g) {
|
||||
SceneManager.render(g);
|
||||
g.setColor(Color.BLACK);
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@ package diveengine2d;
|
|||
public class RigidBody extends DiveScript{
|
||||
|
||||
public float dx, dy, drot;
|
||||
public float friction = 0.99f;
|
||||
public float friction;
|
||||
|
||||
public void update() {
|
||||
entity.x += dx;
|
||||
entity.y += dy;
|
||||
entity.rotation += drot;
|
||||
dx *= .3;
|
||||
dy *= .3;
|
||||
drot *= .3;
|
||||
dx *= friction;
|
||||
dy *= friction;
|
||||
drot *= friction;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ public class SceneManager {
|
|||
Color color = new Color(r, g, b);
|
||||
|
||||
scopeObject.peek().getClass().getField(key).set(scopeObject.peek(), color);
|
||||
}else if(value.endsWith("F") || value.endsWith("f")) {
|
||||
}else if(value.endsWith("I") || value.endsWith("i")) {
|
||||
value = value.substring(0, value.length() - 1);
|
||||
|
||||
int intValue;
|
||||
|
|
@ -81,6 +81,18 @@ public class SceneManager {
|
|||
continue;
|
||||
}
|
||||
|
||||
scopeObject.peek().getClass().getField(key).set(scopeObject.peek(), intValue);
|
||||
}else if(value.endsWith("F") || value.endsWith("f")) {
|
||||
value = value.substring(0, value.length() - 1);
|
||||
|
||||
float intValue;
|
||||
try{
|
||||
intValue = Float.parseFloat(value);
|
||||
}catch(Exception e) {
|
||||
System.out.println(value + " is not a float");
|
||||
continue;
|
||||
}
|
||||
|
||||
scopeObject.peek().getClass().getField(key).set(scopeObject.peek(), intValue);
|
||||
}
|
||||
|
||||
|
|
@ -120,7 +132,6 @@ public class SceneManager {
|
|||
continue;
|
||||
}
|
||||
}
|
||||
component.create();
|
||||
component.entity = (Entity) scopeObject.peek();
|
||||
((Entity)scopeObject.peek()).addComponent(component);
|
||||
scopeObject.push(component);
|
||||
|
|
@ -128,6 +139,11 @@ public class SceneManager {
|
|||
scopeObject.pop();
|
||||
}
|
||||
}
|
||||
for(Entity e : entities) {
|
||||
for(DiveScript script : e.components) {
|
||||
script.create();
|
||||
}
|
||||
}
|
||||
}catch(Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue