Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OOP JS in Simple Game #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added images/boss.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 41 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Simple Canvas Game</title>
</head>
<body>
<script src="js/game.js"></script>
</body>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Simple Canvas Game</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
</head>
<body>
<script src="js/curl.js"></script>
<script>
curl({
'baseUrl': '',
'paths': {
'curl': 'js/curl',
'jquery': '//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min',
'monster.js': 'js/Monster.js',
'hero.js': 'js/Hero.js',
'game.js': 'js/Game.js',
'level.js': 'js/Level.js'
}
});
</script>
<script>
var Game = Game || {};

curl(['jquery', 'js!game.js!order', 'js!level.js!order', 'js!monster.js!order', 'js!hero.js!order'],
function($) {
goblins = Game.init();
goblins.start();

window.goblins = goblins;

setInterval(function() { window.goblins.run(); }, 1);
}
);
</script>
</body>
</html>
38 changes: 38 additions & 0 deletions js/Hero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//====================================================================================
// HERO CLASS
//====================================================================================
Game.Hero = (function(win, doc) {

/**
@constructor
*/
function Hero() {
this.speed = 256;
this.x = 0;
this.y = 0;
}

//-----------------------------------------------------------------------------------------------------
// PRIVATE METHODS
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------------------------
// EVENT HANDLERS
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------------------------
// PUBLIC METHODS
//-----------------------------------------------------------------------------------------------------
Hero.prototype = {
'init': function() {

}
};
//-----------------------------------------------------------------------------------------------------

return Hero;

}(window, document));
//====================================================================================
47 changes: 47 additions & 0 deletions js/Level.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//====================================================================================
// LEVEL CLASS
//====================================================================================
Game.Level = (function(win, doc) {

/**
@constructor
*/
function Level() {
this.stages = [{
"numEnemies": 3,
"numBosses": 0,
"enemyStrength": 1 }, {
"numEnemies": 6,
"numBosses": 0,
"enemyStrength": 1 }];
}

//-----------------------------------------------------------------------------------------------------
// PRIVATE METHODS
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------------------------
// EVENT HANDLERS
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------------------------
// PUBLIC METHODS
//-----------------------------------------------------------------------------------------------------
Level.prototype = {
'get': function(numLevel) {
//make sure numLevel is within the amount of stages
if((numLevel < this.stages.length - 1) && (numLevel < 0)) {
return false;
}

return this.stages[numLevel];
}
};
//-----------------------------------------------------------------------------------------------------

return new Level();

}(window, document));
//====================================================================================
37 changes: 37 additions & 0 deletions js/Monster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//====================================================================================
// MONSTER CLASS
//====================================================================================
Game.Monster = (function(win, doc) {

/**
@constructor
*/
function Monster() {
this.x = 0;
this.y = 0;
}

//-----------------------------------------------------------------------------------------------------
// PRIVATE METHODS
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------------------------
// EVENT HANDLERS
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------------------------
// PUBLIC METHODS
//-----------------------------------------------------------------------------------------------------
Monster.prototype = {
'init': function() {

}
};
//-----------------------------------------------------------------------------------------------------

return Monster;

}(window, document));
//====================================================================================
23 changes: 23 additions & 0 deletions js/curl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading