Skip to content
Browse files

add custom urls for including this game into different pages.

also add a small hook for ending the game and eventually saving the score.
  • Loading branch information...
1 parent 8901c90 commit 60d80346e8aa0d00e8cee7bc3347dfaea37c35cb @Krassmus Krassmus committed
Showing with 51 additions and 45 deletions.
  1. +12 −12 assets/js/levels.js
  2. +7 −2 assets/js/player.js
  3. +24 −24 assets/js/sounds.js
  4. +7 −7 assets/js/sprites.js
  5. +1 −0 index.html
View
24 assets/js/levels.js
@@ -3,17 +3,17 @@ Crafty.scene("Loading",function(){
var toLoad = [
//Images
- "assets/img/bg.png",
- "assets/img/ships.png",
- "assets/img/weapon1_small.png",
- "assets/img/weapon2.png",
- "assets/img/dmg.png",
- "assets/img/asteroid64.png",
- "assets/img/asteroid32.png",
- "assets/img/explosion.png",
- "media/sounds/explode.mp3",
- "media/sounds/explode.ogg",
- "media/sounds/explode.wav",
+ game_path + "/assets/img/bg.png",
+ game_path + "/assets/img/ships.png",
+ game_path + "/assets/img/weapon1_small.png",
+ game_path + "/assets/img/weapon2.png",
+ game_path + "/assets/img/dmg.png",
+ game_path + "/assets/img/asteroid64.png",
+ game_path + "/assets/img/asteroid32.png",
+ game_path + "/assets/img/explosion.png",
+ game_path + "/media/sounds/explode.mp3",
+ game_path + "/media/sounds/explode.ogg",
+ game_path + "/media/sounds/explode.wav",
];
Crafty.background("black");
Crafty.e("2D","DOM","Text").css({
@@ -46,7 +46,7 @@ Crafty.scene("Loading",function(){
//Level 1 Scene
Crafty.scene("Level1",function(){
//Setup background of level
- Crafty.background("url(assets/img/bg.png)");
+ Crafty.background("url(" + game_path + "/assets/img/bg.png)");
//Play background music and repeat
Crafty.audio.play("space",-1);
$('.level').text('Level: 1');
View
9 assets/js/player.js
@@ -179,6 +179,7 @@
if(this.lives <= 0){
this.destroy();
this.infos.alert.show().text('Game Over!').effect('pulsate',500);
+ gameHooks.endGame(this.score);
Crafty.pause();
}else{
this.reset();
@@ -214,5 +215,9 @@
updateLives:function(){
this.infos.lives.text("Lives: "+this.lives);
}
-
-});
+
+});
+
+var gameHooks = {
+ endGame: function (score) {}
+}
View
48 assets/js/sounds.js
@@ -1,56 +1,56 @@
Crafty.audio.add({
space: [
- "media/music/through-space.wav",
- "media/music/through-space.mp3",
- "media/music/through-space.ogg"
+ game_path + "/media/music/through-space.wav",
+ game_path + "/media/music/through-space.mp3",
+ game_path + "/media/music/through-space.ogg"
]
});
Crafty.audio.add({
spaceship: [
- "media/music/spaceship.wav",
- "media/music/spaceship.mp3",
- "media/music/spaceship.ogg"
+ game_path + "/media/music/spaceship.wav",
+ game_path + "/media/music/spaceship.mp3",
+ game_path + "/media/music/spaceship.ogg"
]
});
Crafty.audio.add({
explosion0: [
- "media/sounds/explodemini.wav",
- "media/sounds/explodemini.mp3",
- "media/sounds/explodemini.ogg"
+ game_path + "/media/sounds/explodemini.wav",
+ game_path + "/media/sounds/explodemini.mp3",
+ game_path + "/media/sounds/explodemini.ogg"
]
});
Crafty.audio.add({
explosion1: [
- "media/sounds/explode.wav",
- "media/sounds/explode.mp3",
- "media/sounds/explode.ogg"
+ game_path + "/media/sounds/explode.wav",
+ game_path + "/media/sounds/explode.mp3",
+ game_path + "/media/sounds/explode.ogg"
]
});
Crafty.audio.add({
laser1: [
- "media/sounds/laser1.wav",
- "media/sounds/laser1.mp3",
- "media/sounds/laser1.ogg"
+ game_path + "/media/sounds/laser1.wav",
+ game_path + "/media/sounds/laser1.mp3",
+ game_path + "/media/sounds/laser1.ogg"
]
});
Crafty.audio.add({
laser2: [
- "media/sounds/laser2.wav",
- "media/sounds/laser2.mp3",
- "media/sounds/laser2.ogg"
+ game_path + "/media/sounds/laser2.wav",
+ game_path + "/media/sounds/laser2.mp3",
+ game_path + "/media/sounds/laser2.ogg"
]
});
Crafty.audio.add({
laser3: [
- "media/sounds/laser3.wav",
- "media/sounds/laser3.mp3",
- "media/sounds/laser3.ogg"
+ game_path + "/media/sounds/laser3.wav",
+ game_path + "/media/sounds/laser3.mp3",
+ game_path + "/media/sounds/laser3.ogg"
]
});
Crafty.audio.add({
laser4: [
- "media/sounds/laser4.wav",
- "media/sounds/laser4.mp3",
- "media/sounds/laser4.ogg"
+ game_path + "/media/sounds/laser4.wav",
+ game_path + "/media/sounds/laser4.mp3",
+ game_path + "/media/sounds/laser4.ogg"
]
});
View
14 assets/js/sprites.js
@@ -1,4 +1,4 @@
-Crafty.sprite("assets/img/ships.png",{
+Crafty.sprite(game_path + "/assets/img/ships.png",{
//Gold
ship1:[0,0,44,47],
ship2:[47,0,40,47],
@@ -19,22 +19,22 @@ Crafty.sprite("assets/img/ships.png",{
ship16:[340,48,67,47]
});
-Crafty.sprite(5,13,"assets/img/weapon1_small.png",{
+Crafty.sprite(5,13,game_path + "/assets/img/weapon1_small.png",{
laser1:[0,0]
});
-Crafty.sprite(27,36,"assets/img/weapon2.png",{
+Crafty.sprite(27,36,game_path + "/assets/img/weapon2.png",{
laser2:[0,0]
});
-Crafty.sprite(29,"assets/img/dmg.png",{
+Crafty.sprite(29,game_path + "/assets/img/dmg.png",{
dmg:[0,0]
});
-Crafty.sprite(64,"assets/img/asteroid64.png",{
+Crafty.sprite(64,game_path + "/assets/img/asteroid64.png",{
asteroid64:[0,0]
});
-Crafty.sprite(32,"assets/img/asteroid32.png",{
+Crafty.sprite(32,game_path + "/assets/img/asteroid32.png",{
asteroid32:[0,0]
});
-Crafty.sprite(65,"assets/img/explosion.png",{
+Crafty.sprite(65,game_path + "/assets/img/explosion.png",{
explosion1:[0,0],
explosion2:[0,1],
explosion3:[0,2],
View
1 index.html
@@ -5,6 +5,7 @@
<title>Cron</title>
<script type="text/javascript" src="http://cdn.crafty-modules.com/crafty-DEBUG.js"></script>
+ <script>var game_path = location.href.lastIndexOf("/") !== -1 ? location.href.substring(0, location.href.lastIndexOf("/") + 1) : location.href;</script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<script type="text/javascript" src="assets/js/sprites.js"></script>

0 comments on commit 60d8034

Please sign in to comment.
Something went wrong with that request. Please try again.