added death animation from zombie. zombie can walk between 2 points

This commit is contained in:
bmvolf 2023-08-16 17:21:45 +03:00
parent 5a5a24dffd
commit ff46f3694a
13 changed files with 144 additions and 52 deletions

View file

@ -62,7 +62,7 @@ namespace AnimationsFileCreator
container.TextureFrameInterval = 1; container.TextureFrameInterval = 1;
container.Id = id; container.Id = id;
string json = JsonConvert.SerializeObject(container); string json = JsonConvert.SerializeObject(container);
StreamWriter writer = new StreamWriter(id); StreamWriter writer = new StreamWriter("../../../../DangerousD/Content/animations/" + id);
writer.WriteLine(json); writer.WriteLine(json);
writer.Close(); writer.Close();
} }

View file

@ -13,6 +13,30 @@
#---------------------------------- Content ---------------------------------# #---------------------------------- Content ---------------------------------#
#begin ../../../animation1.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:../../../animation1.png;MonstersAnimations.png
#begin deathAnimation.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:deathAnimation.png
#begin File.spritefont #begin File.spritefont
/importer:FontDescriptionImporter /importer:FontDescriptionImporter
/processor:FontDescriptionProcessor /processor:FontDescriptionProcessor
@ -34,18 +58,6 @@
/processorParam:TextureFormat=Compressed /processorParam:TextureFormat=Compressed
/build:Font2.spritefont /build:Font2.spritefont
#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 #begin PC_Computer_Dangerous_Dave_In_The_Haunted_Mansion_Death_Sequences.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor

View file

