Compare commits

..

No commits in common. "master" and "0.1.1" have entirely different histories.

4 changed files with 12 additions and 44 deletions

View file

@ -1,26 +0,0 @@
# 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)

View file

@ -17,22 +17,24 @@ GameEndType :: enum {
} }
state: GameState state: GameState
ratio: f32 ratio: i32
texture_atlas_image: rl.Image texture_atlas_image: rl.Image
texture_atlas: rl.Texture2D texture_atlas: rl.Texture2D
window_width: i32 camera := rl.Camera2D {
window_height: i32 zoom = GLOBAL_SPRITE_SCALE,
}
window_width : i32; window_height: i32
// orignal resolution of space invaders: 256 x 224 px // orignal resolution of space invaders: 256 x 224 px
setup :: proc(state: ^GameState) { setup :: proc(state: ^GameState) {
using state using state
target_fps = 60 target_fps = 60
// monitor := rl.GetCurrentMonitor() monitor := rl.GetCurrentMonitor()
window_width = rl.GetScreenWidth() window_width = rl.GetMonitorWidth(monitor)
window_height = rl.GetScreenHeight() window_height = rl.GetMonitorHeight(monitor)
current_frame_time = rl.GetTime() current_frame_time = rl.GetTime()
previous_screen = .TITLE previous_screen = .TITLE
@ -58,7 +60,6 @@ update :: proc(state: ^GameState) {
update_screen(state) update_screen(state)
} }
target: rl.RenderTexture2D target: rl.RenderTexture2D
draw :: proc(state: ^GameState) { draw :: proc(state: ^GameState) {
rl.BeginTextureMode(target) rl.BeginTextureMode(target)
@ -74,10 +75,10 @@ draw :: proc(state: ^GameState) {
target.texture, target.texture,
{0, 0, f32(target.texture.width), f32(-target.texture.height)}, {0, 0, f32(target.texture.width), f32(-target.texture.height)},
{ {
(f32(window_width) - (f32(target.texture.width) * ratio)) / 2, f32((window_width - (target.texture.width * ratio)) / 2),
0, 0,
f32(target.texture.width) * ratio, f32(target.texture.width * ratio),
f32(target.texture.height) * ratio, f32(target.texture.height * ratio),
}, },
{0, 0}, {0, 0},
0, 0,
@ -102,11 +103,9 @@ main :: proc() {
state.screen_width = 720 state.screen_width = 720
state.screen_height = 520 state.screen_height = 520
rl.SetWindowMinSize(state.screen_width, state.screen_height)
target = rl.LoadRenderTexture(state.screen_width, state.screen_height) target = rl.LoadRenderTexture(state.screen_width, state.screen_height)
defer rl.UnloadRenderTexture(target) defer rl.UnloadRenderTexture(target)
ratio = f32(window_height) / f32(target.texture.height) ratio = i32(window_height / target.texture.height)
texture_atlas_image = rl.LoadImage(TEXTURE_ATLAS_PATH) texture_atlas_image = rl.LoadImage(TEXTURE_ATLAS_PATH)
texture_atlas = rl.LoadTextureFromImage(texture_atlas_image) texture_atlas = rl.LoadTextureFromImage(texture_atlas_image)
@ -114,11 +113,6 @@ main :: proc() {
log.info("Loaded images") log.info("Loaded images")
for !rl.WindowShouldClose() { for !rl.WindowShouldClose() {
if rl.IsWindowResized() {
window_width = rl.GetScreenWidth()
window_height = rl.GetScreenHeight()
ratio = f32(window_height) / f32(target.texture.height)
}
update(&state) update(&state)
draw(&state) draw(&state)
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB