Last active
December 20, 2015 00:19
-
-
Save susanndelgado/6040917 to your computer and use it in GitHub Desktop.
Working on a game demo to test my JavaScript abilities. This example is not made cross-browser compatible as of yet. My major concern was to be able to create a rpg game with modular coding practices and later it the project turns out worth while I will make it more cross browser compatible and add additional enhancements as needed
This file contains 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 HERO = (function(self) { | |
function init() { | |
console.log('Hero exist!'); | |
} | |
var _globals = { | |
name: 'hero', | |
source: 'hero.png', | |
width: 100, | |
height:100, | |
health: 100 | |
} | |
function setSrc(src){ | |
_globals.source = src; | |
} | |
function getSrc() { | |
return _globals.source; | |
} | |
function setName(name){ | |
_globals.name = name; | |
} | |
function getName() { | |
return _globals.name; | |
} | |
function walk() { | |
_keyBinds().setKeys(); | |
} | |
function _keyBinds(){ | |
return { | |
setKeys: function(e) { | |
document.addEventListener('keydown', function (e) { | |
if (e.keyCode == 37) { | |
console.log(e.keyCode); | |
$('#'+_globals.name).animate( | |
{ | |
'left': '-=10' | |
}, 1); | |
e.preventDefault(); | |
} | |
if (e.keyCode == 39) { | |
console.log(e.keyCode); | |
$('#'+_globals.name).animate( | |
{ | |
'left': '+=10' | |
}, 1); | |
e.preventDefault(); | |
} | |
if (e.keyCode == 38) { | |
console.log(e.keyCode); | |
$('#'+_globals.name).animate( | |
{ | |
'top': '-=10' | |
}, 1); | |
e.preventDefault(); | |
} | |
if (e.keyCode == 40) { | |
console.log(e.keyCode); | |
$('#'+_globals.name).animate( | |
{ | |
'top': '+=10' | |
}, 1); | |
e.preventDefault(); | |
} | |
}); | |
} | |
} | |
} | |
init(); | |
return { | |
//createHero : init, | |
setHeroImg : setSrc, | |
getHeroImg : getSrc, | |
setName : setName, | |
getName : getName, | |
walk : walk | |
}; | |
}(HERO || {})); | |
//game related stuff | |
var TESTRAGE = (function(self){ | |
function init() { | |
console.log('game Exist!') | |
} | |
var _globals = { | |
gamePlay: false, | |
gameWin: false, | |
points: 0, | |
} | |
function gameSetUp(gameObj) { | |
HERO.setHeroImg('img/hero.png'); | |
HERO.setName('hero'); | |
var heroSrc = HERO.getHeroImg(), | |
heroName = HERO.getName(); | |
$('#gameScreen').append('<div id="'+heroName+'"><img src="'+heroSrc+'" alt="hero"/></div>'); | |
HERO.walk(); | |
//enemies : append enemy div | |
} | |
init(); | |
return { | |
gameSetUp : gameSetUp | |
} | |
}(TESTRAGE || {})); | |
$(function() { | |
TESTRAGE.gameSetUp(); | |
//code here | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment