templates.ecal 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import "./const.ecal" as const
  2. import "./helper.ecal" as hlp
  3. /*
  4. newGameWorld creates a new game world datastructure.
  5. */
  6. func newGameWorld(name) {
  7. let ret := hlp.copyMap(DefaultGameWorld)
  8. ret["key"] := name
  9. ret["kind"] := const.NodeKinds.ConfigurationObject
  10. return ret
  11. }
  12. DefaultGameWorld := {
  13. "backdrop" : null,
  14. "screenWidth" : 640,
  15. "screenHeight" : 480,
  16. "screenElementWidth" : 640,
  17. "screenElementHeight" : 480
  18. }
  19. /*
  20. newSpriteNode creates a new sprite node datastructure.
  21. */
  22. func newSpriteNode(id, x, y, dim=20, rot=0, speed=0) {
  23. let ret := hlp.copyMap(DefaultSpriteState)
  24. ret["key"] := id
  25. ret["kind"] := const.NodeKinds.GameWorldObject
  26. ret["id"] := id
  27. ret["x"] := x
  28. ret["y"] := y
  29. ret["dim"] := dim
  30. ret["rot"] := rot
  31. ret["speed"] := speed
  32. return ret
  33. }
  34. DefaultSpriteState := {
  35. /* A unique ID */
  36. "id" : "",
  37. /* Sprite x position */
  38. "x" : 20,
  39. /* Sprite y position */
  40. "y" : 20,
  41. /* Dimensions of the sprite (box) */
  42. "dim" : 20,
  43. /* Flag if the sprite is moving or static */
  44. "isMoving" : true,
  45. /*
  46. Flag if the sprite is kept in the display or if it should be
  47. destroyed once it is outside of the visible area
  48. */
  49. "displayLoop" : true,
  50. /* Turning direction (-1 for left, 1 for right, 0 no turning) */
  51. "dir" : 0,
  52. /* Angle of rotation */
  53. "rot" : 0,
  54. /* Rotation speed for each step (in radians) */
  55. "rotSpeed" : math.Pi / 180,
  56. /* Moving direction (1 forward, -1 backwards, 0 no movement) */
  57. "speed" : 0,
  58. /* Strafing direction of sprite (-1 left, 1 right, 0 no movement) */
  59. "strafe" : 0,
  60. /* Move speed for each step */
  61. "moveSpeed" : 0.21
  62. }