Created
November 28, 2011 04:36
-
-
Save pilate/1399129 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="viewport" content="width=device-width; height=device-height; initial-scale=1.0; maximum-scale=1.0;"/> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> | |
<script type="text/javascript"> | |
window.onload=function(){ | |
// Hide URL bar | |
window.scrollTo(0, 1); | |
// Declare context with canvas | |
var ctx; | |
ctx = $('#canvas')[0].getContext("2d"); | |
// Declare sound | |
var start_sound = document.createElement('audio'); | |
var title_sound = document.createElement('audio'); | |
var cut_1_sound = document.createElement('audio'); | |
// Set sound src | |
start_sound.setAttribute('src', 'sounds/start.mp3'); | |
title_sound.setAttribute('src', 'sounds/title.mp3'); | |
cut_1_sound.setAttribute('src', 'sounds/cut_1.mp3'); | |
// Declare images | |
var start_screen = new Image(); | |
var cut_1 = new Image(); | |
var cut_2 = new Image(); | |
var cut_3 = new Image(); | |
var cut_4 = new Image(); | |
var cut_5 = new Image(); | |
var cut_6 = new Image(); | |
// Set image src | |
start_screen.src = "images/title.jpg"; | |
cut_1.src = "images/cut_1.jpg"; | |
cut_2.src = "images/cut_2.jpg"; | |
cut_3.src = "images/cut_3.jpg"; | |
cut_4.src = "images/cut_4.jpg"; | |
cut_5.src = "images/cut_5.jpg"; | |
cut_6.src = "images/cut_6.jpg"; | |
// Title screen class | |
function title_screen() { | |
var self = this; | |
this.img = start_screen; | |
this.loop = 1; | |
this.draw = function() { | |
ctx.drawImage(start_screen, 0, 0); | |
} | |
this.sound_play = function() { | |
title_sound.play(); | |
} | |
this.get_input = function() { | |
var keysDown = {}; | |
var loop = this.loop; | |
addEventListener("keydown", function (e) { | |
keysDown[e.keyCode] = true; | |
console.log("pressed"); | |
if (e.keyCode == 13) { | |
console.log("ENTER pressed"); | |
self.loop = 0; | |
} | |
}, false); | |
addEventListener("keyup", function (e) { | |
delete keysDown[e.keyCode]; | |
}, false); | |
} | |
this.run = function() { | |
while (this.loop == 1) { | |
this.get_input(); | |
this.sound_play(); | |
this.draw(); | |
this.loop = 0; | |
} | |
} | |
} | |
// Start game | |
oso_title_screen = new title_screen; | |
oso_title_screen.run(); | |
} | |
</script> | |
</head> | |
<body style="margin:0;padding:0;"> | |
<canvas id="canvas" width="480" height="320"> | |
Your browser does not support the canvas element. | |
</canvas> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment