merge fixes, minor monster fixes, physics to be remade very soon

This commit is contained in:
SergoDobro 2023-08-16 13:09:35 +03:00
parent 18d8ff814d
commit 13a6f05475
13 changed files with 55 additions and 39 deletions

3
.gitignore vendored
View file

@ -1,4 +1,5 @@
bin
obj
.vs
.idea
.idea
DangerousD.sln.DotSettings.user

View file

@ -13,7 +13,7 @@
#---------------------------------- Content ---------------------------------#
#begin ../../../animation1.png
#begin animation1.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
@ -23,7 +23,7 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:../../../animation1.png;animation1.png
/build:animation1.png
#begin File.spritefont
/importer:FontDescriptionImporter

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View file

@ -13,17 +13,6 @@ namespace DangerousD.GameCore.GameObjects
public Entity(Vector2 position) : base(position) {}
public void SetPosition(Vector2 position) { targetPosition = position; }
public override void Update(GameTime gameTime)
{
if (Vector2.Distance(Pos, targetPosition) > 0.5f)
{
Vector2 dir = targetPosition - Pos;
dir.Normalize();
_pos += dir * speed;
}
base.Update(gameTime);
}
}
}

View file

@ -11,4 +11,4 @@ namespace DangerousD.GameCore.GUI
void Update(GameTime gameTime);
void Draw(SpriteBatch spriteBatch);
}
}
}

View file

@ -22,7 +22,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
//здесь я не понял
}
public virtual void Update(GameTime gameTime, Player player)
public override void Update(GameTime gameTime)
{
if (monster_health <= 0)
{

View file

@ -19,7 +19,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{
Width = 72;
Height = 120;
monster_speed = 20;
monster_speed = 10;
GraphicsComponent.StartAnimation("ZombieLeftAttack");
name = "Zombie";
leftBorder = (int)position.X;
@ -27,14 +27,18 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
}
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack" }, "ZombieMoveLeft");
public override void Update(GameTime gameTime, Player player)
public override void Update(GameTime gameTime)
{
if (AppManager.Instance.GameManager.GetPlayer1.Pos.X>Pos.X)
isGoRight = true;
else
isGoRight = false;
Move(gameTime);
if(Pos.X + 20 <= player.Pos.X || Pos.X - 20 >= player.Pos.X)
if(Pos.X + 20 <= AppManager.Instance.GameManager.GetPlayer1.Pos.X || Pos.X - 20 >= AppManager.Instance.GameManager.GetPlayer1.Pos.X)
{
Attack();
player.Death(name);
AppManager.Instance.GameManager.GetPlayer1.Death(name);
}
base.Update(gameTime);
@ -46,13 +50,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{
GraphicsComponent.StopAnimation();
GraphicsComponent.StartAnimation("ZombieRightAttack");
AppManager.Instance.GameManager.Player.Death(name);
AppManager.Instance.GameManager.players[0].Death(name);
}
else if (!isGoRight)
{
GraphicsComponent.StopAnimation();
GraphicsComponent.StartAnimation("ZombieLeftAttack");
AppManager.Instance.GameManager.Player.Death(name);
AppManager.Instance.GameManager.players[0].Death(name);
}
}
@ -67,19 +71,15 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
if (isGoRight)
{
if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight")
{
GraphicsComponent.StartAnimation("ZombieMoveRight");
velocity = new Vector2(monster_speed, 0);
}
velocity = new Vector2(monster_speed, 0);
}
else if (!isGoRight)
{
if(GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft")
{
GraphicsComponent.StartAnimation("ZombieMoveLeft");
velocity = new Vector2(-monster_speed, 0);
}
velocity = new Vector2(-monster_speed, 0);
}
}

View file

@ -12,9 +12,11 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
{
public Player(Vector2 position) : base(position)
{
Width = 32;
Height = 64;
}
protected override GraphicsComponent GraphicsComponent => throw new NotImplementedException();
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack" }, "ZombieMoveLeft");//TODO: Change to player
public void Kill()
{

View file

@ -11,7 +11,7 @@ public abstract class LivingEntity : Entity
{
acceleration = new Vector2(0, 10);
}
public void SetPosition(Vector2 position) { targetPosition = position; }
public void SetPosition(Vector2 position) { targetPosition = position; _pos = position; } //TODO befrend targetpos and physics engine
public override void Update(GameTime gameTime)
{
@ -19,7 +19,7 @@ public abstract class LivingEntity : Entity
{
Vector2 dir = targetPosition - Pos;
dir.Normalize();
Pos += dir * velocity;
_pos += dir * velocity;
}
base.Update(gameTime);
}

View file

@ -10,10 +10,16 @@ namespace DangerousD.GameCore.Levels
{
public void InitLevel()
{
var Трава = new GrassBlock(new Vector2(0, 128));
var Death = new TestAnimationDeath(new Vector2(128, 128));
new Player(new Vector2(0,0));
var Zombie = new Zombie(new Vector2(256, 128));
var Frank = new Frank(new Vector2(384, 128));
new GrassBlock(new Vector2(0, 224));
for (int i = 0; i < 50; i++)
{
new GrassBlock(new Vector2(i*32, 256));
}
new GrassBlock(new Vector2(500, 224));
}
}
}

View file

@ -18,13 +18,16 @@ namespace DangerousD.GameCore
public List<MapObject> mapObjects;
public MapManager mapManager;
public PhysicsManager physicsManager;
public List<Player> players;
public Player GetPlayer1 { get; private set; }
public GameManager()
{
livingEntities = new List<LivingEntity>();
mapObjects = new List<MapObject>();
entities = new List<Entity>();
players = new List<Player>();
mapManager = new MapManager();
physicsManager = new PhysicsManager();
mapManager.Init();
}
@ -36,6 +39,11 @@ namespace DangerousD.GameCore
entities.Add(gameObject as Entity);
if (gameObject is MapObject)
mapObjects.Add(gameObject as MapObject);
if (gameObject is Player)
{
players.Add(gameObject as Player);
GetPlayer1= players[0];
}
}
public void Draw(SpriteBatch _spriteBatch)
@ -56,7 +64,10 @@ namespace DangerousD.GameCore
item.Update(gameTime);
foreach (var item in livingEntities)
item.Update(gameTime);
physicsManager.UpdateCollisions(entities, livingEntities, mapObjects, gameTime);
}
}
}

