This file contains hidden or 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 lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>HTML5 Javascript Games!</title> | |
<style> | |
#player { | |
height: 100px; |
This file contains hidden or 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
var Player = function(settings) { | |
// Settings | |
var playerElement = null; | |
// Prevent player from escaping the game window | |
function wall() { | |
} |
This file contains hidden or 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
var Player = function(settings) { | |
// Settings | |
var playerElement = null; | |
// Prevent player from escaping the game window | |
function wall() { | |
var playerRect = playerElement.getBoundingClientRect(); // get the active style values of our moving player | |
var w = parseInt(window.innerWidth); |
This file contains hidden or 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
// World settings | |
var assets = []; // All game objects | |
var player = new Player(settings); // The player | |
assets.push(player); // Add the player as a game asset |
This file contains hidden or 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
var Game = function() { | |
/* SETTINGS */ | |
// Game settings | |
var settings = {}; // Containes all game settings | |
settings.playerSpeed = 8; // The speed of the player | |
settings.walls = true; // The player can not go outside the screen | |
settings.automatic = false; // The player will move by itself | |
settings.godmode = false; // Debug mode |
This file contains hidden or 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
/* Animation */ | |
var self = this; | |
window.requestAnimFrame = (function(){ | |
return window.requestAnimationFrame || | |
window.webkitRequestAnimationFrame || | |
window.mozRequestAnimationFrame || | |
function(callback){ | |
window.setTimeout(callback, 1000 / 60); // 60 frames per sec | |
}; | |
})(); |
NewerOlder