Rev 289 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package com.gebauz.pingk.entities;
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.Bauzoid.math.Vector4;
import com.gebauz.pingk.game.GameConsts;
import com.gebauz.pingk.game.GameLogic;
public class PaddleImpact
extends Entity
{
public class ImpactElement
{
private Sprite mImpactSprite =
null;
private float x
;
private float y
;
private float mRotation
;
private float mLifeTime
;
public ImpactElement
(Sprite sprite,
float posX,
float posY,
float rotation
)
{
mImpactSprite = sprite
;
x = posX
;
y = posY
;
mRotation = rotation
;
mLifeTime = 0.0f
;
}
public void update
(float deltaTime
)
{
mLifeTime += deltaTime
;
}
public void render
()
{
mImpactSprite.
x = x
;
mImpactSprite.
y = y
;
mImpactSprite.
angle = mRotation
;
float alpha = 1.0f - MathUtil.
clamp(mLifeTime / GameConsts.
PADDLE_IMPACT_LIFETIME, 0.0f, 1.0f
);
mImpactSprite.
color =
new Vector4
(GameConsts.
PINGK_COLOR.
x, GameConsts.
PINGK_COLOR.
y,
GameConsts.
PINGK_COLOR.
z, alpha
);
mImpactSprite.
render();
}
public boolean isDone
()
{
return (mLifeTime
> GameConsts.
PADDLE_IMPACT_LIFETIME);
}
}
private GameLogic mGameLogic =
null;
private Sprite mImpactSprite =
null;
private Vector<ImpactElement
> mImpacts =
new Vector<ImpactElement
>();
public PaddleImpact
(GameLogic gameLogic
)
{
super(gameLogic
);
}
public void init
()
{
// init sprite
mImpactSprite =
new Sprite
(getGameLogic
().
getGraphics(),
new Texture
(Gdx.
files.
internal("data/textures/paddleimpact.png")));
mImpactSprite.
x =
0;
mImpactSprite.
y =
0;
mImpactSprite.
w = GameConsts.
PADDLE_IMPACT_WIDTH;
mImpactSprite.
h = GameConsts.
PADDLE_IMPACT_HEIGHT;
mImpactSprite.
centerPivot();
mImpactSprite.
color = GameConsts.
PINGK_COLOR;
}
public void exit
()
{
mImpacts.
clear();
if (mImpactSprite
!=
null)
{
mImpactSprite.
dispose();
mImpactSprite =
null;
}
}
public void update
(float deltaTime
)
{
int i =
0;
while (i
< mImpacts.
size())
{
ImpactElement element = mImpacts.
get(i
);
element.
update(deltaTime
);
if (element.
isDone())
{
mImpacts.
remove(i
);
continue;
}
i++
;
}
}
public void render
()
{
for (int i =
0; i
< mImpacts.
size(); i++
)
{
mImpacts.
get(i
).
render();
}
}
public void addImpact
(float x,
float y,
float rot
)
{
mImpacts.
add(new ImpactElement
(mImpactSprite, x, y, rot
));
}
}