View file

@ -19,6 +19,13 @@ namespace DangerousD.GameCore.Managers
{
item.velocity = item.velocity + item.acceleration * delta;
}
//SD setting positions before check
foreach (var item in livingEntities)
{
item.SetPosition(item.Pos + item.velocity);
}
CheckCollisions(livingEntities, mapObjects);
OnCollision(entities, livingEntities);
OnCollision(livingEntities);
@ -44,24 +51,24 @@ namespace DangerousD.GameCore.Managers
if (livingEntities[i].Rectangle.Right > mapObjects[j].Rectangle.Left)
{
//livingEntities[i].SetPosition(livingEntities[i].Pos- new Vector2(livingEntities[i].velocity.X));
livingEntities[i].velocity.X = 0;
livingEntities[i].SetPosition(new Vector2(livingEntities[i].Pos.X - (livingEntities[i].Rectangle.Right - mapObjects[j].Rectangle.Left),
livingEntities[i].Pos.Y));
}
else if (livingEntities[i].Rectangle.Left < mapObjects[j].Rectangle.Right)
if (livingEntities[i].Rectangle.Left < mapObjects[j].Rectangle.Right)
{
livingEntities[i].velocity.X = 0;
livingEntities[i].SetPosition(new Vector2(livingEntities[i].Pos.X + mapObjects[j].Rectangle.Right - livingEntities[i].Rectangle.Left,
livingEntities[i].Pos.Y));
}
else if (livingEntities[i].Rectangle.Bottom > mapObjects[j].Rectangle.Top)
if (livingEntities[i].Rectangle.Bottom > mapObjects[j].Rectangle.Top)
{
livingEntities[i].velocity.Y = 0;
livingEntities[i].SetPosition(new Vector2(livingEntities[i].Pos.X,
livingEntities[i].Pos.Y - (livingEntities[i].Rectangle.Bottom - mapObjects[j].Rectangle.Top)));
}
else if (livingEntities[i].Rectangle.Top < mapObjects[j].Rectangle.Bottom)
if (livingEntities[i].Rectangle.Top < mapObjects[j].Rectangle.Bottom)
{
livingEntities[i].velocity.Y = 0;
livingEntities[i].SetPosition(new Vector2(livingEntities[i].Pos.X,