Tuesday 25 February 2014

Beat monster game by HTML5

From last article about animation, today we move to the game beat monster.
In this game, we create a map as matrix 4x4. Then, each time users click or mouse over monster, we change its location. If user click on head of monster, he ore she get one point. In this game, we learn how to make sound every click of user.
First of all, check over the game as below:




To play sound we use this function:
function play(sound) {
if (window.HTMLAudioElement) {
var snd = new Audio('');
if(snd.canPlayType('audio/ogg')) {
snd = new Audio('sounds/' + sound + '.ogg');
}
else if(snd.canPlayType('audio/mp3')) {
snd = new Audio('sounds/' + sound + '.mp3');
}
snd.play();
}
else {
alert('HTML5 Audio is not supported by your browser!');
}
}
You can download source code here: http://dl.tmtn.vn/1d

No comments:

Post a Comment