Maiu Merge Hunchman

This commit is contained in:
MARKPRO44 2023-08-18 18:20:45 +03:00
commit 38f1064ec4
16 changed files with 212 additions and 91 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View file

@ -2,8 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View file

@ -2,7 +2,6 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Windows.Forms;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection.Metadata; using System.Reflection.Metadata;
@ -17,13 +16,6 @@ namespace AnimationsFileCreator
Console.WriteLine("Добро пожаловать в костыльную программу по созданию файлов анимации для игры DungerousD"); Console.WriteLine("Добро пожаловать в костыльную программу по созданию файлов анимации для игры DungerousD");
Console.Write("Введите название текстуры (нажмите enter, чтобы выбрать файл во всплывающем окошке): "); Console.Write("Введите название текстуры (нажмите enter, чтобы выбрать файл во всплывающем окошке): ");
string textureName = Console.ReadLine(); string textureName = Console.ReadLine();
if (textureName == "")
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.ShowDialog();
textureName = dialog.FileName.Split('\\').Last();
textureName = textureName.Split('.')[0];
}
Console.WriteLine("Введите количество кадров анимации: "); Console.WriteLine("Введите количество кадров анимации: ");
int framesCount = int.Parse(Console.ReadLine()); int framesCount = int.Parse(Console.ReadLine());
Console.WriteLine("Введите длительность кадра в анимации: "); Console.WriteLine("Введите длительность кадра в анимации: ");

View file

@ -0,0 +1 @@
{"id":"HunchmanMoveLeft","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":124,"Width":24,"Height":24},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":4,"isCycle":true,"offset":"0, 0"}

View file

@ -0,0 +1 @@
{"id":"HunchmanMoveRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":100,"Width":24,"Height":23},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":4,"isCycle":true,"offset":"0, 0"}

View file

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

View file

@ -1,3 +1,64 @@
<<<<<<< HEAD
<?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="2" name="Слой объектов 1" class="LivingEntities.Monsters.FlameSkull">
<object id="1" x="400" y="1000">
<point/>
</object>
</objectgroup>
<objectgroup id="3" name="Слой объектов 2" class="LivingEntities.Monsters.FrankBalls">
<object id="2" x="-162" y="160">
<point/>
</object>
</objectgroup>
<objectgroup id="4" name="Слой объектов 3" class="LivingEntities.Monsters.Hunchman">
<object id="3" x="300" y="230">
<point/>
</object>
</objectgroup>
</map>
=======
<?xml version="1.0" encoding="UTF-8"?> <?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"> <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"/> <tileset firstgid="1" source="../Desktop/DangerousD map/map.tsx"/>
@ -73,3 +134,4 @@
</objectgroup> </objectgroup>
</map> </map>
>>>>>>> main

25
DangerousD/DangerousD.sln Normal file
View file

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 25.0.1705.7
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DangerousD", "DangerousD.csproj", "{A51FB3C2-D16C-42DF-B65A-6EC67AF07506}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A51FB3C2-D16C-42DF-B65A-6EC67AF07506}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A51FB3C2-D16C-42DF-B65A-6EC67AF07506}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A51FB3C2-D16C-42DF-B65A-6EC67AF07506}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A51FB3C2-D16C-42DF-B65A-6EC67AF07506}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F6C9C555-FA45-4C6A-BEB3-8352B2653CB0}
EndGlobalSection
EndGlobal

View file

@ -38,6 +38,12 @@ namespace DangerousD.GameCore
{ {
} }
protected int obsticles = 0;
public virtual void OnCollisionWithObsticle(GameObject gameObject)
{
obsticles++;//SD
}
public virtual void Initialize() public virtual void Initialize()
{ {
} }
@ -53,6 +59,7 @@ namespace DangerousD.GameCore
public virtual void Update(GameTime gameTime) public virtual void Update(GameTime gameTime)
{ {
obsticles = 0;
GraphicsComponent.Update(); GraphicsComponent.Update();
} }

View file

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using DangerousD.GameCore.GameObjects.MapObjects;
namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{ {
@ -17,21 +18,21 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
private bool isFlyRight = true; private bool isFlyRight = true;
private bool isFlyUp = true; private bool isFlyUp = true;
private bool isAttacking = false; private bool isAttacking = false;
public Rectangle Collision public Rectangle Collision
{ {
get { return collision; } get { return collision; }
} }
public FrankBalls(Vector2 position) : base(position) public FrankBalls(Vector2 position) : base(new Vector2(300, 200))
{ {
this.position = position;
name = "FrankBalls"; name = "FrankBalls";
Width = 40; Width = 40;
Height = 40; Height = 40;
monster_speed = 3; monster_speed = 3;
velocity = new Vector2(3,-3); velocity = new Vector2(3,-3);
acceleration = Vector2.Zero; acceleration = Vector2.Zero;
velocity = new Vector2(monster_speed, monster_speed);
} }
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "BallMoveRight" }, "BallMoveRight"); protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "BallMoveRight" }, "BallMoveRight");
@ -65,7 +66,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public override void Move(GameTime gameTime) public override void Move(GameTime gameTime)
{ {
var getColsHor = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, 50, 2)); var getColsHor = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, 50, 2));
var getColsVer= AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, 50, 2)); ; var getColsVer= AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, 50, 2)); ;
if (isFlyRight) if (isFlyRight)

