public override void Update() { speed *= 1.0125f; Vector2 playerPos = Game1.getPlayer().getCenter(); speed.Normalize(); Vector2 pointRotatedUp = getCenter() + Vector2.Transform(speed, Matrix.CreateRotationZ(0.1f)); Vector2 pointRotatedDown = getCenter() + Vector2.Transform(speed, Matrix.CreateRotationZ(-0.1f)); if ((playerPos - pointRotatedUp).Length() < (playerPos - pointRotatedDown).Length()) { if (angleSpeed < 0) { angleSpeed = 0; } angleSpeed += 0.001f; } if ((playerPos - pointRotatedUp).Length() > (playerPos - pointRotatedDown).Length()) { if (angleSpeed > 0) { angleSpeed = 0; } angleSpeed -= 0.001f; } angle += angleSpeed; speed = MapTools.AngleToVector(angle); speed *= travelSpeed; if (collidesWithMap().collided) { destroy = true; Light light = new PointLight { Position = new Vector2(getCenter().X, getCenter().Y) - speed, Scale = new Vector2(500), // Range of the light source (how far the light will travel) Radius = 1f, Intensity = 1f, Color = new Color(1f, 0.5f, 0, 1), CastsShadows = false, ShadowType = ShadowType.Illuminated // Will not lit hulls themselves }; ExplosionHandler.addExplosion(light); } if (CollidesWithPlayer()) { Game1.getPlayer().die(); Light light = new PointLight { Position = new Vector2(getCenter().X, getCenter().Y) - speed, Scale = new Vector2(1500), // Range of the light source (how far the light will travel) Radius = 1f, Intensity = 1f, Color = new Color(5f, 0.5f, 0, 1), ShadowType = ShadowType.Solid // Will not lit hulls themselves }; ExplosionHandler.addExplosion(light); } smokeEmitter.pos = oldPos; smokeEmitter.Direction = angle + Math.PI; smokeEmitter.update(); if (destroy == true) { particleEmitter.pos = oldPos; particleEmitter.start(); particleEmitter.update(); } oldPos = pos; base.Update(); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { state = Keyboard.GetState(); if (state.IsKeyDown(Keys.O)) { penumbra.AmbientColor = new Color(penumbra.AmbientColor.R + 1, penumbra.AmbientColor.G + 1, penumbra.AmbientColor.B + 1); } if (state.IsKeyDown(Keys.I)) { penumbra.AmbientColor = new Color(penumbra.AmbientColor.R - 1, penumbra.AmbientColor.G - 1, penumbra.AmbientColor.B - 1); } if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } // TODO: Add your update logic here if (Keyboard.GetState().IsKeyDown(Keys.T) && !prevState.IsKeyDown(Keys.T) && !EditorGui.saveText.isActive) { running = !running; } if (!running) { EditorGui.Update(GraphicsDevice); } if (running) { WorldInfo.updateGravity(); if (WorldInfo.angle == 0) { if (WorldInfo.angle == 0) { world.frameInit(); //if (!TextDialog.isInDialog) player.Input((float)gameTime.ElapsedGameTime.TotalSeconds); //if (!TextDialog.isInDialog) if (!TextDialog.isInDialog) { world.update(GraphicsDevice); } FreeGravityBox.setAllSpeedChains(); world.checkForWalls(); player.update(0); if (!TextDialog.isInDialog) { world.applyChanges(GraphicsDevice); } world.correctDownCollisions(); world.correctRightCollisions(); world.correctLeftCollisions(); //if(Math.Abs(player.fallSpeed) >= Math.Abs(player.speed)) { player.correctUpCollision(); player.correctDownCollision(); player.correctRightCollision(); player.correctLeftCollision(); /* if (player.collidesLeft(true) && player.isGrounded().collided) * player.decideCollisionCorrection(true); * else if (player.collidesRight(true) && player.isGrounded().collided) * player.decideCollisionCorrection(false); * * if (player.collidesRight(true)) * player.correctRightCollision(); * else if (player.collidesLeft(true)) * player.correctLeftCollision(); * if (player.isGrounded().collided) * player.correctDownCollision(); * if (player.collidesUp().collided) * player.correctUpCollision();*/ //player.correctDownCollision(); // player.correctRightCollision(); //player.correctLeftCollision(); //} else /*{ * player.correctRightCollision(); * player.correctLeftCollision(); * * player.correctUpCollision(); * player.correctDownCollision(); * * * }*/ if (!TextDialog.isInDialog) { player.inputGravityChange(); } } } } world.cleanDestroyedItems(); ExplosionHandler.update(); if (state.IsKeyDown(Keys.Z) && prevState.IsKeyUp(Keys.Z)) { penumbra.Visible = !penumbra.Visible; } if (state.IsKeyDown(Keys.Y) && prevState.IsKeyUp(Keys.Y)) { bloomEnabled = !bloomEnabled; } cam.update(); base.Update(gameTime); prevState = state; }