diff --git a/Blarg.GameFramework/Blarg.GameFramework.csproj b/Blarg.GameFramework/Blarg.GameFramework.csproj index f5ddf15..f89f667 100644 --- a/Blarg.GameFramework/Blarg.GameFramework.csproj +++ b/Blarg.GameFramework/Blarg.GameFramework.csproj @@ -43,6 +43,24 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Blarg.GameFramework/ILooper.cs b/Blarg.GameFramework/ILooper.cs new file mode 100644 index 0000000..0be5747 --- /dev/null +++ b/Blarg.GameFramework/ILooper.cs @@ -0,0 +1,9 @@ +using System; + +namespace Blarg.GameFramework +{ + public interface ILooper + { + } +} + diff --git a/Blarg.GameFramework/IO/IFileSystem.cs b/Blarg.GameFramework/IO/IFileSystem.cs new file mode 100644 index 0000000..648afa2 --- /dev/null +++ b/Blarg.GameFramework/IO/IFileSystem.cs @@ -0,0 +1,13 @@ +using System; +using System.IO; + +namespace Blarg.GameFramework.IO +{ + public interface IFileSystem + { + Stream Open(string filename); + string TranslateFilePath(string path); + + string AssetsPath { get; } + } +} diff --git a/Blarg.GameFramework/Input/IKeyboard.cs b/Blarg.GameFramework/Input/IKeyboard.cs new file mode 100644 index 0000000..18cfc3b --- /dev/null +++ b/Blarg.GameFramework/Input/IKeyboard.cs @@ -0,0 +1,20 @@ +using System; + +namespace Blarg.GameFramework.Input +{ + public interface IKeyboard + { + bool HasPhysicalKeysForGameControls { get; } + + bool IsDown(Key key); + bool IsPressed(Key key); + void Lock(Key key); + + void OnPostUpdate(float delta); + + void Reset(); + + void RegisterListener(IKeyboardListener listener); + void UnregisterListener(IKeyboardListener listener); + } +} diff --git a/Blarg.GameFramework/Input/IKeyboardListener.cs b/Blarg.GameFramework/Input/IKeyboardListener.cs new file mode 100644 index 0000000..5f8b354 --- /dev/null +++ b/Blarg.GameFramework/Input/IKeyboardListener.cs @@ -0,0 +1,10 @@ +using System; + +namespace Blarg.GameFramework.Input +{ + public interface IKeyboardListener + { + bool OnKeyDown(Key key); + bool OnKeyUp(Key key); + } +} diff --git a/Blarg.GameFramework/Input/IMouse.cs b/Blarg.GameFramework/Input/IMouse.cs new file mode 100644 index 0000000..7f0006e --- /dev/null +++ b/Blarg.GameFramework/Input/IMouse.cs @@ -0,0 +1,23 @@ +using System; + +namespace Blarg.GameFramework.Input +{ + public interface IMouse + { + bool IsDown(MouseButton button); + bool IsPressed(MouseButton button); + void Lock(MouseButton button); + + int X { get; } + int Y { get; } + int DeltaX { get; } + int DeltaY { get; } + + void OnPostUpdate(float delta); + + void Reset(); + + void RegisterListener(IMouseListener listener); + void UnregisterListener(IMouseListener listener); + } +} diff --git a/Blarg.GameFramework/Input/IMouseListener.cs b/Blarg.GameFramework/Input/IMouseListener.cs new file mode 100644 index 0000000..c1419f8 --- /dev/null +++ b/Blarg.GameFramework/Input/IMouseListener.cs @@ -0,0 +1,11 @@ +using System; + +namespace Blarg.GameFramework.Input +{ + public interface IMouseListener + { + bool OnMouseButtonDown(MouseButton button, int x, int y); + bool OnMouseButtonUp(MouseButton button, int x, int y); + bool OnMouseMove(int x, int y, int deltaX, int deltaY); + } +} diff --git a/Blarg.GameFramework/Input/ITouchListener.cs b/Blarg.GameFramework/Input/ITouchListener.cs new file mode 100644 index 0000000..f45dabf --- /dev/null +++ b/Blarg.GameFramework/Input/ITouchListener.cs @@ -0,0 +1,11 @@ +using System; + +namespace Blarg.GameFramework.Input +{ + public interface ITouchListener + { + bool OnTouchDown(int id, int x, int y, bool isPrimary); + bool OnTouchUp(int id, bool isPrimary); + bool OnTouchMove(int id, int x, int y, int deltaX, int deltaY, bool isPrimary); + } +} diff --git a/Blarg.GameFramework/Input/ITouchPointer.cs b/Blarg.GameFramework/Input/ITouchPointer.cs new file mode 100644 index 0000000..e43d909 --- /dev/null +++ b/Blarg.GameFramework/Input/ITouchPointer.cs @@ -0,0 +1,19 @@ +using System; + +namespace Blarg.GameFramework.Input +{ + public interface ITouchPointer + { + int Id { get; } + int X { get; } + int Y { get; } + int DeltaX { get; } + int DeltaY { get; } + bool IsTouching { get; } + + bool IsTouchingWithinArea(int left, int top, int right, int bottom); + bool IsTouchingWithinArea(ref Rect area); + bool IsTouchingWithinArea(int centerX, int centerY, int radius); + bool IsTouchingWithinArea(ref Circle area); + } +} diff --git a/Blarg.GameFramework/Input/ITouchScreen.cs b/Blarg.GameFramework/Input/ITouchScreen.cs new file mode 100644 index 0000000..bfdac3a --- /dev/null +++ b/Blarg.GameFramework/Input/ITouchScreen.cs @@ -0,0 +1,23 @@ +using System; + +namespace Blarg.GameFramework.Input +{ + public interface ITouchScreen + { + bool IsMultitouchAvailable { get; } + bool IsTouching { get; } + bool WasTapped { get; } + int DownPointersCount { get; } + + ITouchPointer[] Pointers { get; } + ITouchPointer PrimaryPointer { get; } + ITouchPointer GetPointerById(int id); + + void OnPostUpdate(float delta); + + void Reset(); + + void RegisterListener(ITouchListener listener); + void UnregisterListener(ITouchListener listener); + } +} diff --git a/Blarg.GameFramework/Input/Key.cs b/Blarg.GameFramework/Input/Key.cs new file mode 100644 index 0000000..04043f0 --- /dev/null +++ b/Blarg.GameFramework/Input/Key.cs @@ -0,0 +1,170 @@ +using System; + +namespace Blarg.GameFramework.Input +{ + // this is based off OpenTK.Input.Key + + // this enum needs to include values that can encompass buttons used + // by all framework supported platforms (even if some of them go + // unused on certain platforms) + + public enum Key + { + Unknown = 0, + + /*** Base keys **********/ + + LeftShift, + RightShift, + LeftCtrl, + RightCtrl, + LeftAlt, + RightAlt, + LeftWindows, + RightWindows, + Menu, + F1, + F2, + F3, + F4, + F5, + F6, + F7, + F8, + F9, + F10, + F11, + F12, + F13, + F14, + F15, + F16, + F17, + F18, + F19, + F20, + F21, + F22, + F23, + F24, + F25, + F26, + F27, + F28, + F29, + F30, + F31, + F32, + F33, + F34, + F35, + Up, + Down, + Left, + Right, + Enter, + Escape, + Space, + Tab, + Backspace, + Insert, + Delete, + PageUp, + PageDown, + Home, + End, + CapsLock, + ScrollLock, + PrtScr, + Pause, + NumLock, + Clear, + Sleep, + Numpad0, + Numpad1, + Numpad2, + Numpad3, + Numpad4, + Numpad5, + Numpad6, + Numpad7, + Numpad8, + Numpad9, + NumpadDivide, + NumpadMultiply, + NumpadSubtract, + NumpadAdd, + NumpadDecimal, + NumpadEnter, + A, + B, + C, + D, + E, + F, + G, + H, + I, + J, + K, + L, + M, + N, + O, + P, + Q, + R, + S, + T, + U, + V, + W, + X, + Y, + Z, + Num0, + Num1, + Num2, + Num3, + Num4, + Num5, + Num6, + Num7, + Num8, + Num9, + Tilde, + Minus, + Plus, + LeftBracket, + RightBracket, + Semicolon, + Quote, + Comma, + Period, + Slash, + BackSlash, + + /*** Shared **************/ + + VolumeUp, + VolumeDown, + ButtonA, + ButtonB, + ButtonX, + ButtonY, + ButtonL, + ButtonR, + ButtonStart, + ButtonSelect, + + /*** Android extras ******/ + // some already exist above (home, menu, etc) + + Back, + Search, + + /*************************/ + + LastKey + } +} diff --git a/Blarg.GameFramework/Input/MouseButton.cs b/Blarg.GameFramework/Input/MouseButton.cs new file mode 100644 index 0000000..24cfb00 --- /dev/null +++ b/Blarg.GameFramework/Input/MouseButton.cs @@ -0,0 +1,27 @@ +using System; + +namespace Blarg.GameFramework.Input +{ + // this is based off OpenTK.Input.MouseButton + + // this enum needs to include values that can encompass buttons used + // by all framework supported platforms (even if some of them go + // unused on certain platforms) + + public enum MouseButton + { + Left, + Middle, + Right, + Button1, + Button2, + Button3, + Button4, + Button5, + Button6, + Button7, + Button8, + Button9, + LastButton + } +} diff --git a/Blarg.GameFramework/Math/Circle.cs b/Blarg.GameFramework/Math/Circle.cs new file mode 100644 index 0000000..8fad91d --- /dev/null +++ b/Blarg.GameFramework/Math/Circle.cs @@ -0,0 +1,68 @@ +using System; +using System.Runtime.InteropServices; + +namespace Blarg.GameFramework +{ + [StructLayout(LayoutKind.Sequential)] + public struct Circle : IEquatable + { + public int X; + public int Y; + public int Radius; + + public int Diameter + { + get { return Radius * 2; } + } + + public Circle(int x, int y, int radius) + { + X = x; + Y = y; + Radius = radius; + } + + public bool Contains(int x, int y) + { + int squaredDistance = ((X - x) * (X - x)) + ((Y - y) * (Y - y)); + int squaredRadius = Radius * Radius; + if (squaredDistance <= squaredRadius) + return true; + else + return false; + } + + public static bool operator ==(Circle left, Circle right) + { + return left.Equals(right); + } + + public static bool operator !=(Circle left, Circle right) + { + return !left.Equals(right); + } + + public override bool Equals(object obj) + { + if (obj is Circle) + return this.Equals((Circle)obj); + else + return false; + } + + public bool Equals(Circle other) + { + return (X == other.X && Y == other.Y && Radius == other.Radius); + } + + public override int GetHashCode() + { + return X.GetHashCode() ^ Y.GetHashCode() ^ Radius.GetHashCode(); + } + + public override string ToString() + { + return String.Format("{{Center:{0},{1} Radius:{2}}}", X, Y, Radius); + } + } +} diff --git a/Blarg.GameFramework/Math/Rect.cs b/Blarg.GameFramework/Math/Rect.cs new file mode 100644 index 0000000..4306234 --- /dev/null +++ b/Blarg.GameFramework/Math/Rect.cs @@ -0,0 +1,107 @@ +using System; +using System.Runtime.InteropServices; + +namespace Blarg.GameFramework +{ + [StructLayout(LayoutKind.Sequential)] + public struct Rect : IEquatable + { + public int Left; + public int Top; + public int Right; + public int Bottom; + + public int Width + { + get { return Math.Abs(Right - Left); } + } + + public int Height + { + get { return Math.Abs(Bottom - Top); } + } + + public Rect(int left, int top, int right, int bottom) + { + Left = left; + Top = top; + Right = right; + Bottom = bottom; + } + + public Rect(ref Rect r) + { + Left = r.Left; + Top = r.Top; + Right = r.Right; + Bottom = r.Bottom; + } + + public Rect(Rect r) + : this(ref r) + { + } + + public void Set(int left, int top, int right, int bottom) + { + Left = left; + Top = top; + Right = right; + Bottom = bottom; + } + + public void Set(ref Rect r) + { + Left = r.Left; + Top = r.Top; + Right = r.Right; + Bottom = r.Bottom; + } + + public void Set(Rect r) + { + Set(ref r); + } + + public bool Contains(int x, int y) + { + if (x >= Left && y >= Top && x <= Right && y <= Bottom) + return true; + else + return false; + } + + public static bool operator ==(Rect left, Rect right) + { + return left.Equals(right); + } + + public static bool operator !=(Rect left, Rect right) + { + return !left.Equals(right); + } + + public override bool Equals(object obj) + { + if (obj is Rect) + return this.Equals((Rect)obj); + else + return false; + } + + public bool Equals(Rect other) + { + return (Left == other.Left && Top == other.Top && Right == other.Right && Bottom == other.Bottom); + } + + public override int GetHashCode() + { + return Left.GetHashCode() ^ Top.GetHashCode() ^ Right.GetHashCode() ^ Bottom.GetHashCode(); + } + + public override string ToString() + { + return String.Format("{{{0}-{1},{2}-{3}}}", Left, Top, Right, Bottom); + } + } +}