diff --git a/README.md b/README.md new file mode 100644 index 0000000..c048214 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# Space Invaders + +## About +This is a simple clone I wrote in a weekend using `odin-lang` and the available `raylib` bindings. + +# Software used +* `Aseprite` for pixel art +* `neovim` and the `ols` LSP +* `make` + +# Building & running +This should be buildable through the makefile on any platform (Windows, OSX & Linux) as long as you have the Odin compiler on hand. +If the makefile is causing you trouble the project can be directly ran with (which creates a binary file as well): + +```bash +odin run . +``` +or compiled to a binary with a custom output directory & speed optimizations (although they are not needed at all): +```bash +odin build . -out:space_invaders.exe -o:speed +``` + +# Gallery +![Space Invaders Start Game Screen](https://git.stefanstefanov.eu/bersk/odin-space-invaders/raw/commit/fd0cb31206a526aefe8be0cbf391e7f446c86afe/repo/start_game_screenshot.png) + +![In Game Screen](https://git.stefanstefanov.eu/bersk/odin-space-invaders/raw/commit/fd0cb31206a526aefe8be0cbf391e7f446c86afe/repo/in_game_screenshot.png) \ No newline at end of file diff --git a/main.odin b/main.odin index 85a7d5a..291bab2 100644 --- a/main.odin +++ b/main.odin @@ -17,24 +17,22 @@ GameEndType :: enum { } state: GameState -ratio: i32 +ratio: f32 texture_atlas_image: rl.Image texture_atlas: rl.Texture2D -camera := rl.Camera2D { - zoom = GLOBAL_SPRITE_SCALE, -} +window_width: i32 +window_height: i32 -window_width : i32; window_height: i32 // orignal resolution of space invaders: 256 x 224 px setup :: proc(state: ^GameState) { using state target_fps = 60 - monitor := rl.GetCurrentMonitor() - window_width = rl.GetMonitorWidth(monitor) - window_height = rl.GetMonitorHeight(monitor) + // monitor := rl.GetCurrentMonitor() + window_width = rl.GetScreenWidth() + window_height = rl.GetScreenHeight() current_frame_time = rl.GetTime() previous_screen = .TITLE @@ -60,6 +58,7 @@ update :: proc(state: ^GameState) { update_screen(state) } + target: rl.RenderTexture2D draw :: proc(state: ^GameState) { rl.BeginTextureMode(target) @@ -75,10 +74,10 @@ draw :: proc(state: ^GameState) { target.texture, {0, 0, f32(target.texture.width), f32(-target.texture.height)}, { - f32((window_width - (target.texture.width * ratio)) / 2), + (f32(window_width) - (f32(target.texture.width) * ratio)) / 2, 0, - f32(target.texture.width * ratio), - f32(target.texture.height * ratio), + f32(target.texture.width) * ratio, + f32(target.texture.height) * ratio, }, {0, 0}, 0, @@ -103,9 +102,11 @@ main :: proc() { state.screen_width = 720 state.screen_height = 520 + rl.SetWindowMinSize(state.screen_width, state.screen_height) + target = rl.LoadRenderTexture(state.screen_width, state.screen_height) defer rl.UnloadRenderTexture(target) - ratio = i32(window_height / target.texture.height) + ratio = f32(window_height) / f32(target.texture.height) texture_atlas_image = rl.LoadImage(TEXTURE_ATLAS_PATH) texture_atlas = rl.LoadTextureFromImage(texture_atlas_image) @@ -113,6 +114,11 @@ main :: proc() { log.info("Loaded images") for !rl.WindowShouldClose() { + if rl.IsWindowResized() { + window_width = rl.GetScreenWidth() + window_height = rl.GetScreenHeight() + ratio = f32(window_height) / f32(target.texture.height) + } update(&state) draw(&state) } diff --git a/repo/in_game_screenshot.png b/repo/in_game_screenshot.png new file mode 100644 index 0000000..5444f6d Binary files /dev/null and b/repo/in_game_screenshot.png differ diff --git a/repo/start_game_screenshot.png b/repo/start_game_screenshot.png new file mode 100644 index 0000000..9cfa28a Binary files /dev/null and b/repo/start_game_screenshot.png differ