Skip to content

Commit 4f10e26

Browse files
committed
Gamebox is now fully static
1 parent f88e5f5 commit 4f10e26

File tree

9 files changed

+87
-43
lines changed

9 files changed

+87
-43
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
the animation system is one of the more complex systems RayWrapper has
2+
3+
but it isn't has difficult as it used to be, you don't want to use the old revisions of this system x.x
4+
5+
to sum it up, the animation system is a keyframe system
6+
7+
to start you need a class that extends from the animation abstract class and make a constructor for it
8+
9+
```c#
10+
public class ExampleAnimation : Animation
11+
{
12+
// objects go here
13+
14+
public ExampleAnimation()
15+
{
16+
// animation steps go here, don't
17+
// forget to init the objects before starting the animation steps
18+
}
19+
20+
```
21+
22+
the most difficult part of this system is how to animate
23+
24+
there are 2 layers to the system, `stepConditions` and `Transitions`
25+
26+
the `stepCondidtions` allow you to test for things before the next step can proceed, if you need a stepCondition anywhere, you need to add them for previous steps (you can just make it return true)
27+
28+
now for `Transitions`
29+
30+
inorder to add a transition to an animation, you can do `AddTransition(step, transition)` (animation steps start at 0 btw)
31+
32+
there are a few different types of transitions
33+
- Move
34+
- Size
35+
- Slide
36+
37+
it shouldn't be too difficult to fill out the requirements for the transitions, if you need help you can go to the Animations example (https://github.com/SWCreeperKing/RayWrapper/tree/master/RayWrapperTester/Animations)
38+
39+
the Animation also has its own gameobject register to add to
40+
41+
once you made your animation you need to add it to the `Animator`
42+
43+
the `Animator` has 2 options for animations:
44+
- normal (animations can stack)
45+
- queue (animations wait for one to pass before the next one can)

Examples & Docs/Discord Integration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ in the `Init()` of your `GameLoop` do the following:
66

77
```C#
88
GameBox.discordAppId = // this should be the app id used for richpresence
9-
GameBox.Gb.InitDiscord();
9+
GameBox.InitDiscord();
1010
```
1111
now you need to set discord integration stuff, there are alot of values you can play with for discord integration
1212

Examples & Docs/Save System.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
the built in save system is (should be) very trust worthy
22

33
```C#
4-
using static GameBox; // do this so you dont need to do GameBox.Gb all the time
5-
64
new GameBox(new Program(), new Vector2(window width, window height, "title"))
75

86
public class Program : GameLoop
97
{
108
public override void Init()
119
{
12-
Gb.InitSaveSystem("developer name", "app name");
10+
GameBox.InitSaveSystem("developer name", "app name");
1311

1412
// for every object you want to save
1513
// its best to nest save objects to not create ALOT of files
16-
Gb.RegisterSaveItem(obj, "file name");
14+
GameBox.RegisterSaveItem(obj, "file name");
1715
}
1816

1917
public override void UpdateLoop()
@@ -31,10 +29,10 @@ make sure to execute AFTER the save items are registered in `Init()`
3129

3230
```c#
3331
// load
34-
Gb.LoadItems();
32+
GameBox.LoadItems();
3533

