physicist.js 1.4 KB

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