2008-01-16 11:45:17 +00:00
|
|
|
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;
|
2008-01-20 10:16:37 +00:00
|
|
|
camera <- null;
|
|
|
|
mainSceneGraph <- null;
|
2008-01-16 11:45:17 +00:00
|
|
|
|
|
|
|
function Initialize()
|
|
|
|
{
|
2008-01-18 13:00:18 +00:00
|
|
|
::font = Font();//Font ("DejaVuSans.ttf", 24, 1 );
|
2008-01-16 11:45:17 +00:00
|
|
|
::logo = Image ("image.png", 0.0, 0.0, 1.0, 1.0);
|
|
|
|
::body = RigidBody();
|
2008-01-20 10:16:37 +00:00
|
|
|
::camera = Camera();
|
|
|
|
::mainSceneGraph = SceneGraph();
|
2008-01-24 22:16:53 +00:00
|
|
|
// ::camera.lookAt (0.0, 0.0, 0.0);
|
2008-01-20 10:16:37 +00:00
|
|
|
::mainSceneGraph.setCamera (::camera);
|
2008-01-24 22:16:53 +00:00
|
|
|
setSceneGraph(::mainSceneGraph);
|
|
|
|
local model = Model ("combat");
|
|
|
|
local node = SceneNode("test");
|
|
|
|
node.setModel (model);
|
|
|
|
node.setPosition (0.0, 0.0, -50.0);
|
|
|
|
::mainSceneGraph.attachNode (node);
|
|
|
|
|
2008-01-20 10:16:37 +00:00
|
|
|
}
|
2008-01-16 11:45:17 +00:00
|
|
|
|
2008-01-20 10:16:37 +00:00
|
|
|
function OnFrame (delta, total)
|
|
|
|
{
|
|
|
|
::camera.setPosition (::body.getPosition());
|
2008-01-16 11:45:17 +00:00
|
|
|
}
|
|
|
|
|
2008-01-20 10:16:37 +00:00
|
|
|
function OnOverlay (delta, total)
|
2008-01-16 11:45:17 +00:00
|
|
|
{
|
|
|
|
::frameCount += 1
|
|
|
|
::lastFPS += delta;
|
|
|
|
|
|
|
|
if (::lastFPS > 0.1)
|
|
|
|
{
|
|
|
|
::FPS = ::frameCount * 10;
|
|
|
|
::frameCount = 0;
|
|
|
|
::lastFPS -= 0.1;
|
|
|
|
}
|
2008-01-24 22:16:53 +00:00
|
|
|
/*
|
2008-01-20 10:16:37 +00:00
|
|
|
if (total < 2.0)
|
|
|
|
::logo.draw (0.5, 0.5);
|
|
|
|
else
|
2008-01-24 22:16:53 +00:00
|
|
|
*/
|
2008-01-16 11:45:17 +00:00
|
|
|
{
|
2008-01-20 10:16:37 +00:00
|
|
|
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 );
|
|
|
|
}
|
2008-01-16 11:45:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-20 10:16:37 +00:00
|
|
|
function OnStep (delta, total)
|
2008-01-16 11:45:17 +00:00
|
|
|
{
|
2008-01-24 22:16:53 +00:00
|
|
|
::body.applyLocalForce( Vector(0.0, 0.0, 1.0) );
|
2008-01-20 10:16:37 +00:00
|
|
|
}
|
2008-01-16 11:45:17 +00:00
|
|
|
|
|
|
|
function Shutdown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|