115 lines
1.8 KiB
Plaintext
115 lines
1.8 KiB
Plaintext
|
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;
|
||
|
|
||
|
function Initialize()
|
||
|
{
|
||
|
::font = Font ("DejaVuSans.ttf", 24, 1 );
|
||
|
::logo = Image ("image.png", 0.0, 0.0, 1.0, 1.0);
|
||
|
::body = RigidBody();
|
||
|
|
||
|
}
|
||
|
|
||
|
function OnFrame( delta )
|
||
|
{
|
||
|
::frameCount += 1
|
||
|
::lastFPS += delta;
|
||
|
|
||
|
if (::lastFPS > 0.1)
|
||
|
{
|
||
|
::FPS = ::frameCount * 10;
|
||
|
::frameCount = 0;
|
||
|
::lastFPS -= 0.1;
|
||
|
}
|
||
|
|
||
|
if (::FPS > 0)
|
||
|
{
|
||
|
local fps = "FPS: " + FPS + " / " + (1.0/::FPS)*1000.0 + " ms";
|
||
|
::font.print( 10, 10, fps, 1, 1 );
|
||
|
}
|
||
|
// ::logo.draw (0.5, 0.5);
|
||
|
|
||
|
v <- ::body.getPosition();
|
||
|
::font.print(10, 40, "Position: " + v.x + ", " + v.y + ", " + v.z, 1, 1 );
|
||
|
}
|
||
|
|
||
|
function OnStep( delte )
|
||
|
{
|
||
|
::body.applyLocalForce( Vector(0.0, 0.0, 1.0) );
|
||
|
}
|
||
|
|
||
|
function Shutdown()
|
||
|
{
|
||
|
}
|
||
|
|