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

Fullscreen support #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
33 changes: 29 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FernetJS Invaders</title>

<!--
<script type="text/javascript" src="scripts/classes/class.js"></script>
<script type="text/javascript" src="scripts/classes/static.js"></script>
Expand All @@ -27,6 +26,13 @@
window.addEventListener('load', function(){
initInvaders404();
});

document.documentElement.addEventListener('keypress', function(ev){
var keycd = ev.which || ev.keyCode;
if(ev.ctrlKey && [10, 13].indexOf(keycd) !== -1 && invaders){
invaders.goFullscreen();
}
});

function play (){
var splash = document.getElementById('splash');
Expand Down Expand Up @@ -54,6 +60,7 @@
invaders = new Invaders404({
onLoose: function(){
showSplash();
window.invaders.exitFullscreen();
},
onWin: function(){
showSplash();
Expand All @@ -65,9 +72,9 @@
</script>
<style type="text/css">
.ctn {
width: 600px;
height: 400px;
position: relative;
width: 600px;
height: 400px;
position: relative;
}

#splash {
Expand Down Expand Up @@ -100,6 +107,24 @@
border: 1px solid silver;
background-color:#000;
}

#canvas:fullscreen {
width: 100% !important;
height: 100% !important;
display: block;
}

#canvas:-webkit-full-screen {
width: 100% !important;
height: 100% !important;
display: block;
}

#canvas:-moz-full-screen {
width: 100% !important;
height: 100% !important;
display: block;
}
</style>
</head>
<body>
Expand Down
4 changes: 2 additions & 2 deletions invaders404.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions scripts/classes/invaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,18 @@ var Invaders404 = Class.extend({
callback();
}
}, this.loopInterval);
},
goFullscreen : function(){
var canvas = this.canvas,
requestFullscreen = canvas.requestFullscreen || canvas.mozRequestFullScreen || canvas.webkitRequestFullScreen;
if(requestFullscreen){
requestFullscreen.call(canvas);
}
},
exitFullscreen : function(){
var cancelFullscreen = document.cancelFullscreen || document.mozCancelFullScreen || document.webkitCancelFullScreen;
if(cancelFullscreen){
cancelFullscreen.call(document);
}
}
});
2 changes: 1 addition & 1 deletion scripts/classes/ship.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var Ship = DrawableElement.extend({

this.maxMove = {
left: options.maxMoveLeft,
right: options.maxMoveRight,
right: options.maxMoveRight
};

this.onShipHit = options.onShipHit || function(){};
Expand Down