Code formatting
This commit is contained in:
@@ -1,27 +1,33 @@
|
|||||||
|
|
||||||
window.Images = new ImageLoader();
|
window.Images = new ImageLoader();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Particle
|
||||||
|
//
|
||||||
var Particle = function(game, position, image) {
|
var Particle = function(game, position, image) {
|
||||||
this.Game = game;
|
this.Game = game;
|
||||||
this.GameEntity = new GameEntity(
|
this.GameEntity = new GameEntity(
|
||||||
game.GameScreen,
|
game.GameScreen,
|
||||||
position,
|
position,
|
||||||
{X:image.naturalWidth, Y:image.naturalHeight},
|
{X:image.naturalWidth, Y:image.naturalHeight},
|
||||||
image,
|
image,
|
||||||
"Particle"
|
"Particle"
|
||||||
);
|
);
|
||||||
this.Speed = Vec2D.Scale(Vec2D.Normalize({
|
this.Speed = Vec2D.Scale(Vec2D.Normalize({
|
||||||
X: Math.floor(Math.random() * 33)-16,
|
X: Math.floor(Math.random() * 33)-16,
|
||||||
Y: Math.floor(Math.random() * 33)-16}),32);
|
Y: Math.floor(Math.random() * 33)-16}),32);
|
||||||
};
|
};
|
||||||
Particle.prototype = {
|
Particle.prototype = {
|
||||||
Update: function() {
|
Update: function() {
|
||||||
this.Speed = Vec2D.Scale(this.Speed, 1.2);
|
this.Speed = Vec2D.Scale(this.Speed, 1.2);
|
||||||
this.GameEntity.AddPosition(this.Speed);
|
this.GameEntity.AddPosition(this.Speed);
|
||||||
if(this.GameEntity.InsideScreen()==false){
|
if(this.GameEntity.InsideScreen()==false){
|
||||||
this.GameEntity.Delete();
|
this.GameEntity.Delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -33,7 +39,7 @@ var CandyEntity = function(game, color, gridPosition){
|
|||||||
this.Game = game;
|
this.Game = game;
|
||||||
this.GridPosition = gridPosition || {X: 0, Y: 0};
|
this.GridPosition = gridPosition || {X: 0, Y: 0};
|
||||||
this.Color = color;
|
this.Color = color;
|
||||||
this.GameEntity = new GameEntity(
|
this.GameEntity = new GameEntity(
|
||||||
game.GameScreen,
|
game.GameScreen,
|
||||||
null,
|
null,
|
||||||
{X: 32, Y: 32},
|
{X: 32, Y: 32},
|
||||||
@@ -53,15 +59,15 @@ CandyEntity.prototype = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
Delete: function(){
|
Delete: function(){
|
||||||
var frag;
|
var frag;
|
||||||
for(var i=0; i<4; i++){
|
for(var i=0; i<4; i++){
|
||||||
frag = new Particle(
|
frag = new Particle(
|
||||||
this.Game,
|
this.Game,
|
||||||
this.GameEntity.PositionDest,
|
this.GameEntity.PositionDest,
|
||||||
Images.GetImage(this.Color)
|
Images.GetImage(this.Color)
|
||||||
);
|
);
|
||||||
this.Game.GameScreen.AddEntity(frag);
|
this.Game.GameScreen.AddEntity(frag);
|
||||||
}
|
}
|
||||||
this.GameEntity.Delete();
|
this.GameEntity.Delete();
|
||||||
},
|
},
|
||||||
SetOffset: function(x, y){
|
SetOffset: function(x, y){
|
||||||
@@ -299,8 +305,6 @@ CandyFucker.prototype = {
|
|||||||
var entCandy = this.RemoveCandy(x, y);
|
var entCandy = this.RemoveCandy(x, y);
|
||||||
if(entCandy){
|
if(entCandy){
|
||||||
entCandy.Delete();
|
entCandy.Delete();
|
||||||
// FIXME: explosion FX
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,21 +1,27 @@
|
|||||||
var Vec2D = {
|
|
||||||
Scale: function(vecIn, scale) {
|
|
||||||
return {
|
|
||||||
X: vecIn.X * scale,
|
|
||||||
Y: vecIn.Y * scale
|
|
||||||
};
|
|
||||||
},
|
|
||||||
Normalize: function(vecIn){
|
|
||||||
var len = Math.sqrt(
|
|
||||||
(vecIn.X * vecIn.X) +
|
|
||||||
(vecIn.Y * vecIn.Y));
|
|
||||||
return {
|
|
||||||
X: vecIn.X / len,
|
|
||||||
Y: vecIn.Y / len};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Vec2D
|
||||||
|
//
|
||||||
|
var Vec2D = {
|
||||||
|
Scale: function(vecIn, scale) {
|
||||||
|
return {
|
||||||
|
X: vecIn.X * scale,
|
||||||
|
Y: vecIn.Y * scale
|
||||||
|
};
|
||||||
|
},
|
||||||
|
Normalize: function(vecIn){
|
||||||
|
var len = Math.sqrt(
|
||||||
|
(vecIn.X * vecIn.X) +
|
||||||
|
(vecIn.Y * vecIn.Y));
|
||||||
|
return {
|
||||||
|
X: vecIn.X / len,
|
||||||
|
Y: vecIn.Y / len
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
//
|
//
|
||||||
@@ -182,10 +188,10 @@ GameEntity.prototype = {
|
|||||||
this.PositionDest.X = position.X;
|
this.PositionDest.X = position.X;
|
||||||
this.PositionDest.Y = position.Y;
|
this.PositionDest.Y = position.Y;
|
||||||
},
|
},
|
||||||
AddPosition: function(delta) {
|
AddPosition: function(delta) {
|
||||||
this.PositionDest.X = this.Position.X + delta.X;
|
this.PositionDest.X = this.Position.X + delta.X;
|
||||||
this.PositionDest.Y = this.Position.Y + delta.Y;
|
this.PositionDest.Y = this.Position.Y + delta.Y;
|
||||||
},
|
},
|
||||||
Delete: function(){
|
Delete: function(){
|
||||||
this.Deleted = true;
|
this.Deleted = true;
|
||||||
},
|
},
|
||||||
@@ -198,16 +204,16 @@ GameEntity.prototype = {
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
InsideScreen: function(){
|
InsideScreen: function(){
|
||||||
return (
|
return (
|
||||||
(this.Position.X+(this.Size.X/2))>0 &&
|
(this.Position.X+(this.Size.X/2))>0 &&
|
||||||
(this.Position.Y+(this.Size.Y/2))>0 &&
|
(this.Position.Y+(this.Size.Y/2))>0 &&
|
||||||
(this.Position.X-(this.Size.X/2))
|
(this.Position.X-(this.Size.X/2))
|
||||||
<this.GameScreen.Size.X &&
|
<this.GameScreen.Size.X &&
|
||||||
(this.Position.Y-(this.Size.Y/2))
|
(this.Position.Y-(this.Size.Y/2))
|
||||||
<this.GameScreen.Size.Y
|
<this.GameScreen.Size.Y
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
Debug: false
|
Debug: false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user