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

Game Start/Stop #1

Open
GregLaFauci opened this issue Feb 26, 2019 · 2 comments
Open

Game Start/Stop #1

GregLaFauci opened this issue Feb 26, 2019 · 2 comments

Comments

@GregLaFauci
Copy link
Owner

currently the game is just set to run. when there is a crash the game just reloads.

let's make the game start on a keypress (maybe 's')

let's make the game show a score screen, and ask the user if they want to play again.

additional functionality to implement:

'p' for pause

@keonnicholas
Copy link
Collaborator

Added, 'p' to pause.
Added splash modal div on game start.

@GregLaFauci
Copy link
Owner Author

code for creating a button directly on canvas

//Function to get the mouse position
function getMousePos(canvas, event) {
var rect = canvas.getBoundingClientRect();
return {
x: event.clientX - rect.left,
y: event.clientY - rect.top
};
}
//Function to check whether a point is inside a rectangle
function isInside(pos, rect){
return pos.x > rect.x && pos.x < rect.x+rect.width && pos.y < rect.y+rect.height && pos.y > rect.y
}

var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
//The rectangle should have x,y,width,height properties
var rect = {
x:250,
y:350,
width:200,
height:100
};
//Binding the click event on the canvas
canvas.addEventListener('click', function(evt) {
var mousePos = getMousePos(canvas, evt);

if (isInside(mousePos,rect)) {
    alert('clicked inside rect');
}else{
    alert('clicked outside rect');
}   

}, false);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants