Permalink
Browse files

Added flicker effect , changed Functions to Events, better Explosion …

…added
  • Loading branch information...
1 parent 30c3461 commit 02ae999c7c517fdda12ef903b2aa74e9aefdbdd7 @BlackScorp committed Mar 19, 2012
View
Deleted file not rendered
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Deleted file not rendered
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Deleted file not rendered
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -1,13 +1,16 @@
Crafty.c("RandomExplosion",{
init:function(){
- var rand = Crafty.math.randomInt(1,4);
+ var rand = Crafty.math.randomInt(1,3);
this.addComponent("2D","Canvas","explosion"+rand,"SpriteAnimation")
- .animate("explode1",0,0,4)
- .animate("explode2",0,1,4)
- .animate("explode3",0,2,4)
- .animate("explode4",0,3,4)
- .animate("explode"+rand,10)
- .delay(function(){this.destroy()},500);
+ .animate("explode1",0,0,16)
+ .animate("explode2",0,1,16)
+ .animate("explode3",0,2,16)
+
+ .animate("explode"+rand,10,0)
+ .bind("AnimationEnd",function(){
+ this.destroy();
+ });
+
Crafty.audio.play("explosion"+(rand %2));
}
@@ -19,3 +22,18 @@ Crafty.c("Damage",{
}
});
+Crafty.c("Flicker",{
+ init:function(){
+ this.bind("EnterFrame",function(frame){
+ if(frame.frame % 5 == 0 && this.has("Flicker")){
+ if(this.alpha == 0.5){
+ this.alpha = 1.0;
+ }else{
+ this.alpha = 0.5;
+ }
+ }
+ }).bind("RemoveComponent",function(){
+ this.alpha = 1.0;
+ });
+ }
+});
View
@@ -10,40 +10,52 @@ Crafty.c("Enemy",{
this.requires("2D,Canvas,Collision")
//Destroy all enemies if they leave the viewport
.bind("EnterFrame",function(){
- if(this.x > Crafty.viewport.width+this.w ||
+ if(this.x > Crafty.viewport.width + this.w ||
this.x < -this.w ||
this.y < -this.h ||
- this.y > Crafty.viewport.height+this.h){
+ this.y > Crafty.viewport.height +this.h){
this.destroy();
}
})
//Describe behavior on getting hitted by Player Bullet
.onHit("PlayerBullet",function(ent){
var bullet = ent[0].obj;
this.playerID = bullet.playerID; //Which player hurted you
- this.hurt(bullet.dmg); //Hurt the enemy with bullet damage
+ this.trigger("Hurt",bullet.dmg); //Hurt the enemy with bullet damage
bullet.destroy(); //Destroy the bullet
})
//Describe behavior on getting hitted by Player
.onHit("Player",function(ent){
var player = ent[0].obj;
//Hurt the player with my hp
- Crafty(player[0]).hurt(this.hp);
+ Crafty(player[0]).trigger("Hurt",this.hp);
//Hurt enemy with all hp he has
- this.hurt(this.hp);
- });
- },
- //Function to hurt the enemy
- hurt:function(dmg){
- //Create a damage effect
- Crafty.e("Damage").attr({
- x:this.x,
- y:this.y
+ this.trigger("Hurt",this.hp);
+ })
+ //Event triggered when enemy was hurt
+ .bind("Hurt",function(dmg){
+ //Create a damage effect
+ Crafty.e("Damage").attr({
+ x:this.x,
+ y:this.y
+ });
+ //Reduce HP
+ this.hp -= dmg;
+ //Die if hp is 0
+ if(this.hp <= 0) this.trigger("Die");
+ })
+ .bind("Die",function(){
+ //Create a random explosion at his position
+ var exp = Crafty.e("RandomExplosion");
+ exp.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();
});
- //Reduce HP
- this.hp -= dmg;
- //Die if hp is 0
- if(this.hp <= 0) this.die();
}
});
@@ -72,26 +84,26 @@ Crafty.c("Asteroid",{
y:-this.h, //display asteroid over the viewport at start
x:Crafty.math.randomInt(this.w,Crafty.viewport.width - this.w),//random position within the viewport
rotation:Crafty.math.randomInt(0,360) //rotate it random
- });
- },
- //Function to die
- die:function(){
- //Create a random explosion at his position
- Crafty.e("RandomExplosion").attr({
- x:this.x,
- y:this.y
- });
- //Create 1-4 Small asteroids
- for(var i = 0;i<Crafty.math.randomInt(1,4);i++){
- Crafty.e("SmallAsteroid").attr({
+ })
+ .onHit("SmallAsteroid",function(){
+ this.trigger("Die");
+ })
+ //Event to die
+ .bind("Die",function(){
+ //Create a random explosion at his position
+ Crafty.e("RandomExplosion").attr({
x:this.x,
y:this.y
});
- }
- //Trigger the player event to calculate points
- Crafty(this.playerID).trigger("Killed",this.points);
- //Destroy the asteroid
- this.destroy();
+ //Create 1-4 Small asteroids
+ for(var i = 0;i<Crafty.math.randomInt(1,4);i++){
+ Crafty.e("SmallAsteroid").attr({
+ x:this.x,
+ y:this.y
+ });
+ }
+
+ });
}
});
@@ -113,15 +125,7 @@ Crafty.c("SmallAsteroid",{
.attr({
rotation:Crafty.math.randomInt(0,360)
});
- },
-
- die:function(){
- Crafty.e("RandomExplosion").attr({
- x:this.x,
- y:this.y
- });
- Crafty(this.playerID).trigger("Killed",this.points);
- this.destroy();
+
}
});
@@ -154,16 +158,9 @@ Crafty.c("Kamikaze",{
attacking = true;
if(attacking)
- this.y += 6;
- });
- },
- die:function(){
- Crafty.e("RandomExplosion").attr({
- x:this.x,
- y:this.y
+ this.y += 4;
});
- Crafty(this.playerID).trigger("Killed",this.points);
- this.destroy();
+
}
});
@@ -185,28 +182,20 @@ Crafty.c("Level1",{
x = Math.abs((this.x+this._w/2)-player.x);
if((x<40)&& this._y < player.y && frame.frame % 20 == 0){
- this.shoot();
+ this.trigger("Shoot");
}
- this.y += 2;
- });
- },
- die:function(){
- Crafty.e("RandomExplosion").attr({
- x:this.x,
- y:this.y
+ this.y += 1.5;
+ })
+ .bind("Shoot",function(){
+ 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,
+ rotation: this._rotation,
+ xspeed: 5 * Math.sin(this._rotation / (180 / Math.PI)),
+ yspeed: 5 * Math.cos(this._rotation / (180 / Math.PI))
+ });
});
- Crafty(this.playerID).trigger("Killed",this.points);
- this.destroy();
- },
- shoot:function(){
- 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,
- rotation: this._rotation,
- xspeed: 20 * Math.sin(this._rotation / (180 / Math.PI)),
- yspeed: 20 * Math.cos(this._rotation / (180 / Math.PI))
- });
}
});
Crafty.c("Level2",{
@@ -232,27 +221,19 @@ Crafty.c("Level2",{
if((x<40)&& this._y < player.y && frame.frame % 20 == 0){
- this.shoot();
+ this.trigger("Shoot");
}
- this.y += 2;
- });
- },
- die:function(){
- Crafty.e("RandomExplosion").attr({
- x:this.x,
- y:this.y
+ this.y += 1.5;
+ })
+ .bind("Shoot",function(){
+ 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,
+ rotation: this._rotation,
+ xspeed: 5 * Math.sin(this._rotation / (180 / Math.PI)),
+ yspeed: 5 * Math.cos(this._rotation / (180 / Math.PI))
+ });
});
- Crafty(this.playerID).trigger("Killed",this.points);
- this.destroy();
- },
- shoot:function(){
- 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,
- rotation: this._rotation,
- xspeed: 20 * Math.sin(this._rotation / (180 / Math.PI)),
- yspeed: 20 * Math.cos(this._rotation / (180 / Math.PI))
- });
}
});
View
@@ -46,18 +46,16 @@ Crafty.scene("Loading",function(){
bar.progressbar({
value:~~e.percent
});
- console.log("Loaded: ");
- console.log(src);
+
},
function(e) {
- //uh oh, error loading
- console.log("Error on loading: ");
- console.log(e.src);
+ //uh oh, error loading
+
}
);
//Play background music and repeat will work only Safari /IE
Crafty.audio.play("spaceship",-1);
- Crafty.audio.play("spaceship.ogg",-1); //Works with others
+ Crafty.audio.play("spaceship.ogg",-1); //Works with others
});
//Level 1 Scene
Crafty.scene("Level1",function(){
@@ -74,15 +72,15 @@ Crafty.scene("Level1",function(){
var spotEnemys = function(frame){
//Spot each 50th Fram one Asteroid
- if(frame % 50 == 0 && Crafty("Asteroid").length < 1 && Crafty("SmallAsteroid").length < 1){
+ if(frame % 50 == 0 && Crafty("Asteroid").length < 4 && Crafty("SmallAsteroid").length < 10){
Crafty.e("Asteroid");
}
if(frame % 70 == 0 && Crafty("Kamikaze").length < 1){
Crafty.e("Kamikaze");
}
if(frame % 80 == 0 && Crafty("Level1").length < 1){
- Crafty.e("Level1");
+ Crafty.e("Rookie");
}
if(frame % 90 == 0 && Crafty("Level2").length < 1){
Crafty.e("Level2");
Oops, something went wrong.

0 comments on commit 02ae999

Please sign in to comment.