Add Door, reverse play of animation
This commit is contained in:
parent
a811021e7c
commit
c5ac15987c
6 changed files with 61 additions and 23 deletions
|
@ -10,7 +10,7 @@ namespace ZoFo.GameCore.GameObjects.Entities
|
||||||
{
|
{
|
||||||
public abstract class Entity : GameObject
|
public abstract class Entity : GameObject
|
||||||
{
|
{
|
||||||
public override GraphicsComponent graphicsComponent => null;
|
protected override GraphicsComponent graphicsComponent => null;
|
||||||
public CollisionComponent collisionComponent { get; protected set; }
|
public CollisionComponent collisionComponent { get; protected set; }
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
protected Entity(Vector2 position) : base(position)
|
protected Entity(Vector2 position) : base(position)
|
||||||
|
|
|
@ -1,8 +1,24 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using ZoFo.GameCore.ZoFo_graphics;
|
||||||
|
|
||||||
namespace ZoFo.GameCore.GameObjects.Entities.Interactables;
|
namespace ZoFo.GameCore.GameObjects.Entities.Interactables;
|
||||||
|
|
||||||
public class Door
|
public class Door : Interactable
|
||||||
{
|
{
|
||||||
public bool isOpened;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -19,7 +19,7 @@ public class Interactable : Entity
|
||||||
AppManager.Instance.server.AddData(new UpdateInteractionReady((sender as Player).Id, isReady));
|
AppManager.Instance.server.AddData(new UpdateInteractionReady((sender as Player).Id, isReady));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnInteraction()
|
public virtual void OnInteraction()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ public abstract class GameObject
|
||||||
public Vector2 position;
|
public Vector2 position;
|
||||||
|
|
||||||
public Vector2 rotation; //вектор направления объекта
|
public Vector2 rotation; //вектор направления объекта
|
||||||
public abstract GraphicsComponent graphicsComponent { get; }
|
protected abstract GraphicsComponent graphicsComponent { get; }
|
||||||
|
|
||||||
#region ServerSide
|
#region ServerSide
|
||||||
public GameObject(Vector2 position)
|
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 is null) color = new Color(1, 0, 0, 0.25f);
|
||||||
if (color.Value.A == 255) color = new Color(color.Value, 0.25f);
|
if (color.Value.A == 255) color = new Color(color.Value, 0.25f);
|
||||||
//spriteBatch.Draw(debugTexture,
|
//spriteBatch.Draw(debugTexture,
|
||||||
// new Rectangle((_rectangle.X - GraphicsComponent.CameraPosition.X) * GraphicsComponent.scaling,
|
// new Rectangle((_rectangle.X - graphicsComponent.CameraPosition.X) * graphicsComponent.scaling,
|
||||||
// (_rectangle.Y - GraphicsComponent.CameraPosition.Y) * GraphicsComponent.scaling,
|
// (_rectangle.Y - graphicsComponent.CameraPosition.Y) * graphicsComponent.scaling,
|
||||||
// _rectangle.Width * GraphicsComponent.scaling,
|
// _rectangle.Width * graphicsComponent.scaling,
|
||||||
// _rectangle.Height * GraphicsComponent.scaling), color.Value);
|
// _rectangle.Height * graphicsComponent.scaling), color.Value);
|
||||||
|
|
||||||
//TODO: debugTexture
|
//TODO: debugTexture
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace ZoFo.GameCore.GameObjects.MapObjects
|
||||||
{
|
{
|
||||||
public virtual bool IsColliderOn { get; protected set; } = true;//Who added that?
|
public virtual bool IsColliderOn { get; protected set; } = true;//Who added that?
|
||||||
public Rectangle sourceRectangle;
|
public Rectangle sourceRectangle;
|
||||||
public override GraphicsComponent graphicsComponent { get; } = new();
|
protected override GraphicsComponent graphicsComponent { get; } = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Создается простой объект на карте - no animations, только где, насколько крупно рисовать, по какой сорс ректанглу рисовать и из какой текстуры
|
/// Создается простой объект на карте - no animations, только где, насколько крупно рисовать, по какой сорс ректанглу рисовать и из какой текстуры
|
||||||
|
|
|
@ -26,6 +26,7 @@ namespace ZoFo.GameCore.ZoFo_graphics
|
||||||
private AnimationContainer currentAnimation;
|
private AnimationContainer currentAnimation;
|
||||||
static public int scaling = 5;
|
static public int scaling = 5;
|
||||||
public int parentId;
|
public int parentId;
|
||||||
|
public bool reverse;
|
||||||
public AnimationContainer CurrentAnimation
|
public AnimationContainer CurrentAnimation
|
||||||
{
|
{
|
||||||
get
|
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)
|
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);
|
currentAnimation = animations.Find(x => x.Id == startedanimationId);
|
||||||
|
if (reverse)
|
||||||
|
currentFrame = currentAnimation.FramesCount;
|
||||||
|
else
|
||||||
|
currentFrame = 0;
|
||||||
|
|
||||||
buildSourceRectangle();
|
buildSourceRectangle();
|
||||||
SetInterval();
|
SetInterval();
|
||||||
|
@ -154,16 +160,7 @@ namespace ZoFo.GameCore.ZoFo_graphics
|
||||||
SetInterval();
|
SetInterval();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update()
|
private void AnimationEnd()
|
||||||
{
|
|
||||||
if (currentAnimation is null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (interval == 0)
|
|
||||||
{
|
|
||||||
currentFrame++;
|
|
||||||
if (currentAnimation.FramesCount <= currentFrame)
|
|
||||||
{
|
{
|
||||||
if (!currentAnimation.IsCycle)
|
if (!currentAnimation.IsCycle)
|
||||||
{
|
{
|
||||||
|
@ -176,7 +173,32 @@ namespace ZoFo.GameCore.ZoFo_graphics
|
||||||
}
|
}
|
||||||
|
|
||||||
currentFrame = 0;
|
currentFrame = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
if (currentAnimation is null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (interval == 0)
|
||||||
|
{
|
||||||
|
if (reverse)
|
||||||
|
{
|
||||||
|
currentFrame--;
|
||||||
|
if (currentFrame <= 0)
|
||||||
|
{
|
||||||
|
AnimationEnd();
|
||||||
|
reverse = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
currentFrame++;
|
||||||
|
if (currentAnimation.FramesCount <= currentFrame)
|
||||||
|
{
|
||||||
|
AnimationEnd();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildSourceRectangle();
|
buildSourceRectangle();
|
||||||
|
|
Loading…
Add table
Reference in a new issue