Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rudimentary border and increase squares' size for better performance #126

Merged
merged 1 commit into from
Jun 3, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions client/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,12 @@ function drawEnemy(enemy) {
}

function drawgrid(){
for (var x = xoffset; x < screenWidth; x += screenHeight/20) {
for (var x = xoffset; x < screenWidth; x += screenHeight/10) {
graph.moveTo(x, 0);
graph.lineTo(x, screenHeight);
}

for (var y = yoffset ; y < screenHeight; y += screenHeight/20) {
for (var y = yoffset ; y < screenHeight; y += screenHeight/10) {
graph.moveTo(0, y);
graph.lineTo(screenWidth, y);
}
Expand All @@ -341,6 +341,44 @@ function drawgrid(){
graph.stroke();
}

function drawborder() {
// Left-vertical
if (player.x <= screenWidth/2) {
graph.beginPath();
graph.moveTo(screenWidth/2 - player.x, 0 ? player.y > screenHeight/2 : screenHeight/2 - player.y);
graph.lineTo(screenWidth/2 - player.x, gameHeight + screenHeight/2 - player.y);
graph.strokeStyle = "#000000";
graph.stroke();
}

// Top-horizontal
if (player.y <= screenHeight/2) {
graph.beginPath();
graph.moveTo(0 ? player.x > screenWidth/2 : screenWidth/2 - player.x, screenHeight/2 - player.y);
graph.lineTo(gameWidth + screenWidth/2 - player.x, screenHeight/2 - player.y);
graph.strokeStyle = "#000000";
graph.stroke();
}

// Right-vertical
if (gameWidth - player.x <= screenWidth/2) {
graph.beginPath();
graph.moveTo(gameWidth + screenWidth/2 - player.x, screenHeight/2 - player.y);
graph.lineTo(gameWidth + screenWidth/2 - player.x, gameHeight + screenHeight/2 - player.y);
graph.strokeStyle = "#000000";
graph.stroke();
}

// Bottom-horizontal
if (gameHeight - player.y <= screenHeight/2) {
graph.beginPath();
graph.moveTo(gameWidth + screenWidth/2 - player.x, gameHeight + screenHeight/2 - player.y);
graph.lineTo(screenWidth/2 - player.x, gameHeight + screenHeight/2 - player.y);
graph.strokeStyle = "#000000";
graph.stroke();
}
}

function gameInput(mouse) {
target.x = mouse.clientX;
target.y = mouse.clientY;
Expand All @@ -366,6 +404,7 @@ function gameLoop() {
graph.fillStyle = backgroundColor;
graph.fillRect(0, 0, screenWidth, screenHeight);
drawgrid();
drawborder();
for (var i = 0; i < foods.length; i++) {
drawFood(foods[i]);
}
Expand Down