Skip to content

Instantly share code, notes, and snippets.

@snggeng
snggeng / index.html
Last active June 6, 2017 01:55
html for html5 game tutorial
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML5 Javascript Games!</title>
<style>
#player {
height: 100px;
var Player = function(settings) {
// Settings
var playerElement = null;
// Prevent player from escaping the game window
function wall() {
}
@snggeng
snggeng / player.js
Last active June 6, 2017 02:59
Player Object
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);
@snggeng
snggeng / game.js
Last active June 6, 2017 01:19
Creating Game Objects
// World settings
var assets = []; // All game objects
var player = new Player(settings); // The player
assets.push(player); // Add the player as a game asset
@snggeng
snggeng / game.js
Created June 4, 2017 12:40
template for HTML5 game engine psuedo-code 1
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
@snggeng
snggeng / game.js
Last active June 6, 2017 01:20
Using window.request and cancel AnimationFrame
/* 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
};
})();