Skip to content

Commit

Permalink
Created visalization for tail nibbling based on snakeInfo.tailProtect…
Browse files Browse the repository at this point in the history
…edForGameTicks - issue #150 - See game with ID 948f701b-248b-4a3f-b2f5-7e18e4a5b601
  • Loading branch information
jonas.ohrn committed Dec 15, 2016
1 parent d776e8c commit 95827a2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/util/TileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Colors from './Colors';

const deadSnakes = [];
const imgCache = {};
const toRad = Math.PI / 180;

function _renderSnakeBody(stage, map, snake, tileSize, color) {
const lastIndex = snake.positions.length - 1;
Expand Down Expand Up @@ -55,6 +56,19 @@ function _renderSnakeBody(stage, map, snake, tileSize, color) {
const rotation = _getTailRotation(snake.positions, map);
const snakeTail = Images.getSnakeTail(color.code);
_renderImage(stage, pos, tileSize, snakeTail, rotation, color.alpha, lineWidth);

const ticks = snake.tailProtectedForGameTicks;
if (ticks > 0) {
const arc = new createjs.Shape();
const angle = rotation + 90;

arc.graphics
.setStrokeStyle(ticks + 1)
.beginStroke('white')
.arc(posX + halfTile, posY + halfTile, halfTile,
(angle - 45) * toRad, (angle + 45) * toRad);
stage.addChild(arc);
}
} else {
const prevPos = _getTileCoordinate(snake.positions[index - 1], map);
const nextPos = _getTileCoordinate(snake.positions[index + 1], map);
Expand Down

0 comments on commit 95827a2

Please sign in to comment.