Permalink
Browse files

added sounds, bullet can destroy bullets

  • Loading branch information...
1 parent 547ca06 commit 8901c901c8a3ade1cc90dd22969598c0b012735a @BlackScorp committed Feb 19, 2012
Showing with 69 additions and 54 deletions.
  1. +2 −2 assets/js/enemys.js
  2. +1 −1 assets/js/game.js
  3. +10 −16 assets/js/levels.js
  4. +3 −3 assets/js/player.js
  5. +47 −28 assets/js/sounds.js
  6. +5 −1 assets/js/weapons.js
  7. +1 −3 index.html
View
@@ -126,7 +126,7 @@ Crafty.c("Kamikaze",{
attacking = true;
if(attacking)
- this.y += 8;
+ this.y += 6;
});
},
die:function(){
@@ -218,7 +218,7 @@ Crafty.c("Level2",{
this.destroy();
},
shoot:function(){
- var bullet = Crafty.e("Weapon2","EnemyBullet");
+ var bullet = Crafty.e("Weapon1","EnemyBullet");
bullet.attr({
x: this._x+this._w/2-bullet.w/2,
y: this._y+this._h-bullet.h/2,
View
@@ -21,6 +21,6 @@ $(function(){
bars.shield.progressbar({
value: 0
});
-
+ //$('#interface').hide();
Crafty.scene("Level1");
});
View
@@ -5,20 +5,15 @@ Crafty.scene("Loading",function(){
//Images
"assets/img/bg.png",
"assets/img/ships.png",
- "assets/img/weapon1.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/music/through-space.ogg",
- "media/sounds/explodemini.wav",
+ "media/sounds/explode.mp3",
+ "media/sounds/explode.ogg",
"media/sounds/explode.wav",
- "media/sounds/laser1.wav",
- "media/sounds/laser2.wav",
- "media/sounds/laser3.wav",
- "media/sounds/laser4.wav"
];
Crafty.background("black");
Crafty.e("2D","DOM","Text").css({
@@ -31,8 +26,8 @@ Crafty.scene("Loading",function(){
});
Crafty.load(toLoad,
function() {
- //when loaded
- Crafty.scene("Level1"); //go to Level1 scene
+ //when loaded
+ // Crafty.scene("Level1"); //go to Level1 scene
},
function(e) {
@@ -53,23 +48,22 @@ Crafty.scene("Level1",function(){
//Setup background of level
Crafty.background("url(assets/img/bg.png)");
//Play background music and repeat
- //Crafty.audio.play("space",-1);
+ Crafty.audio.play("space",-1);
$('.level').text('Level: 1');
var spotEnemys = function(frame){
//Spot each 50th Fram one Asteroid
- if(frame % 50 == 0 && Crafty("Asteroid").length < 3){
- Crafty.e("Asteroid");
-
+ if(frame % 50 == 0 && Crafty("Asteroid").length < 1){
+ Crafty.e("Asteroid");
}
if(frame % 70 == 0 && Crafty("Kamikaze").length < 1){
Crafty.e("Kamikaze");
}
- if(frame % 80 == 0 && Crafty("Level1").length < 2){
+ if(frame % 80 == 0 && Crafty("Level1").length < 1){
Crafty.e("Level1");
}
- if(frame % 90 == 0 && Crafty("Level2").length < 2){
+ if(frame % 90 == 0 && Crafty("Level2").length < 1){
Crafty.e("Level2");
}
};
View
@@ -1,4 +1,4 @@
-Crafty.c("Player",{
+ Crafty.c("Player",{
hp:{
current:10,
max:10,
@@ -57,8 +57,8 @@ Crafty.c("Player",{
/*Dont allow to move the player out of Screen*/
if(this.x+this.w > Crafty.viewport.width ||
this.x+this.w < this.w ||
- this.y+this.h < this.h ||
- this.y+this.h > Crafty.viewport.height){
+ this.y+this.h-35 < this.h ||
+ this.y+this.h+35 > Crafty.viewport.height){
this.attr({
x:from.x,
y:from.y
View
@@ -1,37 +1,56 @@
Crafty.audio.add({
space: [
- "media/music/through-space.wav",
- "media/music/through-space.mp3",
- "media/music/through-space.ogg"
- ],
+ "media/music/through-space.wav",
+ "media/music/through-space.mp3",
+ "media/music/through-space.ogg"
+ ]
+});
+Crafty.audio.add({
+ spaceship: [
+ "media/music/spaceship.wav",
+ "media/music/spaceship.mp3",
+ "media/music/spaceship.ogg"
+ ]
+});
+Crafty.audio.add({
explosion0: [
- "media/sounds/explodemini.wav",
- "media/sounds/explodemini.mp3",
- "media/sounds/explodemini.ogg"
- ],
+ "media/sounds/explodemini.wav",
+ "media/sounds/explodemini.mp3",
+ "media/sounds/explodemini.ogg"
+ ]
+});
+Crafty.audio.add({
explosion1: [
- "media/sounds/explode.wav",
- "media/sounds/explode.mp3",
- "media/sounds/explode.ogg"
- ],
+ "media/sounds/explode.wav",
+ "media/sounds/explode.mp3",
+ "media/sounds/explode.ogg"
+ ]
+ });
+Crafty.audio.add({
laser1: [
- "media/sounds/laser1.wav",
- "media/sounds/laser1.mp3",
- "media/sounds/laser1.ogg"
- ],
+ "media/sounds/laser1.wav",
+ "media/sounds/laser1.mp3",
+ "media/sounds/laser1.ogg"
+ ]
+ });
+Crafty.audio.add({
laser2: [
- "media/sounds/laser2.wav",
- "media/sounds/laser2.mp3",
- "media/sounds/laser2.ogg"
- ],
+ "media/sounds/laser2.wav",
+ "media/sounds/laser2.mp3",
+ "media/sounds/laser2.ogg"
+ ]
+ });
+Crafty.audio.add({
laser3: [
- "media/sounds/laser3.wav",
- "media/sounds/laser3.mp3",
- "media/sounds/laser3.ogg"
- ],
+ "media/sounds/laser3.wav",
+ "media/sounds/laser3.mp3",
+ "media/sounds/laser3.ogg"
+ ]
+ });
+Crafty.audio.add({
laser4: [
- "media/sounds/laser4.wav",
- "media/sounds/laser4.mp3",
- "media/sounds/laser4.ogg"
+ "media/sounds/laser4.wav",
+ "media/sounds/laser4.mp3",
+ "media/sounds/laser4.ogg"
]
- });
+});
@@ -2,14 +2,18 @@ Crafty.c("Bullet",{
dmg:0,
firerate:0,
init:function(){
- this.addComponent("2D","Canvas")
+ this.addComponent("2D","Canvas","Collision")
.bind("EnterFrame",function(){
if(this.x > Crafty.viewport.width+this.w ||
this.x < -this.w ||
this.y < -this.h ||
this.y > Crafty.viewport.height+this.h){
this.destroy();
}
+ })
+ .onHit("Bullet",function(ent){
+ this.destroy();
+ ent[0].obj.destroy();
});
}
});
View
@@ -3,10 +3,8 @@
<head>
<meta charset="UTF-8" />
<title>Cron</title>
- <!--
<script type="text/javascript" src="http://cdn.crafty-modules.com/crafty-DEBUG.js"></script>
- -->
- <script type="text/javascript" src="http://localhost/~pengy/crafty/crafty.js"></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 8901c90

Please sign in to comment.