@ -0,0 +1 @@
{"id":"DeathFromZombie","textureName":"deathAnimation","startSpriteRectangle":{"X":1,"Y":99,"Width":48,"Height":48},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":5,"isCycle":false,"offset":"0, 0"}

View file

@ -1 +1 @@
{"id":"ZombieLeftAttack","textureName":"MonstersAnimations","startSpriteRectangle":{"X":126,"Y":50,"Width":50,"Height":40},"frameSecond":[{"Item1":0,"Item2":25}],"textureFrameInterval":1,"framesCount":3,"isCycle":false,"offset":"16, 0"} {"id":"ZombieLeftAttack","textureName":"MonstersAnimations","startSpriteRectangle":{"X":126,"Y":50,"Width":50,"Height":40},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":3,"isCycle":false,"offset":"16, 0"}

View file

@ -1 +1 @@
{"id":"ZombieRightAttack","textureName":"MonstersAnimations","startSpriteRectangle":{"X":126,"Y":9,"Width":50,"Height":40},"frameSecond":[{"Item1":0,"Item2":25}],"textureFrameInterval":1,"framesCount":3,"isCycle":false,"offset":"16, 0"} {"id":"ZombieRightAttack","textureName":"MonstersAnimations","startSpriteRectangle":{"X":126,"Y":9,"Width":50,"Height":40},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":3,"isCycle":false,"offset":"16, 0"}

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View file

@ -30,7 +30,7 @@ namespace DangerousD.GameCore
AppManager.Instance.GameManager.Register(this); AppManager.Instance.GameManager.Register(this);
} }
public virtual void OnCollision() public virtual void OnCollision(GameObject gameObject)
{ {
} }

View file

@ -15,30 +15,23 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
private bool isGoRight = true; private bool isGoRight = true;
int leftBorder; int leftBorder;
int rightBorder; int rightBorder;
bool isAttaking = false;
public Zombie(Vector2 position) : base(position) public Zombie(Vector2 position) : base(position)
{ {
Width = 72; Width = 72;
Height = 120; Height = 120;
monster_speed = 10; monster_speed = 3;
GraphicsComponent.StartAnimation("ZombieLeftAttack");
name = "Zombie"; name = "Zombie";
leftBorder = (int)position.X; leftBorder = (int)position.X - 60;
rightBorder = (int)position.X + 200; rightBorder = (int)position.X + 120;
} }
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");
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime)
{ {
if (AppManager.Instance.GameManager.GetPlayer1.Pos.X>Pos.X) if (!isAttaking)
isGoRight = true;
else
isGoRight = false;
Move(gameTime);
if(Pos.X + 20 <= AppManager.Instance.GameManager.GetPlayer1.Pos.X || Pos.X - 20 >= AppManager.Instance.GameManager.GetPlayer1.Pos.X)
{ {
Attack(); Move(gameTime);
AppManager.Instance.GameManager.GetPlayer1.Death(name);
} }
base.Update(gameTime); base.Update(gameTime);
@ -46,16 +39,22 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public override void Attack() public override void Attack()
{ {
velocity.X = 0;
isAttaking = true;
if (isGoRight) if (isGoRight)
{ {
GraphicsComponent.StopAnimation(); if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight")
GraphicsComponent.StartAnimation("ZombieRightAttack"); {
GraphicsComponent.StartAnimation("ZombieAttackRight");
}
AppManager.Instance.GameManager.players[0].Death(name); AppManager.Instance.GameManager.players[0].Death(name);
} }
else if (!isGoRight) else if (!isGoRight)
{ {
GraphicsComponent.StopAnimation(); if (GraphicsComponent.GetCurrentAnimation != "ZombieLeftAttack")
GraphicsComponent.StartAnimation("ZombieLeftAttack"); {
GraphicsComponent.StartAnimation("ZombieLeftAttack");
}
AppManager.Instance.GameManager.players[0].Death(name); AppManager.Instance.GameManager.players[0].Death(name);
} }
} }
@ -67,20 +66,45 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public override void Move(GameTime gameTime) public override void Move(GameTime gameTime)
{ {
double delta = gameTime.ElapsedGameTime.TotalSeconds; float delta = (float)gameTime.ElapsedGameTime.TotalSeconds;
if (isGoRight) if (isGoRight)
{ {
if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight") if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight")
{
GraphicsComponent.StartAnimation("ZombieMoveRight"); GraphicsComponent.StartAnimation("ZombieMoveRight");
velocity = new Vector2(monster_speed, 0); }
velocity.X = monster_speed;
} }
else if (!isGoRight) else if (!isGoRight)
{ {
if(GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft") if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft")
{
GraphicsComponent.StartAnimation("ZombieMoveLeft"); GraphicsComponent.StartAnimation("ZombieMoveLeft");
velocity = new Vector2(-monster_speed, 0); }
velocity.X = -monster_speed;
} }
if(Pos.X >= rightBorder)
{
isGoRight = false;
}
else if(Pos.X <= leftBorder)
{
isGoRight = true;
}
}
public override void OnCollision(GameObject gameObject)
{
if(gameObject is Player)
{
if (AppManager.Instance.GameManager.players[0].IsAlive)
{
Attack();
}
}
base.OnCollision(gameObject);
} }
public void TakeDamage(int damage) public void TakeDamage(int damage)

View file

@ -5,18 +5,21 @@ 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.PlayerDeath;
namespace DangerousD.GameCore.GameObjects.LivingEntities namespace DangerousD.GameCore.GameObjects.LivingEntities
{ {
public class Player : LivingEntity public class Player : LivingEntity
{ {
bool isAlive = true;
public Player(Vector2 position) : base(position) public Player(Vector2 position) : base(position)
{ {
Width = 32; Width = 32;
Height = 64; Height = 64;
} }
public bool IsAlive { get { return isAlive; } }
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack" }, "ZombieMoveLeft");//TODO: Change to player protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack", "DeathFromZombie" }, "ZombieMoveLeft");//TODO: Change to player
public void Kill() public void Kill()
{ {
@ -25,7 +28,11 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
public void Death(string monsterName) public void Death(string monsterName)
{ {
//анимация по имени монстра if(monsterName == "Zombie")
{
DeathRectangle deathRectangle = new DeathRectangle(Pos, "DeathFrom" + monsterName);
}
isAlive = false;
} }
} }
} }

View file

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DangerousD.GameCore.GameObjects;
using DangerousD.GameCore.Graphics;
using Microsoft.Xna.Framework;
namespace DangerousD.GameCore.GameObjects.PlayerDeath
{
public class DeathRectangle : GameObject
{
public DeathRectangle(Vector2 pos, string DeathType) : base(pos)
{
Height = 128;
Width = 128;
PlayDeath(DeathType);
}
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> {"DeathFromZombie"},
"DeathFromZombie");
private void PlayDeath(string deathName)
{
if (GraphicsComponent.GetCurrentAnimation != "DeathFromZombie")
{
GraphicsComponent.StartAnimation("DeathFromZombie");
}
}
}
}

