KumiScript/Game.cs

51 lines
1.6 KiB
C#
Raw Normal View History

2024-01-26 05:37:51 +00:00
using KumiScript.Renderer;
using SDL2;
public class EngineWindow
{
internal ushort width {get; private set;}
internal ushort height {get; private set;}
internal string title {get; private set;}
public EngineWindow(ushort horizontalResolution, ushort verticalResolution, string windowTitle)
{
width = horizontalResolution;
height = verticalResolution;
title = windowTitle;
if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO) < 0)
throw new Exception("SDL2 Video init failed!");
if (SDL_image.IMG_Init(SDL_image.IMG_InitFlags.IMG_INIT_PNG) < 0)
throw new Exception("SDL2 Image init failed!");
}
public void show()
{
SDLWindow window = new SDLWindow(width, height, title);
SDLRenderer renderer = new SDLRenderer(window);
bool mainLoop = true;
SDL.SDL_Event e;
Scene s = new Scene(renderer);
SceneElement background = new SceneElement(new Background("Resources/Backgrounds/test.png", renderer), 0, 0);
SceneElement seiba = new SceneElement(new Sprite("Resources/Sprites/test.png", renderer), 0, 0);
s.AddElement(background);
s.AddElement(seiba);
while (mainLoop)
{
while (SDL.SDL_PollEvent(out e) > 0)
{
switch (e.type)
{
case SDL.SDL_EventType.SDL_QUIT:
mainLoop = false;
break;
}
renderer.Clear();
s.DrawScene();
renderer.SwapBuffers();
}
}
}
}