Blame |
Last modification |
View Log
| RSS feed
package com.gebauz.pingk.entities;
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 PowerUp
extends Entity
{
public enum Type
{
POWERUP_CONCAVE,
POWERUP_MOSAIC,
POWERUP_FLOWER,
POWERUP_HOURGLASS,
POWERUP_CRYSTAL,
POWERUP_BARRIER_HORIZONTAL,
POWERUP_BARRIER_VERTICAL,
POWERUP_BOMB,
};
public static String TEXTURES
[] =
{
"data/textures/icon_concave.png",
//R.drawable.icon_concave,
"data/textures/icon_chess.png",
//R.drawable.icon_chess,
"data/textures/icon_flower.png",
//R.drawable.icon_flower,
"data/textures/icon_hourglass.png",
//R.drawable.icon_hourglass,
"data/textures/icon_crystal.png",
//R.drawable.icon_crystal,
"data/textures/icon_barrier_horizontal.png",
//R.drawable.icon_barrier_horizontal,
"data/textures/icon_barrier_vertical.png",
//R.drawable.icon_barrier_vertical,
"data/textures/icon_bomb.png" //R.drawable.icon_bomb
};
private Type mType =
Type.
POWERUP_CONCAVE;
private Sprite mSprite =
null;
private Sprite mBubble =
null;
private float mPosX = 0.0f
;
private float mPosY = 0.0f
;
private float mTimer = 0.0f
;
public PowerUp
(GameLogic gameLogic,
Type type,
float posX,
float posY
)
{
super(gameLogic
);
mType = type
;
mPosX = posX
;
mPosY = posY
;
}
@
Override
public void init
()
{
//mPowerUpEffect = new PowerUpEffect(mGameLogic);
mSprite =
new Sprite
(getGraphics
(),
new Texture
(Gdx.
files.
internal(TEXTURES
[mType.
ordinal()])));
mSprite.
x = mPosX
;
mSprite.
y = mPosY
;
mSprite.
w = GameConsts.
POWERUP_SIZE;
mSprite.
h = GameConsts.
POWERUP_SIZE;
mSprite.
centerPivot();
mSprite.
color = GameConsts.
PINGK_COLOR.
copy();
mBubble =
new Sprite
(getGraphics
(),
new Texture
(Gdx.
files.
internal("data/textures/bubble.png")));
mBubble.
x = mPosX
;
mBubble.
y = mPosY
;
mBubble.
w = GameConsts.
POWERUP_BUBBLE_SIZE;
mBubble.
h = GameConsts.
POWERUP_BUBBLE_SIZE;
mBubble.
centerPivot();
mBubble.
color =
new Vector4
(GameConsts.
PINGK_COLOR.
x, GameConsts.
PINGK_COLOR.
y, GameConsts.
PINGK_COLOR.
z, 0.9f
);
mTimer = 0.0f
;
}
@
Override
public void exit
()
{
}
@
Override
public void update
(float deltaTime
)
{
mTimer += deltaTime
;
}
@
Override
public void render
()
{
float lifeFactor = MathUtil.
clamp(mTimer / GameConsts.
POWERUP_APPEAR_TIME, 0.0f, 1.0f
);
mSprite.
w = GameConsts.
POWERUP_BUBBLE_SIZE * lifeFactor
;
mSprite.
h = GameConsts.
POWERUP_BUBBLE_SIZE * lifeFactor
;
mSprite.
centerPivot();
mSprite.
render();
float cos =
(float)Math.
cos(mTimer
* GameConsts.
POWERUP_WOBBLE_SPEED);
float sin =
(float)Math.
sin(mTimer
* GameConsts.
POWERUP_WOBBLE_SPEED);
mBubble.
x = mSprite.
x;
mBubble.
y = mSprite.
y;
mBubble.
w = GameConsts.
POWERUP_BUBBLE_SIZE + cos
* GameConsts.
POWERUP_WOBBLE_OFFSET;
mBubble.
h = GameConsts.
POWERUP_BUBBLE_SIZE + sin
* GameConsts.
POWERUP_WOBBLE_OFFSET;
mBubble.
w *= lifeFactor
;
mBubble.
h *= lifeFactor
;
mBubble.
centerPivot();
mBubble.
render();
}
public float getX
()
{
return mPosX
;
}
public float getY
()
{
return mPosY
;
}
public Type getType
()
{
return mType
;
}
public boolean isInside
(float x,
float y
)
{
return mSprite.
isInside(x, y
);
}
}