HUD
This commit is contained in:
commit
e67d56d6bf
25 changed files with 460 additions and 96 deletions
|
@ -14,14 +14,7 @@
|
||||||
|
|
||||||
#---------------------------------- Content ---------------------------------#
|
#---------------------------------- Content ---------------------------------#
|
||||||
|
|
||||||
#begin ButtonFont.spritefont
|
#begin MonstersAnimations.png
|
||||||
/importer:FontDescriptionImporter
|
|
||||||
/processor:FontDescriptionProcessor
|
|
||||||
/processorParam:PremultiplyAlpha=True
|
|
||||||
/processorParam:TextureFormat=Compressed
|
|
||||||
/build:ButtonFont.spritefont
|
|
||||||
|
|
||||||
#begin checkboxs_off-on.png
|
|
||||||
/importer:TextureImporter
|
/importer:TextureImporter
|
||||||
/processor:TextureProcessor
|
/processor:TextureProcessor
|
||||||
/processorParam:ColorKeyColor=255,0,255,255
|
/processorParam:ColorKeyColor=255,0,255,255
|
||||||
|
@ -87,6 +80,13 @@
|
||||||
/processorParam:Quality=Best
|
/processorParam:Quality=Best
|
||||||
/build:DoomTestSong.mp3
|
/build:DoomTestSong.mp3
|
||||||
|
|
||||||
|
#begin Font_12.spritefont
|
||||||
|
/importer:FontDescriptionImporter
|
||||||
|
/processor:FontDescriptionProcessor
|
||||||
|
/processorParam:PremultiplyAlpha=True
|
||||||
|
/processorParam:TextureFormat=Compressed
|
||||||
|
/build:Font_12.spritefont
|
||||||
|
|
||||||
#begin Font_25.spritefont
|
#begin Font_25.spritefont
|
||||||
/importer:FontDescriptionImporter
|
/importer:FontDescriptionImporter
|
||||||
/processor:FontDescriptionProcessor
|
/processor:FontDescriptionProcessor
|
||||||
|
@ -252,7 +252,19 @@
|
||||||
/processorParam:TextureFormat=Color
|
/processorParam:TextureFormat=Color
|
||||||
/build:textboxbackground6-1.png
|
/build:textboxbackground6-1.png
|
||||||
|
|
||||||
#begin tiles.png
|
#begin MonstersAnimations.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:MonstersAnimations.png
|
||||||
|
|
||||||
|
#begin PC_Computer_Dangerous_Dave_In_The_Haunted_Mansion_Death_Sequences.png
|
||||||
/importer:TextureImporter
|
/importer:TextureImporter
|
||||||
/processor:TextureProcessor
|
/processor:TextureProcessor
|
||||||
/processorParam:ColorKeyColor=255,0,255,255
|
/processorParam:ColorKeyColor=255,0,255,255
|
||||||
|
@ -264,6 +276,18 @@
|
||||||
/processorParam:TextureFormat=Color
|
/processorParam:TextureFormat=Color
|
||||||
/build:tiles.png
|
/build:tiles.png
|
||||||
|
|
||||||
|
#begin playerAnimation.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:playerAnimation.png
|
||||||
|
|
||||||
#begin wall.jpg
|
#begin wall.jpg
|
||||||
/importer:TextureImporter
|
/importer:TextureImporter
|
||||||
/processor:TextureProcessor
|
/processor:TextureProcessor
|
||||||
|
|
64
DangerousD/Content/Font_12.spritefont
Normal file
64
DangerousD/Content/Font_12.spritefont
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
This file contains an xml description of a font, and will be read by the XNA
|
||||||
|
Framework Content Pipeline. Follow the comments to customize the appearance
|
||||||
|
of the font in your game, and to change the characters which are available to draw
|
||||||
|
with.
|
||||||
|
-->
|
||||||
|
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
|
||||||
|
<Asset Type="Graphics:FontDescription">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Modify this string to change the font that will be imported.
|
||||||
|
-->
|
||||||
|
<FontName>Arial</FontName>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Size is a float value, measured in points. Modify this value to change
|
||||||
|
the size of the font.
|
||||||
|
-->
|
||||||
|
<Size>12</Size>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Spacing is a float value, measured in pixels. Modify this value to change
|
||||||
|
the amount of spacing in between characters.
|
||||||
|
-->
|
||||||
|
<Spacing>0</Spacing>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
UseKerning controls the layout of the font. If this value is true, kerning information
|
||||||
|
will be used when placing characters.
|
||||||
|
-->
|
||||||
|
<UseKerning>true</UseKerning>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
|
||||||
|
and "Bold, Italic", and are case sensitive.
|
||||||
|
-->
|
||||||
|
<Style>Regular</Style>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
If you uncomment this line, the default character will be substituted if you draw
|
||||||
|
or measure text that contains characters which were not included in the font.
|
||||||
|
-->
|
||||||
|
<!-- <DefaultCharacter>*</DefaultCharacter> -->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
CharacterRegions control what letters are available in the font. Every
|
||||||
|
character from Start to End will be built and made available for drawing. The
|
||||||
|
default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
|
||||||
|
character set. The characters are ordered according to the Unicode standard.
|
||||||
|
See the documentation for more information.
|
||||||
|
-->
|
||||||
|
<CharacterRegions>
|
||||||
|
<CharacterRegion>
|
||||||
|
<Start> </Start>
|
||||||
|
<End>~</End>
|
||||||
|
</CharacterRegion>
|
||||||
|
<CharacterRegion>
|
||||||
|
<Start>а</Start>
|
||||||
|
<End>я</End>
|
||||||
|
</CharacterRegion>
|
||||||
|
</CharacterRegions>
|
||||||
|
</Asset>
|
||||||
|
</XnaContent>
|
1
DangerousD/Content/animations/HunchmanAttackLeft
Normal file
1
DangerousD/Content/animations/HunchmanAttackLeft
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"id":"HunchmanAttackLeft","textureName":"MonstersAnimations","startSpriteRectangle":{"X":101,"Y":124,"Width":40,"Height":24},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":3,"isCycle":true,"offset":"0, 0"}
|
1
DangerousD/Content/animations/HunchmanAttackRight
Normal file
1
DangerousD/Content/animations/HunchmanAttackRight
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"id":"HunchmanAttackRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":101,"Y":99,"Width":40,"Height":24},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":3,"isCycle":true,"offset":"0, 0"}
|
1
DangerousD/Content/animations/HunchmanMoveLeft
Normal file
1
DangerousD/Content/animations/HunchmanMoveLeft
Normal 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"}
|
3
DangerousD/Content/animations/HunchmanMoveRight
Normal file
3
DangerousD/Content/animations/HunchmanMoveRight
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
|
||||||
|
{"id":"HunchmanMoveRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":99,"Width":24,"Height":24},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":4,"isCycle":true,"offset":"0, 0"}
|
||||||
|
|
1
DangerousD/Content/animations/playerJumpLeft
Normal file
1
DangerousD/Content/animations/playerJumpLeft
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"id":"playerJumpLeft","textureName":"playerAnimation","startSpriteRectangle":{"X":101,"Y":34,"Width":24,"Height":32},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":3,"isCycle":false,"offset":"0, 0"}
|
1
DangerousD/Content/animations/playerJumpRight
Normal file
1
DangerousD/Content/animations/playerJumpRight
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"id":"playerJumpRight","textureName":"playerAnimation","startSpriteRectangle":{"X":126,"Y":1,"Width":24,"Height":32},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":3,"isCycle":false,"offset":"0, 0"}
|
20
DangerousD/Content/animations/playerMoveLeft
Normal file
20
DangerousD/Content/animations/playerMoveLeft
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"id": "playerMoveLeft",
|
||||||
|
"textureName": "playerAnimation",
|
||||||
|
"startSpriteRectangle": {
|
||||||
|
"X": 26,
|
||||||
|
"Y": 34,
|
||||||
|
"Width": 24,
|
||||||
|
"Height": 32
|
||||||
|
},
|
||||||
|
"frameSecond": [
|
||||||
|
{
|
||||||
|
"Item1": 0,
|
||||||
|
"Item2": 8
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"textureFrameInterval": 1,
|
||||||
|
"framesCount": 4,
|
||||||
|
"isCycle": true,
|
||||||
|
"offset": "0, 0"
|
||||||
|
}
|
20
DangerousD/Content/animations/playerMoveRight
Normal file
20
DangerousD/Content/animations/playerMoveRight
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"id": "playerMoveRight",
|
||||||
|
"textureName": "playerAnimation",
|
||||||
|
"startSpriteRectangle": {
|
||||||
|
"X": 26,
|
||||||
|
"Y": 1,
|
||||||
|
"Width": 24,
|
||||||
|
"Height": 32
|
||||||
|
},
|
||||||
|
"frameSecond": [
|
||||||
|
{
|
||||||
|
"Item1": 0,
|
||||||
|
"Item2": 8
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"textureFrameInterval": 1,
|
||||||
|
"framesCount": 4,
|
||||||
|
"isCycle": true,
|
||||||
|
"offset": "0, 0"
|
||||||
|
}
|
1
DangerousD/Content/animations/playerRightStay
Normal file
1
DangerousD/Content/animations/playerRightStay
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"id":"playerRightStay","textureName":"playerAnimation","startSpriteRectangle":{"X":1,"Y":1,"Width":24,"Height":32},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"}
|
1
DangerousD/Content/animations/playerStayLeft
Normal file
1
DangerousD/Content/animations/playerStayLeft
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"id":"playerStayLeft","textureName":"playerAnimation","startSpriteRectangle":{"X":1,"Y":34,"Width":24,"Height":32},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"}
|
BIN
DangerousD/Content/playerAnimation.png
Normal file
BIN
DangerousD/Content/playerAnimation.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
50
DangerousD/GameCore/GUI/DebugHUD.cs
Normal file
50
DangerousD/GameCore/GUI/DebugHUD.cs
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using MonogameLibrary.UI.Elements;
|
||||||
|
using static System.String;
|
||||||
|
|
||||||
|
namespace DangerousD.GameCore.GUI
|
||||||
|
{
|
||||||
|
public class DebugHUD : IDrawableObject
|
||||||
|
{
|
||||||
|
private SpriteFont _spriteFont;
|
||||||
|
private Dictionary<string, string> _text = new();
|
||||||
|
|
||||||
|
public void Initialize()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadContent()
|
||||||
|
{
|
||||||
|
_spriteFont = AppManager.Instance.Content.Load<SpriteFont>("Font_12");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw(SpriteBatch spriteBatch)
|
||||||
|
{
|
||||||
|
spriteBatch.Begin();
|
||||||
|
spriteBatch.DrawString(
|
||||||
|
_spriteFont,
|
||||||
|
Join("\n", _text.Select(el => el.Key + ": " + el.Value).ToList()),
|
||||||
|
new Vector2(10, 10),
|
||||||
|
Color.Cyan,
|
||||||
|
0,
|
||||||
|
Vector2.Zero,
|
||||||
|
1,
|
||||||
|
SpriteEffects.None,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
spriteBatch.End();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Set(string key, string value)
|
||||||
|
{
|
||||||
|
_text[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,8 +17,6 @@ namespace DangerousD.GameCore
|
||||||
public int Width { get; set; }
|
public int Width { get; set; }
|
||||||
public int Height { get; set; }
|
public int Height { get; set; }
|
||||||
public Rectangle Rectangle => new Rectangle((int)Pos.X, (int)Pos.Y, Width, Height);
|
public Rectangle Rectangle => new Rectangle((int)Pos.X, (int)Pos.Y, Width, Height);
|
||||||
public Vector2 velocity;
|
|
||||||
public Vector2 acceleration;
|
|
||||||
protected abstract GraphicsComponent GraphicsComponent { get; }
|
protected abstract GraphicsComponent GraphicsComponent { get; }
|
||||||
public GameObject(Vector2 pos)
|
public GameObject(Vector2 pos)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,7 @@ using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
namespace DangerousD.GameCore.GUI
|
namespace DangerousD.GameCore.GUI
|
||||||
{
|
{
|
||||||
interface IDrawableObject
|
public interface IDrawableObject
|
||||||
{
|
{
|
||||||
void Initialize();
|
void Initialize();
|
||||||
void LoadContent();
|
void LoadContent();
|
||||||
|
|
|
@ -4,7 +4,9 @@ using Microsoft.Xna.Framework.Content;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.Authentication.ExtendedProtection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
@ -12,15 +14,71 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
|
||||||
{
|
{
|
||||||
public class Hunchman : CoreEnemy
|
public class Hunchman : CoreEnemy
|
||||||
{
|
{
|
||||||
|
GameManager gameManager;
|
||||||
|
bool isAttacking;
|
||||||
public Hunchman(Vector2 position) : base(position)
|
public Hunchman(Vector2 position) : base(position)
|
||||||
{
|
{
|
||||||
|
Width = 48;
|
||||||
|
Height = 48;
|
||||||
|
monster_speed = -2;
|
||||||
|
monster_health = 1;
|
||||||
|
name = "HunchMan";
|
||||||
|
velocity = new Vector2(monster_speed, 0);
|
||||||
|
gameManager = AppManager.Instance.GameManager;
|
||||||
|
isAttacking = false;
|
||||||
|
isAlive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "HunchmanMoveLeft", "HunchmanMoveRight", "HunchmanAttackLeft", "HunchmanAttackRight" }, "HunchmanMoveRight");
|
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string>
|
||||||
|
{ "HunchmanMoveLeft", "HunchmanMoveRight", "HunchmanAttackLeft", "HunchmanAttackRight" }, "HunchmanMoveLeft");
|
||||||
|
|
||||||
|
public override void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
// P.S. Всё в классе можешь смело удалять и переписывать с нуля.
|
||||||
|
gameManager = AppManager.Instance.GameManager;
|
||||||
|
|
||||||
|
if (!isAttacking)
|
||||||
|
{
|
||||||
|
Attack();
|
||||||
|
Move(gameTime);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
velocity.X = 0;
|
||||||
|
}
|
||||||
|
Death();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public override void Attack()
|
public override void Attack()
|
||||||
{
|
{
|
||||||
|
GameObject gameObject;
|
||||||
|
foreach (var player in gameManager.players)
|
||||||
|
{
|
||||||
|
if (player.Pos.Y + player.Height >= Pos.Y && player.Pos.Y <= Pos.Y + Height)
|
||||||
|
{
|
||||||
|
gameObject = gameManager.physicsManager.RayCast(this, player);
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Attack(GameTime gameTime)
|
public override void Attack(GameTime gameTime)
|
||||||
|
@ -30,12 +88,45 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
|
||||||
|
|
||||||
public override void Death()
|
public override void Death()
|
||||||
{
|
{
|
||||||
|
if (monster_health <= 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
{
|
||||||
|
monster_speed *= -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
velocity.X = monster_speed;
|
||||||
|
|
||||||
|
if (velocity.X > 0)
|
||||||
|
{
|
||||||
|
if (GraphicsComponent.GetCurrentAnimation != "HunchmanMoveRight")
|
||||||
|
{
|
||||||
|
GraphicsComponent.StartAnimation("HunchmanMoveRight");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (velocity.X < 0)
|
||||||
|
{
|
||||||
|
if (GraphicsComponent.GetCurrentAnimation != "HunchmanMoveLeft")
|
||||||
|
{
|
||||||
|
GraphicsComponent.StartAnimation("HunchmanMoveLeft");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnCollision(GameObject gameObject)
|
||||||
|
{
|
||||||
|
monster_speed *= -1;
|
||||||
|
_pos.X += 5 * monster_speed;
|
||||||
|
Debug.WriteLine("Collision");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Target()
|
public override void Target()
|
||||||
|
|
|
@ -13,7 +13,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
|
||||||
{
|
{
|
||||||
public class Zombie : CoreEnemy
|
public class Zombie : CoreEnemy
|
||||||
{
|
{
|
||||||
private bool isGoRight = true;
|
|
||||||
float leftBorder;
|
float leftBorder;
|
||||||
float rightBorder;
|
float rightBorder;
|
||||||
bool isAttaking = false;
|
bool isAttaking = false;
|
||||||
|
@ -25,9 +24,18 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
|
||||||
Height = 40;
|
Height = 40;
|
||||||
monster_speed = 3;
|
monster_speed = 3;
|
||||||
name = "Zombie";
|
name = "Zombie";
|
||||||
leftBorder = (int)position.X - 100;
|
leftBorder = (int)position.X - 50;
|
||||||
rightBorder = (int)position.X + 100;
|
rightBorder = (int)position.X + 50;
|
||||||
physicsManager = new PhysicsManager();
|
physicsManager = new PhysicsManager();
|
||||||
|
Random random = new Random();
|
||||||
|
if(random.Next(0, 2) == 0)
|
||||||
|
{
|
||||||
|
isGoRight = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isGoRight = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack" }, "ZombieMoveLeft");
|
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack" }, "ZombieMoveLeft");
|
||||||
|
|
||||||
|
@ -38,7 +46,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
|
||||||
Target();
|
Target();
|
||||||
Move(gameTime);
|
Move(gameTime);
|
||||||
}
|
}
|
||||||
|
fixBorder();
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +58,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
|
||||||
{
|
{
|
||||||
if (GraphicsComponent.GetCurrentAnimation != "ZombieRightAttack")
|
if (GraphicsComponent.GetCurrentAnimation != "ZombieRightAttack")
|
||||||
{
|
{
|
||||||
GraphicsComponent.StartAnimation("ZombieAttackRight");
|
GraphicsComponent.StartAnimation("ZombieRightAttack");
|
||||||
}
|
}
|
||||||
AppManager.Instance.GameManager.players[0].Death(name);
|
AppManager.Instance.GameManager.players[0].Death(name);
|
||||||
}
|
}
|
||||||
|
@ -71,7 +79,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
|
||||||
|
|
||||||
public override void Move(GameTime gameTime)
|
public override void Move(GameTime gameTime)
|
||||||
{
|
{
|
||||||
float delta = (float)gameTime.ElapsedGameTime.TotalSeconds;
|
|
||||||
if (isGoRight)
|
if (isGoRight)
|
||||||
{
|
{
|
||||||
if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight")
|
if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight")
|
||||||
|
@ -113,7 +120,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
|
||||||
}
|
}
|
||||||
public override void Target()
|
public override void Target()
|
||||||
{
|
{
|
||||||
if (AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - 50, (int)Pos.Y, Width + 100, Height), typeof(Player)) != null)
|
if (AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - 50, (int)Pos.Y, Width + 100, Height), typeof(Player)).Count > 0)
|
||||||
{
|
{
|
||||||
if (isGoRight && this._pos.X <= AppManager.Instance.GameManager.players[0].Pos.X)
|
if (isGoRight && this._pos.X <= AppManager.Instance.GameManager.players[0].Pos.X)
|
||||||
{
|
{
|
||||||
|
@ -130,10 +137,19 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override void Attack(GameTime gameTime)
|
public void fixBorder()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
if(leftBorder <= 0)
|
||||||
|
{
|
||||||
|
leftBorder = 0;
|
||||||
|
}
|
||||||
|
if(rightBorder >= 800)
|
||||||
|
{
|
||||||
|
rightBorder = 760;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Attack(GameTime gameTime)
|
||||||
|
{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@ namespace DangerousD.GameCore.GameObjects.PlayerDeath
|
||||||
{
|
{
|
||||||
public DeathRectangle(Vector2 pos, string DeathType) : base(pos)
|
public DeathRectangle(Vector2 pos, string DeathType) : base(pos)
|
||||||
{
|
{
|
||||||
Height = 128;
|
Height = 48;
|
||||||
Width = 128;
|
Width = 48;
|
||||||
PlayDeath(DeathType);
|
PlayDeath(DeathType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,8 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
public class Player : LivingEntity
|
public class Player : LivingEntity
|
||||||
{
|
{
|
||||||
bool isAlive = true;
|
bool isAlive = true;
|
||||||
|
bool isRight;
|
||||||
|
string stayAnimation;
|
||||||
bool isJump = false;
|
bool isJump = false;
|
||||||
public int health;
|
public int health;
|
||||||
public bool isGoRight = false;
|
public bool isGoRight = false;
|
||||||
|
@ -21,6 +23,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
public int rightBorder;
|
public int rightBorder;
|
||||||
public int leftBorder;
|
public int leftBorder;
|
||||||
public bool isVisible = true;
|
public bool isVisible = true;
|
||||||
|
private bool isAttacked = false;
|
||||||
public GameObject objectAttack;
|
public GameObject objectAttack;
|
||||||
|
|
||||||
public Player(Vector2 position) : base(position)
|
public Player(Vector2 position) : base(position)
|
||||||
|
@ -30,7 +33,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
|
|
||||||
AppManager.Instance.InputManager.ShootEvent += Shoot;
|
AppManager.Instance.InputManager.ShootEvent += Shoot;
|
||||||
|
|
||||||
AppManager.Instance.InputManager.MovEventJump += AnimationJump;
|
AppManager.Instance.InputManager.MovEventJump += Jump;
|
||||||
AppManager.Instance.InputManager.MovEventDown += MoveDown;
|
AppManager.Instance.InputManager.MovEventDown += MoveDown;
|
||||||
|
|
||||||
velocity = new Vector2(0, 0);
|
velocity = new Vector2(0, 0);
|
||||||
|
@ -38,9 +41,11 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
leftBorder = (int)position.X - 100;
|
leftBorder = (int)position.X - 100;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsAlive { get { return isAlive; } }
|
public bool IsAlive { get { return isAlive; } }
|
||||||
|
|
||||||
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack", "DeathFromZombie" }, "ZombieMoveLeft");//TODO: Change to player
|
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "playerMoveLeft", "playerMoveRight", "DeathFromZombie", "playerRightStay", "playerStayLeft",
|
||||||
|
"playerJumpRight" , "playerJumpLeft"}, "playerStayLeft");
|
||||||
|
|
||||||
public void Attack()
|
public void Attack()
|
||||||
{
|
{
|
||||||
|
@ -66,23 +71,26 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
}
|
}
|
||||||
public void Death(string monsterName)
|
public void Death(string monsterName)
|
||||||
{
|
{
|
||||||
/*if(monsterName == "Zombie")
|
isAttacked = true;
|
||||||
|
if(monsterName == "Zombie")
|
||||||
{
|
{
|
||||||
DeathRectangle deathRectangle = new DeathRectangle(Pos, "DeathFrom" + monsterName);
|
DeathRectangle deathRectangle = new DeathRectangle(Pos, "DeathFrom" + monsterName);
|
||||||
deathRectangle.Gr.actionOfAnimationEnd += (a) =>
|
deathRectangle.Gr.actionOfAnimationEnd += (a) =>
|
||||||
{
|
{
|
||||||
if (a == "DeathFrom" + monsterName)
|
if (a == "DeathFrom" + monsterName)
|
||||||
{
|
{
|
||||||
AppManager.Instance.ChangeGameState(GameState.GameOver);
|
AppManager.Instance.ChangeGameState(GameState.Death);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
isAlive = false;*/
|
isAlive = false;
|
||||||
}
|
}
|
||||||
public void AnimationJump()
|
public void Jump()
|
||||||
{
|
{
|
||||||
velocity.Y = -11;
|
if (isOnGround)
|
||||||
isJump = true;
|
{
|
||||||
|
velocity.Y = -11;
|
||||||
|
}
|
||||||
// здесь будет анимация
|
// здесь будет анимация
|
||||||
}
|
}
|
||||||
public void Shoot()
|
public void Shoot()
|
||||||
|
@ -93,33 +101,34 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
public override void Update(GameTime gameTime)
|
public override void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
GraphicsComponent.CameraPosition = (_pos-new Vector2(200, 350)).ToPoint();
|
GraphicsComponent.CameraPosition = (_pos-new Vector2(200, 350)).ToPoint();
|
||||||
velocity.X = 0.5f;
|
if (!isAttacked)
|
||||||
if (velocity.Y == 0)
|
|
||||||
{
|
{
|
||||||
isJump = false;
|
Move(gameTime);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
velocity.X = 0;
|
||||||
}
|
}
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
Move(gameTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Move(GameTime gameTime)
|
public void Move(GameTime gameTime)
|
||||||
{
|
{
|
||||||
float delta = (float)gameTime.ElapsedGameTime.TotalSeconds;
|
float delta = (float)gameTime.ElapsedGameTime.TotalSeconds;
|
||||||
if (AppManager.Instance.InputManager.VectorMovementDirection.X==1)
|
velocity.X = 5 * AppManager.Instance.InputManager.VectorMovementDirection.X;
|
||||||
|
if (AppManager.Instance.InputManager.VectorMovementDirection.X > 0)
|
||||||
{
|
{
|
||||||
if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight")//идёт направо
|
if (GraphicsComponent.GetCurrentAnimation != "playerMoveRight")//идёт направо
|
||||||
{
|
{
|
||||||
GraphicsComponent.StartAnimation("ZombieMoveRight");
|
GraphicsComponent.StartAnimation("playerMoveRight");
|
||||||
}
|
}
|
||||||
velocity.X = 5;
|
|
||||||
}
|
}
|
||||||
else if (AppManager.Instance.InputManager.VectorMovementDirection.X == -1)//идёт налево
|
else if (AppManager.Instance.InputManager.VectorMovementDirection.X < 0)//идёт налево
|
||||||
{
|
{
|
||||||
if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft")
|
if (GraphicsComponent.GetCurrentAnimation != "playerMoveLeft")
|
||||||
{
|
{
|
||||||
GraphicsComponent.StartAnimation("ZombieMoveLeft");
|
GraphicsComponent.StartAnimation("playerMoveLeft");
|
||||||
}
|
}
|
||||||
velocity.X = -5;
|
|
||||||
}
|
}
|
||||||
else if(AppManager.Instance.InputManager.VectorMovementDirection.X == 0)//стоит
|
else if(AppManager.Instance.InputManager.VectorMovementDirection.X == 0)//стоит
|
||||||
{
|
{
|
||||||
|
@ -127,13 +136,12 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
{
|
{
|
||||||
GraphicsComponent.StartAnimation("ZombieMoveLeft");
|
GraphicsComponent.StartAnimation("ZombieMoveLeft");
|
||||||
}
|
}
|
||||||
velocity.X = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void MoveDown()
|
public void MoveDown()
|
||||||
{
|
{
|
||||||
|
// ПОЧЕМУ
|
||||||
velocity.Y = -11;
|
velocity.Y = -11;
|
||||||
isJump = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ namespace DangerousD.GameCore.GameObjects;
|
||||||
|
|
||||||
public abstract class LivingEntity : Entity
|
public abstract class LivingEntity : Entity
|
||||||
{
|
{
|
||||||
private Vector2 targetPosition;
|
public bool isOnGround = true;
|
||||||
public Vector2 velocity;
|
public Vector2 velocity;
|
||||||
public Vector2 acceleration;
|
public Vector2 acceleration;
|
||||||
public LivingEntity(Vector2 position) : base(position)
|
public LivingEntity(Vector2 position) : base(position)
|
||||||
|
@ -13,7 +13,7 @@ public abstract class LivingEntity : Entity
|
||||||
}
|
}
|
||||||
public override void SetPosition(Vector2 position)
|
public override void SetPosition(Vector2 position)
|
||||||
{
|
{
|
||||||
targetPosition = position; _pos = position;
|
_pos = position;
|
||||||
|
|
||||||
} //TODO befrend targetpos and physics engine
|
} //TODO befrend targetpos and physics engine
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,13 @@ using DangerousD.GameCore.Managers;
|
||||||
namespace DangerousD.GameCore
|
namespace DangerousD.GameCore
|
||||||
{
|
{
|
||||||
public enum MultiPlayerStatus { SinglePlayer, Host, Client }
|
public enum MultiPlayerStatus { SinglePlayer, Host, Client }
|
||||||
|
<<<<<<< HEAD
|
||||||
public enum GameState { Menu, Options, Lobby, Game, Login, Death, HUD }
|
public enum GameState { Menu, Options, Lobby, Game, Login, Death, HUD }
|
||||||
|
=======
|
||||||
|
public enum GameState { Menu, Options, Lobby, Game, Login, Death,
|
||||||
|
GameOver
|
||||||
|
}
|
||||||
|
>>>>>>> e6d0f2b8a092647a5c02741fd70194bfb376b202
|
||||||
public class AppManager : Game
|
public class AppManager : Game
|
||||||
{
|
{
|
||||||
public static AppManager Instance { get; private set; }
|
public static AppManager Instance { get; private set; }
|
||||||
|
@ -24,13 +30,14 @@ namespace DangerousD.GameCore
|
||||||
public GameState gameState { get; private set; }
|
public GameState gameState { get; private set; }
|
||||||
public MultiPlayerStatus multiPlayerStatus { get; private set; } = MultiPlayerStatus.SinglePlayer;
|
public MultiPlayerStatus multiPlayerStatus { get; private set; } = MultiPlayerStatus.SinglePlayer;
|
||||||
public Point resolution = new Point(1920, 1080);
|
public Point resolution = new Point(1920, 1080);
|
||||||
public Point inGameResolution = new Point(1920, 1080);
|
public Point inGameResolution = new Point(1366, 768);
|
||||||
IDrawableObject MenuGUI;
|
IDrawableObject MenuGUI;
|
||||||
IDrawableObject OptionsGUI;
|
IDrawableObject OptionsGUI;
|
||||||
IDrawableObject LoginGUI;
|
IDrawableObject LoginGUI;
|
||||||
IDrawableObject LobbyGUI;
|
IDrawableObject LobbyGUI;
|
||||||
IDrawableObject DeathGUI;
|
IDrawableObject DeathGUI;
|
||||||
IDrawableObject HUD;
|
IDrawableObject HUD;
|
||||||
|
public DebugHUD DebugHUD;
|
||||||
|
|
||||||
public GameManager GameManager { get; private set; } = new();
|
public GameManager GameManager { get; private set; } = new();
|
||||||
public AnimationBuilder AnimationBuilder { get; private set; } = new AnimationBuilder();
|
public AnimationBuilder AnimationBuilder { get; private set; } = new AnimationBuilder();
|
||||||
|
@ -64,6 +71,7 @@ namespace DangerousD.GameCore
|
||||||
LobbyGUI = new LobbyGUI();
|
LobbyGUI = new LobbyGUI();
|
||||||
DeathGUI = new DeathGUI();
|
DeathGUI = new DeathGUI();
|
||||||
HUD = new HUD();
|
HUD = new HUD();
|
||||||
|
DebugHUD = new DebugHUD();
|
||||||
UIManager.resolution = resolution;
|
UIManager.resolution = resolution;
|
||||||
UIManager.resolutionInGame = inGameResolution;
|
UIManager.resolutionInGame = inGameResolution;
|
||||||
}
|
}
|
||||||
|
@ -74,6 +82,7 @@ namespace DangerousD.GameCore
|
||||||
MenuGUI.Initialize();
|
MenuGUI.Initialize();
|
||||||
LoginGUI.Initialize();
|
LoginGUI.Initialize();
|
||||||
|
|
||||||
|
DebugHUD.Initialize();
|
||||||
OptionsGUI.Initialize();
|
OptionsGUI.Initialize();
|
||||||
HUD.Initialize();
|
HUD.Initialize();
|
||||||
LobbyGUI.Initialize();
|
LobbyGUI.Initialize();
|
||||||
|
@ -84,6 +93,7 @@ namespace DangerousD.GameCore
|
||||||
protected override void LoadContent()
|
protected override void LoadContent()
|
||||||
{
|
{
|
||||||
_spriteBatch = new SpriteBatch(GraphicsDevice);
|
_spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||||
|
DebugHUD.LoadContent();
|
||||||
MenuGUI.LoadContent();
|
MenuGUI.LoadContent();
|
||||||
LoginGUI.LoadContent();
|
LoginGUI.LoadContent();
|
||||||
OptionsGUI.LoadContent();
|
OptionsGUI.LoadContent();
|
||||||
|
@ -131,6 +141,7 @@ namespace DangerousD.GameCore
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
DebugHUD.Update(gameTime);
|
||||||
|
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
}
|
}
|
||||||
|
@ -174,6 +185,7 @@ namespace DangerousD.GameCore
|
||||||
_spriteBatch.End();
|
_spriteBatch.End();
|
||||||
|
|
||||||
|
|
||||||
|
DebugHUD.Draw(_spriteBatch);
|
||||||
base.Draw(gameTime);
|
base.Draw(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace DangerousD.GameCore
|
||||||
public List<Player> players;
|
public List<Player> players;
|
||||||
public List<GameObject> otherObjects = new();
|
public List<GameObject> otherObjects = new();
|
||||||
|
|
||||||
public Player GetPlayer1 { get; private set; }
|
public Player GetPlayer1;
|
||||||
public GameManager()
|
public GameManager()
|
||||||
{
|
{
|
||||||
others = new List<GameObject>();
|
others = new List<GameObject>();
|
||||||
|
@ -72,6 +72,35 @@ namespace DangerousD.GameCore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Remove(GameObject gameObject)
|
||||||
|
{
|
||||||
|
GetAllGameObjects.Remove(gameObject);
|
||||||
|
if (gameObject is Player objPl)
|
||||||
|
{
|
||||||
|
livingEntities.Remove(gameObject as LivingEntity);
|
||||||
|
players.Remove(objPl);
|
||||||
|
}
|
||||||
|
else if (gameObject is LivingEntity objLE)
|
||||||
|
{
|
||||||
|
livingEntities.Remove(objLE);
|
||||||
|
}
|
||||||
|
else if (gameObject is Entity objE)
|
||||||
|
{
|
||||||
|
entities.Remove(objE);
|
||||||
|
}
|
||||||
|
else if (gameObject is MapObject obj)
|
||||||
|
{
|
||||||
|
if (obj.IsColliderOn)
|
||||||
|
mapObjects.Remove(obj);
|
||||||
|
else
|
||||||
|
BackgroundObjects.Remove(obj);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
otherObjects.Remove(gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Draw(SpriteBatch _spriteBatch)
|
public void Draw(SpriteBatch _spriteBatch)
|
||||||
{
|
{
|
||||||
foreach (var item in BackgroundObjects)
|
foreach (var item in BackgroundObjects)
|
||||||
|
|
|
@ -4,6 +4,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.LivingEntities;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
|
|
||||||
namespace DangerousD.GameCore.Managers
|
namespace DangerousD.GameCore.Managers
|
||||||
|
@ -20,9 +21,9 @@ namespace DangerousD.GameCore.Managers
|
||||||
item.velocity = item.velocity + item.acceleration * delta;
|
item.velocity = item.velocity + item.acceleration * delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckCollisions(livingEntities, mapObjects);
|
CheckCollisionsLE_MO(livingEntities, mapObjects);
|
||||||
OnCollision(entities, livingEntities);
|
CheckCollisionsE_LE(entities, livingEntities);
|
||||||
OnCollision(livingEntities);
|
CheckCollisionsLE_LE(livingEntities);
|
||||||
|
|
||||||
//entities dont move
|
//entities dont move
|
||||||
//Living entities dont move
|
//Living entities dont move
|
||||||
|
@ -33,68 +34,88 @@ namespace DangerousD.GameCore.Managers
|
||||||
//OnCollision
|
//OnCollision
|
||||||
|
|
||||||
}
|
}
|
||||||
public void CheckCollisions(List<LivingEntity> livingEntities,
|
private void CheckCollisionsLE_MO(List<LivingEntity> livingEntities,
|
||||||
List<MapObject> mapObjects)
|
List<MapObject> mapObjects)
|
||||||
{
|
{
|
||||||
LivingEntity currentEntity;
|
foreach (var currentEntity in livingEntities)
|
||||||
Rectangle oldRect;
|
|
||||||
for (int i = 0; i < livingEntities.Count; i++)
|
|
||||||
{
|
{
|
||||||
currentEntity = livingEntities[i];
|
var currentRect = currentEntity.Rectangle;
|
||||||
oldRect = currentEntity.Rectangle;
|
var newRect = currentRect;
|
||||||
bool isXNormalise = true;
|
|
||||||
bool isYNormalise = true;
|
|
||||||
|
|
||||||
oldRect.Offset((int)currentEntity.velocity.X, 0);
|
#region x collision
|
||||||
for (int j = 0; j < mapObjects.Count; j++)
|
var collidedX = false;
|
||||||
|
var tryingRectX = currentRect;
|
||||||
|
tryingRectX.Offset((int)Math.Ceiling(currentEntity.velocity.X), 0);
|
||||||
|
foreach (var mapObject in mapObjects)
|
||||||
{
|
{
|
||||||
if (Math.Abs(mapObjects[i].Pos.X - currentEntity.Pos.X) < 550 && Math.Abs(mapObjects[i].Pos.Y - currentEntity.Pos.Y) < 550)
|
if (
|
||||||
|
Math.Abs(mapObject.Pos.X - currentEntity.Pos.X) < 550
|
||||||
|
&& Math.Abs(mapObject.Pos.Y - currentEntity.Pos.Y) < 550
|
||||||
|
&& tryingRectX.Intersects(mapObject.Rectangle)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (oldRect.Intersects(mapObjects[j].Rectangle))
|
collidedX = true;
|
||||||
{
|
|
||||||
isXNormalise = false;
|
|
||||||
oldRect.Offset(-(int)currentEntity.velocity.X, 0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!isXNormalise)
|
|
||||||
currentEntity.velocity.X = 0;
|
|
||||||
|
|
||||||
|
|
||||||
oldRect.Offset(0, (int)currentEntity.velocity.Y);
|
|
||||||
for (int j = 0; j < mapObjects.Count; j++)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (oldRect.Intersects(mapObjects[j].Rectangle))
|
|
||||||
{
|
|
||||||
isYNormalise = false;
|
|
||||||
oldRect.Offset(0, -(int)currentEntity.velocity.Y);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isYNormalise)
|
if (collidedX)
|
||||||
|
{
|
||||||
|
currentEntity.velocity.X = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newRect.X = tryingRectX.X;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region y collision
|
||||||
|
var collidedY = false;
|
||||||
|
var tryingRectY = currentRect;
|
||||||
|
tryingRectY.Offset(0, (int)Math.Ceiling(currentEntity.velocity.Y));
|
||||||
|
if (currentEntity is Player)
|
||||||
|
{
|
||||||
|
AppManager.Instance.DebugHUD.Set("velocity", currentEntity.velocity.ToString());
|
||||||
|
AppManager.Instance.DebugHUD.Set("intersects y", "");
|
||||||
|
}
|
||||||
|
foreach (var mapObject in mapObjects)
|
||||||
|
{
|
||||||
|
if (tryingRectY.Intersects(mapObject.Rectangle))
|
||||||
|
{
|
||||||
|
if (currentEntity is Player) AppManager.Instance.DebugHUD.Set("intersects y", mapObject.GetType().ToString());
|
||||||
|
collidedY = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
currentEntity.isOnGround = collidedY && currentEntity.velocity.Y > 0;
|
||||||
|
if (collidedY)
|
||||||
|
{
|
||||||
currentEntity.velocity.Y = 0;
|
currentEntity.velocity.Y = 0;
|
||||||
currentEntity.SetPosition(new Vector2(oldRect.X, oldRect.Y));
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newRect.Y = tryingRectY.Y;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
currentEntity.SetPosition(new Vector2(newRect.X, newRect.Y));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public void OnCollision(List<Entity> entities, List<LivingEntity> livingEntities)
|
private void CheckCollisionsE_LE(List<Entity> entities, List<LivingEntity> livingEntities)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < entities.Count; i++)
|
foreach (var entity in entities)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < livingEntities.Count; j++)
|
foreach (var livingEntity in livingEntities)
|
||||||
{
|
{
|
||||||
if (livingEntities[j].Rectangle.Intersects(entities[i].Rectangle))
|
if (livingEntity.Rectangle.Intersects(entity.Rectangle))
|
||||||
{
|
{
|
||||||
livingEntities[j].OnCollision(entities[i]);
|
livingEntity.OnCollision(entity);
|
||||||
entities[i].OnCollision(livingEntities[j]);
|
entity.OnCollision(livingEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public void OnCollision(List<LivingEntity> livingEntities)
|
private void CheckCollisionsLE_LE(List<LivingEntity> livingEntities)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < livingEntities.Count; i++)
|
for (int i = 0; i < livingEntities.Count; i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,6 +40,7 @@ namespace DangerousD.GameCore
|
||||||
|
|
||||||
public void StartAmbientSound(string soundName) // запустить звук у которого нет позиции
|
public void StartAmbientSound(string soundName) // запустить звук у которого нет позиции
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
var sound = new Sound(Sounds[soundName]);
|
var sound = new Sound(Sounds[soundName]);
|
||||||
sound.SoundEffect.IsLooped = false;
|
sound.SoundEffect.IsLooped = false;
|
||||||
sound.SoundEffect.Play();
|
sound.SoundEffect.Play();
|
||||||
|
|
Loading…
Add table
Reference in a new issue