protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); RasterizerState rs = new RasterizerState(); rs.CullMode = CullMode.None; spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, rs, null, Game1.Camera.Transform); f.draw(spriteBatch); spriteBatch.End(); spriteBatch.Begin(); mBox.draw(spriteBatch); spriteBatch.End(); base.Draw(gameTime); spriteBatch.Begin(); int floorIndex = 0; if (f.GetType() == typeof(Floor1)) { floorIndex = 1; } else if (f.GetType() == typeof(Floor2)) { floorIndex = 2; } else if (f.GetType() == typeof(Floor3)) { floorIndex = 3; } else if (f.GetType() == typeof(Floor4)) { floorIndex = 4; } spriteBatch.DrawString(Fonts.Normal, "Floor: " + floorIndex, Vector2.Zero, Color.White); spriteBatch.End(); }
public void update(GameTime gameTime, Floor floor) { base.update(gameTime); keys = Keyboard.GetState(); //Play proper breathing sound if (floor.GetType() == typeof(Floor1) || floor.GetType() == typeof(Floor2)) { if (breathing.State == SoundState.Stopped) { breathing.Play(); } else { breathing.Resume(); } } else { if (breathing.State == SoundState.Playing) { breathing.Stop(); } if (heavyB.State == SoundState.Stopped) { heavyB.Play(); } } this.Position += this.velocity; velocity = Vector2.Zero; //Check for X direction movement--adjust sprite if need if ((keys.IsKeyDown(Keys.D) || keys.IsKeyDown(Keys.Right)) && this.Position.X + this.rec.Width < floor.DrawingRec.Width) { velocity.X = this.Speed; Flip = false; } if ((keys.IsKeyDown(Keys.A) || keys.IsKeyDown(Keys.Left)) && this.Position.X > floor.DrawingRec.X) { velocity.X = -this.Speed; Flip = true; } //Play proper animation/walking Sounds if (velocity.X == 0) { playAnimation(aniIdle); if (walking.State == SoundState.Playing) { walking.Stop(); } } else { if (walking.State == SoundState.Stopped) { stepIndex = (stepIndex + 1) % 2; switch (stepIndex) { case 0: walking = Sound.Steps.Step3.CreateInstance(); break; case 1: walking = Sound.Steps.Step4.CreateInstance(); break; } walking.Play(); } else { walking.Resume(); } playAnimation(aniWalk); } //Find closes object Focus = null; float minDis = floor.DrawingRec.Width; int minIndex = -1; for (int i = 0; i < floor.Objects.Length; i++) { if (measureDis(floor.Objects[i]) < minDis) { minDis = measureDis(floor.Objects[i]); minIndex = i; } } if (minIndex != -1 && minDis < 150) { Focus = floor.Objects[minIndex]; } oldkeys = keys; }