protected override void LoadContent() { spriteBatch = new SpriteBatch(graphics.GraphicsDevice); frontParticleSystem = new ParticleSystem(); entityParticleSystem = new ParticleSystem(); particleTools = new ParticleTools(frontParticleSystem, entityParticleSystem, Content); player = new Player(Content, particleTools, Units.TileToGame(ScreenWidth / 2), Units.TileToGame(ScreenHeight / 2)); damageTexts.AddDamageable(player); bat = new FirstCaveBat(Content, Units.TileToGame(7), Units.TileToGame(ScreenHeight / 2 + 1)); damageTexts.AddDamageable(bat); map = Map.CreateSlopeTestMap(Content); pickups.Add(new PowerDoritoPickup(Content, bat.CenterX, bat.CenterY, PowerDoritoPickup.SizeType.Medium)); pickups.Add(new PowerDoritoPickup(Content, bat.CenterX, bat.CenterY, PowerDoritoPickup.SizeType.Medium)); pickups.Add(new PowerDoritoPickup(Content, bat.CenterX, bat.CenterY, PowerDoritoPickup.SizeType.Medium)); base.LoadContent(); }
protected override void Update(GameTime gameTime) { input.BeginFrame(); if (input.WasKeyPressed(Keys.Escape)) { Exit(); } // Player horizontal movement if (input.IsKeyHeld(Keys.Left) && input.IsKeyHeld(Keys.Right)) { player.StopMoving(); } else if (input.IsKeyHeld(Keys.Left)) { player.StartMovingLeft(); } else if (input.IsKeyHeld(Keys.Right)) { player.StartMovingRight(); } else { player.StopMoving(); } if (input.IsKeyHeld(Keys.Up) && input.IsKeyHeld(Keys.Down)) { player.LookHorizontal(); } else if (input.IsKeyHeld(Keys.Up)) { player.LookUp(); } else if (input.IsKeyHeld(Keys.Down)) { player.LookDown(); } else { player.LookHorizontal(); } // Player Jump Logic if (input.WasKeyPressed(Keys.Z)) { player.StartJump(); } else if (input.WasKeyReleased(Keys.Z)) { player.StopJump(); } if (input.WasKeyPressed(Keys.X)) { player.StartFire(); } else if (input.WasKeyReleased(Keys.X)) { player.StopFire(); } player.debugCollidingTiles.Clear(); player.debugOppositeCollidingTiles.Clear(); Timer.UpdateAll(gameTime); damageTexts.Update(gameTime); pickups.Update(gameTime, map); frontParticleSystem.Update(gameTime); entityParticleSystem.Update(gameTime); player.Update(gameTime, map); if (bat != null) { if (!bat.Update(gameTime, player.CenterX)) { DeathCloudParticle.CreateRandomDeathCloud(particleTools, bat.CenterX, bat.CenterY, 3); pickups.Add(FlashingPickup.HeartPickup(Content, bat.CenterX, bat.CenterY)); damageTexts.damageTextDict[bat.DamageText] = null; bat = null; } } List<IProjectile> projectiles = player.Projectiles; for (int i = 0; i < projectiles.Count; i++) { if (bat != null && bat.CollisionRectangle.Intersects(projectiles[i].CollisionRectangle)) { bat.TakeDamage(projectiles[i].ContactDamage); projectiles[i].CollideWithEnemy(); } } pickups.HandleCollisions(player); if (bat != null && bat.DamageRectangle.Intersects(player.DamageRectangle)) { player.TakeDamage(bat.ContactDamage); } input.EndFrame(); base.Update(gameTime); }
protected override void Update(GameTime gameTime) { input.BeginFrame(); if (input.WasKeyPressed(Keys.Escape)) { Exit(); } // Player horizontal movement if (input.IsKeyHeld(Keys.Left) && input.IsKeyHeld(Keys.Right)) { player.StopMoving(); } else if (input.IsKeyHeld(Keys.Left)) { player.StartMovingLeft(); } else if (input.IsKeyHeld(Keys.Right)) { player.StartMovingRight(); } else { player.StopMoving(); } if (input.IsKeyHeld(Keys.Up) && input.IsKeyHeld(Keys.Down)) { player.LookHorizontal(); } else if (input.IsKeyHeld(Keys.Up)) { player.LookUp(); } else if (input.IsKeyHeld(Keys.Down)) { player.LookDown(); } else { player.LookHorizontal(); } // Player Jump Logic if (input.WasKeyPressed(Keys.Z)) { player.StartJump(); } else if (input.WasKeyReleased(Keys.Z)) { player.StopJump(); } if (input.WasKeyPressed(Keys.X)) { player.StartFire(); } else if (input.WasKeyReleased(Keys.X)) { player.StopFire(); } player.debugCollidingTiles.Clear(); player.debugOppositeCollidingTiles.Clear(); Timer.UpdateAll(gameTime); damageTexts.Update(gameTime); pickups.Update(gameTime, map); frontParticleSystem.Update(gameTime); entityParticleSystem.Update(gameTime); player.Update(gameTime, map); if (bat != null) { if (!bat.Update(gameTime, player.CenterX)) { DeathCloudParticle.CreateRandomDeathCloud(particleTools, bat.CenterX, bat.CenterY, 3); pickups.Add(FlashingPickup.HeartPickup(Content, bat.CenterX, bat.CenterY)); damageTexts.damageTextDict[bat.DamageText] = null; bat = null; } } List <IProjectile> projectiles = player.Projectiles; for (int i = 0; i < projectiles.Count; i++) { if (bat != null && bat.CollisionRectangle.Intersects(projectiles[i].CollisionRectangle)) { bat.TakeDamage(projectiles[i].ContactDamage); projectiles[i].CollideWithEnemy(); } } pickups.HandleCollisions(player); if (bat != null && bat.DamageRectangle.Intersects(player.DamageRectangle)) { player.TakeDamage(bat.ContactDamage); } input.EndFrame(); base.Update(gameTime); }