train_leaves_in_one_minute.nut 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. class TrainManager {
  2. image = null
  3. text = null
  4. time = 0
  5. time_multiplier = 1
  6. random_thing = 0
  7. sound = "sounds/phone.wav"
  8. train = [
  9. sector.trainint
  10. sector.trainbg
  11. sector.trainbg2
  12. ]
  13. constructor(_time = 60) {
  14. image = FloatingImage("images/objects/train/train.png")
  15. image.set_anchor_point(ANCHOR_TOP)
  16. image.set_pos(-22, 43)
  17. text = TextObject()
  18. text.set_anchor_point(ANCHOR_TOP)
  19. text.set_pos(34, 50)
  20. text.set_front_fill_color(0, 0, 0, 0)
  21. text.set_back_fill_color(0, 0, 0, 0)
  22. random_thing = rand()
  23. sector.settings.add_object("scriptedobject", "dummy_tux_" + random_thing, -64, -64, "auto",
  24. "(physic-enabled #f)(solid #f)(name \"dummy_tux_" + random_thing+ "\")(sprite \"/images/creatures/tux/tux.sprite\")")
  25. time = _time + 1
  26. }
  27. function start() {
  28. image.set_visible(true)
  29. text.set_visible(true)
  30. while(time > 0) {
  31. time--
  32. text.set_text(time.tostring())
  33. if(time == 5) play_sound(sound)
  34. wait(time_multiplier)
  35. }
  36. leave()
  37. }
  38. function leave() {
  39. text.set_text("Train is departing!")
  40. //text.set_pos(50, 50)
  41. local cur_speed = 0
  42. depart()
  43. while(true) {
  44. cur_speed += 0.02
  45. image.set_pos(image.get_pos_x() + cur_speed, image.get_pos_y())
  46. wait(0.01)
  47. }
  48. }
  49. function depart(_sound = true) {
  50. if(_sound) play_sound(sound)
  51. foreach(v in train) v.start_moving()
  52. }
  53. function losing_cutscene() {
  54. if(time > 0) return
  55. Tux.deactivate()
  56. Tux.activate()
  57. stop_music(5)
  58. Tux.use_scripting_controller(true)
  59. wait(2)
  60. Tux.do_scripting_controller("left", true)
  61. wait(0.1)
  62. Tux.do_scripting_controller("left", false)
  63. wait(0.9)
  64. Tux.do_scripting_controller("right", true)
  65. wait(0.1)
  66. Tux.do_scripting_controller("right", false)
  67. wait(2)
  68. if(sector.Tux.get_bonus() == "none")
  69. DummyTux.set_action("small-stand-right")
  70. if(sector.Tux.get_bonus() == "grow")
  71. DummyTux.set_action("big-stand-right")
  72. if(sector.Tux.get_bonus() == "fireflower")
  73. DummyTux.set_action("fire-stand-right")
  74. if(sector.Tux.get_bonus() == "iceflower")
  75. DummyTux.set_action("ice-stand-right")
  76. if(sector.Tux.get_bonus() == "airflower")
  77. DummyTux.set_action("air-stand-right")
  78. if(sector.Tux.get_bonus() == "earthflower")
  79. DummyTux.set_action("earth-stand-right")
  80. Tux.set_visible(false)
  81. DummyTux.set_pos(Tux.get_x(), Tux.get_y())
  82. Tux.kill(true)
  83. wait(0.01)
  84. stop_music(0)
  85. }
  86. function win() {
  87. Tux.trigger_sequence("endsequence")
  88. depart(false)
  89. }
  90. }
  91. sector.train_manager <- TrainManager()
  92. /*
  93. sector.time <- 60
  94. Text.set_anchor_point(ANCHOR_TOP)
  95. //Text.set_pos(22, 50)
  96. Text.set_front_fill_color(0, 0, 0, 0)
  97. Text.set_back_fill_color(0, 0, 0, 0)
  98. Text.set_visible(true)
  99. //Train <- FloatingImage("images/creatures/tux/small/stand-0.png");
  100. Train <- FloatingImage("levels/bonusislands/Train.png");
  101. Train.set_anchor_point(ANCHOR_TOP)
  102. Train.set_pos(-22, 43)
  103. Train.set_visible(true)
  104. //Text.set_pos(Train.get_width(), 50)
  105. Text.set_pos(34, 50)
  106. for(local t = sector.time; t > -1; t -= 1) {
  107. sector.set_time <- function(timm) t = timm
  108. Text.set_text(t.tostring())
  109. sector.time = t
  110. if(t == 5) play_sound("sounds/phone.wav")
  111. wait(1)
  112. }
  113. Text.set_text(""sounds/phone.wav"")
  114. play_sound("sounds/phone.wav")
  115. trainint.start_moving()
  116. trainbg.start_moving()
  117. trainbg2.start_moving()
  118. local speed = 0.01
  119. while(true) {
  120. Train.set_pos(Train.get_pos_x() + speed, Train.get_pos_y())
  121. speed += 0.01
  122. wait(0.01)
  123. }
  124. if(sector.time < 1) {
  125. Tux.deactivate()
  126. Tux.activate()
  127. stop_music(5)
  128. Tux.use_scripting_controller(true)
  129. wait(2)
  130. Tux.do_scripting_controller("left", true)
  131. wait(0.1)
  132. Tux.do_scripting_controller("left", false)
  133. wait(0.9)
  134. Tux.do_scripting_controller("right", true)
  135. wait(0.1)
  136. Tux.do_scripting_controller("right", false)
  137. wait(2)
  138. if((sector.Tux.get_bonus() == ("small"))
  139. DummyTux.set_action("small-stand-right")
  140. if((sector.Tux.get_bonus() == ("big"))
  141. DummyTux.set_action("big-stand-right")
  142. if((sector.Tux.get_bonus() == ("fire"))
  143. DummyTux.set_action("fire-stand-right")
  144. if((sector.Tux.get_bonus() == ("ice"))
  145. DummyTux.set_action("ice-stand-right")
  146. if((sector.Tux.get_bonus() == ("air"))
  147. DummyTux.set_action("air-stand-right")
  148. if((sector.Tux.get_bonus() == ("earth"))
  149. DummyTux.set_action("earth-stand-right")
  150. Tux.set_visible(false)
  151. DummyTux.set_pos(Tux.get_x(), Tux.get_y())
  152. Tux.kill(true)
  153. wait(0.01)
  154. stop_music(0)
  155. }
  156. if(sector.time > 0) {
  157. //level ends
  158. Tux.trigger_sequence("endsequence")
  159. // train moves
  160. trainint.start_moving();
  161. trainbg.start_moving();
  162. trainbg2.start_moving();
  163. //wait(1);
  164. //Effect.fade_out(1);
  165. }
  166. */