View file

@ -9,129 +9,126 @@ using System.Linq;
using System.Security.Authentication.ExtendedProtection; using System.Security.Authentication.ExtendedProtection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using DangerousD.GameCore.Managers;
namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{ {
public class Hunchman : CoreEnemy public class Hunchman : CoreEnemy
{ {
GameManager gameManager; private bool isGoRight = false;
bool isAttacking; private bool isAttaking = false;
private bool isTarget = false;
private bool isVisible = true;
float leftBoarder;
float rightBoarder;
PhysicsManager physicsManager;
public Hunchman(Vector2 position) : base(position) public Hunchman(Vector2 position) : base(position)
{ {
Width = 48; Width = 20;
Height = 48; Height = 30;
monster_speed = -2; leftBoarder = (int)position.X - 100;
monster_health = 1; rightBoarder = (int)position.X + 100;
name = "HunchMan"; name = "Hunchman";
velocity = new Vector2(monster_speed, 0); GraphicsComponent.StartAnimation("HunchmanMoveLeft");
gameManager = AppManager.Instance.GameManager; monster_speed = 3;
isAttacking = false; physicsManager = new PhysicsManager();
isAlive = true;
} }
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string>
{ "HunchmanMoveLeft", "HunchmanMoveRight", "HunchmanAttackLeft", "HunchmanAttackRight" }, "HunchmanMoveLeft"); { "HunchmanMoveLeft", "HunchmanMoveRight", "HunchmanAttackLeft", "HunchmanAttackRight" }, "HunchmanMoveLeft");
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime)
{ {
// P.S. Всё в классе можешь смело удалять и переписывать с нуля. if (!isAttaking)
gameManager = AppManager.Instance.GameManager;
if (!isAttacking)
{ {
Attack(); Target();
Move(gameTime); Move(gameTime);
} }
else base.Update(gameTime);
{
velocity.X = 0;
}
Death();
} }
public override void Attack() public override void Attack()
{ {
GameObject gameObject; var animation = GraphicsComponent.GetCurrentAnimation;
foreach (var player in gameManager.players) isAttaking = true;
if (isGoRight)
{ {
if (player.Pos.Y + player.Height >= Pos.Y && player.Pos.Y <= Pos.Y + Height) if (animation != "HunchmanAttackRight")
{ {
gameObject = gameManager.physicsManager.RayCast(this, player); GraphicsComponent.StartAnimation("HunchmanAttackRight");
if (gameObject is null)
{
isAttacking = true;
GraphicsComponent.StopAnimation();
if (velocity.X > 0)
{
if (GraphicsComponent.GetCurrentAnimation != "HunchmanAttackRight")
{
GraphicsComponent.StartAnimation("HunchmanAttackRight");
}
}
else if (velocity.X < 0)
{
if (GraphicsComponent.GetCurrentAnimation != "HunchmanAttackLeft")
{
GraphicsComponent.StartAnimation("HunchmanAttackLeft");
}
}
}
} }
HunchmanDagger hunchmanDagger = new HunchmanDagger(Pos,isGoRight);
}
else
{
if (animation != "HunchmanAttackLeft")
{
GraphicsComponent.StartAnimation("HunchmanAttackLeft");
}
HunchmanDagger hunchmanDagger = new HunchmanDagger(Pos, isGoRight);
} }
} }
public override void Attack(GameTime gameTime) public override void Attack(GameTime gameTime)
{ {}
}
public override void Death() public override void Death()
{ {
for (int i = 0; i < 3; i++)
{
Particle particle = new Particle(Pos);
}
if (monster_health <= 0) if (monster_health <= 0)
{ {
isVisible = false;
} }
} }
public override void Move(GameTime gameTime) public override void Move(GameTime gameTime)
{ {
if (gameManager.physicsManager.RayCast(this, new Vector2(Pos.X + Width + 10, Pos.Y + Height)) is not null) velocity.X = 0;
var animation = GraphicsComponent.GetCurrentAnimation;
if (isGoRight)
{ {
monster_speed *= -1; if (animation != "HunchmanMoveRight")
}
velocity.X = monster_speed;
if (velocity.X > 0)
{
if (GraphicsComponent.GetCurrentAnimation != "HunchmanMoveRight")
{ {
GraphicsComponent.StartAnimation("HunchmanMoveRight"); GraphicsComponent.StartAnimation("HunchmanMoveRight");
} }
velocity.X = monster_speed;
} }
else
else if (velocity.X < 0)
{ {
if (GraphicsComponent.GetCurrentAnimation != "HunchmanMoveLeft") if (animation != "HunchmanMoveLeft")
{ {
GraphicsComponent.StartAnimation("HunchmanMoveLeft"); GraphicsComponent.StartAnimation("HunchmanMoveLeft");
} }
velocity.X = -monster_speed;
} }
if (_pos.X >= rightBoarder)
{
isGoRight = false;
}
else if (_pos.X <= leftBoarder)
{
isGoRight = true;
}
} }
public override void OnCollision(GameObject gameObject)
{
monster_speed *= -1;
_pos.X += 5 * monster_speed;
Debug.WriteLine("Collision");
}
public void Target() public void Target()
{ {
throw new NotImplementedException(); var player = AppManager.Instance.GameManager.players[0];
if (physicsManager.RayCast(this, player) == null)
{
Attack();
}
} }
} }
} }

