//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); }
//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); }