game.script 991 B

12345678910111213141516171819202122
  1. function init(self)
  2. -- get input to this script
  3. msg.post(".", "acquire_input_focus")
  4. -- animate some game objects
  5. go.animate("enemy1", "position.x", go.PLAYBACK_LOOP_PINGPONG, 720, go.EASING_INOUTQUAD, 5, 0)
  6. go.animate("enemy2", "position.x", go.PLAYBACK_LOOP_PINGPONG, 720, go.EASING_INOUTQUAD, 5, 0.5)
  7. go.animate("enemy3", "position.x", go.PLAYBACK_LOOP_PINGPONG, 720, go.EASING_INOUTQUAD, 5, 1)
  8. go.animate("enemy4", "position.x", go.PLAYBACK_LOOP_PINGPONG, 720, go.EASING_INOUTQUAD, 5, 1.5)
  9. end
  10. function on_input(self, action_id, action)
  11. if action_id == hash("key_left") then
  12. msg.post("timestep:/controller", "change_speed", { amount = -0.01 })
  13. elseif action_id == hash("key_right") then
  14. msg.post("timestep:/controller", "change_speed", { amount = 0.01 })
  15. elseif action_id == hash("key_space") and action.pressed then
  16. -- flip self.to between 0 and 3 each time
  17. self.to = 3 - (self.to or 0)
  18. msg.post("timestep:/controller", "animate_speed", { to = self.to })
  19. end
  20. end