made window responsive
This commit is contained in:
parent
cac2399825
commit
4b3478a9e9
|
|
@ -1,5 +1,5 @@
|
|||
var window = new Window("ASDLteroids", (int)(800 * Scene.SCALE), (int)(600 * Scene.SCALE));
|
||||
var renderer = new Renderer(window);
|
||||
var scene = new Scene(renderer);
|
||||
var scene = new Scene(renderer, window);
|
||||
|
||||
scene.Run();
|
||||
|
|
|
|||
11
src/Scene.cs
11
src/Scene.cs
|
|
@ -3,12 +3,13 @@ using static SDL2.SDL;
|
|||
class Scene
|
||||
{
|
||||
public const double SCALE = 2;
|
||||
public const int SCREEN_WIDTH = (int)(800 * SCALE);
|
||||
public const int SCREEN_HEIGHT = (int)(600 * SCALE);
|
||||
public static int SCREEN_WIDTH = (int)(800 * SCALE);
|
||||
public static int SCREEN_HEIGHT = (int)(600 * SCALE);
|
||||
private Ship ship;
|
||||
private UI ui;
|
||||
private Renderer renderer;
|
||||
private static Scene? instance;
|
||||
private Window window;
|
||||
|
||||
public Ufo ufo;
|
||||
public HashSet<Shot> Shots;
|
||||
|
|
@ -18,11 +19,12 @@ class Scene
|
|||
public AudioPlayer AudioPlayer;
|
||||
public bool running = true;
|
||||
|
||||
public Scene(Renderer renderer)
|
||||
public Scene(Renderer renderer, Window window)
|
||||
{
|
||||
this.ship = new Ship(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
|
||||
this.ufo = new Ufo(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
|
||||
this.ui = new UI();
|
||||
this.window = window;
|
||||
this.Shots = new HashSet<Shot>();
|
||||
this.Asteroids = new HashSet<Asteroid>();
|
||||
this.renderer = renderer;
|
||||
|
|
@ -50,6 +52,9 @@ class Scene
|
|||
DateTime start = DateTime.Now;
|
||||
while (true)
|
||||
{
|
||||
var size = window.GetSize();
|
||||
SCREEN_WIDTH = size.width;
|
||||
SCREEN_HEIGHT = size.height;
|
||||
start = DateTime.Now;
|
||||
pollEvents();
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ class Window
|
|||
|
||||
public Window(string title, int w, int h)
|
||||
{
|
||||
window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WindowFlags.SDL_WINDOW_VULKAN);
|
||||
window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WindowFlags.SDL_WINDOW_VULKAN | SDL_WindowFlags.SDL_WINDOW_RESIZABLE);
|
||||
}
|
||||
|
||||
public Window(string title, int x, int y, int w, int h, SDL_WindowFlags flags)
|
||||
|
|
@ -23,4 +23,11 @@ class Window
|
|||
{
|
||||
return this.window;
|
||||
}
|
||||
|
||||
public (int width, int height) GetSize()
|
||||
{
|
||||
int w, h;
|
||||
SDL_GetWindowSize(this.window, out w, out h);
|
||||
return (w, h);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue