Skip to content

Commit

Permalink
Merge pull request #110 from danprince/food-polygons
Browse files Browse the repository at this point in the history
adds random rotation to each food
  • Loading branch information
igorantun committed Jun 1, 2015
2 parents a05ca28 + d11ef1e commit c105e67
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 11 additions & 3 deletions client/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ function SetupSocket(socket) {

}

function drawCircle(centerX, centerY, size) {
function drawCircle(centerX, centerY, size, rotation) {
rotation = rotation || 0;

var theta = 0,
x = 0,
y = 0,
Expand All @@ -249,7 +251,7 @@ function drawCircle(centerX, centerY, size) {
graph.beginPath();

for(var i = 0; i < size; i++) {
theta = (i / size) * 2 * Math.PI;
theta = rotation + (i / size) * 2 * Math.PI;
x = centerX + radius * Math.sin(theta);
y = centerY + radius * Math.cos(theta);
graph.lineTo(x, y);
Expand All @@ -264,7 +266,13 @@ function drawFood(food) {
graph.strokeStyle = food.color.border || foodConfig.borderColor;
graph.fillStyle = food.color.fill || foodConfig.fillColor;
graph.lineWidth = foodConfig.border;
drawCircle(food.x - player.x + screenWidth / 2, food.y - player.y + screenHeight / 2, foodConfig.size);

drawCircle(
food.x - player.x + screenWidth / 2,
food.y - player.y + screenHeight / 2,
foodConfig.size,
food.rotation
);
}

function drawPlayer() {
Expand Down
3 changes: 2 additions & 1 deletion server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ function addFoods(target) {
id: (new Date()).getTime(),
x: genPos(0, target.gameWidth),
y: genPos(0, target.gameHeight),
color: randomColor()
color: randomColor(),
rotation: Math.random() * (Math.PI * 2)
});
}

Expand Down

0 comments on commit c105e67

Please sign in to comment.