From 8faeeb98f0139599ac541bfae6d8147ce6bb5686 Mon Sep 17 00:00:00 2001 From: Matt Thorson Date: Tue, 26 May 2020 22:23:02 -0700 Subject: [PATCH] Facings enum. StateMachine fixes --- src/Components/Logic/StateMachine.bf | 6 ++-- src/Struct/Cardinals.bf | 46 ++++++++++++++++++++++++++++ src/Struct/Facings.bf | 32 +++++++++++++++++++ 3 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 src/Struct/Facings.bf diff --git a/src/Components/Logic/StateMachine.bf b/src/Components/Logic/StateMachine.bf index 30e8be2..133732c 100644 --- a/src/Components/Logic/StateMachine.bf +++ b/src/Components/Logic/StateMachine.bf @@ -78,7 +78,7 @@ namespace Strawberry private bool CallEnter() { let s = states[state]; - if (s != null) + if (s != null && s.Enter != null) { inStateCall = true; let set = s.Enter(); @@ -92,7 +92,7 @@ namespace Strawberry private bool CallUpdate() { let s = states[state]; - if (s != null) + if (s != null && s.Update != null) { inStateCall = true; let set = s.Update(); @@ -106,7 +106,7 @@ namespace Strawberry private bool CallExit() { let s = states[state]; - if (s != null) + if (s != null && s.Exit != null) { inStateCall = true; let set = s.Exit(); diff --git a/src/Struct/Cardinals.bf b/src/Struct/Cardinals.bf index 214dc78..64cb7be 100644 --- a/src/Struct/Cardinals.bf +++ b/src/Struct/Cardinals.bf @@ -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) diff --git a/src/Struct/Facings.bf b/src/Struct/Facings.bf new file mode 100644 index 0000000..e104b0d --- /dev/null +++ b/src/Struct/Facings.bf @@ -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; + } + } +}