1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
using System.Numerics;
using Raylib_cs;
namespace OnekoOnline;
static class OnekoOnline
{
public static readonly ConfigFile Config = new("config.conf");
public static Net.Server? Server;
public static Net.Client? Client;
public static readonly int WindowX = 320;
public static readonly int WindowY = 240;
public static readonly int WindowScale = Config.GetValue("WindowScale", 2);
public static Vector2 Resolution => new(WindowX, WindowY);
public static readonly bool SpectatorMode = Config.GetValue("SpectatorMode", false);
public static Font DefaultFont;
const ConfigFlags raylibConfFlags = ConfigFlags.VSyncHint;
public static void Main()
{
Raylib.SetConfigFlags(raylibConfFlags);
Raylib.InitWindow(WindowX*WindowScale, WindowY*WindowScale, "OnekoOnline");
Raylib.SetTargetFPS(30);
Raylib.HideCursor();
MouseLocal LocalMouse = new();
if (!SpectatorMode) {OnekoLocal LocalOneko = new();}
RenderTexture2D RenderTexture = Raylib.LoadRenderTexture(WindowX, WindowY);
int port = Config.GetValue("ServerPort", 42069);
string serverPassword = Config.GetValue("ServerPassword", "");
if (Config.GetValue("HostServer", false)) {
Server = new(port, Config.GetValue("ServerMaxUsers", 32));
Client = new("127.0.0.1", port, serverPassword);
} else {
Client = new(Config.GetValue("ServerIP", "pond.sarahduck.ca"), port, serverPassword);
}
Net.Client.UserConnected += OnekoNet.SpawnNetNeko;
Net.Client.UserConnected += MouseNet.SpawnNetMouse;
DefaultFont = Raylib.LoadFont("misc/MPlusBitmap.fnt");
while (!Raylib.WindowShouldClose())
{
//Poll networking
Client?.Poll();
Server?.Poll();
Raylib.BeginTextureMode(RenderTexture);
Raylib.ClearBackground(Color.Gray);
Raylib.DrawTextEx(DefaultFont, "こんにちは", new(17,18), 11, 0, Color.White);
Raylib.DrawText("Oneko Online", 10, 9, 8, Color.White);
Drawable.DrawAll();
Raylib.EndTextureMode();
Raylib.BeginDrawing();
//Dunno why, but it renders upside down, so I flip it here
Raylib.DrawTexturePro(RenderTexture.Texture, new Rectangle(0f,0f,WindowX,-WindowY), new Rectangle(0,0,WindowX*WindowScale,WindowY*WindowScale), Vector2.Zero,0f,Color.White);
Raylib.EndDrawing();
}
Client?.Disconnect();
Server?.Disconnect();
Drawable.DisposeAll();
Raylib.CloseWindow();
Config.SaveFile();
}
}
|