Subversion Repositories AndroidProjects

Rev

Rev 753 | Rev 1008 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.gebauz.PonPonChun.gamestates;

import com.badlogic.gdx.Gdx;
import com.gebauz.Bauzoid.game.Game;
import com.gebauz.Bauzoid.gamestates.BaseGameState;
import com.gebauz.Bauzoid.graphics.sprite.Sprite;
import com.gebauz.Bauzoid.math.MathUtil;
import com.gebauz.Bauzoid.menu.Menu;
import com.gebauz.Bauzoid.menu.MenuUtil;
import com.gebauz.PonPonChun.game.GameConsts;

public class CreditsState extends BaseGameState
{
        // Constants========================================================================================
       
        public static final float PARTICLE_SPEED = 50.0f;
        public static final float TARGET_Y = 370;
        public static final float START_Y = 500;

        // Embedded Types===================================================================================
       
        public class SleepParticle
        {
                public float y;
               
                public SleepParticle(float y)
                {
                        this.y = y;
                }
               
                public void update(float deltaTime)
                {
                        y -= deltaTime * PARTICLE_SPEED;
                        if (y < TARGET_Y)
                        {
                                y = START_Y;
                        }

                }
               
                public void render()
                {
                        float x = 190 - MathUtil.sin(y * 4 + 40) * 10;
                        getFonts().getFont("scoring").drawText("Z", x, y, 3.0f);
                }
        }

        // Fields===========================================================================================
       
        private Sprite mBackground = null;
        private Sprite mCat = null;
       
        private Menu mMenu = null;
       
        private SleepParticle mParticles[] = new SleepParticle[3];

        // Methods==========================================================================================

        public CreditsState(Game game)
        {
                super(game);
                setFading(true, true);
                mBackground = new Sprite(getGraphics(), "data/textures/landscape.png");
                mCat = new Sprite(getGraphics(), "data/textures/sleepycat.png");
        }

        @Override
        public void init(String param)
        {
                mBackground.init(0, 0, GameConsts.VIRTUAL_SCREEN_WIDTH, GameConsts.VIRTUAL_SCREEN_HEIGHT, 0, 0);
                mCat.init(300, 530, 300, 300);
               
                mMenu = MenuUtil.createMenuFromFile(getGame(), Gdx.files.internal("data/menus/credits.txt"));
                mMenu.init();
               
                float posY = START_Y;
                for (int i = 0; i < mParticles.length; i++)
                {
                        mParticles[i] = new SleepParticle(posY);
                        posY -= 33;
                }
        }

        @Override
        public void exit()
        {
                if (mBackground != null)
                {
                        mBackground.dispose();
                        mBackground = null;
                }
               
                if (mCat != null)
                {
                        mCat.dispose();
                        mCat = null;
                }
               
                if (mMenu != null)
                {
                        mMenu.exit();
                        mMenu = null;
                }
               
                for (int i = 0; i < mParticles.length; i++)
                {
                        mParticles[i] = null;
                }
        }

        @Override
        public void update(float deltaTime)
        {
                mMenu.update(deltaTime);
               
                for (int i = 0; i < mParticles.length; i++)
                {
                        mParticles[i].update(deltaTime);
                }
               
                if (Gdx.input.justTouched())
                {
                        getGameStateManager().switchTo(com.gebauz.PonPonChun.gamestates.TitleState.class, "");                 
                }
        }

        @Override
        public void render()
        {
                getGraphics().clear(0.35f, 0.25f, 0.35f, 0.0f);
               
                getRenderStates().projection.setOrtho(
                                0.0f,
                                GameConsts.VIRTUAL_SCREEN_WIDTH-1,
                                GameConsts.VIRTUAL_SCREEN_HEIGHT-1,
                                0.0f,
                                0.0f,
                                1.0f
                        );
               
                mBackground.render();  
               
                mCat.render();
               
                mMenu.render();
               
                for (int i = 0; i < mParticles.length; i++)
                {
                        mParticles[i].render();
                }
        }
       
        // Getters/Setters==================================================================================

}