Commit 8ebe1f89 authored by Hubert Denkmair's avatar Hubert Denkmair
Browse files

make SnakeSegment independent from Snake

parent 14b41de5
......@@ -29,16 +29,6 @@ function Snake(headTexture, bodyTexture, name, colorScheme, world_size_x, world_
this.Container.addChild(this._nameSprite);
}
Snake.prototype.GetBodyTexture = function()
{
return this._bodyTexture;
};
Snake.prototype.GetCurrentSnakeScale = function()
{
return this.spriteScale;
};
Snake.prototype.SetData = function(data)
{
this.heading = data.heading;
......@@ -70,12 +60,14 @@ Snake.prototype.SetLength = function(newLength)
for (let i=this.GetLength(); i<newLength; i++)
{
let segment = new SnakeSegment(this);
let segment = new SnakeSegment(this._bodyTexture);
if (this._segments.length > 0)
{
segment.ClonePosition(this._segments[this._segments.length-1]);
}
segment.SetTint(this._colorScheme[i % this._colorScheme.length]);
segment.SetScale(this.spriteScale);
this._segmentContainer.addChildAt(segment.GetSprite(), 0);
this._segments.push(segment);
}
......
"use strict";
function SnakeSegment(snake)
function SnakeSegment(texture)
{
this.x = 0;
this.y = 0;
this._sprite = new PIXI.Sprite(snake.GetBodyTexture());
this._sprite = new PIXI.Sprite(texture);
this._sprite.anchor.set(0.5);
this._sprite.alpha = 0.8;
this.SetScale(snake.GetCurrentSnakeScale());
}
SnakeSegment.prototype.GetSprite = function()
......@@ -45,14 +44,6 @@ SnakeSegment.prototype.MoveDirection = function(direction, length)
);
};
SnakeSegment.prototype.MoveRelative = function(dx, dy)
{
this.SetPosition(
this.x + dx,
this.y + dy
);
};
SnakeSegment.prototype.UpdateSprites = function()
{
this._sprite.x = this.x;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment