Add Door, reverse play of animation

This commit is contained in:
Mootfrost777 2024-08-17 10:04:53 +03:00
parent a811021e7c
commit c5ac15987c
6 changed files with 61 additions and 23 deletions

View file

@ -10,7 +10,7 @@ namespace ZoFo.GameCore.GameObjects.Entities
{
public abstract class Entity : GameObject
{
public override GraphicsComponent graphicsComponent => null;
protected override GraphicsComponent graphicsComponent => null;
public CollisionComponent collisionComponent { get; protected set; }
public int Id { get; set; }
protected Entity(Vector2 position) : base(position)

View file

@ -1,8 +1,24 @@
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using ZoFo.GameCore.ZoFo_graphics;
namespace ZoFo.GameCore.GameObjects.Entities.Interactables;
public class Door
public class Door : Interactable
{
public bool isOpened;
protected override GraphicsComponent graphicsComponent { get; } = new(new List<string> { "DoorInteraction" }, "DoorInteraction");
public Door(Vector2 position) : base(position)
{
graphicsComponent.actionOfAnimationEnd += _ => { isOpened = !isOpened; };
}
public override void OnInteraction()
{
graphicsComponent.StartAnimation("DoorInteraction", isOpened);
}
}

View file

@ -19,7 +19,7 @@ public class Interactable : Entity
AppManager.Instance.server.AddData(new UpdateInteractionReady((sender as Player).Id, isReady));
}
public void OnInteraction()
public virtual void OnInteraction()
{
}

View file

@ -13,7 +13,7 @@ public abstract class GameObject
public Vector2 position;
public Vector2 rotation; //вектор направления объекта
public abstract GraphicsComponent graphicsComponent { get; }
protected abstract GraphicsComponent graphicsComponent { get; }
#region ServerSide
public GameObject(Vector2 position)
@ -84,10 +84,10 @@ public abstract class GameObject
if (color is null) color = new Color(1, 0, 0, 0.25f);
if (color.Value.A == 255) color = new Color(color.Value, 0.25f);
//spriteBatch.Draw(debugTexture,
// new Rectangle((_rectangle.X - GraphicsComponent.CameraPosition.X) * GraphicsComponent.scaling,
// (_rectangle.Y - GraphicsComponent.CameraPosition.Y) * GraphicsComponent.scaling,
// _rectangle.Width * GraphicsComponent.scaling,
// _rectangle.Height * GraphicsComponent.scaling), color.Value);
// new Rectangle((_rectangle.X - graphicsComponent.CameraPosition.X) * graphicsComponent.scaling,
// (_rectangle.Y - graphicsComponent.CameraPosition.Y) * graphicsComponent.scaling,
// _rectangle.Width * graphicsComponent.scaling,
// _rectangle.Height * graphicsComponent.scaling), color.Value);
//TODO: debugTexture
}

View file

@ -15,7 +15,7 @@ namespace ZoFo.GameCore.GameObjects.MapObjects
{
public virtual bool IsColliderOn { get; protected set; } = true;//Who added that?
public Rectangle sourceRectangle;
public override GraphicsComponent graphicsComponent { get; } = new();
protected override GraphicsComponent graphicsComponent { get; } = new();
/// <summary>
/// Создается простой объект на карте - no animations, только где, насколько крупно рисовать, по какой сорс ректанглу рисовать и из какой текстуры

View file

@ -26,6 +26,7 @@ namespace ZoFo.GameCore.ZoFo_graphics
private AnimationContainer currentAnimation;
static public int scaling = 5;
public int parentId;
public bool reverse;
public AnimationContainer CurrentAnimation
{
get
@ -126,7 +127,7 @@ namespace ZoFo.GameCore.ZoFo_graphics
}
}
public void StartAnimation(string startedanimationId)
public void StartAnimation(string startedanimationId, bool reverse = false)
{
/*
if (AppManager.Instance.multiPlayerStatus != MultiPlayerStatus.SinglePlayer)
@ -138,8 +139,13 @@ namespace ZoFo.GameCore.ZoFo_graphics
}
}
*/
currentFrame = 0;
this.reverse = reverse;
currentAnimation = animations.Find(x => x.Id == startedanimationId);
if (reverse)
currentFrame = currentAnimation.FramesCount;
else
currentFrame = 0;
buildSourceRectangle();
SetInterval();
@ -154,6 +160,21 @@ namespace ZoFo.GameCore.ZoFo_graphics
SetInterval();
}
private void AnimationEnd()
{
if (!currentAnimation.IsCycle)
{
if (actionOfAnimationEnd != null)
{
actionOfAnimationEnd(currentAnimation.Id);
}
currentAnimation = neitralAnimation;
}
currentFrame = 0;
}
public void Update()
{
if (currentAnimation is null)
@ -162,21 +183,22 @@ namespace ZoFo.GameCore.ZoFo_graphics
}
if (interval == 0)
{
currentFrame++;
if (currentAnimation.FramesCount <= currentFrame)
if (reverse)
{
if (!currentAnimation.IsCycle)
currentFrame--;
if (currentFrame <= 0)
{
if (actionOfAnimationEnd != null)
{
actionOfAnimationEnd(currentAnimation.Id);
}
currentAnimation = neitralAnimation;
AnimationEnd();
reverse = false;
}
}
else
{
currentFrame++;
if (currentAnimation.FramesCount <= currentFrame)
{
AnimationEnd();
}
currentFrame = 0;
}
buildSourceRectangle();