game.js 1007 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. (function() {
  2. 'use strict';
  3. function Game() {
  4. this.player = null;
  5. }
  6. Game.prototype = {
  7. create: function () {
  8. var x = this.game.width / 2
  9. , y = this.game.height / 2;
  10. this.player = this.add.sprite(x, y, 'player');
  11. this.player.anchor.setTo(0.5, 0.5);
  12. this.input.onDown.add(this.onInputDown, this);
  13. },
  14. update: function () {
  15. var x, y, cx, cy, dx, dy, angle, scale;
  16. x = this.input.position.x;
  17. y = this.input.position.y;
  18. cx = this.world.centerX;
  19. cy = this.world.centerY;
  20. angle = Math.atan2(y - cy, x - cx) * (180 / Math.PI);
  21. this.player.angle = angle;
  22. dx = x - cx;
  23. dy = y - cy;
  24. scale = Math.sqrt(dx * dx + dy * dy) / 100;
  25. this.player.scale.x = scale * 0.6;
  26. this.player.scale.y = scale * 0.6;
  27. },
  28. onInputDown: function () {
  29. this.game.state.start('menu');
  30. }
  31. };
  32. window['trexrunner'] = window['trexrunner'] || {};
  33. window['trexrunner'].Game = Game;
  34. }());