本文整理汇总了C#中Weapon.Update方法的典型用法代码示例。如果您正苦于以下问题:C# Weapon.Update方法的具体用法?C# Weapon.Update怎么用?C# Weapon.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Weapon
的用法示例。
在下文中一共展示了Weapon.Update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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)
{
float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
input.Update(deltaTime);
if (input.Quit)
{
Exit();
return;
}
switch (input.Weapon)
{
case 1:
CurrentWeapon = new Hand(Content);
break;
case 2:
CurrentWeapon = new DoubleHand(Content);
break;
case 3:
CurrentWeapon = new GatlingHand(Content);
break;
case 4:
CurrentWeapon = new DoubleGatlingHand(Content);
break;
default:
break;
}
var newPokeballs =
(from pokeball in pokeballs
let colliders =
from pokemon in pokemons
where Vector2.Distance(pokeball.Position, pokemon.Position) < 32.0f
select pokemon
where pokeball.X > 0.0f &&
pokeball.X < 800.0f &&
pokeball.Y > -40.0f &&
pokeball.Y < 450.0f &&
colliders.Count() == 0
select pokeball.CreateMoved(-Vector2.UnitY * 200.0f * deltaTime)).ToList();
CurrentWeapon.Update(deltaTime, red.Position);
if (input.Shooting)
{
CurrentWeapon.PullTrigger();
}
newPokeballs.AddRange(CurrentWeapon.NewPokeballs);
var newPokemons =
(from pokemon in pokemons
let colliders =
from pokeball in pokeballs
where Vector2.Distance(pokeball.Position, pokemon.Position) < 32.0f
select pokeball
where pokemon.X >= 0.0f &&
pokemon.X < 800.0f &&
pokemon.Y >= -32.0f &&
pokemon.Y < 500.0f &&
colliders.Count() == 0
select pokemon.CreateMoved(Vector2.UnitY * 50.0f * deltaTime)).ToList();
Vector2 redVelocity = input.redMovement * redSpeed;
var newRed = red.CreateMoved(redVelocity * deltaTime);
if (newRed.X < 10)
{
newRed = new Entity(new Vector2(10, 400), red.Appearance);
} else if (newRed.X > 800-24)
{
newRed = new Entity(new Vector2(800-24, 400), red.Appearance);
}
switch (gameLogic.Execute(deltaTime))
{
case InstructionResult.DoneAndSpawnPokemon:
newPokemons.Add(
new Entity(new Vector2((float)(random.NextDouble() * 768.0), -32.0f),
Content.Load<Texture2D>("pokemon/" + random.Next(152) + ".png")));
break;
case InstructionResult.RunningAndSpawnPokemon:
newPokemons.Add(
new Entity(new Vector2((float)(random.NextDouble() * 768.0), -32.0f),
Content.Load<Texture2D>("pokemon/" + random.Next(152) + ".png")));
break;
}
pokemons = newPokemons;
pokeballs = newPokeballs;
red = newRed;
base.Update(gameTime);
}