Added HUD drawing logic.
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
using AlienAttack.MonoGame.Things.Weapons;
|
||||
using AlienAttack.MonoGame.Things.Bullets;
|
||||
using AlienAttack.MonoGame.Things.Enemies;
|
||||
using AlienAttack.MonoGame.Things.Items;
|
||||
using AlienAttack.MonoGame.Things.Weapons;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things;
|
||||
|
||||
@@ -35,7 +40,6 @@ internal class Player : MoveableSprite
|
||||
protected PlayerHorizontalMoveState MoveState = PlayerHorizontalMoveState.None;
|
||||
protected MoveFlag MoveFlags;
|
||||
protected ulong MoveThreshold = 0;
|
||||
//protected ulong FireThreshold = 0;
|
||||
protected ICollection<IWeapon> ActiveWeapons = [];
|
||||
|
||||
protected int CurrentExhaustFrame = 1;
|
||||
@@ -44,11 +48,16 @@ internal class Player : MoveableSprite
|
||||
protected int CurrentExhaustAnimationThreshold = 10;
|
||||
protected int CurrentExhaustDirection = 1;
|
||||
|
||||
public int Health { get; protected set; }
|
||||
public int Shield { get; protected set; }
|
||||
|
||||
public Player(int x, int y) : base(x, y)
|
||||
{
|
||||
BoundBox = new Rectangle(0, 0, 64, 64);
|
||||
ActiveWeapons.Add(new Minigun());
|
||||
ActiveWeapons.Add(new FastMinigun());
|
||||
//ActiveWeapons.Add(new FastMinigun());
|
||||
Health = 100;
|
||||
Shield = 100;
|
||||
}
|
||||
|
||||
//Texture2D texture = Game
|
||||
@@ -244,12 +253,6 @@ internal class Player : MoveableSprite
|
||||
|
||||
private void CheckFire(SpriteUpdateContext context)
|
||||
{
|
||||
//if (FireThreshold > 0)
|
||||
//{
|
||||
// FireThreshold--;
|
||||
// return;
|
||||
//}
|
||||
|
||||
foreach (IWeapon weapon in ActiveWeapons)
|
||||
{
|
||||
weapon.UpdateFireThreshold();
|
||||
@@ -262,14 +265,6 @@ internal class Player : MoveableSprite
|
||||
{
|
||||
weapon.TryFire(this, context);
|
||||
}
|
||||
|
||||
//MinigunBulletSmall bullet1 = new((int)Position.X + 12, (int)Position.Y + 6, 0, -4, this);
|
||||
//MinigunBulletSmall bullet2 = new((int)Position.X + BoundBox.Width - 20, (int)Position.Y + 6, 0, -4, this);
|
||||
|
||||
//context.SpawnSprite(bullet1);
|
||||
//context.SpawnSprite(bullet2);
|
||||
|
||||
//FireThreshold = 15;
|
||||
}
|
||||
|
||||
private static bool IsFireButtonPressed()
|
||||
@@ -280,4 +275,68 @@ internal class Player : MoveableSprite
|
||||
|
||||
return keyState.IsKeyDown(Keys.Space) || mouseState.LeftButton == ButtonState.Pressed || gamePadState.Buttons.A == ButtonState.Pressed;
|
||||
}
|
||||
|
||||
private void TakeDamage(int amount)
|
||||
{
|
||||
if (Shield >= amount)
|
||||
{
|
||||
TakeShieldDamage(amount);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Shield > 0)
|
||||
{
|
||||
int remainder = amount - Shield;
|
||||
|
||||
TakeShieldDamage(Shield);
|
||||
TakeHealthDamage(remainder);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
TakeHealthDamage(amount);
|
||||
}
|
||||
|
||||
private void GiveShield(int amount)
|
||||
{
|
||||
Shield = Math.Clamp(Shield + amount, 0, 100);
|
||||
}
|
||||
|
||||
private void TakeShieldDamage(int amount)
|
||||
{
|
||||
Shield = Math.Clamp(Shield - amount, 0, 100);
|
||||
}
|
||||
|
||||
private void GiveHealth(int amount)
|
||||
{
|
||||
Health = Math.Clamp(Health + amount, 0, 100);
|
||||
}
|
||||
|
||||
private void TakeHealthDamage(int amount)
|
||||
{
|
||||
Health = Math.Clamp(Health - amount, 0, 100);
|
||||
}
|
||||
|
||||
public override void OnCollision(SpriteCollisionContext context)
|
||||
{
|
||||
if (context.Sprite is Bullet bullet && bullet.Owner is not Player)
|
||||
{
|
||||
TakeDamage(bullet.Damage);
|
||||
}
|
||||
|
||||
if (context.Sprite is EnemyShip enemyShip)
|
||||
{
|
||||
TakeDamage(enemyShip.CrashDamage);
|
||||
}
|
||||
|
||||
if (context.Sprite is Shields)
|
||||
{
|
||||
GiveShield(20);
|
||||
}
|
||||
|
||||
if (context.Sprite is Health)
|
||||
{
|
||||
GiveHealth(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user