Merge branch 'main' into particlesBranch

This commit is contained in:
bmvolf 2023-08-18 10:39:47 +03:00
commit b30a8515d2
8 changed files with 120 additions and 33 deletions

View file

@ -29,7 +29,8 @@ namespace DangerousD.GameCore.GameObjects.Entities
Player player = (Player)gameObject;
if (player.isUping)
{
AppManager.Instance.GameManager.Remove(this);
//тут спавн лута
}
}
}

View file

@ -59,7 +59,13 @@ namespace DangerousD.GameCore
{
GraphicsComponent.DrawAnimation(Rectangle, spriteBatch);
//debug
//wdaspriteBatch.Draw(debugTexture,new Rectangle(Rectangle.X-GraphicsComponent.CameraPosition.X,Rectangle.Y-GraphicsComponent.CameraPosition.Y,Rectangle.Width,Rectangle.Height), Color.White);
if (AppManager.Instance.InputManager.CollisionsCheat)
{
spriteBatch.Draw(debugTexture,
new Rectangle(Rectangle.X - GraphicsComponent.CameraPosition.X,
Rectangle.Y - GraphicsComponent.CameraPosition.Y, Rectangle.Width, Rectangle.Height),
Color.White);
}
}
}

View file

@ -131,6 +131,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
if (AppManager.Instance.GameManager.players[0].IsAlive)
{
Attack();
}
}
base.OnCollision(gameObject);

View file

