Esempio 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,
                                                       (int)(this.mummy.Location.Y + 0.5) - (int)(elapsed * this.mummy.Speed),
                                                       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.CollisionULeftWalls(this.mummy);
                this.right = MummyManager.CollisionURightWalls(this.mummy);
                int geheelAantalmalen32 = (int)(this.mummy.Location.Y + 0.5) / 32;
                this.mummy.Location = new Vector2(this.mummy.Location.X, geheelAantalmalen32 * 32);
                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 = 2000f;
                    this.mummy.IState = state;
                }
                else if (this.left)
                {
                    IStateMummy state = new MummyWalkLeft(this.mummy);
                    state.ChangeStateTime = 2000f;
                    this.mummy.IState = state;
                }
                else if (this.right)
                {
                    IStateMummy state = new MummyWalkRight(this.mummy);
                    state.ChangeStateTime = 2000f;
                    this.mummy.IState = state;
                }
                else
                {
                    IStateMummy state = new MummyWalkDown(this.mummy);
                    state.ChangeStateTime = 2000f;
                    this.mummy.IState = state;
                }
            }

            ////////////////////////////////////////////////////////////////////////////////////
            //this.timer += elapsed;
            //if (this.timer > changeStateTime)
            //{
            //    int module = (int)(this.mummy.Location.Y + 0.5) % 32;
            //    if (module <= this.mummy.Speed * elapsed)
            //    {
            //        int geheelAantalmalen32 = (int)(this.mummy.Location.Y + 0.5) / 32;
            //        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, 2);
            //    }

            //}
            base.Update(gameTime);
        }
Esempio 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 + 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);
        }