private bool Spike_OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact) { if ((typeof(ILivingThing).IsAssignableFrom(fixtureB.Body.GetType()))) { ILivingThing hitObject = fixtureB.Body as ILivingThing; hitObject.DealDamage(100); return(true); } return(true); }
public void Attack(float damagePoints, Character attacker, ILivingThing target) { PositionService positionService = new PositionService(); FactionService factionService = new FactionService(); if (target is Character enemy) { if (attacker.Equals(target) || !positionService.IsInRange(attacker, enemy) || factionService.IsAllies(attacker, enemy)) { return; } damagePoints *= CalculateThreshold(attacker, enemy); } target.SetDamage(damagePoints); }
private bool Bullet_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact) { if (fixtureB.Body.GetType() == typeof(Bullet) || fixtureB.Body.GetType() == typeof(Rocket) || fixtureB.Body.GetType() == typeof(Player)) { return(false); } if (fixtureA.Body.GetType() == typeof(Bullet) && gameObjects.Contains((Bullet)fixtureA.Body)) { physicsWorld.RemoveBody(fixtureA.Body); gameObjects.Remove((Bullet)fixtureA.Body); if (fixtureB.Body is ILivingThing) { ILivingThing hitObject = fixtureB.Body as ILivingThing; Bullet bull = fixtureA.Body as Bullet; hitObject.DealDamage(bull.Damage); } return(true); } return(false); }
private bool Laser_OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact) { //Pass through other robots if (fixtureB.Body is Robot) { return(false); } if (fixtureA.Body.GetType() == typeof(Bullet) && gameObjects.Contains((Bullet)fixtureA.Body)) { physicsWorld.RemoveBody(fixtureA.Body); gameObjects.Remove((Bullet)fixtureA.Body); if (fixtureB.Body is Player) { ILivingThing hitObject = fixtureB.Body as ILivingThing; Bullet bull = fixtureA.Body as Bullet; hitObject.DealDamage(bull.Damage); } return(true); } return(true); }
public void Fight(ILivingThing attacker, ILivingThing attacked) { attacker.Attack(attacked); }
public void AddFighter(ILivingThing creature) { listOfLivingCreatures[0] = creature; }
public void Attack(ILivingThing enemy) { Console.WriteLine("I'm a monster: GRRRR on " + enemy.ToString()); }
/// <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) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } switch (State) { case GameState.LEVEL: physicsWorld.Step((float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f); #region Mouse Inputs if (Mouse.GetState().ScrollWheelValue < mouseWheelLoc) { player.CycleNextWeapon(); } else if (Mouse.GetState().ScrollWheelValue > mouseWheelLoc) { player.CyclePreviousWeapon(); } mouseWheelLoc = Mouse.GetState().ScrollWheelValue; #endregion #region Camera int Y_CAMERA_THRESHOLD = (ScreenHeight / 2) + 100; //X movement if (ConvertUnits.ToDisplayUnits(player.Position.X) > (-1 * (gameCamera.Position.X)) + ScreenWidth - X_CAMERA_THRESHOLD) { gameCamera.Move(new Vector2(-1 * (ConvertUnits.ToDisplayUnits(player.Position.X) - (-1 * (gameCamera.Position.X) + ScreenWidth - X_CAMERA_THRESHOLD)), 0)); } else if (ConvertUnits.ToDisplayUnits(player.Position.X) < (-1 * (gameCamera.Position.X)) + X_CAMERA_THRESHOLD) { gameCamera.Move(new Vector2(-1 * (ConvertUnits.ToDisplayUnits(player.Position.X) - (-1 * (gameCamera.Position.X) + X_CAMERA_THRESHOLD)), 0)); } //Y movement float playerY = ConvertUnits.ToDisplayUnits(player.Position.Y); if (playerY > gameCamera.Position.Y + 700 && gameCamera.Position.Y > 0) { gameCamera.Move(new Vector2(0, -1 * (ConvertUnits.ToDisplayUnits(player.Position.Y) - (-1 * (gameCamera.Position.Y) + 400)))); } else if (playerY < gameCamera.Position.Y + Y_CAMERA_THRESHOLD + 100) { gameCamera.Move(new Vector2(0, -1 * (ConvertUnits.ToDisplayUnits(player.Position.Y) - (-1 * (gameCamera.Position.Y) + Y_CAMERA_THRESHOLD)))); } CameraOffset = gameCamera.Position; #endregion #region Keyboard inputs if (player.LinearVelocity.Y != 0) { player.State = PlayerState.JUMPING; } else if (Keyboard.GetState().IsKeyDown(Keys.D) || Keyboard.GetState().IsKeyDown(Keys.A)) { player.State = PlayerState.RUNNING; } else { player.State = PlayerState.IDLE; } //TODO: fix ground colloision detection if (Keyboard.GetState().IsKeyDown(Keys.Space) && player.LinearVelocity.Y == 0) { MediaPlayerHelper.MediaPlayerHelper.Instance.PlaySound(JumpEffect); player.ApplyForce(new Vector2(0, -200.0f)); } if (Keyboard.GetState().IsKeyDown(Keys.D) && player.LinearVelocity.X < 5.0f) { player.ApplyForce(new Vector2(20.0f, 0)); } else if (Keyboard.GetState().IsKeyDown(Keys.A) && player.LinearVelocity.X > -5.0f) { player.ApplyForce(new Vector2(-20.0f, 0)); } if (Keyboard.GetState().IsKeyDown(Keys.R)) { player.EquipedWeapon.Reload(); } #endregion #region Update HUD hud.Health = player.Health; hud.AmmoLoaded = player.EquipedWeapon.LoadedAmmo; hud.AmmoReserve = player.EquipedWeapon.ReserveAmmo; hud.Reloading = player.EquipedWeapon.Reloading; hud.selection = player.EquipedWeaponSlot; #endregion #region world cleanup for (int i = gameObjects.Count - 1; i >= 0; i--) { if (gameObjects[i] is ILivingThing) { ILivingThing deadObject = gameObjects[i] as ILivingThing; if (deadObject.Health <= 0) { if (!(deadObject is Player)) { Body deadBody = deadObject as Body; CreateExplosion(deadBody.Position); } physicsWorld.RemoveBody(deadObject as Body); gameObjects.RemoveAt(i); } } else if (gameObjects[i] is Bullet) { Bullet bullet = gameObjects[i] as Bullet; if (bullet.OffScreen()) { physicsWorld.RemoveBody(bullet); gameObjects.RemoveAt(i); } } else if (gameObjects[i] is Explosion) { Explosion explosion = gameObjects[i] as Explosion; if (!explosion.IsAlive) { gameObjects.RemoveAt(i); } } else if (gameObjects[i] is SmokeParticle) { SmokeParticle smoke = gameObjects[i] as SmokeParticle; if (!smoke.IsAlive) { gameObjects.RemoveAt(i); } } } if (player.Health <= 0) { MediaPlayerHelper.MediaPlayerHelper.Instance.PlaySound(deathEffect); respawnPlayer(); } #endregion #region Misc Updates player.Update(gameTime); crosshair.Update(gameTime); for (int i = gameObjects.Count - 1; i >= 0; i--) { gameObjects[i].Update(gameTime); } #endregion break; case GameState.MAIN_MENU: mainMenu.Update(gameTime); gameCamera.Position = Vector2.Zero; break; case GameState.LEVEL_COMPLETE: levelCompleteMenu.Update(gameTime); gameCamera.Position = Vector2.Zero; break; case GameState.OPTIONS_MENU: throw new NotImplementedException(); break; } base.Update(gameTime); }
//if you want a method to be overridable, it should be virtual or abstract public virtual void Attack(ILivingThing enemy) { Console.WriteLine(Name + " is attacking " + enemy.ToString()); }