Facings enum. StateMachine fixes

This commit is contained in:
Matt Thorson 2020-05-26 22:23:02 -07:00
parent be9e1cd877
commit 8faeeb98f0
3 changed files with 81 additions and 3 deletions

View File

@ -78,7 +78,7 @@ namespace Strawberry
private bool CallEnter() private bool CallEnter()
{ {
let s = states[state]; let s = states[state];
if (s != null) if (s != null && s.Enter != null)
{ {
inStateCall = true; inStateCall = true;
let set = s.Enter(); let set = s.Enter();
@ -92,7 +92,7 @@ namespace Strawberry
private bool CallUpdate() private bool CallUpdate()
{ {
let s = states[state]; let s = states[state];
if (s != null) if (s != null && s.Update != null)
{ {
inStateCall = true; inStateCall = true;
let set = s.Update(); let set = s.Update();
@ -106,7 +106,7 @@ namespace Strawberry
private bool CallExit() private bool CallExit()
{ {
let s = states[state]; let s = states[state];
if (s != null) if (s != null && s.Exit != null)
{ {
inStateCall = true; inStateCall = true;
let set = s.Exit(); let set = s.Exit();

View File

@ -9,6 +9,44 @@ namespace Strawberry
case Left; case Left;
case Up; case Up;
public int X
{
get
{
switch (this)
{
case .Left:
return -1;
case .Right:
return 1;
case .Up:
case .Down:
default:
}
return 0;
}
}
public int Y
{
get
{
switch (this)
{
case .Up:
return -1;
case .Down:
return 1;
case .Left:
case .Right:
default:
}
return 0;
}
}
public Cardinals Opposite() public Cardinals Opposite()
{ {
switch (this) switch (this)
@ -54,6 +92,14 @@ namespace Strawberry
} }
} }
static public implicit operator Cardinals(Facings f)
{
if (f == Facings.Right)
return Cardinals.Right;
else
return Cardinals.Left;
}
static public implicit operator Point(Cardinals c) static public implicit operator Point(Cardinals c)
{ {
switch (c) switch (c)

32
src/Struct/Facings.bf Normal file
View File

@ -0,0 +1,32 @@
namespace Strawberry
{
public enum Facings
{
case Right = 1;
case Left = -1;
public Facings Opposite()
{
if (this == .Right)
return .Left;
else
return .Right;
}
static public Facings FromInt(int i, Facings ifZero = .Right)
{
if (i == 0)
return ifZero;
else
return i;
}
static public implicit operator Facings(int i)
{
if (i < 0)
return .Left;
else
return .Right;
}
}
}