Main
using System;
using Sifteo;
using Libraries;

namespace App
{
    // Purpose:
    // Game cube.  Contains basics for game related cubes.  Derive from this for different cube types.
    public class GameCubeWrapper : BaseCubeWrapper
    {
        // Purpose:
        // Retrive the application.
        public RPSApp GetApp()
        {
            return m_app;
        }

        // Sprite to display with.
        protected const String m_spriteID = "BaseSprite";
       
        // Represents the type of the cube, if it is a player cube or another cube.
        public CubeType m_cubeType;

        // Store the objects to render, etc.
        public ObjManager m_objs = new ObjManager();

        // Store the actual type of the application.  Makes it easier to use.
        protected RPSApp m_app;

        // Use for a non-game selection value.
        // No actual game attacks should be this.  It is for cube releated actions, not gameplay actions.
        protected const String m_noSelection = "None";
   
        // Renderer to use.
        protected Renderer m_renderer = new Renderer();

        // Purpose:
        // Constructor.
        // app      -
        // cube     - Cube the properties are for.
        // cubeType - What type of cube it is.
        public GameCubeWrapper(RPSApp app,
                               Cube cube,
                               CubeType cubeType) : base(app, cube)
        {
            m_renderer.SetSortBeforeRender(true);

            // Basic sprite that will be used for backgrounds, possibley other stuff.
            Sprite sprite = new Sprite("", 0, 0, 0, 0, 128, 128, 1, 0, true);
            sprite.m_renderIfCubeRender = true;
            sprite.SetLayer(0);
            sprite.SetRenderOrder(10);
            sprite.SetID(m_spriteID);
            m_objs.StoreObj(sprite);


            // Always skip a render frame or else input doesn't work right.
            m_useRenderSkip = true;

            m_app = app;
            m_cubeType = cubeType;
        }
       
        // Handle updating anything needed for the cube.
        // If the cube is marked for render, add in anything that needs to be rendered.
        protected override void HandleUpdate()
        {
            base.HandleUpdate();
        }

        // Purpose:
        // Render the cube.
        // paint - Value is true if the paint command should happen at the end of the function, false if not.
        public override void Render(bool paint)
        {
            base.Render(false);
            m_renderer.Render(m_cube);
       
            if(paint)
                m_cube.Paint();
        }

        // Purpose:
        // Update the cube.
        public override void Tick()
        {
            // Determine what needs to be rendered.
            UpdateRenderer();
            if(m_renderer.ContainsRenderObj())
            {
                m_renderer.Sort();
                m_needRender = true;
            }

            base.Tick();
        }

        // Purpose:
        // Update the renderer, adding render objects.
        // Do this in the update before a render.  Any sprites that can be rendered should go in here.
        // Sprites, etc should already be in the state they are for rendering.
        protected virtual void UpdateRenderer()
        {
            m_objs.FillObjRenderer(m_renderer, m_needRender);
        }
       
        // Purpose:
        // Check if a new render is needed.  Override and check sprites/backgrounds/whatever.
        // Returns true if a render is needed, false if not.
        protected virtual bool CheckNeedsRender()
        {
            return m_needRender;
        }
    }
}

 
Website copyright (c) 2012 Benjamin Millek, all rights reserved.