Blame |
Last modification |
View Log
| RSS feed
package com.gebauz.pingk.effects;
import java.util.Vector;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.gebauz.Bauzoid.graphics.sprite.Sprite;
import com.gebauz.Bauzoid.math.MathUtil;
import com.gebauz.pingk.entities.Entity;
import com.gebauz.pingk.game.GameConsts;
import com.gebauz.pingk.game.GameLogic;
public class FlowerEffect
extends Entity
{
public class Particle
{
private float mSize = GameConsts.
POWERUP_FLOWER_PARTICLE_SIZE;
private float x
;
private float y
;
private float mLifeTime
;
public Particle
(float posX,
float posY
)
{
x = posX
;
y = posY
;
mLifeTime = 0.0f
;
}
public void update
(float deltaTime
)
{
mSize += GameConsts.
POWERUP_FLOWER_PARTICLE_GROWTH * deltaTime
;
mLifeTime += deltaTime
;
}
public void render
()
{
mFlower.
x = x
;
mFlower.
y = y
;
mFlower.
w = mSize
;
mFlower.
h = mSize
;
mFlower.
pivotX = mFlower.
w/2.0f
;
mFlower.
pivotY = mFlower.
h/2.0f
;
float alpha = 1.0f
;
if (mLifeTime
> (GameConsts.
POWERUP_FLOWER_PARTICLE_LIFETIME - GameConsts.
POWERUP_FLOWER_PARTICLE_FADE_OUT))
alpha = MathUtil.
clamp(GameConsts.
POWERUP_FLOWER_PARTICLE_LIFETIME -
(mLifeTime / GameConsts.
POWERUP_FLOWER_PARTICLE_FADE_OUT), 0.0f, 1.0f
);
else if (mLifeTime
< GameConsts.
POWERUP_FLOWER_PARTICLE_FADE_IN)
alpha = MathUtil.
clamp(mLifeTime/GameConsts.
POWERUP_FLOWER_PARTICLE_FADE_IN, 0.0f, 1.0f
);
mFlower.
color.
w = alpha
;
mFlower.
render();
}
public boolean isDone
()
{
return (mLifeTime
> GameConsts.
POWERUP_FLOWER_PARTICLE_LIFETIME);
}
}
private Sprite mFlower =
null;
private float mFlowerTimer = 0.0f
;
private Vector<Particle
> mParticles =
new Vector<Particle
>();
public FlowerEffect
(GameLogic gameLogic
)
{
super(gameLogic
);
}
@
Override
public void init
()
{
mFlower =
new Sprite
(getGraphics
(),
new Texture
(Gdx.
files.
internal("data/textures/flower.png")));
mFlower.
color = GameConsts.
PINGK_COLOR.
copy();
}
@
Override
public void exit
()
{
if (mFlower
!=
null)
{
mFlower.
dispose();
mFlower =
null;
}
}
@
Override
public void update
(float deltaTime
)
{
if (getGameLogic
().
getPowerUpLogic().
isFlowerActive())
{
// spawn flowers
mFlowerTimer -= deltaTime
;
while (mFlowerTimer
< 0.0f
)
{
mFlowerTimer += GameConsts.
POWERUP_FLOWER_PARTICLE_INTERVAL;
spawnParticle
(getGameLogic
().
getBall().
getX(), getGameLogic
().
getBall().
getY());
}
}
int i =
0;
while (i
< mParticles.
size())
{
Particle p = mParticles.
get(i
);
p.
update(deltaTime
);
if (p.
isDone())
{
mParticles.
remove(i
);
continue;
}
i++
;
}
}
@
Override
public void render
()
{
for (int i =
0; i
< mParticles.
size(); i++
)
{
mParticles.
get(i
).
render();
}
}
public void spawnParticle
(float x,
float y
)
{
if (mParticles.
size() >= GameConsts.
POWERUP_FLOWER_MAX_PARTICLES)
return;
if (getGameLogic
().
getPlayPhase() == GameLogic.
PHASE_SCORE)
return;
float posX = x + getGameLogic
().
getGame().
getRandomFloat(-GameConsts.
POWERUP_FLOWER_PARTICLE_SPREAD, GameConsts.
POWERUP_FLOWER_PARTICLE_SPREAD);
float posY = y + getGameLogic
().
getGame().
getRandomFloat(-GameConsts.
POWERUP_FLOWER_PARTICLE_SPREAD, GameConsts.
POWERUP_FLOWER_PARTICLE_SPREAD);
Particle p =
new Particle
(posX, posY
);
mParticles.
add(p
);
}
}