Compare commits
2 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
4b3478a9e9 | |
|
|
cac2399825 |
|
|
@ -1,5 +1,5 @@
|
||||||
var window = new Window("ASDLteroids", (int)(800 * Scene.SCALE), (int)(600 * Scene.SCALE));
|
var window = new Window("ASDLteroids", (int)(800 * Scene.SCALE), (int)(600 * Scene.SCALE));
|
||||||
var renderer = new Renderer(window);
|
var renderer = new Renderer(window);
|
||||||
var scene = new Scene(renderer);
|
var scene = new Scene(renderer, window);
|
||||||
|
|
||||||
scene.Run();
|
scene.Run();
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,6 @@
|
||||||
|
|
||||||
A Asteroids clone written with SDL2 in C#
|
A Asteroids clone written with SDL2 in C#
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
|
|
|
||||||
11
src/Scene.cs
11
src/Scene.cs
|
|
@ -3,12 +3,13 @@ using static SDL2.SDL;
|
||||||
class Scene
|
class Scene
|
||||||
{
|
{
|
||||||
public const double SCALE = 2;
|
public const double SCALE = 2;
|
||||||
public const int SCREEN_WIDTH = (int)(800 * SCALE);
|
public static int SCREEN_WIDTH = (int)(800 * SCALE);
|
||||||
public const int SCREEN_HEIGHT = (int)(600 * SCALE);
|
public static int SCREEN_HEIGHT = (int)(600 * SCALE);
|
||||||
private Ship ship;
|
private Ship ship;
|
||||||
private UI ui;
|
private UI ui;
|
||||||
private Renderer renderer;
|
private Renderer renderer;
|
||||||
private static Scene? instance;
|
private static Scene? instance;
|
||||||
|
private Window window;
|
||||||
|
|
||||||
public Ufo ufo;
|
public Ufo ufo;
|
||||||
public HashSet<Shot> Shots;
|
public HashSet<Shot> Shots;
|
||||||
|
|
@ -18,11 +19,12 @@ class Scene
|
||||||
public AudioPlayer AudioPlayer;
|
public AudioPlayer AudioPlayer;
|
||||||
public bool running = true;
|
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.ship = new Ship(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
|
||||||
this.ufo = new Ufo(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
|
this.ufo = new Ufo(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
|
||||||
this.ui = new UI();
|
this.ui = new UI();
|
||||||
|
this.window = window;
|
||||||
this.Shots = new HashSet<Shot>();
|
this.Shots = new HashSet<Shot>();
|
||||||
this.Asteroids = new HashSet<Asteroid>();
|
this.Asteroids = new HashSet<Asteroid>();
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
|
|
@ -50,6 +52,9 @@ class Scene
|
||||||
DateTime start = DateTime.Now;
|
DateTime start = DateTime.Now;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
var size = window.GetSize();
|
||||||
|
SCREEN_WIDTH = size.width;
|
||||||
|
SCREEN_HEIGHT = size.height;
|
||||||
start = DateTime.Now;
|
start = DateTime.Now;
|
||||||
pollEvents();
|
pollEvents();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ class Window
|
||||||
|
|
||||||
public Window(string title, int w, int h)
|
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)
|
public Window(string title, int x, int y, int w, int h, SDL_WindowFlags flags)
|
||||||
|
|
@ -23,4 +23,11 @@ class Window
|
||||||
{
|
{
|
||||||
return this.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