Sfoglia il codice sorgente

physicistView offset

Kevin Heinicke 10 anni fa
parent
commit
9dc2033fc0
2 ha cambiato i file con 21 aggiunte e 5 eliminazioni
  1. 17 3
      js/script.js
  2. 4 2
      js/views/physicist.js

+ 17 - 3
js/script.js

@@ -1,5 +1,8 @@
 var stage, controller;
 
+var minimum_cell_size = 30;
+var maximum_grid_size = 100;
+
 function init() {
     // Do not use this for now...
     // createjs.MotionGuidePlugin.install();
@@ -24,9 +27,20 @@ function init() {
 function resize() {
     var height = window.innerHeight;
     var width = window.innerWidth;
-    window.cell_size = height > width ?
-        height / controller.grid_size.y :
-        width / controller.grid_size.x;
+    if((height / minimum_cell_size) > maximum_grid_size){
+        window.cell_size = height / maximum_grid_size;
+        controller.grid_size.y = maximum_grid_size;
+    } else {
+        controller.grid_size.y = Math.floor(height / minimum_cell_size);
+        window.cell_size = minimum_cell_size;
+    }
+    if((width / minimum_cell_size) > maximum_grid_size){
+        window.cell_size = width / maximum_grid_size;
+        controller.grid_size.y = maximum_grid_size;
+    } else {
+        controller.grid_size.x = Math.floor(width / minimum_cell_size);
+        window.cell_size = minimum_cell_size;
+    }
     controller.stage.canvas.width = width;
     controller.stage.canvas.height = height;
 }

+ 4 - 2
js/views/physicist.js

@@ -3,7 +3,9 @@
         // this.graphics.beginFill("red").drawCircle(0, 0, window.cell_size * 0.9 / 2);
         // TODO: read those values from json/whatever
         var width = 131;
+        this.width = width;
         var height = 135;
+        this.height = height;
         var spriteSheet = new createjs.SpriteSheet({
             framerate: 15,
             images: ["img/physicist/physicist-spritesheet.png"],
@@ -23,8 +25,8 @@
     // PhysicistView.prototype = new createjs.Shape();
 
     PhysicistView.prototype.update = function(){
-        this.x = cell_size * this.model.position.x;
-        this.y = cell_size * this.model.position.y;
+        this.x = cell_size * this.model.position.x + cell_size / 2;
+        this.y = cell_size * this.model.position.y + cell_size / 2;
         this.rotation = this.model.direction.x > 0 ? -90 :
             this.model.direction.x < 0 ? 90 :
             this.model.direction.y > 0 ? 0 : 180;