Particle effects con candy deletion

This commit is contained in:
2015-12-01 06:41:06 +01:00
parent 17d2e063ff
commit dda5c8e77c
2 changed files with 66 additions and 1 deletions

View File

@@ -1,6 +1,30 @@
window.Images = new ImageLoader();
var Particle = function(game, position, image) {
this.Game = game;
this.GameEntity = new GameEntity(
game.GameScreen,
position,
{X:image.naturalWidth, Y:image.naturalHeight},
image,
"Particle"
);
this.Speed = Vec2D.Scale(Vec2D.Normalize({
X: Math.floor(Math.random() * 33)-16,
Y: Math.floor(Math.random() * 33)-16}),32);
};
Particle.prototype = {
Update: function() {
this.Speed = Vec2D.Scale(this.Speed, 1.2);
this.GameEntity.AddPosition(this.Speed);
if(this.GameEntity.InsideScreen()==false){
this.GameEntity.Delete();
}
}
};
/////////////////////////////////////////
//
// CandyEntity
@@ -9,7 +33,7 @@ var CandyEntity = function(game, color, gridPosition){
this.Game = game;
this.GridPosition = gridPosition || {X: 0, Y: 0};
this.Color = color;
this.GameEntity = new GameEntity(
this.GameEntity = new GameEntity(
game.GameScreen,
null,
{X: 32, Y: 32},
@@ -29,6 +53,15 @@ CandyEntity.prototype = {
});
},
Delete: function(){
var frag;
for(var i=0; i<4; i++){
frag = new Particle(
this.Game,
this.GameEntity.PositionDest,
Images.GetImage(this.Color)
);
this.Game.GameScreen.AddEntity(frag);
}
this.GameEntity.Delete();
},
SetOffset: function(x, y){