Skip to content

Commit

Permalink
Updated issue #152 - Fixed rendering of dead snakes to use same code …
Browse files Browse the repository at this point in the history
…as normal snakes with alpha on body and head/tail images.

Improved line rendering at edges.
Restored .eslintrc file to original.
  • Loading branch information
jonas.ohrn committed Dec 15, 2016
1 parent 06fd329 commit d776e8c
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 274 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"props": false
}],
"no-console": ["off"],
"no-mixed-operators": ["off"],
"react/jsx-indent": ["off"]
}
}
44 changes: 4 additions & 40 deletions app/constants/Images.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,9 @@ import snake000000Tail from '../design/images/snakes/000000/000000_TAIL.png';
import snakeFF4848Tail from '../design/images/snakes/FF4848/FF4848_TAIL.png';
import snake9AF48ETail from '../design/images/snakes/9AF48E/9AF48E_TAIL.png';
import snake9BF3F0Tail from '../design/images/snakes/9BF3F0/9BF3F0_TAIL.png';
// 50% alpha
import deadSnakeTail50 from '../design/images/snakes/999999/grey-dead-tail-50.svg';
import deadSnakeHead50 from '../design/images/snakes/999999/grey-dead-head-50.svg';
import deadSnakeBody50 from '../design/images/snakes/999999/grey-dead-body-50.svg';
// 70% alpha
import deadSnakeTail70 from '../design/images/snakes/999999/grey-dead-tail-70.svg';
import deadSnakeHead70 from '../design/images/snakes/999999/grey-dead-head-70.svg';
import deadSnakeBody70 from '../design/images/snakes/999999/grey-dead-body-70.svg';
// 100% alpha
import deadSnakeTail100 from '../design/images/snakes/999999/grey-dead-tail-100.svg';
import deadSnakeHead100 from '../design/images/snakes/999999/grey-dead-head-100.svg';
import deadSnakeBody100 from '../design/images/snakes/999999/grey-dead-body-100.svg';

const starImg = star;

Expand Down Expand Up @@ -60,9 +51,9 @@ function _getSnakeHead(color) {
return snake9AF48E;
case '#9BF3F0' :
return snake9BF3F0;
case '#dead' : {
case '#dead' :
case '#999999' :
return deadSnakeHead100;
}
default:
return snake000000;
}
Expand Down Expand Up @@ -92,44 +83,17 @@ function _getSnakeTail(color) {
return snake9AF48ETail;
case '#9BF3F0' :
return snake9BF3F0Tail;
default:
return snake000000Tail;
}
}

function _getDeadImage(part, alpha) {
switch (part) {
case 'head':
if (alpha === 70) {
return deadSnakeHead70;
} else if (alpha === 50) {
return deadSnakeHead50;
}
return deadSnakeHead100;
case 'tail':
if (alpha === 70) {
return deadSnakeTail70;
} else if (alpha === 50) {
return deadSnakeTail50;
}
case '#999999' :
return deadSnakeTail100;
default:
if (alpha === 70) {
return deadSnakeBody70;
} else if (alpha === 50) {
return deadSnakeBody50;
}
return deadSnakeBody100;
return snake000000Tail;
}
}

export default {
getStarImage(position) {
return { src: starImg, key: 'star_' + position };
},
getDeadImage(part, alpha) {
return { src: _getDeadImage(part, alpha), key: undefined };
},
getSnakeHead(color) {
return { src: _getSnakeHead(color), key: 'head_' + color };
},
Expand Down
10 changes: 0 additions & 10 deletions app/design/images/snakes/999999/grey-dead-body-100.svg

This file was deleted.

10 changes: 0 additions & 10 deletions app/design/images/snakes/999999/grey-dead-body-50.svg

This file was deleted.

10 changes: 0 additions & 10 deletions app/design/images/snakes/999999/grey-dead-body-70.svg

This file was deleted.

16 changes: 0 additions & 16 deletions app/design/images/snakes/999999/grey-dead-head-50.svg

This file was deleted.

16 changes: 0 additions & 16 deletions app/design/images/snakes/999999/grey-dead-head-70.svg

This file was deleted.

10 changes: 0 additions & 10 deletions app/design/images/snakes/999999/grey-dead-tail-50.svg

This file was deleted.

10 changes: 0 additions & 10 deletions app/design/images/snakes/999999/grey-dead-tail-70.svg

This file was deleted.

14 changes: 6 additions & 8 deletions app/game/components/GameBoard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ import GameControl from './sidebar/GameControl';

function getGameState() {
const state = Store.getActiveGameState();
const deadSnakes = Store.getDeadSnakes();
return { state, deadSnakes };
return { state };
}

const propTypes = {
deadSnakes: React.PropTypes.array.isRequired,// eslint-disable-line
state: React.PropTypes.object.isRequired, // eslint-disable-line
params: React.PropTypes.object.isRequired,
routes: React.PropTypes.object.isRequired,
routes: React.PropTypes.array.isRequired,
};

class GameBoard extends React.Component {
Expand Down Expand Up @@ -103,11 +101,11 @@ class GameBoard extends React.Component {
}

renderDeadSnakes(mapEvent, tileSize, state) {
const allDeadSnakes = this.props.deadSnakes.filter(snake =>
const allDeadSnakes = state.deadSnakes.filter(snake =>
(mapEvent.worldTick > snake.worldTick && snake.worldTick + snake.ttl >= mapEvent.worldTick)
);

const collisions = this.props.deadSnakes.filter(snake =>
const collisions = state.deadSnakes.filter(snake =>
mapEvent.worldTick === (snake.worldTick + 1)
);

Expand Down Expand Up @@ -164,8 +162,8 @@ class GameBoard extends React.Component {
<div className="gameboard">
<canvas
id="canvas"
width={size.width + 1}
height={size.height + 1}
width={size.width + 0}
height={size.height + 0}
ref={(c) => {
this.canvas = c;
}}
Expand Down
2 changes: 1 addition & 1 deletion app/util/Colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export default {
getBoardColor(i) {
return boardColors[i];
},

getSnakeColor(i) {
return snakeColors[i];
},
DEAD_SNAKE: '#999999',
};
Loading

0 comments on commit d776e8c

Please sign in to comment.