GAM456-SpaceInvaders / SpaceInvaders / 4_GameObject / Ship / Ship.cs
Ship.cs
Raw
using System;
using System.Diagnostics;


namespace SpaceInvaders
{
    public class Ship : Ships
    {
        //-------------------------------------------------------------------
        //  FIELDS
        //-------------------------------------------------------------------

        public float speed;
        private ShipMissileState pMissileState;
        private ShipMoveState pMoveState;


        //-------------------------------------------------------------------
        //  CONSTRUCTION
        //-------------------------------------------------------------------

        public Ship(GameObject.ObjectName objName, Sprite.SpriteName spriteName, float x, float y)
            : base(objName, spriteName, x, y, Ships.ShipType.Ship)
        {
            this.x = x;
            this.y = y;

            this.speed = 5.0f;
            this.pMissileState = null;
            this.pMoveState = null;
            this.SetCollisionColor(0, 0, 1);
        }


        //-------------------------------------------------------------------
        //  PUBLIC METHODS
        //-------------------------------------------------------------------

        public void SetMissileState(ShipMan.MissileState state)
        {
            this.pMissileState = ShipMan.GetMissileState(state);
        }

        public void SetMoveState(ShipMan.MoveState state)
        {
            this.pMoveState = ShipMan.GetMoveState(state);
        }

        public void MoveRight()
        {
            this.pMoveState.MoveRight(this);
        }

        public void MoveLeft()
        {
            this.pMoveState.MoveLeft(this);
        }

        public void ShootMissile()
        {
            this.pMissileState.ShootMissile(this);
        }

        public void ResurrectShip(float x, float y)
        {
            this.x = x;
            this.y = y;

            base.Ressurect();
            this.pColObj.pCollisionSprite.SetColor(1.0f, 0.0f, 0.0f);
        }

        public override void Update()
        {
            base.Update();
        }

        public override void Remove()
        {
            Debug.WriteLine("Removing: {0}: ", this.name);

            this.pColObj.pCollisionRect.Set(0, 0, 0, 0);
            base.Update();

            //update parent
            GameObject pParent = (GameObject)this.pParent;
            pParent.Update();

            //remove it
            base.Remove();
        }


        //-------------------------------------------------------------------
        //  VISITOR METHODS
        //-------------------------------------------------------------------

        public override void Accept(Visitor other)
        {
            other.Visit(this);
        }


    } //end class

} //end namespace