buffer starts n stuff

rotation
Marcus Gosselin 2016-02-16 04:48:35 -05:00
parent 70b234f156
commit 394fcd6a45
3 changed files with 26 additions and 19 deletions

View File

@ -67,10 +67,12 @@ public class Engine extends Canvas {
while(true) { while(true) {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
updateScene(); updateScene();
repaint(); Graphics2D g = (Graphics2D)bs.getDrawGraphics();
render(g);
bs.show();
int elapsed = (int)(System.currentTimeMillis() - startTime); int elapsed = (int)(System.currentTimeMillis() - startTime);
try{ try{
Thread.sleep(16 - elapsed); Thread.sleep(17 - elapsed);
}catch(Exception e) { }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) { private void render(Graphics2D g) {
SceneManager.render(g); SceneManager.render(g);
g.setColor(Color.BLACK); g.setColor(Color.BLACK);

View File

@ -3,14 +3,14 @@ package diveengine2d;
public class RigidBody extends DiveScript{ public class RigidBody extends DiveScript{
public float dx, dy, drot; public float dx, dy, drot;
public float friction = 0.99f; public float friction;
public void update() { public void update() {
entity.x += dx; entity.x += dx;
entity.y += dy; entity.y += dy;
entity.rotation += drot; entity.rotation += drot;
dx *= .3; dx *= friction;
dy *= .3; dy *= friction;
drot *= .3; drot *= friction;
} }
} }

View File

@ -70,7 +70,7 @@ public class SceneManager {
Color color = new Color(r, g, b); Color color = new Color(r, g, b);
scopeObject.peek().getClass().getField(key).set(scopeObject.peek(), color); 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); value = value.substring(0, value.length() - 1);
int intValue; int intValue;
@ -81,6 +81,18 @@ public class SceneManager {
continue; 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); scopeObject.peek().getClass().getField(key).set(scopeObject.peek(), intValue);
} }
@ -120,7 +132,6 @@ public class SceneManager {
continue; continue;
} }
} }
component.create();
component.entity = (Entity) scopeObject.peek(); component.entity = (Entity) scopeObject.peek();
((Entity)scopeObject.peek()).addComponent(component); ((Entity)scopeObject.peek()).addComponent(component);
scopeObject.push(component); scopeObject.push(component);
@ -128,6 +139,11 @@ public class SceneManager {
scopeObject.pop(); scopeObject.pop();
} }
} }
for(Entity e : entities) {
for(DiveScript script : e.components) {
script.create();
}
}
}catch(Exception e) { }catch(Exception e) {
System.out.println(e.getMessage()); System.out.println(e.getMessage());
return false; return false;