Simple game engine with complete export to scripting language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

115 lines
1.8 KiB

  1. EntityList <- [];
  2. class Entity
  3. {
  4. function tick (time)
  5. {
  6. }
  7. function step (time)
  8. {
  9. }
  10. }
  11. function onFrame (time)
  12. {
  13. for(local i = 0; i < EntityList.len();)
  14. {
  15. if( EntityList[i].tick( time ) == 1 )
  16. {
  17. EntityList.remove(i);
  18. continue;
  19. }
  20. ++i;
  21. }
  22. }
  23. function onStep (time)
  24. {
  25. for(local i = 0; i < EntityList.len(); ++i )
  26. {
  27. EntityList[i].step( time )
  28. }
  29. }
  30. class Asteroid extends Entity
  31. {
  32. rigidbody = null;
  33. trafonode = null;
  34. modelnode = null;
  35. constructor()
  36. {
  37. rigidbody = RigidBody (this);
  38. rigidbody.addCollisionMesh ("asteroid.collision", 1000.0);
  39. model = Model ("asteroid");
  40. node = Node();
  41. node.setPositionProvider (rigidbody);
  42. node.setRenderProvider (model);
  43. sprite = Sprite ("name");
  44. spritenode = Node (node);
  45. spritenode.setRenderProvider (sprite);
  46. spritenode.setRelativePosition (Vector(10.0, 0.0, 0.0));
  47. //pg = ParticleGenerator ("comettail");
  48. }
  49. function setPosition( position )
  50. {
  51. rigidbody.setPosition( position );
  52. }
  53. }
  54. font <- null;
  55. logo <- null;
  56. lastFPS <- 0;
  57. frameCount <- 0;
  58. FPS <- 1;
  59. body <- null;
  60. function Initialize()
  61. {
  62. ::font = Font();//Font ("DejaVuSans.ttf", 24, 1 );
  63. ::logo = Image ("image.png", 0.0, 0.0, 1.0, 1.0);
  64. ::body = RigidBody();
  65. }
  66. function OnFrame( delta )
  67. {
  68. ::frameCount += 1
  69. ::lastFPS += delta;
  70. if (::lastFPS > 0.1)
  71. {
  72. ::FPS = ::frameCount * 10;
  73. ::frameCount = 0;
  74. ::lastFPS -= 0.1;
  75. }
  76. if (::FPS > 0)
  77. {
  78. local fps = "FPS: " + FPS + " / " + (1.0/::FPS)*1000.0 + " ms";
  79. ::font.print( 10, 10, fps, 1, 1 );
  80. }
  81. // ::logo.draw (0.5, 0.5);
  82. v <- ::body.getPosition();
  83. ::font.print(10, 40, "Position: " + v.x + ", " + v.y + ", " + v.z, 1, 1 );
  84. }
  85. function OnStep( delte )
  86. {
  87. ::body.applyLocalForce( Vector(0.0, 0.0, 1.0) );
  88. }
  89. function Shutdown()
  90. {
  91. }