Ejemplo n.º 1
0
        //update
        public override void Update(GameTime gameTime)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
            ////////////////////////////////////////////////////////////////////////////////////////////////////////
            this.mummy.CollisionRect = new Rectangle((int)(this.mummy.Location.X + 0.5) - (int)(elapsed * this.mummy.Speed),
                                                       (int)this.mummy.Location.Y,
                                                       this.mummy.CollisionText.Width + (int)(elapsed * this.mummy.Speed),
                                                       this.mummy.CollisionText.Height);

            if (!MummyManager.CollisionDectectionWalls(this.mummy))
                this.mummy.Location -= new Vector2(this.mummy.Speed * elapsed, 0f);
            else
            {
                this.up = MummyManager.CollisionLUpWalls(this.mummy);
                this.down = MummyManager.CollisionLDownWalls(this.mummy);
                int geheelAantalmalen32 = (int)(this.mummy.Location.X + 0.5) / 32;
                this.mummy.Location = new Vector2(geheelAantalmalen32 * 32, this.mummy.Location.Y);
                IStateMummy state;
                if (this.up && this.down)
                {
                    if ( this.random.Next(2) == 0)
                        state = new MummyWalkUp(this.mummy);
                    else
                        state = new MummyWalkDown(this.mummy);
                }
                else if (this.up)
                {
                    state = new MummyWalkUp(this.mummy);
                }
                else if (this.down)
                {
                    state = new MummyWalkDown(this.mummy);
                }
                else
                {
                    state = new MummyWalkRight(this.mummy);
                }
                state.ChangeStateTime = 2f;
                this.mummy.IState = state;
            }
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////
            this.timer += elapsed;
            ////this.mummy.Location -= new Vector2(this.mummy.Speed * elapsed, 0f);
            if (this.timer > changeStateTime)
            {
                int module = (int)(this.mummy.Location.X + 0.5) % 32;
                //Console.WriteLine("module = {0}", module);
                if (module <= this.mummy.Speed * elapsed)
                {
                    int geheelAantalmalen32 = (int)(this.mummy.Location.X + 0.5) / 32;
                    this.mummy.Location = new Vector2(geheelAantalmalen32 * 32, this.mummy.Location.Y);
                    this.mummy.IState = new MummyWander(this.mummy, 1);
                }
            }
            base.Update(gameTime);
        }
Ejemplo n.º 2
0
        //update
        public override void Update(GameTime gameTime)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
            ////////////////////////////////////////////////////////////////
            this.mummy.CollisionRect = new Rectangle((int)this.mummy.Location.X,
                                                        (int)this.mummy.Location.Y,
                                                        this.mummy.CollisionText.Width,
                                                        this.mummy.CollisionText.Height + (int)(elapsed * this.mummy.Speed));

            if (!MummyManager.CollisionDectectionWalls(this.mummy))
                this.mummy.Location += new Vector2(0f, this.mummy.Speed * elapsed);
            else
            {
                this.left = MummyManager.CollisionDLeftWalls(this.mummy);
                this.right = MummyManager.CollisionDRightWalls(this.mummy);
                int geheelAantalmalen32 = ((int)(this.mummy.Location.X + 0.5) / 32);
                this.mummy.Location = new Vector2(geheelAantalmalen32 * 32, this.mummy.Location.Y);
                if (this.left && this.right)
                {
                    IStateMummy state;
                    if (this.random.Next(2) == 0)
                    {
                        state = new MummyWalkLeft(this.mummy);
                    }
                    else
                    {
                        state = new MummyWalkRight(this.mummy);
                    }
                    state.ChangeStateTime = 2f;
                    this.mummy.IState = state;
                }
                else if (this.left)
                {
                    IStateMummy state = new MummyWalkLeft(this.mummy);
                    state.ChangeStateTime = 2f;
                    this.mummy.IState = state;
                }
                else if (this.right)
                {
                    IStateMummy state = new MummyWalkRight(this.mummy);
                    state.ChangeStateTime = 2f;
                    this.mummy.IState = state;
                }
                else
                {
                    IStateMummy state = new MummyWalkUp(this.mummy);
                    state.ChangeStateTime = 2f;
                    this.mummy.IState = state;
                }
            }
            ///////////////////////////////////////////////////////////////////////
               this.timer += elapsed;
               //// this.mummy.Location += new Vector2(0f, this.mummy.Speed * elapsed);
               if (this.timer > changeStateTime)
               {

               int module = (int)this.mummy.Location.Y % 32;
               //Console.WriteLine("module = {0}", module);
               if (module >= 32 - this.mummy.Speed * elapsed)
               {
                   int geheelAantalmalen32 = ((int)this.mummy.Location.Y / 32) + 1;
                   this.mummy.Location = new Vector2(this.mummy.Location.X, geheelAantalmalen32 * 32);
                   //Console.WriteLine("module = {0} en int geheelAantalmalen32 = {1}", module, geheelAantalmalen32);
                   this.mummy.IState = new MummyWander(this.mummy, 0);
               }
               }
            base.Update(gameTime);
        }
Ejemplo n.º 3
0
        //update
        public override void Update(GameTime gameTime)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
            //////////////////////////////////////////////////////////////
            this.mummy.CollisionRect = new Rectangle((int)this.mummy.Location.X,
                                                        (int)this.mummy.Location.Y,
                                                        this.mummy.CollisionText.Width + (int)(elapsed * this.mummy.Speed),
                                                        this.mummy.CollisionText.Height);

               // Console.WriteLine("Up {0} en Down {1}", this.up, this.down);
            if (!MummyManager.CollisionDectectionWalls(this.mummy))
            {
                this.mummy.Location += new Vector2(this.mummy.Speed * elapsed, 0f);
            }
            else
            {
                this.up = MummyManager.CollisionRUpWalls(this.mummy);
                this.down = MummyManager.CollisionRDownWalls(this.mummy);
                int geheelAantalmalen32 = ((int)(this.mummy.Location.X + 0.5) / 32);
                this.mummy.Location = new Vector2(geheelAantalmalen32 * 32, this.mummy.Location.Y);
                if (this.up && this.down)
                {
                    IStateMummy state;
                    if (this.random.Next(2) == 0)
                        state = new MummyWalkUp(this.mummy);
                    else
                        state = new MummyWalkDown(this.mummy);
                    state.ChangeStateTime = 2000f;
                    this.mummy.IState = state;
                }
                else if (this.up)
                {
                    IStateMummy state = new MummyWalkUp(this.mummy);
                    state.ChangeStateTime = 2000f;
                    this.mummy.IState = state;
                }
                else if (this.down)
                {
                    IStateMummy state = new MummyWalkDown(this.mummy);
                    state.ChangeStateTime = 2000f;
                    this.mummy.IState = state;
                }
                else
                {
                    IStateMummy state = new MummyWalkLeft(this.mummy);
                    state.ChangeStateTime = 2000f;
                    this.mummy.IState = state;
                }
            }
            //////////////////////////////////////////////////////////////////////////////////////

            base.Update(gameTime);
        }