View file

@ -10,9 +10,9 @@ namespace DangerousD.GameCore.Levels
{ {
public void InitLevel() public void InitLevel()
{ {
new Player(new Vector2(0,0)); new Player(new Vector2(80,0));
var Zombie = new Zombie(new Vector2(256, 128)); var Zombie = new Zombie(new Vector2(140, 128));
var Frank = new Frank(new Vector2(384, 128)); var Frank = new Frank(new Vector2(384, 128));
new GrassBlock(new Vector2(0, 224)); new GrassBlock(new Vector2(0, 224));

View file

@ -19,6 +19,7 @@ namespace DangerousD.GameCore
public MapManager mapManager; public MapManager mapManager;
public PhysicsManager physicsManager; public PhysicsManager physicsManager;
public List<Player> players; public List<Player> players;
public List<GameObject> otherObjects = new();
public Player GetPlayer1 { get; private set; } public Player GetPlayer1 { get; private set; }
public GameManager() public GameManager()
{ {
@ -33,16 +34,27 @@ namespace DangerousD.GameCore
internal void Register(GameObject gameObject) internal void Register(GameObject gameObject)
{ {
if (gameObject is LivingEntity)
livingEntities.Add(gameObject as LivingEntity);
if (gameObject is Entity)
entities.Add(gameObject as Entity);
if (gameObject is MapObject)
mapObjects.Add(gameObject as MapObject);
if (gameObject is Player) if (gameObject is Player)
{ {
livingEntities.Add(gameObject as LivingEntity);
players.Add(gameObject as Player); players.Add(gameObject as Player);
GetPlayer1= players[0]; GetPlayer1 = players[0];
}
else if (gameObject is LivingEntity)
{
livingEntities.Add(gameObject as LivingEntity);
}
else if (gameObject is Entity)
{
entities.Add(gameObject as Entity);
}
else if (gameObject is MapObject)
{
mapObjects.Add(gameObject as MapObject);
}
else
{
otherObjects.Add(gameObject);
} }
} }
@ -54,6 +66,8 @@ namespace DangerousD.GameCore
item.Draw(_spriteBatch); item.Draw(_spriteBatch);
foreach (var item in livingEntities) foreach (var item in livingEntities)
item.Draw(_spriteBatch); item.Draw(_spriteBatch);
foreach (var item in otherObjects)
item.Draw(_spriteBatch);
} }
public void Update(GameTime gameTime) public void Update(GameTime gameTime)
@ -64,6 +78,8 @@ namespace DangerousD.GameCore
item.Update(gameTime); item.Update(gameTime);
foreach (var item in livingEntities) foreach (var item in livingEntities)
item.Update(gameTime); item.Update(gameTime);
foreach (var item in otherObjects)
item.Update(gameTime);
physicsManager.UpdateCollisions(entities, livingEntities, mapObjects, gameTime); physicsManager.UpdateCollisions(entities, livingEntities, mapObjects, gameTime);

View file

@ -92,8 +92,8 @@ namespace DangerousD.GameCore.Managers
{ {
if (livingEntities[j].Rectangle.Intersects(entities[i].Rectangle)) if (livingEntities[j].Rectangle.Intersects(entities[i].Rectangle))
{ {
livingEntities[j].OnCollision(); livingEntities[j].OnCollision(entities[i]);
entities[i].OnCollision(); entities[i].OnCollision(livingEntities[j]);
} }
} }
} }
@ -107,8 +107,8 @@ namespace DangerousD.GameCore.Managers
{ {
if (livingEntities[i].Rectangle.Intersects(livingEntities[j].Rectangle)) if (livingEntities[i].Rectangle.Intersects(livingEntities[j].Rectangle))
{ {
livingEntities[i].OnCollision(); livingEntities[i].OnCollision(livingEntities[j]);
livingEntities[j].OnCollision(); livingEntities[j].OnCollision(livingEntities[i]);
} }
} }
} }