@ -12,29 +12,58 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
public class Particle : LivingEntity
{
int delay;
bool isFall;
public Particle(Vector2 position) : base(position)
{
Width = 14;
Height = 14;
Random random = new Random();
velocity = new Vector2(random.Next(3, 15), random.Next(3,30));
velocity = new Vector2(random.Next(-6, 6), random.Next(-8,4));
acceleration.Y = 10;
delay = 100;
isFall = false;
isOnGround = false;
}
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "GibsMoveLeftBottom", "GibsMoveLeftTop", "GibsMoveRightBottom", "GibsMoveRightTop" }, "GibsMoveRightTop");
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "GibsMoveLeftBottom", "GibsMoveLeftTop", "GibsMoveRightBottom", "GibsMoveRightTop", "GibsNotMove" }, "GibsMoveRightTop");
public override void Update(GameTime gameTime)
{
delay--;
if (velocity.X > 0)
if (delay<=80)
{
velocity.X--;
velocity.X=0;
}
if(velocity.Y<=0)
if(isOnGround)
{
GraphicsComponent.StartAnimation("GipsNoMove");
GraphicsComponent.StartAnimation("GibsNotMove");
Width = 16;
Height = 5;
isFall=true;
; }
else if(!isFall)
{
Width = 14;
Height= 14;
if (velocity.Y<0 && velocity.X>0)
{
GraphicsComponent.StartAnimation("GibsMoveRightTop");
}
else if (velocity.Y < 0 && velocity.X < 0)
{
GraphicsComponent.StartAnimation("GibsMoveLeftTop");
}
else if (velocity.Y > 0 && velocity.X > 0)
{
GraphicsComponent.StartAnimation("GibsMoveRightBottom");
}
else if (velocity.Y > 0 && velocity.X < 0)
{
GraphicsComponent.StartAnimation("GibsMoveLeftBottom");
}
}
if(delay<=0)
{
AppManager.Instance.GameManager.Remove(this);

View file

@ -27,7 +27,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
private bool isAttacked = false;
private bool isShooting = false;
public GameObject objectAttack;
public bool isInvincible;
private int bullets;
public bool FallingThroughPlatform = false;
public bool isUping = false;
@ -94,6 +93,10 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
}
public void Death(string monsterName)
{
if (AppManager.Instance.InputManager.InvincibilityCheat)
{
return;
}
isAttacked = true;
if(monsterName == "Zombie")
{
@ -185,10 +188,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
if (isOnGround && FallingThroughPlatform)
{
FallingThroughPlatform = false;
AppManager.Instance.DebugHUD.Log("not falling");
}
GraphicsComponent.SetCameraPosition(Pos);
if (!isAttacked || isInvincible)
if (!isAttacked || AppManager.Instance.InputManager.InvincibilityCheat)
{
if (!isShooting)
{
@ -254,7 +256,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
{
FallingThroughPlatform = true;
isOnGround = false;
AppManager.Instance.DebugHUD.Log("FallingThroughPlatform");
}
}

View file

@ -237,23 +237,25 @@ namespace DangerousD.GameCore.Graphics
public static void SetCameraPosition(Vector2 playerPosition)
{
CameraPosition = (playerPosition).ToPoint();
CameraPosition.X -= 300;
CameraPosition.Y -= 200;
if (CameraPosition.X < AppManager.Instance.GameManager.CameraBorder.X)
{
CameraPosition.X = (int)AppManager.Instance.GameManager.CameraBorder.X;
}
CameraPosition.X -= 200;
CameraPosition.Y -= 120;
if (CameraPosition.X > AppManager.Instance.GameManager.CameraBorder.Y - 460)
{
CameraPosition.X = (int)AppManager.Instance.GameManager.CameraBorder.Y - 460;
}
if (CameraPosition.Y < AppManager.Instance.GameManager.CameraBorder.Z)
{
CameraPosition.Y = (int)AppManager.Instance.GameManager.CameraBorder.Z;
}
if (CameraPosition.Y > AppManager.Instance.GameManager.CameraBorder.W - 470)
if (CameraPosition.X < AppManager.Instance.GameManager.CameraBorder.X)
{
CameraPosition.Y = (int)AppManager.Instance.GameManager.CameraBorder.W - 470;
CameraPosition.X = (int)AppManager.Instance.GameManager.CameraBorder.X;
}
if (CameraPosition.Y > AppManager.Instance.GameManager.CameraBorder.W - 240)
{
CameraPosition.Y = (int)AppManager.Instance.GameManager.CameraBorder.W - 240;
}
AppManager.Instance.DebugHUD.Set("CameraPosition", $"{CameraPosition.X}, {CameraPosition.Y}");
}

View file

@ -6,11 +6,12 @@ using System.Diagnostics;
using System.Text;
using System.Xml.Serialization;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
namespace DangerousD.GameCore
{
public enum ScopeState { Up, Middle, Down }
public enum ControlsState { Gamepad, Keyboard, Mouse }
public enum ControlsState { Gamepad, Keyboard }
public class InputManager
{
public delegate void Delegat();
@ -21,31 +22,77 @@ namespace DangerousD.GameCore
Vector2 vectorMovementDirection;
ScopeState scopeState; // Положение оружия. Up, Middle, Down.
ControlsState controlsState;
private bool _overrideControls = false;
private bool _cheatsEnabled = false;
public bool InvincibilityCheat { get; private set; } = false;
public bool CollisionsCheat { get; private set; } = false;
private bool isJumpDown; // Блокирует физическое нажатие прыжка и спуска
private bool isShoot;
public Vector2 VectorMovementDirection { get => vectorMovementDirection; }
public ScopeState ScopeState { get => scopeState; }
public string currentControlsState = "";
public InputManager()
{
this.isJumpDown = false;
this.isShoot = false;
scopeState = ScopeState.Middle;
controlsState= ControlsState.Mouse;
controlsState= ControlsState.Keyboard;
vectorMovementDirection = new Vector2(0, 0);
}
public void SetState(ControlsState controlsStates)
{
currentControlsState = controlsStates.ToString();
}
public void Update()
{
// Работа с GamePad
if (GamePad.GetState(0).IsConnected)
{
{
GamePadState gamepadState = GamePad.GetState(0);
if (gamepadState.Triggers.Left >= 0.9 && gamepadState.Triggers.Right >= 0.9)
{
_cheatsEnabled = true;
}
if (_cheatsEnabled)
{
if (gamepadState.Buttons.Y == ButtonState.Pressed)
{
InvincibilityCheat = true;
}
if (gamepadState.Buttons.B == ButtonState.Pressed)
{
CollisionsCheat = true;
}
}
}
{
var keyboardState = Keyboard.GetState();
if (keyboardState.IsKeyDown(Keys.LeftShift) && keyboardState.IsKeyDown(Keys.RightShift))
{
_cheatsEnabled = true;
}
if (_cheatsEnabled)
{
if (keyboardState.IsKeyDown(Keys.I))
{
InvincibilityCheat = true;
}
if (keyboardState.IsKeyDown(Keys.C))
{
CollisionsCheat = true;
}
}
}
if (_cheatsEnabled)
{
AppManager.Instance.DebugHUD.Set("cheats", _cheatsEnabled.ToString());
AppManager.Instance.DebugHUD.Set("invincible", InvincibilityCheat.ToString());
}
// Работа с GamePad
if (_overrideControls ? controlsState == ControlsState.Gamepad : GamePad.GetState(0).IsConnected)
{
controlsState = ControlsState.Gamepad;
// Обработка гейм-пада. Задает Vector2 vectorMovementDirection являющийся вектором отклонения левого стика.
GamePadState gamePadState = GamePad.GetState(0);
vectorMovementDirection = gamePadState.ThumbSticks.Left;
@ -93,12 +140,12 @@ namespace DangerousD.GameCore
{
isShoot = false;
}
SetState(ControlsState.Gamepad);
}
// Работа с KeyBoard
else
{
controlsState = ControlsState.Keyboard;
KeyboardState keyBoardState = Keyboard.GetState(); // Состояние клавиатуры
// Обработка движения вправо-влево. Меняет у вектора vectorMovementDirection значение X на -1/0/1.

View file

@ -179,11 +179,11 @@ namespace DangerousD.GameCore
}
if (item.Pos.Y < CameraBorder.Z)
{
CameraBorder.Z = item.Pos.X;
CameraBorder.Z = item.Pos.Y;
}
if (item.Pos.Y > CameraBorder.W)
{
CameraBorder.W = item.Pos.X;
CameraBorder.W = item.Pos.Y;
}
}
}