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 | |
}; | |
})(); |
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
// 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 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
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
<!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
// Create the object asset | |
function create() { | |
// in-line styling is important because we will be using the element's | |
// in-line styling to manipulate it's movement, as above in the move() | |
// function | |
playerElement = document.getElementById('player'); | |
playerElement.style.top = '400px'; | |
playerElement.style.left = '400px'; | |
playerElement.style.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
// Move the ball around manually | |
function move(interactions){ | |
if(interactions.up){ | |
playerElement.style.top = parseInt(playerElement.style.top)-8+"px"; | |
} | |
if(interactions.down){ | |
playerElement.style.top = parseInt(playerElement.style.top)+8+"px"; | |
} |
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
// Setup event listeners | |
function setupEvents() { | |
document.addEventListener('keyup', function(event){ | |
var keyName = event.key; | |
switch(keyName) { | |
case "ArrowRight": | |
interactions.right = false; | |
break; |
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
const Enemy = function(settings) { | |
// Settings | |
let enemyElement = null | |
// Prevent enemy from escaping the game window | |
function wall() { | |
const enemyRect = enemyElement.getBoundingClientRect() // get the active style values of our moving enemy | |
const w = parseInt(window.innerWidth) |
OlderNewer