Rev 70 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package com.gebauz.pingK.game;
import java.util.Vector;
import android.util.Log;
import com.gebauz.framework.util.GLUtil;
import com.gebauz.framework.util.MathUtil;
import com.gebauz.framework.util.Sprite2D;
import com.gebauz.pingK.R;
public class PlayField
{
public class Impact
{
private float x
;
private float y
;
private float mAngle
;
private float mLifeTime
;
private Sprite2D mImpactSprite =
null;
public Impact
(Sprite2D sprite,
float posX,
float posY,
float rotation
)
{
mImpactSprite = sprite
;
x = posX
;
y = posY
;
mAngle = rotation
;
mLifeTime = 0.0f
;
}
public void update
(float deltaTime
)
{
mLifeTime += deltaTime
;
mImpactSprite.
update(deltaTime
);
}
public void render
()
{
mImpactSprite.
x = x
;
mImpactSprite.
y = y
;
mImpactSprite.
angle = mAngle
;
float life = MathUtil.
clamp(mLifeTime / GameConsts.
PLAYFIELD_IMPACT_LIFETIME, 0.0f, 1.0f
);
float alpha = 1.0f - life
;
mImpactSprite.
w = GameConsts.
PLAYFIELD_IMPACT_SIZE + GameConsts.
PLAYFIELD_IMPACT_SIZE_GROWTH * life
;
mImpactSprite.
h = GameConsts.
PLAYFIELD_IMPACT_SIZE + GameConsts.
PLAYFIELD_IMPACT_SIZE_GROWTH * life
;
mImpactSprite.
pivotX = mImpactSprite.
w / 2.0f
;
mImpactSprite.
pivotY = mImpactSprite.
h;
mImpactSprite.
setColor(GameConsts.
PINGK_COLOR.
x, GameConsts.
PINGK_COLOR.
y, GameConsts.
PINGK_COLOR.
z, alpha
);
mImpactSprite.
render();
}
public boolean isDone
()
{
return (mLifeTime
> GameConsts.
PLAYFIELD_IMPACT_LIFETIME);
}
}
private GameLogic mGameLogic =
null;
private Sprite2D mBackground =
new Sprite2D
();
private Sprite2D mScoreBarBackground =
new Sprite2D
();
private Sprite2D mImpactSprite =
new Sprite2D
();
private Vector<Impact
> mImpacts =
new Vector<Impact
>();
public PlayField
(GameLogic gameLogic
)
{
mGameLogic = gameLogic
;
}
public void init
()
{
mBackground.
init(R.
drawable.
playfield,
0,
0, GameConsts.
VIRTUAL_SCREEN_WIDTH, mGameLogic.
getVirtualPlayFieldHeight());
mBackground.
pivotX = 0.0f
;
mBackground.
pivotY = 0.0f
;
mScoreBarBackground.
init(R.
drawable.
scorebarbg,
0, mGameLogic.
getVirtualPlayFieldHeight(), GameConsts.
VIRTUAL_SCREEN_WIDTH, mGameLogic.
getVirtualScoreBarHeight());
mScoreBarBackground.
pivotX = 0.0f
;
mScoreBarBackground.
pivotY = 0.0f
;
mImpactSprite.
init(R.
drawable.
wallimpact,
0,
0, GameConsts.
PLAYFIELD_IMPACT_SIZE, GameConsts.
PLAYFIELD_IMPACT_SIZE);
mImpactSprite.
pivotX = GameConsts.
PLAYFIELD_IMPACT_SIZE / 2.0f
;
mImpactSprite.
pivotY = GameConsts.
PLAYFIELD_IMPACT_SIZE;
}
public void exit
()
{
}
public void update
(float deltaTime
)
{
mBackground.
update(deltaTime
);
int i =
0;
while (i
< mImpacts.
size())
{
Impact impact = mImpacts.
get(i
);
impact.
update(deltaTime
);
if (impact.
isDone())
{
mImpacts.
remove(i
);
continue;
}
i++
;
}
}
public void render
()
{
renderImpacts
();
mScoreBarBackground.
render();
mBackground.
render();
}
public void renderImpacts
()
{
for (int i =
0; i
< mImpacts.
size(); i++
)
{
mImpacts.
get(i
).
render();
}
}
public void createImpact
(float x,
float y,
float rot
)
{
//Log.v(GameConsts.LOG_TAG, "Impact: " + x + ", " + y + " r=" + rot);
mImpacts.
add(new Impact
(mImpactSprite, x, y, rot
));
}
}