physicist.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. (function(window) {
  2. function PhysicistView(modelObject){
  3. // this.graphics.beginFill("red").drawCircle(0, 0, window.cell_size * 0.9 / 2);
  4. // TODO: read those values from json/whatever
  5. createjs.Sprite.call(this);
  6. var width = 131;
  7. this.width = width;
  8. var height = 135;
  9. this.height = height;
  10. var spriteSheet = new createjs.SpriteSheet({
  11. framerate: 15,
  12. images: ["img/physicist/physicist-spritesheet.png"],
  13. frames: {regX: height/2, height: height, count: 8, regY: width/2, width: width},
  14. animations: {run: [0, 7]}
  15. });
  16. var scale = width > height ? cell_size / width : cell_size / height;
  17. this.scaleX = scale;
  18. this.scaleY = scale;
  19. this.spriteSheet = spriteSheet;
  20. this.gotoAndPlay("run");
  21. this.currentAnimationFrame = Math.floor(Math.random() * 7);
  22. this.model = modelObject;
  23. this.model.view = this;
  24. }
  25. PhysicistView.prototype = new createjs.Sprite();
  26. // PhysicistView.prototype = new createjs.Shape();
  27. PhysicistView.prototype.update = function(){
  28. this.x = cell_size * this.model.position.x + cell_size / 2;
  29. this.y = cell_size * this.model.position.y + cell_size / 2;
  30. this.rotation = this.model.direction.x > 0 ? -90 :
  31. this.model.direction.x < 0 ? 90 :
  32. this.model.direction.y > 0 ? 0 : 180;
  33. }
  34. window.PhysicistView = PhysicistView;
  35. }(window));