This commit is contained in:
SergoDobro 2023-08-18 05:15:50 +03:00
commit ea55e2b4f2
17 changed files with 240 additions and 41 deletions

View file

@ -0,0 +1 @@
{"id":"GibsMoveLeftBottom","textureName":"MonstersAnimations","startSpriteRectangle":{"X":70,"Y":724,"Width":14,"Height":11},"frameSecond":[{"Item1":0,"Item2":6}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"}

View file

@ -0,0 +1 @@
{"id":"GibsMoveLeftTop","textureName":"MonstersAnimations","startSpriteRectangle":{"X":2,"Y":721,"Width":14,"Height":12},"frameSecond":[{"Item1":0,"Item2":8}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"}

View file

@ -0,0 +1 @@
{"id":"GibsMoveRightBottom","textureName":"MonstersAnimations","startSpriteRectangle":{"X":106,"Y":722,"Width":13,"Height":12},"frameSecond":[{"Item1":0,"Item2":6}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"}

View file

@ -0,0 +1 @@
{"id":"GibsMoveRightTop","textureName":"MonstersAnimations","startSpriteRectangle":{"X":37,"Y":721,"Width":14,"Height":13},"frameSecond":[{"Item1":0,"Item2":6}],"textureFrameInterval":1,"framesCount":2,"isCycle":true,"offset":"0, 0"}

View file

@ -0,0 +1 @@
{"id":"GibsNotMove","textureName":"MonstersAnimations","startSpriteRectangle":{"X":137,"Y":731,"Width":16,"Height":5},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"}

View file

@ -752,7 +752,7 @@
</object>
</objectgroup>
<objectgroup id="10" name="Player" class="LivingEntities.Player">
<object id="47" x="-525" y="461.333">
<object id="47" x="-500" y="461.333">
<point/>
</object>
</objectgroup>

View file

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="left-up" width="200" height="200" tilewidth="16" tileheight="16" infinite="1" nextlayerid="5" nextobjectid="5">
<tileset firstgid="1" source="../Desktop/DangerousD map/map.tsx"/>
<layer id="1" name="Слой тайлов 1" class="StopTile" width="200" height="200">
<data encoding="csv">
<chunk x="-16" y="0" width="16" height="16">
294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,
294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294
</chunk>
<chunk x="0" y="0" width="16" height="16">
294,294,294,294,294,321,321,321,321,321,321,321,321,321,321,321,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321,
0,321,321,321,321,321,321,321,321,321,0,0,0,0,0,321,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321,
294,294,294,294,321,321,321,321,321,321,321,321,321,321,321,321
</chunk>
</data>
</layer>
<objectgroup id="755" name="Zombies" class="LivingEntities.Player" locked="1">
<object id="26" x="-50" y="100">
<point/>
</object>
</objectgroup>
<objectgroup id="2" name="Слой объектов 1" class="LivingEntities.Monsters.FlameSkull">
<object id="1" x="1" y="100">
<point/>
</object>
</objectgroup>
<objectgroup id="3" name="Слой объектов 2" class="LivingEntities.Monsters.FrankBalls">
<object id="2" x="1" y="100">
<point/>
</object>
</objectgroup>
<objectgroup id="4" name="Слой объектов 3" class="LivingEntities.Monsters.Frank">
<object id="3" x="-56" y="100">
<point/>
</object>
</objectgroup>
<objectgroup id="5" name="Zombies" class="LivingEntities.Monsters.Spider">
<object id="4" x="1" y="100">
<point/>
</object>
</objectgroup>
<objectgroup id="2" name="Слой объектов 1" class="LivingEntities.Monsters.Slime">
<object id="5" x="1" y="100">
<point/>
</object>
</objectgroup>
</map>

View file

@ -11,7 +11,6 @@ namespace DangerousD.GameCore.GUI
{
public class HUD : AbstractGui
{
int ammout = 0;
List<Rect> rects = new List<Rect> { };
int wigth = AppManager.Instance.inGameResolution.X;
int height = AppManager.Instance.inGameResolution.Y;
@ -27,9 +26,8 @@ namespace DangerousD.GameCore.GUI
}
public override void Update(GameTime gameTime)
{
rects.Clear();
for (int i = 0; i < ammout; i++)
for (int i = 0; i < AppManager.Instance.GameManager.GetPlayer1.Bullets; i++)
{
rects.Add(new Rect(Manager) { rectangle = new Rectangle(wigth / 29 + i * 13, height / 17, 5, 20), mainColor = Color.Yellow });
rects[i].LoadTexture(AppManager.Instance.Content);

View file

@ -15,6 +15,7 @@ namespace DangerousD.GameCore
protected Vector2 _pos;
public Vector2 Pos => _pos;
public int id;
public bool isIdFromHost = false;
public int Width { get; set; }
public int Height { get; set; }
public Rectangle Rectangle => new Rectangle((int)Pos.X, (int)Pos.Y, Width, Height);

View file

@ -78,7 +78,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public override void Death()
{
for (int i = 0; i < 3; i++)
{
Particle particle = new Particle(Pos);
}
AppManager.Instance.GameManager.Remove(this);
}
public override void Move(GameTime gameTime)
@ -160,6 +166,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{
monster_health--;
GraphicsComponent.StartAnimation("ZombieRightAttack");
Particle particle = new Particle(Pos);
if (monster_health <= 0)
{
Death();

View file

@ -0,0 +1,46 @@
using DangerousD.GameCore.Graphics;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DangerousD.GameCore.GameObjects.LivingEntities
{
public class Particle : LivingEntity
{
int delay;
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));
acceleration.Y = 10;
delay = 100;
}
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "GibsMoveLeftBottom", "GibsMoveLeftTop", "GibsMoveRightBottom", "GibsMoveRightTop" }, "GibsMoveRightTop");
public override void Update(GameTime gameTime)
{
delay--;
if (velocity.X > 0)
{
velocity.X--;
}
if(velocity.Y<=0)
{
GraphicsComponent.StartAnimation("GipsNoMove");
; }
if(delay<=0)
{
AppManager.Instance.GameManager.Remove(this);
}
base.Update(gameTime);
}
}
}

View file

@ -32,16 +32,23 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
private int bullets;
public bool FallingThroughPlatform = false;
public Player(Vector2 position) : base(position)
public int Bullets { get { return bullets; } }
public Player(Vector2 position, bool isNetworkPlayer = false) : base(position)
{
Width = 16;
Height = 32;
AppManager.Instance.InputManager.ShootEvent += Shoot;
AppManager.Instance.InputManager.MovEventJump += Jump;
AppManager.Instance.InputManager.MovEventDown += MoveDown;
AppManager.Instance.InputManager.ShootEvent += Shoot;
if (!isNetworkPlayer)
{
AppManager.Instance.InputManager.ShootEvent += Shoot;
AppManager.Instance.InputManager.MovEventJump += Jump;
AppManager.Instance.InputManager.MovEventDown += MoveDown;
}
velocity = new Vector2(0, 0);
rightBorder = (int)position.X + 100;
@ -61,11 +68,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
};
}
public Player(Vector2 position, bool isInvincible) : this(position)
{
this.isInvincible = isInvincible;
}
public bool IsAlive { get { return isAlive; } }
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "playerMoveLeft", "playerMoveRight", "DeathFromZombie", "playerRightStay", "playerStayLeft",

View file

@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using DangerousD.GameCore.Managers;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
@ -16,7 +17,7 @@ namespace DangerousD.GameCore.Graphics
private List<Texture2D> textures;
private List<string> texturesNames;
private AnimationContainer currentAnimation;
static private int scaling=3;
static private int scaling = 4;
public AnimationContainer CurrentAnimation
{
get
@ -129,10 +130,10 @@ namespace DangerousD.GameCore.Graphics
{
if (!currentAnimation.IsCycle)
{
if(actionOfAnimationEnd != null)
if (actionOfAnimationEnd != null)
{
actionOfAnimationEnd(currentAnimation.Id);
}
}
currentAnimation = neitralAnimation;
}
@ -152,10 +153,10 @@ namespace DangerousD.GameCore.Graphics
{
Texture2D texture = textures[texturesNames.FindIndex(x => x == currentAnimation.TextureName)];
float scale;
if (currentAnimation.Offset.X!=0)
if (currentAnimation.Offset.X != 0)
{
destinationRectangle.X -= (int)currentAnimation.Offset.X;
scale=destinationRectangle.Height/sourceRectangle.Height;
scale = destinationRectangle.Height / sourceRectangle.Height;
destinationRectangle.Width = (int)(sourceRectangle.Width * scale);
}
@ -235,9 +236,26 @@ namespace DangerousD.GameCore.Graphics
}
public static void SetCameraPosition(Vector2 playerPosition)
{
CameraPosition=(playerPosition).ToPoint();
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;
}
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)
{
CameraPosition.Y = (int)AppManager.Instance.GameManager.CameraBorder.W - 470;
}
AppManager.Instance.DebugHUD.Set("CameraPosition", $"{CameraPosition.X}, {CameraPosition.Y}");
}
public static Point CameraPosition = new Point(-700, 300);
}

View file

@ -12,6 +12,7 @@ using MonogameLibrary.UI.Base;
using DangerousD.GameCore.Managers;
using DangerousD.GameCore.GameObjects.LivingEntities;
using DangerousD.GameCore.GameObjects;
using System.Threading.Tasks;
namespace DangerousD.GameCore
{
@ -111,6 +112,8 @@ namespace DangerousD.GameCore
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
if (GameManager.GetPlayer1 != null)
DebugHUD.Set("Objid: ", GameManager.GetPlayer1.id.ToString());
InputManager.Update();
SoundManager.Update();
@ -203,6 +206,7 @@ namespace DangerousD.GameCore
break;
case GameState.Game:
GameManager.mapManager.LoadLevel("lvl");
GameManager.FindBorders();
break;
case GameState.Death:
break;
@ -225,24 +229,41 @@ namespace DangerousD.GameCore
case NetworkTaskOperationEnum.CreateEntity:
break;
case NetworkTaskOperationEnum.SendPosition:
LivingEntity entity = GameManager.livingEntities.Find(x => x.id == networkTask.objId);
entity.SetPosition(networkTask.position);
if (networkTask.objId != GameManager.GetPlayer1.id)
{
LivingEntity entity = GameManager.livingEntities.Find(x => x.id == networkTask.objId);
entity.SetPosition(networkTask.position);
if (multiPlayerStatus == MultiPlayerStatus.Host)
{
NetworkTasks.Add(networkTask);
}
}
break;
case NetworkTaskOperationEnum.ChangeState:
break;
case NetworkTaskOperationEnum.ConnectToHost:
Player connectedPlayer = new Player(Vector2.Zero);
Player connectedPlayer = new Player(Vector2.Zero, true);
NetworkTasks.Add(new NetworkTask(connectedPlayer.id));
NetworkTask task = new NetworkTask();
NetworkTasks.Add(task.AddConnectedPlayer(GameManager.GetPlayer1.id, GameManager.GetPlayer1.Pos));
foreach (Player player in GameManager.players)
{
if (player.id != connectedPlayer.id)
{
NetworkTasks.Add(task.AddConnectedPlayer(player.id, player.Pos));
}
}
break;
case NetworkTaskOperationEnum.GetClientPlayerId:
GameManager.GetPlayer1.id = networkTask.objId;
if (!GameManager.GetPlayer1.isIdFromHost)
{
GameManager.GetPlayer1.id = networkTask.objId;
GameManager.GetPlayer1.isIdFromHost = true;
}
break;
case NetworkTaskOperationEnum.AddConnectedPlayer:
Player remoteConnectedPlayer = new Player(networkTask.position);
Player remoteConnectedPlayer = new Player(networkTask.position, true);
remoteConnectedPlayer.id = networkTask.objId;
GameManager.players.Add(remoteConnectedPlayer);
break;
default:
break;

View file

@ -28,7 +28,7 @@ namespace DangerousD.GameCore
public PhysicsManager physicsManager;
public List<Player> players;
public List<GameObject> otherObjects = new();
public Vector4 CameraBorder;
public Player GetPlayer1 { get; private set; }
public GameManager()
{
@ -42,6 +42,7 @@ namespace DangerousD.GameCore
players = new List<Player>();
mapManager = new MapManager(1);
physicsManager = new PhysicsManager();
CameraBorder = Vector4.Zero;
}
@ -129,7 +130,6 @@ namespace DangerousD.GameCore
public void Update(GameTime gameTime)
{
AppManager.Instance.DebugHUD.Set("playerId: ", GetPlayer1.id.ToString());
if (AppManager.Instance.NetworkTasks.Count > 0)
{
AppManager.Instance.NetworkManager.SendMsg(AppManager.Instance.NetworkTasks.ToList());
@ -147,15 +147,15 @@ namespace DangerousD.GameCore
{
livingEntitiesWithoutPlayers[i].Update(gameTime);
}
GetPlayer1.Update(gameTime);
}
else
{
for (int i = 0; i < livingEntitiesWithoutPlayers.Count; i++)
{
livingEntitiesWithoutPlayers[i].PlayAnimation();
}
GetPlayer1.Update(gameTime);
}
GetPlayer1.Update(gameTime);
foreach (var item in otherObjects)
@ -163,5 +163,27 @@ namespace DangerousD.GameCore
physicsManager.UpdateCollisions(entities, livingEntities, mapObjects, players, gameTime);
}
public void FindBorders()
{
foreach (var item in GetAllGameObjects)
{
if (item.Pos.X<CameraBorder.X)
{
CameraBorder.X = item.Pos.X;
}
if (item.Pos.X > CameraBorder.Y)
{
CameraBorder.Y = item.Pos.X;
}
if (item.Pos.Y < CameraBorder.Z)
{
CameraBorder.Z = item.Pos.X;
}
if (item.Pos.Y > CameraBorder.W)
{
CameraBorder.W = item.Pos.X;
}
}
}
}
}

View file

@ -98,9 +98,9 @@ namespace DangerousD.GameCore.Managers
new Vector2(float.Parse(entity.Attributes["x"].Value, CultureInfo.InvariantCulture) + offsetX,
float.Parse(entity.Attributes["y"].Value, CultureInfo.InvariantCulture) + offsetY) * _scale;
Entity inst;
if (type.Equals(typeof(Player)) && entity.Attributes["name"] is not null && entity.Attributes["name"].Value == "DEBUGUS")
if (type.Equals(typeof(Player)))
{
inst = (Entity)Activator.CreateInstance(type, pos, true);
inst = (Entity)Activator.CreateInstance(type, pos, false);
}
else
{

View file

@ -91,7 +91,7 @@ namespace DangerousD.GameCore.Network
}
catch { }
}
public void SendMsg(List<NetworkTask> networkTask)
public void SendMsg(List<NetworkTask> networkTask, Socket ignoreSocket = null)
{
byte[] Data = Encoding.Unicode.GetBytes(JsonConvert.SerializeObject(networkTask));
int count = Data.Length;
@ -101,8 +101,11 @@ namespace DangerousD.GameCore.Network
{
foreach (Socket socket in clientSockets)
{
socket.Send(BitConverter.GetBytes(count));
socket.Send(Data);
if (!(socket == ignoreSocket))
{
socket.Send(BitConverter.GetBytes(count));
socket.Send(Data);
}
}
}
catch { }
@ -148,7 +151,8 @@ namespace DangerousD.GameCore.Network
}
else
{
GetReceivingMessages(JsonConvert.DeserializeObject<List<NetworkTask>>(so.sb.ToString()));
List<NetworkTask> tasks = JsonConvert.DeserializeObject<List<NetworkTask>>(so.sb.ToString());
GetReceivingMessages(tasks);
}
}
catch { }