granade animation + arrow conttrols + started loading screen

This commit is contained in:
SergoDobro 2024-09-11 23:04:03 +03:00
parent 6d47993988
commit 0cc6b1250a
17 changed files with 316 additions and 199 deletions

View file

@ -459,7 +459,7 @@ namespace AnimatorFileCreatorAdvanced.Core.GUI
{ {
if (!buildDone) return; if (!buildDone) return;
ticksPassed++; ticksPassed++;
if (ticksPassed > 3) if (ticksPassed > 1)
{ {
ticksPassed = 0; ticksPassed = 0;
SetNextFrame(); SetNextFrame();

View file

@ -146,6 +146,9 @@
#begin Textures/Animations/explosion_1.animation #begin Textures/Animations/explosion_1.animation
/copy:Textures/Animations/explosion_1.animation /copy:Textures/Animations/explosion_1.animation
#begin Textures/Animations/OneAnimationPerItem/granade_spinning.animation
/copy:Textures/Animations/OneAnimationPerItem/granade_spinning.animation
#begin Textures/Animations/player_idle_down_mining.animation #begin Textures/Animations/player_idle_down_mining.animation
/copy:Textures/Animations/player_idle_down_mining.animation /copy:Textures/Animations/player_idle_down_mining.animation
@ -383,6 +386,18 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/AnimationTextures/Character/hr-level1_running.png /build:Textures/AnimationTextures/Character/hr-level1_running.png
#begin Textures/AnimationTextures/OneAnimationPerItem/granade.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/AnimationTextures/OneAnimationPerItem/granade.png
#begin Textures/AnimationTextures/Player/Grenade.png #begin Textures/AnimationTextures/Player/Grenade.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
@ -683,6 +698,18 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/GUI/MenuBackground.jpg /build:Textures/GUI/MenuBackground.jpg
#begin Textures/GUI/mouse_pressed.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/GUI/mouse_pressed.png
#begin Textures/GUI/mouse.png #begin Textures/GUI/mouse.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

View file

@ -0,0 +1 @@
{"id":"granade_spinning","textureName":"Textures/AnimationTextures/OneAnimationPerItem/granade","startSpriteRectangle":{"X":0,"Y":0,"Width":256,"Height":256},"frameSecond":[{"Item1":0,"Item2":2}],"textureFrameInterval":0,"framesCount":6,"isCycle":true,"offset":"0, 0"}

View file

@ -1 +1 @@
{"id":"player_running","textureName":"Textures/AnimationTextures/Player/Run","startSpriteRectangle":{"X":0,"Y":0,"Width":128,"Height":128},"frameSecond":[{"Item1":0,"Item2":1}],"textureFrameInterval":0,"framesCount":8,"isCycle":true,"offset":"0, 0"} {"id":"player_running","textureName":"Textures/AnimationTextures/Player/Run","startSpriteRectangle":{"X":0,"Y":0,"Width":128,"Height":128},"frameSecond":[{"Item1":0,"Item2":5}],"textureFrameInterval":0,"framesCount":8,"isCycle":true,"offset":"0, 0"}

View file

@ -1 +1 @@
{"id":"zombie_walk","textureName":"Textures/AnimationTextures/Zombie/zombie_spritesheet_v1","startSpriteRectangle":{"X":0,"Y":32,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":30}],"textureFrameInterval":0,"framesCount":8,"isCycle":true,"offset":"0, 0"} {"id":"zombie_walk","textureName":"Textures/AnimationTextures/Zombie/zombie_spritesheet_v1","startSpriteRectangle":{"X":0,"Y":32,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":0,"framesCount":8,"isCycle":true,"offset":"0, 0"}

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

View file

@ -74,7 +74,7 @@ namespace ZoFo.GameCore
}; };
} }
public void OnDataSend(string data) public void OnDataSend(string data)//А это нужно? 0 использований метода :/
{ {
//List<UpdateTileCreated> updateDatas = JsonSerializer.Deserialize<List<UpdateTileCreated>>(data); //List<UpdateTileCreated> updateDatas = JsonSerializer.Deserialize<List<UpdateTileCreated>>(data);
JArray jToken = JsonConvert.DeserializeObject(data) as JArray; JArray jToken = JsonConvert.DeserializeObject(data) as JArray;
@ -94,7 +94,11 @@ namespace ZoFo.GameCore
} }
public void GameEndedUnexpectedly() { } public void GameEndedUnexpectedly() { }
/// <summary>
/// Подключиться к комнате
/// </summary>
/// <param name="ip"></param>
/// <param name="port"></param>
public void JoinRoom(string ip, int port) public void JoinRoom(string ip, int port)
{ {
networkManager.JoinRoom(ip, port); networkManager.JoinRoom(ip, port);
@ -113,7 +117,11 @@ namespace ZoFo.GameCore
float shakeEffect = 0; float shakeEffect = 0;
public void AddShaking(float power) public void AddShaking(float power)
{ {
shakeEffect += power*3; shakeEffect += power;
if (shakeEffect>10)
{
shakeEffect = 10;
}
} }
public void UpdateShaking() public void UpdateShaking()
{ {

View file

@ -22,6 +22,7 @@ public abstract class AbstractGUI
private bool isStartedPrint = false; private bool isStartedPrint = false;
private bool isPressed = false; private bool isPressed = false;
private Texture2D mouse; private Texture2D mouse;
private Texture2D mouse_pressed;
private MouseState mouseState; private MouseState mouseState;
public AbstractGUI() public AbstractGUI()
@ -40,6 +41,7 @@ public abstract class AbstractGUI
{ {
Manager.LoadContent(AppManager.Instance.Content, "Fonts/Font"); Manager.LoadContent(AppManager.Instance.Content, "Fonts/Font");
mouse = AppManager.Instance.Content.Load<Texture2D>("Textures/GUI/mouse"); mouse = AppManager.Instance.Content.Load<Texture2D>("Textures/GUI/mouse");
mouse_pressed = AppManager.Instance.Content.Load<Texture2D>("Textures/GUI/mouse_pressed");
} }
public virtual void Update(GameTime gameTime) public virtual void Update(GameTime gameTime)
@ -52,7 +54,11 @@ public abstract class AbstractGUI
{ {
Manager.Draw(spriteBatch); Manager.Draw(spriteBatch);
spriteBatch.Begin(); spriteBatch.Begin();
if (Mouse.GetState().LeftButton == ButtonState.Pressed)
spriteBatch.Draw(mouse_pressed, new Rectangle(mouseState.Position.X, mouseState.Position.Y, 20, 40), Color.White);
else
spriteBatch.Draw(mouse, new Rectangle(mouseState.Position.X, mouseState.Position.Y, 20, 40), Color.White); spriteBatch.Draw(mouse, new Rectangle(mouseState.Position.X, mouseState.Position.Y, 20, 40), Color.White);
spriteBatch.End(); spriteBatch.End();
} }
} }

View file

@ -20,6 +20,7 @@ public class HUD : AbstractGUI
public AbstractGUI overlayGUI; public AbstractGUI overlayGUI;
protected override void CreateUI() protected override void CreateUI()
{ {
int width = AppManager.Instance.CurentScreenResolution.X; int width = AppManager.Instance.CurentScreenResolution.X;
int height = AppManager.Instance.CurentScreenResolution.Y; int height = AppManager.Instance.CurentScreenResolution.Y;

View file

@ -0,0 +1,39 @@
using Microsoft.Xna.Framework;
using MonogameLibrary.UI.Base;
using MonogameLibrary.UI.Elements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using ZoFo.GameCore.GameManagers;
namespace ZoFo.GameCore.GUI
{
internal class LoadingGameScreenGUI : AbstractGUI
{
private DrawableUIElement menuBackground;
protected override void CreateUI()
{
int width = AppManager.Instance.CurentScreenResolution.X;
int height = AppManager.Instance.CurentScreenResolution.Y;
menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures/GUI/background/waiting" };
Elements.Add(menuBackground);
menuBackground.LoadTexture(AppManager.Instance.Content);
var loading = new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 7, (int)(width / 4), (int)(height / 20)),
text = "Loading...", fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font3" };
Elements.Add(loading);
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
}
}

View file

@ -50,7 +50,8 @@ public class SelectModeMenu : AbstractGUI
server.CreateRoom(false); server.CreateRoom(false);
client.JoinYourself(server.MyIp.Port); client.JoinYourself(server.MyIp.Port);
//AppManager.Instance.ChangeState(GameState.HostPlaying); //AppManager.Instance.ChangeState(GameState.HostPlaying);
AppManager.Instance.SetGUI(new HUD()); AppManager.Instance.SetGUI(new HUD() { });
//server.CreateRoom(1); //server.CreateRoom(1);
//client.JoinYourself(); //client.JoinYourself();

View file

@ -97,20 +97,43 @@ namespace ZoFo.GameCore.GameManagers
#endregion #endregion
#region Работа с KeyBoard #region Работа с KeyBoard
#region InputAttack with mouse
MouseState mouseState = Mouse.GetState();
AppManager.Instance.debugHud.Set("mouse position", $"({mouseState.X}, {mouseState.Y}");
// TODO: CurentScreenResolution
Vector2 a = (AppManager.Instance.CurentScreenResolution / new Point(2, 2)).ToVector2();
InputAttackDirection = Vector2.Normalize(new Vector2(mouseState.X - a.X, mouseState.Y - a.Y));
AppManager.Instance.debugHud.Set("AttackDir(normalize)", $"({a.X}, {a.Y})");
#endregion
#region Состояние клавиатуры #region Состояние клавиатуры
KeyboardState keyBoardState = Keyboard.GetState(); // Состояние клавиатуры KeyboardState keyBoardState = Keyboard.GetState(); // Состояние клавиатуры
#endregion #endregion
#region InputAttack with mouse
MouseState mouseState = Mouse.GetState();
AppManager.Instance.debugHud.Set("mouse position", $"({mouseState.X}, {mouseState.Y}");
Vector2 a = (AppManager.Instance.CurentScreenResolution / new Point(2, 2)).ToVector2(); //player is always in the centre
InputAttackDirection = Vector2.Normalize(new Vector2(mouseState.X - a.X, mouseState.Y - a.Y));
AppManager.Instance.debugHud.Set("AttackDir(normalize)", $"({a.X}, {a.Y})");
if (keyBoardState.IsKeyDown(Keys.Down))
{
InputAttackDirection.Y = 1;
}
else if (keyBoardState.IsKeyDown(Keys.Up))
InputAttackDirection.Y = -1;
else
InputAttackDirection.Y = 0;
if (keyBoardState.IsKeyDown(Keys.Right))
{
InputAttackDirection.X = 1;
}
else if (keyBoardState.IsKeyDown(Keys.Left))
InputAttackDirection.X = -1;
else
InputAttackDirection.X = 0;
#endregion
#region читы #region читы
if (keyBoardState.IsKeyDown(Keys.LeftShift) && keyBoardState.IsKeyDown(Keys.RightShift)) if (keyBoardState.IsKeyDown(Keys.LeftShift) && keyBoardState.IsKeyDown(Keys.RightShift))
_cheatsEnabled = true; _cheatsEnabled = true;
@ -134,19 +157,24 @@ namespace ZoFo.GameCore.GameManagers
#endregion // Cheats #endregion // Cheats
#region Обработка состояния объекта. Задает значение полю scopeState. #region Обработка состояния объекта. Задает значение полю scopeState.
if (keyBoardState.IsKeyDown(Keys.Up) || keyBoardState.IsKeyDown(Keys.W)) bool useReverseControls = false;
if ((keyBoardState.IsKeyDown(Keys.Up) && useReverseControls)
|| (keyBoardState.IsKeyDown(Keys.W) && !useReverseControls))
{ {
InputMovementDirection += new Vector2(0, -1); InputMovementDirection += new Vector2(0, -1);
} }
if (keyBoardState.IsKeyDown(Keys.Down) || keyBoardState.IsKeyDown(Keys.S)) if ((keyBoardState.IsKeyDown(Keys.Down) && useReverseControls)
|| (keyBoardState.IsKeyDown(Keys.S) && !useReverseControls))
{ {
InputMovementDirection += new Vector2(0, 1); InputMovementDirection += new Vector2(0, 1);
} }
if (keyBoardState.IsKeyDown(Keys.Right) || keyBoardState.IsKeyDown(Keys.D)) if ((keyBoardState.IsKeyDown(Keys.Right) && useReverseControls)
|| (keyBoardState.IsKeyDown(Keys.D) && !useReverseControls))
{ {
InputMovementDirection += new Vector2(1, 0); InputMovementDirection += new Vector2(1, 0);
} }
if (keyBoardState.IsKeyDown(Keys.Left) || keyBoardState.IsKeyDown(Keys.A)) if ((keyBoardState.IsKeyDown(Keys.Left) && useReverseControls)
|| (keyBoardState.IsKeyDown(Keys.A) && !useReverseControls))
{ {
InputMovementDirection += new Vector2(-1, 0); InputMovementDirection += new Vector2(-1, 0);
@ -201,7 +229,8 @@ namespace ZoFo.GameCore.GameManagers
/// </summary> /// </summary>
/// <param name="vector"></param> /// <param name="vector"></param>
/// <returns></returns> /// <returns></returns>
public int ConvertAttackVector2ToState(Vector2 vector){ public int ConvertAttackVector2ToState(Vector2 vector)
{
int currentSection = (int)Math.Ceiling(Math.Atan2(vector.Y, int currentSection = (int)Math.Ceiling(Math.Atan2(vector.Y,
vector.X) * (180 / Math.PI) / 360 * 32); vector.X) * (180 / Math.PI) / 360 * 32);
return currentSection; return currentSection;
@ -209,7 +238,8 @@ namespace ZoFo.GameCore.GameManagers
public ScopeState ConvertVector2ToState(Vector2 vector) public ScopeState ConvertVector2ToState(Vector2 vector)
{ {
int currentSection = 0; int currentSection = 0;
if(vector.X == 0f && vector.Y == 0f){ if (vector.X == 0f && vector.Y == 0f)
{
currentScopeState = ScopeState.Idle; currentScopeState = ScopeState.Idle;
} }
else else

View file

@ -205,7 +205,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
} }
currentDatagrammId++; currentDatagrammId++;
AppManager.Instance.ChangeState(GameState.HostPlaying); AppManager.Instance.ChangeState(GameState.HostPlaying);
AppManager.Instance.SetGUI(new HUD());//// AppManager.Instance.SetGUI(new HUD());//// КАКОЙ В СЕРВЕРЕ ЭТО ПИСАТЬ???
} }
public void CloseConnection() public void CloseConnection()
{ {

View file

@ -22,7 +22,7 @@ namespace ZoFo.GameCore.GameObjects
public Zombie(Vector2 position) : base(position) public Zombie(Vector2 position) : base(position)
{ {
health = 5; health = 5;
speed = 7.5f; speed = 6.5f;
graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 30, 30); graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 30, 30);
collisionComponent.stopRectangle = new Rectangle(10, 20, 10, 10); collisionComponent.stopRectangle = new Rectangle(10, 20, 10, 10);
isAttacking = false; isAttacking = false;

View file

@ -290,12 +290,12 @@ public class Player : LivingEntity
{ {
direction.Normalize(); direction.Normalize();
var rect = collisionComponent.stopRectangle.SetOrigin(position); var rect = collisionComponent.stopRectangle.SetOrigin(position);
int size = 10; int size = 30;
rect.X -= size; rect.X -= size;
rect.Y -= size; rect.Y -= size;
rect.Width += 2 * size; rect.Width += 2 * size;
rect.Height += 2 * size; rect.Height += 2 * size;
rect = rect.SetOrigin(direction * 40 * mult); rect = rect.SetOrigin(direction * 60 * mult);
return rect; return rect;
} }
} }

View file

@ -14,7 +14,7 @@ namespace ZoFo.GameCore.GameObjects
/// </summary> /// </summary>
public class Granade : GameObject public class Granade : GameObject
{ {
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "explosion_1" }, "explosion_1"); public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "granade_spinning" }, "granade_spinning");
/// <summary> /// <summary>
/// TODO updates with directed effect /// TODO updates with directed effect
@ -26,7 +26,7 @@ namespace ZoFo.GameCore.GameObjects
if (AppManager.Instance.client.myPlayer != null) if (AppManager.Instance.client.myPlayer != null)
this.positionFrom = AppManager.Instance.client.myPlayer.position; this.positionFrom = AppManager.Instance.client.myPlayer.position;
this.positionTo = positionTo; this.positionTo = positionTo;
graphicsComponent.ObjectDrawRectangle = new Rectangle(-30, -30, 60, 60).SetOrigin(position); graphicsComponent.ObjectDrawRectangle = new Rectangle(-15, -15, 30, 30).SetOrigin(position);
AppManager.Instance.SoundManager.StartSound("gun-gunshot-01", Vector2.Zero, Vector2.Zero, 0.5f, (float)(Random.Shared.NextDouble() * 2 - 1)); AppManager.Instance.SoundManager.StartSound("gun-gunshot-01", Vector2.Zero, Vector2.Zero, 0.5f, (float)(Random.Shared.NextDouble() * 2 - 1));
(graphicsComponent as AnimatedGraphicsComponent).actionOfAnimationEnd += _ => (graphicsComponent as AnimatedGraphicsComponent).actionOfAnimationEnd += _ =>
{ {
@ -34,6 +34,8 @@ namespace ZoFo.GameCore.GameObjects
//Delete_OnClient(this); //Delete_OnClient(this);
}; };
graphicsComponent.ObjectDrawRectangle.X = (int)position.X;
graphicsComponent.ObjectDrawRectangle.Y = (int)position.Y;
} }
Vector2 positionFrom; Vector2 positionFrom;
Vector2 positionTo; Vector2 positionTo;
@ -46,7 +48,7 @@ namespace ZoFo.GameCore.GameObjects
position.Y = (2 * positionTo.Y + 2 * positionFrom.Y - 4 * m) * dt * dt + position.Y = (2 * positionTo.Y + 2 * positionFrom.Y - 4 * m) * dt * dt +
(4 * m - positionTo.Y - 3 * positionFrom.Y) * dt + positionFrom.Y; (4 * m - positionTo.Y - 3 * positionFrom.Y) * dt + positionFrom.Y;
if (dt >= 0.9) if (dt >= 1)
{ {
FlightEndedOnServer(); FlightEndedOnServer();
return; return;
@ -72,12 +74,19 @@ namespace ZoFo.GameCore.GameObjects
} }
public override void Update_OnClient() public override void Update_OnClient()
{ {
float m = Math.Min(positionFrom.Y, positionTo.Y)-40;
position.X = (1 - dt) * positionFrom.X + dt * positionTo.X;
position.Y = (2 * positionTo.Y + 2 * positionFrom.Y - 4 * m) * dt * dt +
(4 * m - positionTo.Y - 3 * positionFrom.Y) * dt + positionFrom.Y;
dt += 0.05f;
if (dt >= 1) if (dt >= 1)
{ {
//Granade Finished the flight //Granade Finished the flight
Instantiate_OnClient(new Explosion(position + ExtentionClass.RandomVector() * 10)); Instantiate_OnClient(new Explosion(position + ExtentionClass.RandomVector() * 10));
Delete_OnClient(this); Delete_OnClient(this);
base.Update_OnClient();
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
@ -94,12 +103,7 @@ namespace ZoFo.GameCore.GameObjects
return; return;
} }
float m = Math.Min(positionFrom.Y, positionTo.Y)-40;
position.X = (1 - dt) * positionFrom.X + dt * positionTo.X;
position.Y = (2 * positionTo.Y + 2 * positionFrom.Y - 4 * m) * dt * dt +
(4 * m - positionTo.Y - 3 * positionFrom.Y) * dt + positionFrom.Y;
dt += 0.05f;
//position = //position =
//base.Update_OnClient(); //base.Update_OnClient();
@ -121,7 +125,7 @@ namespace ZoFo.GameCore.GameObjects
var rect = graphicsComponent.ObjectDrawRectangle; var rect = graphicsComponent.ObjectDrawRectangle;
rect.X = (int)position.X; rect.X = (int)position.X;
rect.Y = (int)position.Y; rect.Y = (int)position.Y;
int size = 10; int size = 20;
rect.X -= size; rect.X -= size;
rect.Y -= size; rect.Y -= size;
rect.Width += 2 * size; rect.Width += 2 * size;