Subversion Repositories AndroidProjects

Rev

Rev 89 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.gebauz.pingK.game;

import java.util.Vector;

import com.gebauz.framework.util.MathUtil;
import com.gebauz.framework.util.Sprite2D;
import com.gebauz.pingK.R;

public class PowerUp
{
        public enum Type
        {
                POWERUP_CONCAVE,
                POWERUP_MOSAIC,
                POWERUP_FLOWER,
                POWERUP_HOURGLASS,
                POWERUP_CRYSTAL,
                POWERUP_BARRIER_HORIZONTAL,
                POWERUP_BARRIER_VERTICAL,      
                POWERUP_BOMB,
        };
       
        public static int TEXTURES[] =
        {
                R.drawable.icon_concave,
                R.drawable.icon_chess,
                R.drawable.icon_flower,
                R.drawable.icon_hourglass,
                R.drawable.icon_crystal,
                R.drawable.icon_barrier_horizontal,
                R.drawable.icon_barrier_vertical,
                R.drawable.icon_bomb
        };
       
        private GameLogic mGameLogic = null;
        private Type mType = Type.POWERUP_CONCAVE;
        private Sprite2D mSprite;
        private Sprite2D mBubble;
       
        private float mTimer = 0.0f;
       
        public PowerUp(GameLogic gameLogic, Type type, float posX, float posY)
        {
                mGameLogic = gameLogic;
                mType = type;
               
                mSprite = new Sprite2D();
                mSprite.init(TEXTURES[type.ordinal()], 0, 0, GameConsts.POWERUP_SIZE, GameConsts.POWERUP_SIZE);
                mSprite.x = posX;
                mSprite.y = posY;
                mSprite.pivotX = mSprite.w/2.0f;
                mSprite.pivotY = mSprite.h/2.0f;
                mSprite.setColor(GameConsts.PINGK_COLOR);      
               
                mBubble = new Sprite2D();
                mBubble.init(R.drawable.bubble, 0, 0, GameConsts.POWERUP_BUBBLE_SIZE, GameConsts.POWERUP_BUBBLE_SIZE);
                mBubble.x = posX;
                mBubble.y = posY;
                mBubble.pivotX = mBubble.w/2.0f;
                mBubble.pivotY = mBubble.h/2.0f;
                mBubble.setColor(GameConsts.PINGK_COLOR.x, GameConsts.PINGK_COLOR.y, GameConsts.PINGK_COLOR.z, 0.9f);  
               
                mTimer = 0.0f;
        }
       
        public void update(float deltaTime)
        {
                mTimer += deltaTime;
               
                mSprite.update(deltaTime);
                mBubble.update(deltaTime);
               
/*              int i = 0;
                while (i < mParticles.size())
                {
                        Particle particle = mParticles.get(i);
                        particle.update(deltaTime);
                        if (particle.isDone())
                        {
                                mParticles.remove(i);
                                continue;
                        }
                       
                        i++;
                }*/
           
        }
       
        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.pivotX = mSprite.w/2.0f;
                mSprite.pivotY = mSprite.h/2.0f;
               
                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.pivotX = mBubble.w/2.0f;
                mBubble.pivotY = mBubble.h/2.0f;
               
                mBubble.render();
        }
       
        public boolean isInside(float x, float y)
        {
                return mSprite.isInside(x, y);
        }
       
        public float getX()
        {
                return mSprite.x;
        }
       
        public float getY()
        {
                return mSprite.y;
        }
       
        public Type getType()
        {
                return mType;          
        }
}