public bool pickUp(Item item) { //Send Item to appropriate class if (item.GetType() == typeof(Salvage)) { invent.add(item); } else if (item.GetType() == typeof(HealthPack)) { int oldhealth = Health; Health += (int)(MaxHealth * 0.05f + 0.5f); return(oldhealth < MaxHealth); } else if (item.GetType() == typeof(Ammo)) { if (CurGun == null) { return(false); } return(CurGun.addAmmo((Ammo)item)); } else if (item.GetType() == typeof(GunItem)) { GunItem gun = (GunItem)item; switch (gun.TechType) { case TechType.HUMAN: guns.Add(new PhysicalGun(this, gun.GunShell)); break; case TechType.ALIEN: guns.Add(new PlasmaGun(this, gun.GunShell)); break; case TechType.ROBOT: guns.Add(new LaserGun(this, gun.GunShell)); break; } } return(true); }
public override void update(GameTime gameTime, IStage stage) { input.start(); base.update(gameTime, stage); //Calc Rotation mousePos.X = input.MousePos.X + Position.X - Game1.View.Width / 2; mousePos.Y = input.MousePos.Y + Position.Y - Game1.View.Height / 2; Vector2 lookVek = mousePos - this.Position; Rotation = (float)Math.Atan2(lookVek.X, -lookVek.Y); //Wep Swap if (input.SwapActDown || input.DeltaWheelValue < 0) { gunIndex = (gunIndex - 1 < 0) ? guns.Count - 1 : gunIndex - 1; } else if (input.SwapActUp || input.DeltaWheelValue > 0) { gunIndex = (gunIndex + 1) % guns.Count; } //Small Delay between switching weapons if (CurGun != guns[gunIndex]) { isSwaping = true; CurGun = null; swapTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (swapTimer >= 0.3f) { CurGun = guns[gunIndex]; CurGun.Clear(); swapTimer = 0; isSwaping = false; } } else { isSwaping = false; } //Check for Movment if (input.Right && this.Position.X < stage.Rec.Width) { velocity.X = this.Speed; } if (input.Left && this.Position.X > stage.Rec.X) { velocity.X = -this.Speed; } if (input.Up && this.Position.Y > stage.Rec.Y) { velocity.Y = -this.Speed; } if (input.Down && this.Position.Y < stage.Rec.Height) { velocity.Y = this.Speed; } //Movement this.Position += this.velocity; velocity = velocity * 0.90f; //Check Collision FutureRec = new Rectangle((int)(Position.X + velocity.X), (int)(Position.Y + velocity.Y), Rec.Width, Rec.Height); foreach (RotatingSprite sprite in stage.Everything) { if (isColliding(FutureRec, Rotation, sprite)) { Velocity = Vector2.Zero; } } //update aggregate classes hud.update(gameTime, stage); foreach (Gun gun in guns) { gun.update(gameTime, stage); } input.end(); }