Rev 292 |
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.pingk.game.GameConsts;
import com.gebauz.pingk.game.GameLogic;
public class PlayField
extends Entity
{
public class Impact
{
private float x
;
private float y
;
private float mAngle
;
private float mLifeTime
;
private Sprite mImpactSprite =
null;
public Impact
(Sprite 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.
color.
w = alpha
; // (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 Sprite mBackground =
null;
private Sprite mImpactSprite =
null;
private Vector<Impact
> mImpacts =
new Vector<Impact
>();
private float mVirtualHeight = 0.0f
;
public PlayField
(GameLogic gameLogic
)
{
super(gameLogic
);
mVirtualHeight =
GameConsts.
VIRTUAL_SCREEN_HEIGHT -
((GameConsts.
SCORE_BAR_HEIGHT * getGraphics
().
getDipToPixelScale() +
0.5f
) * (GameConsts.
VIRTUAL_SCREEN_HEIGHT /
(float)getGraphics
().
getHeight()));
}
@
Override
public void init
()
{
Texture texture =
new Texture
(Gdx.
files.
internal("data/textures/playfield.png"));
mBackground =
new Sprite
(getGraphics
(), texture
);
mBackground.
pivotX =
0;
mBackground.
pivotY =
0;
mBackground.
x =
0;
mBackground.
y =
0;
mBackground.
w = GameConsts.
VIRTUAL_SCREEN_WIDTH;
mBackground.
h = mVirtualHeight
;
mBackground.
color = GameConsts.
PINGK_COLOR;
mImpactSprite =
new Sprite
(getGraphics
(),
new Texture
(Gdx.
files.
internal("data/textures/wallimpact.png")));
mImpactSprite.
x =
0;
mImpactSprite.
y =
0;
mImpactSprite.
w = GameConsts.
PLAYFIELD_IMPACT_SIZE;
mImpactSprite.
h = GameConsts.
PLAYFIELD_IMPACT_SIZE;
mImpactSprite.
pivotX = GameConsts.
PLAYFIELD_IMPACT_SIZE / 2.0f
;
mImpactSprite.
pivotY = GameConsts.
PLAYFIELD_IMPACT_SIZE;
mImpactSprite.
color = GameConsts.
PINGK_COLOR.
copy();
}
@
Override
public void exit
()
{
if (mBackground
!=
null)
{
mBackground.
dispose();
mBackground =
null;
}
if (mImpactSprite
!=
null)
{
mImpactSprite.
dispose();
mImpactSprite =
null;
}
}
@
Override
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++
;
}
}
@
Override
public void render
()
{
renderImpacts
();
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
));
}
public float getVirtualHeight
()
{
return mVirtualHeight
;
}
public boolean isOutOfBoard
(float posX,
float posY
)
{
if ((posY
< GameConsts.
PLAYFIELD_BORDER_Y) ||
(posY
> getVirtualHeight
() - GameConsts.
PLAYFIELD_BORDER_Y))
return true;
if ((posX
< GameConsts.
PLAYFIELD_BORDER_X) ||
(posX
> GameConsts.
VIRTUAL_SCREEN_WIDTH - GameConsts.
PLAYFIELD_BORDER_X))
return true;
return false;
}
public boolean isOutOfBoardInner
(float posX,
float posY
)
{
if ((posY
< GameConsts.
PLAYFIELD_BORDER_Y) ||
(posY
> getVirtualHeight
() - GameConsts.
PLAYFIELD_BORDER_Y))
return true;
if ((posX
< GameConsts.
PADDLE_DISTANCE_FROM_EDGE_X + GameConsts.
PADDLE_WIDTH) ||
(posX
> GameConsts.
VIRTUAL_SCREEN_WIDTH - GameConsts.
PADDLE_DISTANCE_FROM_EDGE_X - GameConsts.
PADDLE_WIDTH))
return true;
return false;
}
}