Permalink
Browse files

First Powerups added

  • Loading branch information...
1 parent 02ae999 commit 546a3d23b2d8b84c588e96c7752fd99bdfa342dd @BlackScorp committed Mar 19, 2012
Showing with 55 additions and 5 deletions.
  1. +9 −3 assets/js/enemys.js
  2. +12 −0 assets/js/player.js
  3. +31 −0 assets/js/powerups.js
  4. +1 −1 assets/js/sprites.js
  5. +2 −1 index.html
View
@@ -1,7 +1,7 @@
/**
* This File describes all enemies
*/
-
+var powerUps = ["Heal","Shield"];
//Basic enemy component
Crafty.c("Enemy",{
playerID:null, //ID of player which has something todo with that enemy
@@ -46,15 +46,21 @@ Crafty.c("Enemy",{
})
.bind("Die",function(){
//Create a random explosion at his position
- var exp = Crafty.e("RandomExplosion");
- exp.attr({
+ Crafty.e("RandomExplosion").attr({
x:this.x-this.w,
y:this.y-this.h
});
//Trigger the player event to calculate points
Crafty(this.playerID).trigger("Killed",this.points);
//Destroy the asteroid
this.destroy();
+ if(Crafty.math.randomInt(0, 100) > 80){
+ var powerUp = powerUps[Crafty.math.randomInt(0, powerUps.length-1)];
+ Crafty.e(powerUp).attr({
+ x:this.x,
+ y:this.y
+ });
+ }
});
}
});
View
@@ -129,6 +129,18 @@ Crafty.c("Player",{
this.trigger("Hurt",bullet.dmg);
bullet.destroy();
})
+ .bind("RestoreHP",function(val){
+ if(this.hp.current < this.hp.max){
+ this.hp.current += val;
+ this.updateHp();
+ }
+ })
+ .bind("RestoreShield",function(val){
+ if(this.shield.current < this.shield.max){
+ this.shield.current += val;
+ this.updateShield();
+ }
+ })
.reset() /*Set initial points*/;
return this;
},
View
@@ -0,0 +1,31 @@
+Crafty.c("PowerUp",{
+ init:function(){
+ this.requires("2D,Canvas,Collision")
+ .onHit("PlayerBullet",function(){
+ this.destroy();
+ })
+ .onHit("Player",function(ent){
+
+ ent[0].obj.trigger(this.effect,this.value);
+ this.destroy();
+ })
+ .bind("EnterFrame",function(){
+ this.y+=1;
+ });
+ }
+});
+
+Crafty.c("Heal",{
+ effect:"RestoreHP",
+ value:1,
+ init:function(){
+ this.requires("PowerUp,heal");
+ }
+});
+Crafty.c("Shield",{
+ effect:"RestoreShield",
+ value:1,
+ init:function(){
+ this.requires("PowerUp,shield");
+ }
+});
@@ -41,7 +41,7 @@ Crafty.sprite(128,game_path + "assets/img/explosion.png",{
explosion3:[0,2]
});
-Crafty.sprite(30,34,game_path + "assets/img/powerups.png",{
+Crafty.sprite(34,30,game_path + "assets/img/powerups.png",{
heal:[0,0],
shield:[0,1],
overheat:[0,2],
View
@@ -13,7 +13,8 @@
<script type="text/javascript" src="assets/js/sprites.js"></script>
<script type="text/javascript" src="assets/js/sounds.js"></script>
-
+
+ <script type="text/javascript" src="assets/js/powerups.js"></script>
<script type="text/javascript" src="assets/js/weapons.js"></script>
<script type="text/javascript" src="assets/js/effects.js"></script>
<script type="text/javascript" src="assets/js/enemys.js"></script>

0 comments on commit 546a3d2

Please sign in to comment.