3634
// save
37-
Gb.SaveItem();
35+
GameBox.SaveItem();
3836
```
3937

4038
adding encryption is very easy to add

Examples & Docs/Scheduler System.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ schedulers are for timing events
55
it is very easy to add a scheduler, however you should use low ms times with caution
66

77
```c#
8-
GameBox.Gb.AddScheduler(new Scheduler(timeInMsToRepeat, onTime: () => {
8+
GameBox.AddScheduler(new Scheduler(timeInMsToRepeat, onTime: () => {
99
// what you want to happpen when it repeats
1010
}, setTime: true by default
1111
/*if set time is false then the scheduler will execute the onTime event on Init*/))

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This is a Wrapper for Raylib-cs
1+
This is a Wrapper for the C# port (Raylib-cs) of RayLib, a 'bare-bones' graphics library
22

33
Made with .Net5
44

RayWrapper/GameBox.cs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Threading.Tasks;
88
using Raylib_cs;
99
using RayWrapper.Animation;
10+
using RayWrapper.Animation.Transitions;
1011
using RayWrapper.CollisionSystem;
1112
using RayWrapper.Discord;
1213
using RayWrapper.GameConsole;
@@ -43,7 +44,7 @@ public class GameBox
4344
public static Vector2 WindowSize { get; private set; }
4445
public static GameLoop Scene { get; set; }
4546
public static string Title { get; private set; }
46-
public static GameBox Gb => _instance;
47+
// public static GameBox Gb => _instance;
4748
public static bool IsMouseOccupied => mouseOccupier != null;
4849
public static bool enableConsole = true;
4950
public static float scale;
@@ -52,7 +53,6 @@ public class GameBox
5253

5354
public static AlertBox alertBox = null;
5455

55-
// public static Animator animator = new();
5656
public static ColorModule backgroundColor = new(40);
5757
public static ColorModule letterboxColor = new(20);
5858
public static bool isDebugTool;
@@ -74,9 +74,10 @@ public class GameBox
7474
private static bool _isDrawing;
7575
private static bool _isConsole;
7676
private static RenderTexture2D _target;
77-
private static GameBox _instance;
77+
// private static GameBox _instance;
7878
private static bool _initDiscord;
7979
private static bool _initCollision;
80+
private static bool _hasInit;
8081

8182
public static int FPS
8283
{
@@ -97,9 +98,9 @@ public static Font Font
9798
public GameBox(GameLoop scene, Vector2 windowSize, string title = "Untitled Window", int fps = 60,
9899
string iconPath = "")
99100
{
100-
if (_instance is not null) throw new ApplicationException("Only 1 instance of GameBox can be created");
101+
if (_hasInit) throw new ApplicationException("Only 1 instance of GameBox can be created");
101102
SetTraceLogCallback(Logger.RayLog);
102-
_instance = this;
103+
_hasInit = true;
103104
SetConfigFlags(ConfigFlags.FLAG_WINDOW_RESIZABLE);
104105
(Scene, WindowSize) = (scene, windowSize);
105106
screenGrid = new ScreenGrid();
@@ -118,7 +119,7 @@ public GameBox(GameLoop scene, Vector2 windowSize, string title = "Untitled Wind
118119
Start();
119120
}
120121

121-
private void Start()
122+
private static void Start()
122123
{
123124
Task.Run(() =>
124125
{
@@ -159,7 +160,7 @@ private void Start()
159160
Dispose();
160161
}
161162

162-
public void InitDiscord()
163+
public static void InitDiscord()
163164
{
164165
if (_initDiscord) return;
165166
_initDiscord = true;
@@ -168,7 +169,7 @@ public void InitDiscord()
168169
AddScheduler(new Scheduler(100, DiscordIntegration.UpdateActivity));
169170
}
170171

171-
public void InitCollision()
172+
public static void InitCollision()
172173
{
173174
if (_initCollision) return;
174175
_initCollision = true;
@@ -190,7 +191,7 @@ public void InitCollision()
190191
});
191192
}
192193

193-
private void Update()
194+
private static void Update()
194195
{
195196
if (f11Fullscreen && IsKeyPressed(KeyboardKey.KEY_F11))
196197
{
@@ -211,7 +212,7 @@ private void Update()
211212
Scene.Update();
212213
}
213214

214-
public void RenderRenderTexture(RenderTexture2D texture2D, Vector2 pos, Action update, Action draw)
215+
public static void RenderRenderTexture(RenderTexture2D texture2D, Vector2 pos, Action update, Action draw)
215216
{
216217
if (!_isDrawing) return;
217218
var before = new Vector2(mousePos.X, mousePos.Y);
@@ -227,7 +228,7 @@ public void RenderRenderTexture(RenderTexture2D texture2D, Vector2 pos, Action u
227228
mousePos = before;
228229
}
229230

230-
public void Render()
231+
private static void Render()
231232
{
232233
BeginTextureMode(_target);
233234
_isDrawing = true;
@@ -271,7 +272,7 @@ public void Render()
271272
_isDrawing = false;
272273
}
273274

274-
public void Dispose()
275+
private static void Dispose()
275276
{
276277
if (_isDrawing) EndDrawing();
277278
_schedulers.Clear();
@@ -281,22 +282,22 @@ public void Dispose()
281282
Environment.Exit(0);
282283
}
283284

284-
public void AddScheduler(Scheduler schedule) => _schedulers.Add(schedule);
285-
public void ChangeFps(int fps) => SetTargetFPS(FPS = fps);
285+
public static void AddScheduler(Scheduler schedule) => _schedulers.Add(schedule);
286+
public static void ChangeFps(int fps) => SetTargetFPS(FPS = fps);
286287
public static long GetTimeMs() => DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
287288

288289
# region save system
289290

290-
public void InitSaveSystem(string developerName, string appName) =>
291+
public static void InitSaveSystem(string developerName, string appName) =>
291292
(DeveloperName, AppName, SaveInit) = (developerName, appName, true);
292293

293294
public static string GetSavePath => File.Exists("UseLocalPath") ? $"{AppName}" : $"{CoreDir}/{DeveloperName}/{AppName}";
294-
public void SaveItems() => SaveList.SaveItems(this);
295-
public void LoadItems() => SaveList.LoadItems(this);
296-
public void DeleteFile(string name) => SaveList.DeleteFile(name, this);
297-
public void DeleteAll() => SaveList.DeleteAll(this);
298-
public void RegisterSaveItem<T>(T obj, string fileName) => SaveList.Add(new SaveItem<T>(obj, fileName));
299-
public void DeRegisterSaveItem(string fileName) => SaveList.RemoveAll(m => m.FileName() == fileName);
295+
public static void SaveItems() => SaveList.SaveItems();
296+
public static void LoadItems() => SaveList.LoadItems();
297+
public static void DeleteFile(string name) => SaveList.DeleteFile(name);
298+
public static void DeleteAll() => SaveList.DeleteAll();
299+
public static void RegisterSaveItem<T>(T obj, string fileName) => SaveList.Add(new SaveItem<T>(obj, fileName));
300+
public static void DeRegisterSaveItem(string fileName) => SaveList.RemoveAll(m => m.FileName() == fileName);
300301

301302
#endregion
302303

@@ -308,7 +309,7 @@ public static void AddTime(long ms)
308309
timeAverage = CollisionTime.Sum() / (double)CollisionTime.Length;
309310
}
310311

311-
public void CalcMousePos()
312+
public static void CalcMousePos()
312313
{
313314
var mouse = GetMousePosition();
314315
scale = Math.Min(GetScreenWidth() / WindowSize.X, GetScreenHeight() / WindowSize.Y);

RayWrapper/Vars/SaveItem.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static void LoadToFile(this ISave t, string path)
105105
sr.Close();
106106
}
107107

108-
public static void SaveItems(this List<ISave> saveList, GameBox gb)
108+
public static void SaveItems(this List<ISave> saveList)
109109
{
110110
singleConsole.WriteToConsole($"{SKYBLUE}Saving Start @ {DateTime.Now:G}");
111111
var start = GetTimeMs();
@@ -116,7 +116,7 @@ public static void SaveItems(this List<ISave> saveList, GameBox gb)
116116
singleConsole.WriteToConsole($"{SKYBLUE}Saved in {new TimeVar(GetTimeMs() - start)}");
117117
}
118118

119-
public static void LoadItems(this List<ISave> saveList, GameBox gb)
119+
public static void LoadItems(this List<ISave> saveList)
120120
{
121121
singleConsole.WriteToConsole($"{SKYBLUE}Loading Start @ {DateTime.Now:G}");
122122
var start = GetTimeMs();
@@ -127,7 +127,7 @@ public static void LoadItems(this List<ISave> saveList, GameBox gb)
127127
singleConsole.WriteToConsole($"{SKYBLUE}Loaded in {new TimeVar(GetTimeMs() - start)}");
128128
}
129129

130-
public static void DeleteFile(this List<ISave> saveList, string name, GameBox gb)
130+
public static void DeleteFile(this IEnumerable<ISave> saveList, string name)
131131
{
132132
ISave.IsSaveInitCheck();
133133
var path = GetSavePath;
@@ -138,7 +138,7 @@ public static void DeleteFile(this List<ISave> saveList, string name, GameBox gb
138138
File.Delete(file);
139139
}
140140

141-
public static void DeleteAll(this List<ISave> saveList, GameBox gb)
141+
public static void DeleteAll(this IEnumerable<ISave> saveList)
142142
{
143143
ISave.IsSaveInitCheck();
144144
var path = GetSavePath;

RayWrapperTester/Program.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public override void Init()
175175
Button bRend = new(new Vector2(60, 90), "test");
176176
_tbv.AddTab("Render 2d test", new EmptyRender(() =>
177177
{
178-
Gb.RenderRenderTexture(rt2d, new Vector2(40, 80), () => bRend.Update(),
178+
RenderRenderTexture(rt2d, new Vector2(40, 80), () => bRend.Update(),
179179
() =>
180180
{
181181
ClearBackground(RED);
@@ -224,23 +224,23 @@ public override void RenderLoop()
224224

225225
public void SaveTesting()
226226
{
227-
Gb.InitSaveSystem("SW_CreeperKing", "SaveTesting");
227+
InitSaveSystem("SW_CreeperKing", "SaveTesting");
228228
var t = new Test();
229-
Gb.RegisterSaveItem(t, "test item");
229+
RegisterSaveItem(t, "test item");
230230
t.i = 10;
231231
Console.WriteLine($"i = {t.i}"); // 10
232-
Gb.SaveItems();
232+
SaveItems();
233233
t.i = 2;
234234
Console.WriteLine($"i = {t.i}"); // 2
235-
Gb.LoadItems();
235+
LoadItems();
236236
Console.WriteLine($"i = {t.i}"); // 10
237237
t.Set(new Test());
238238
Console.WriteLine($"i = {t.i}"); // 6
239-
Gb.LoadItems();
239+
LoadItems();
240240
Console.WriteLine($"i = {t.i}"); // 10
241241
t = new Test();
242242
Console.WriteLine($"i = {t.i}"); // 6
243-
Gb.LoadItems();
243+
LoadItems();
244244
Console.WriteLine($"i = {t.i}"); // 6
245245
}
246246
}

RayWrapperTesterCollision/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static void Main(string[] args)
1919

2020
public override void Init()
2121
{
22-
Gb.InitCollision();
22+
InitCollision();
2323
var wx = WindowSize.X;
2424
var wy = WindowSize.Y;
2525
CollisionLayerTags.Add(("circle", "bar"));

0 commit comments

Comments
 (0)