physicist.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  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. }
  23. PhysicistView.prototype = new createjs.Sprite();
  24. // PhysicistView.prototype = new createjs.Shape();
  25. PhysicistView.prototype.update = function(){
  26. this.x = cell_size * this.model.position.x + cell_size / 2;
  27. this.y = cell_size * this.model.position.y + cell_size / 2;
  28. this.rotation = this.model.direction.x > 0 ? -90 :
  29. this.model.direction.x < 0 ? 90 :
  30. this.model.direction.y > 0 ? 0 : 180;
  31. }
  32. window.PhysicistView = PhysicistView;
  33. }(window));