5soemsmtir84^3bhbsk6ci1_.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /******************************************************************************/
  2. DestructMesh destruct; // since currently there is no way to create 'DestructMesh' from the Editor, we need to create it manually in codes
  3. File SaveGame;
  4. /******************************************************************************/
  5. class Destructible : Game.Destructible
  6. {
  7. virtual void setUnsavedParams()
  8. {
  9. destruct_mesh=&destruct; // set which destructible mesh we want to use
  10. super.setUnsavedParams();
  11. }
  12. virtual void create(Object &obj)
  13. {
  14. super.create(obj);
  15. toStatic(); // default to static mode at the start
  16. }
  17. }
  18. Game.ObjMap<Destructible> Destructibles;
  19. /******************************************************************************/
  20. void InitPre()
  21. {
  22. EE_INIT();
  23. Ms.hide();
  24. Ms.clip(null, 1);
  25. Physics.create(EE_PHYSX_DLL_PATH);
  26. Cam.dist =10;
  27. Cam.yaw =-PI_4;
  28. Cam.pitch=-0.5;
  29. Cam.at.set(16, 0, 16);
  30. }
  31. /******************************************************************************/
  32. bool Init()
  33. {
  34. // create a destruct mesh
  35. Object obj;
  36. obj.base(UID(1134879343, 1157937325, 4232119955, 3140023117));
  37. obj.type(true, ObjType.elmID(OBJ_DESTRUCTIBLE)); // override type to set DESTRUCTIBLE class
  38. if(!obj.mesh())Exit("object has no mesh");
  39. destruct.create(*obj.mesh(), 8, UID(2519161163, 1078307672, 184317862, 2816697732), 1, 32);
  40. // load world
  41. Game.World.activeRange(D.viewRange())
  42. .setObjType(Destructibles, OBJ_DESTRUCTIBLE)
  43. .New(UID(3692432343, 1256681024, 2863582642, 4182715660));
  44. if(Game.World.settings().environment)Game.World.settings().environment->set();
  45. Game.World.objCreate(obj, Matrix().setPos(Cam.at));
  46. return true;
  47. }
  48. /******************************************************************************/
  49. void Shut()
  50. {
  51. Game.World.del();
  52. }
  53. /******************************************************************************/
  54. bool Update()
  55. {
  56. if(Kb.bp(KB_ESC))return false;
  57. if(Kb.bp(KB_F2)) Game.World.save(SaveGame.writeMem()); // save game to file in memory
  58. if(Kb.bp(KB_F3)){SaveGame.pos(0); Game.World.load(SaveGame );} // reset file position and load game from it
  59. Cam.transformByMouse(0.01, 10, CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT));
  60. Game.World.update(Cam.at);
  61. if(Kb.bp(KB_SPACE))
  62. {
  63. REPA(Destructibles)Destructibles[i].toPieces(); // first convert all destructible objects into pieces, this may create more objects in the world
  64. REPA(Destructibles) // now adjust velocities to all objects
  65. {
  66. Destructible &d=Destructibles[i];
  67. REPAO(d.actors).vel(Random(Ball(12)));
  68. }
  69. }
  70. return true;
  71. }
  72. /******************************************************************************/
  73. void Render()
  74. {
  75. Game.World.draw();
  76. }
  77. void Draw()
  78. {
  79. Renderer(Render);
  80. if(Kb.b(KB_LCTRL))
  81. {
  82. Renderer.setDepthForDebugDrawing();
  83. Physics.draw();
  84. }
  85. D.text(0, 0.9, "Press Space to Explode");
  86. }
  87. /******************************************************************************/