mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2025-07-19 20:11:55 +08:00
Facings enum. StateMachine fixes
This commit is contained in:
@ -9,6 +9,44 @@ namespace Strawberry
|
||||
case Left;
|
||||
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()
|
||||
{
|
||||
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)
|
||||
{
|
||||
switch (c)
|
||||
|
32
src/Struct/Facings.bf
Normal file
32
src/Struct/Facings.bf
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user