Skip to content

Commit

Permalink
Individual files
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcbrewer committed Nov 10, 2012
1 parent 8265e3c commit fd7345e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 38 deletions.
20 changes: 17 additions & 3 deletions index.html
Expand Up @@ -2,13 +2,16 @@
<html>
<head>
<title>YOUR GAME NAME HERE</title>

<link rel="stylesheet" type="text/css" href="css/index.css"></link>

<script src="js/vendor/crafty-0.5.3-patch.js"></script>
<script src="js/vendor/underscore-1.4.2.js"></script>
<script src="js/vendor/jquery-1.8.2.js"></script>
<script src="js/game.js"></script>
<script src="js/mo.js"></script>
<script src="js/stu.js"></script>
<script src="js/adam.js"></script>
</head>
<body>
<div id="container">
Expand All @@ -17,5 +20,16 @@ <h1>YOUR GAME NAME HERE</h1>
</div>
<p>YOUR GAME INSTRUCTIONS HERE</p>
</div>

<script>
// kick off the game when the web page is ready
$(document).ready(function() {
var game = new Game();
game.initCrafty();

// start loading things
Crafty.scene('loading');
});
</script>
</body>
</html>
</html>
1 change: 1 addition & 0 deletions js/adam.js
@@ -0,0 +1 @@
adam.js
62 changes: 27 additions & 35 deletions js/game.js
Expand Up @@ -13,7 +13,7 @@
spriteName: function(name) {
this.requires(name);
return this; // so we can chain calls to setup functions
}
}
});

// a component to fade out an entity over time
Expand Down Expand Up @@ -50,8 +50,8 @@
});
},
// set speed of rotation in degrees per frame
rotate: function(speed) {
// rotate about the center of the entity
rotate: function(speed) {
// rotate about the center of the entity
this.origin('center');
this._rotationSpeed = speed;
return this; // so we can chain calls to setup functions
Expand All @@ -77,7 +77,7 @@
// set up animation from column 0, row 1 to column 1
.animate('fly', 0, 1, 1)
// start the animation
.animate('fly', 5, -1)
.animate('fly', 5, -1)
// move left every frame, destroy bullet if its off the screen
.bind("EnterFrame", function() {
this.x += 10;
Expand All @@ -88,7 +88,7 @@
}
});


// targets to shoot at
Crafty.c('Target', {
init: function() {
Expand All @@ -99,12 +99,12 @@
// detect when we get hit by bullets
.onHit('Bullet', this._hitByBullet);
// choose a random position
this._randomlyPosition();
this._randomlyPosition();
},
// randomly position
// randomly position
_randomlyPosition: function() {
this.attr({
x: Crafty.math.randomNumber(500, 800),
x: Crafty.math.randomNumber(500, 800),
y: Crafty.math.randomNumber(0,600-this.h)});
},
// we got hit!
Expand Down Expand Up @@ -137,9 +137,9 @@
}
});

// Player component
Crafty.c('Player', {
init: function() {
// Player component
Crafty.c('Player', {
init: function() {
this.requires('Renderable, Fourway, Collision, ViewportBounded, SpriteAnimation')
.spriteName('player')
.collision()
Expand Down Expand Up @@ -186,30 +186,30 @@

//
// Game loading and initialisation
//
//
var Game = function() {
Crafty.scene('loading', this.loadingScene);
Crafty.scene('main', this.mainScene);
};

Game.prototype.initCrafty = function() {
console.log("page ready, starting CraftyJS");
Crafty.init(1000, 600);
Crafty.canvas.init();

Crafty.modules({ 'crafty-debug-bar': 'release' }, function () {
if (Crafty.debugBar) {
Crafty.debugBar.show();
}
});
};

// A loading scene -- pull in all the slow things here and create sprites
Game.prototype.loadingScene = function() {
var loading = Crafty.e('2D, Canvas, Text, Delay');
loading.attr({x: 512, y: 200, w: 100, h: 20});
loading.text('loading...');

function onLoaded() {
// set up sprites
Crafty.sprite(64, 'img/shooter-sprites.png', {
Expand All @@ -220,29 +220,29 @@
explosion1: [0, 3],
explosion2: [1, 3]
});

// jump to the main scene in half a second
loading.delay(function() {
Crafty.scene('main');
}, 500);
}

function onProgress(progress) {
loading.text('loading... ' + progress.percent + '% complete');
}

function onError() {
loading.text('could not load assets');
}

Crafty.load([
// list of images to load
'img/shooter-sprites.png'
],
],
onLoaded, onProgress, onError);

};

//
// The main game scene
//
Expand All @@ -252,20 +252,12 @@

//create a player...
Crafty.e('Player');

// create some junk to avoid
for (i = 0; i < 5; i++) {
Crafty.e('Target');
}
};

// kick off the game when the web page is ready
$(document).ready(function() {
var game = new Game();
game.initCrafty();

// start loading things
Crafty.scene('loading');
});

})();


})();
1 change: 1 addition & 0 deletions js/mo.js
@@ -0,0 +1 @@
mo.js
1 change: 1 addition & 0 deletions js/stu.js
@@ -0,0 +1 @@
stu.js

0 comments on commit fd7345e

Please sign in to comment.