View file

@ -12,10 +12,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{ {
public class HunchmanDagger : CoreEnemy public class HunchmanDagger : CoreEnemy
{ {
public HunchmanDagger(Vector2 position) : base(position) private bool isGoRight = false;
public HunchmanDagger(Vector2 position, bool isGoRight) : base(position)
{ {
this.isGoRight = isGoRight;
name = "Hunchman"; name = "Hunchman";
monster_speed = 1; monster_speed = 4;
Width = 9; Width = 9;
Height = 6; Height = 6;
} }
@ -34,12 +37,46 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public override void Death() public override void Death()
{ {
AppManager.Instance.GameManager.Remove(this);
} }
public override void Move(GameTime gameTime) public override void Move(GameTime gameTime)
{ {
velocity.X = 0;
var getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle(0, 0, 0, 0));
if (isGoRight)
{
StartCicycleAnimation("HunchmanDaggerRight");
velocity.X = monster_speed;
getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y, Width+5, Height));
if(getCols.Count>0)
{
Death();
}
}
else if (!isGoRight)
{
StartCicycleAnimation("HunchmanDaggerLeft");
velocity.X = -monster_speed;
getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X-5, (int)Pos.Y, Width + 5, Height));
if (getCols.Count > 0)
{
Death();
}
}
}
public override void OnCollision(GameObject gameObject)
{
if (gameObject is Player)
{
AppManager.Instance.GameManager.players[0].Death(name);
}
base.OnCollision(gameObject);
} }
public void Target() public void Target()

View file

@ -236,7 +236,7 @@ namespace DangerousD.GameCore.Graphics
private void SetInterval() private void SetInterval()
{ {
Tuple<int, int> i = currentAnimation.FrameTime.Find(x => x.Item1 == currentFrame); Tuple<int, int> i = currentAnimation.FrameTime.Find(x => x.Item1 == currentFrame);
if (i != null) if (i != null)
{ {
interval = i.Item2; interval = i.Item2;

View file

@ -49,6 +49,7 @@ namespace DangerousD.GameCore
internal void Register(GameObject gameObject) internal void Register(GameObject gameObject)
{ {
GetAllGameObjects.Add(gameObject); GetAllGameObjects.Add(gameObject);
if (gameObject is Entity) if (gameObject is Entity)
{ {
gameObject.id = currentEntityId; gameObject.id = currentEntityId;

View file

@ -68,7 +68,7 @@ namespace DangerousD.GameCore.Managers
{ {
if (tiles[i] != 0) if (tiles[i] != 0)
{ {
Vector2 pos = new(((chunkX+ i % chunkW) * tileSize.X + offsetX) * _scale, Vector2 pos = new(((chunkX+ i % chunkW) * tileSize.X + offsetX) * _scale + 400,
((chunkY + i / chunkW) * tileSize.Y + offsetY) * _scale); ((chunkY + i / chunkW) * tileSize.Y + offsetY) * _scale);
//pos *= _scale; //pos *= _scale;
Rectangle sourceRect = new(new Point((tiles[i] -1) % _columns, (tiles[i] -1) / _columns) * tileSize.ToPoint(), tileSize.ToPoint()); Rectangle sourceRect = new(new Point((tiles[i] -1) % _columns, (tiles[i] -1) / _columns) * tileSize.ToPoint(), tileSize.ToPoint());

View file

@ -135,7 +135,6 @@ namespace DangerousD.GameCore.Managers
player.isOnGround = true; player.isOnGround = true;
player.velocity.Y = 0; player.velocity.Y = 0;
} }
player.SetPosition(new Vector2(newRect.X, newRect.Y)); player.SetPosition(new Vector2(newRect.X, newRect.Y));
} }