Browse Source

fix the snake

Kevin Heinicke 10 years ago
parent
commit
166766f413
4 changed files with 6 additions and 6 deletions
  1. 2 2
      js/controller.js
  2. 1 1
      js/models/snake.js
  3. 2 2
      js/script.js
  4. 1 1
      js/views/physicist.js

+ 2 - 2
js/controller.js

@@ -5,6 +5,7 @@ var Controller = function(){
 	this.collectibles = [];
     this.views = [];
 	this.snake = new Snake(this.initial_length);
+	this.stage = new createjs.Stage("demoCanvas");
 }
 
 Controller.prototype.update_views = function(){
@@ -16,7 +17,6 @@ Controller.prototype.update_views = function(){
 Controller.prototype.start_game = function(){
 	// this.session = new Session();
     var c = this;
-	this.stage = new createjs.Stage("demoCanvas");
 	createjs.Ticker.on("tick", function(e){c.tick(e);});
 	createjs.Ticker.setFPS(20);
 	this.bind_events();
@@ -76,7 +76,7 @@ Controller.prototype.tick = function(event){
 
 Controller.prototype.get_next_cell_position = function(){
 	var ph0 = this.snake.physicists[0];
-	var next_cell = ph0.position;
+	var next_cell = Object.create(ph0.position);
 	next_cell.x += ph0.direction.x;
 	next_cell.y += ph0.direction.y;
 	if (next_cell.x < 0) next_cell.x = this.grid_size.x - 1;

+ 1 - 1
js/models/snake.js

@@ -1,7 +1,7 @@
 var Snake = function(n_physicisits){
 	this.physicists = [];
 	for (var i = 0; i < n_physicisits; i++){
-		this.physicists.push(new Physicist(this, {x: 5 - i, y: 0}));
+		this.physicists.push(new Physicist(this, {x: 0, y: 0}));
 	}
     this.physicists[0].direction = {x: 0, y: 0};
 	this.new_physicists = [];

+ 2 - 2
js/script.js

@@ -3,9 +3,9 @@ var stage, controller;
 function init() {
     controller = new Controller;
 
-    controller.start_game();
-
     resize();
+
+    controller.start_game();
 }
 
 function resize() {

+ 1 - 1
js/views/physicist.js

@@ -1,6 +1,6 @@
 (function(window) {
     function PhysicistView(modelObject){
-        this.graphics.beginFill("red").drawCircle(0, 0, 20);
+        this.graphics.beginFill("red").drawCircle(0, 0, window.cell_size * 0.9 / 2);
         this.model = modelObject;
     }