Skip to content

Instantly share code, notes, and snippets.

@snggeng
Created June 4, 2017 12:40
Show Gist options
  • Save snggeng/223268ffb33cd32a23513fc083167d9d to your computer and use it in GitHub Desktop.
Save snggeng/223268ffb33cd32a23513fc083167d9d to your computer and use it in GitHub Desktop.
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
// World settings
var assets = []; // All game objects
var player = new Player(settings); // The player
assets.push(player); // Add the player as a game asset
var frame = 0; // Frames since the start of the game
/* INTERACTIONS */
// Interactions
var interactions = {};
interactions.up = false; // Up arrow key pressed
interactions.down = false; // Down arrow key pressed
interactions.left = false; // Left arrow key pressed
interactions.right = false; // Right arrow ket pressed
interactions.space = false; // Speace key pressed
// Setup event listeners
function setupEvents() {
// Add event listeners for different types of events in the game
}
// Startup the game
function init(){
setupEvents();
}
/* ANIMATION */
// The render function. It will be called 60 frames/sec
this.render = function(){
for(var i=0; i < assets.length; i++){
assets[i].render(interactions); // render all game objects
}
frame++;
}
// Animate the game by calling the render function in the browser window 60 frames every second
// Some function
init(); // Initialize game settings before game begins
}
var g = new Game(); // Start game
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment