EntityList <- []; class Entity { function tick (time) { } function step (time) { } } function onFrame (time) { for(local i = 0; i < EntityList.len();) { if( EntityList[i].tick( time ) == 1 ) { EntityList.remove(i); continue; } ++i; } } function onStep (time) { for(local i = 0; i < EntityList.len(); ++i ) { EntityList[i].step( time ) } } class Asteroid extends Entity { rigidbody = null; trafonode = null; modelnode = null; constructor() { rigidbody = RigidBody (this); rigidbody.addCollisionMesh ("asteroid.collision", 1000.0); model = Model ("asteroid"); node = Node(); node.setPositionProvider (rigidbody); node.setRenderProvider (model); sprite = Sprite ("name"); spritenode = Node (node); spritenode.setRenderProvider (sprite); spritenode.setRelativePosition (Vector(10.0, 0.0, 0.0)); //pg = ParticleGenerator ("comettail"); } function setPosition( position ) { rigidbody.setPosition( position ); } } font <- null; logo <- null; lastFPS <- 0; frameCount <- 0; FPS <- 1; body <- null; camera <- null; mainSceneGraph <- null; function Initialize() { ::font = Font();//Font ("DejaVuSans.ttf", 24, 1 ); ::logo = Image ("image.png", 0.0, 0.0, 1.0, 1.0); ::body = RigidBody(); ::camera = Camera(); ::mainSceneGraph = SceneGraph(); // ::camera.lookAt (0.0, 0.0, 0.0); ::mainSceneGraph.setCamera (::camera); setSceneGraph(::mainSceneGraph); local model = Model ("combat"); local node = SceneNode("test"); node.setModel (model); node.setPosition (0.0, 0.0, -50.0); ::mainSceneGraph.attachNode (node); } function OnFrame (delta, total) { ::camera.setPosition (::body.getPosition()); } function OnOverlay (delta, total) { ::frameCount += 1 ::lastFPS += delta; if (::lastFPS > 0.1) { ::FPS = ::frameCount * 10; ::frameCount = 0; ::lastFPS -= 0.1; } /* if (total < 2.0) ::logo.draw (0.5, 0.5); else */ { v <- ::body.getPosition(); ::font.print(10, 40, "Position: " + v.x + ", " + v.y + ", " + v.z, 1, 1 ); local seconds = floor(total % 60); if (seconds < 10) ::font.print(10, 70, "Time: " + floor(total / 60.0) + ":0" + seconds, 1, 1 ); else ::font.print(10, 70, "Time: " + floor(total / 60.0) + ":" + seconds, 1, 1 ); if (::FPS > 0) { local fps = "FPS: " + FPS + " / " + (1.0/::FPS)*1000.0 + " ms"; ::font.print( 10, 10, fps, 1, 1 ); } } } function OnStep (delta, total) { ::body.applyLocalForce( Vector(0.0, 0.0, 1.0) ); } function Shutdown() { }