updated build script, added bugged alien shooting
This commit is contained in:
parent
02ca71ec5f
commit
d21ccf3dc8
3 changed files with 51 additions and 13 deletions
13
Makefile
13
Makefile
|
|
@ -4,10 +4,10 @@ DEB_FOLDER=debug_x64_win
|
||||||
BIN_FOLDER=./bin
|
BIN_FOLDER=./bin
|
||||||
|
|
||||||
build: clean
|
build: clean
|
||||||
odin run . -out:bin/${EXE}.exe -debug
|
odin build . -out:${BIN_FOLDER}/${EXE}.exe -debug
|
||||||
|
|
||||||
build_release: clean
|
build_release: clean
|
||||||
odin build . -out:bin/${EXE}_rel.exe -o:speed -subsystem:windows
|
odin build . -out:${BIN_FOLDER}/${EXE}_rel.exe -o:speed -subsystem:windows
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf ${BIN_FOLDER}/${EXE}.*
|
rm -rf ${BIN_FOLDER}/${EXE}.*
|
||||||
|
|
@ -18,6 +18,11 @@ package: build_release
|
||||||
mkdir ${BIN_FOLDER}/${REL_FOLDER}
|
mkdir ${BIN_FOLDER}/${REL_FOLDER}
|
||||||
cp -r ./assets/ ${BIN_FOLDER}/${REL_FOLDER}/
|
cp -r ./assets/ ${BIN_FOLDER}/${REL_FOLDER}/
|
||||||
cp ${BIN_FOLDER}/${EXE}_rel.exe ${BIN_FOLDER}/${REL_FOLDER}/${EXE}.exe
|
cp ${BIN_FOLDER}/${EXE}_rel.exe ${BIN_FOLDER}/${REL_FOLDER}/${EXE}.exe
|
||||||
|
tar.exe -a -c -f ${BIN_FOLDER}/release_x64_win.zip ${BIN_FOLDER}/release_x64_win
|
||||||
|
|
||||||
|
run: build
|
||||||
|
${BIN_FOLDER}/${EXE}.exe
|
||||||
|
|
||||||
|
run_rel: build_release
|
||||||
|
${BIN_FOLDER}/${EXE}_rel.exe
|
||||||
|
|
||||||
run:
|
|
||||||
space_invaders.exe
|
|
||||||
|
|
|
||||||
47
game.odin
47
game.odin
|
|
@ -3,6 +3,8 @@ package space_invaders
|
||||||
import "core:c"
|
import "core:c"
|
||||||
import "core:log"
|
import "core:log"
|
||||||
import glm "core:math/linalg/glsl"
|
import glm "core:math/linalg/glsl"
|
||||||
|
import "core:math/rand"
|
||||||
|
import "core:time"
|
||||||
|
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
|
|
@ -37,6 +39,8 @@ Bullet :: struct {
|
||||||
position: glm.vec2,
|
position: glm.vec2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rng := rand.Rand{}
|
||||||
|
|
||||||
collideAABB :: proc(a_rect: glm.vec2, a_pos: glm.vec2, b_rect: glm.vec2, b_pos: glm.vec2) -> bool {
|
collideAABB :: proc(a_rect: glm.vec2, a_pos: glm.vec2, b_rect: glm.vec2, b_pos: glm.vec2) -> bool {
|
||||||
return(
|
return(
|
||||||
a_pos.x < b_pos.x + f32(b_rect.x / 2) &&
|
a_pos.x < b_pos.x + f32(b_rect.x / 2) &&
|
||||||
|
|
@ -84,6 +88,8 @@ setup_game :: proc(state: ^GameState) {
|
||||||
update_game :: proc(state: ^GameState) {
|
update_game :: proc(state: ^GameState) {
|
||||||
using state
|
using state
|
||||||
|
|
||||||
|
rand.init(&rng, transmute(u64)time.time_to_unix_nano(time.now()))
|
||||||
|
|
||||||
// Poll for keyboard commands (input)
|
// Poll for keyboard commands (input)
|
||||||
{
|
{
|
||||||
// If we're entering the game screen then we need to setup initial state of the game variables
|
// If we're entering the game screen then we need to setup initial state of the game variables
|
||||||
|
|
@ -103,7 +109,7 @@ update_game :: proc(state: ^GameState) {
|
||||||
|
|
||||||
// Press space to change to fire
|
// Press space to change to fire
|
||||||
if (rl.IsKeyPressed(rl.KeyboardKey.SPACE)) {
|
if (rl.IsKeyPressed(rl.KeyboardKey.SPACE)) {
|
||||||
fire_bullet(state, shot_from_player = true)
|
fire_bullet(&bullets, &bullet_index)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rl.IsKeyDown(rl.KeyboardKey.RIGHT)) {
|
if (rl.IsKeyDown(rl.KeyboardKey.RIGHT)) {
|
||||||
|
|
@ -145,16 +151,28 @@ update_game :: proc(state: ^GameState) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for alien_idx in 0..< ALIENS_PER_ROW {
|
// Go over the aliens on the bottom of the column & roll rng
|
||||||
//
|
// to shoot a bullet towards the player
|
||||||
// }
|
for alien_idx in 0 ..< ALIENS_PER_ROW {
|
||||||
|
result := rand.uint32(&rng)
|
||||||
|
for row := ALIEN_ROWS-1; row >= 0; row -= 1 {
|
||||||
|
alien := aliens[(row * ALIENS_PER_ROW) + alien_idx]
|
||||||
|
if alien.alive {
|
||||||
|
if result % 3 == 0 {
|
||||||
|
fire_bullet(&bullets, &bullet_index, false, &alien)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update bullets & aliens
|
// Update bullets & aliens
|
||||||
{
|
{
|
||||||
for &bullet, bi in bullets {
|
for &bullet, bi in bullets {
|
||||||
if !bullet.alive {continue}
|
if !bullet.alive {continue}
|
||||||
// Update bullet pos first
|
// Update bullet pos first
|
||||||
bullet.position.y -= f32(BULLET_SPEED * delta_time)
|
bullet_dir : f32 = bullet.player_bullet ? -1 : 1
|
||||||
|
bullet.position.y += f32(BULLET_SPEED * delta_time) * bullet_dir
|
||||||
}
|
}
|
||||||
corner_alien_pos :=
|
corner_alien_pos :=
|
||||||
shuffle_dir == .RIGHT ? aliens[ALIENS_PER_ROW - 1].position : aliens[0].position
|
shuffle_dir == .RIGHT ? aliens[ALIENS_PER_ROW - 1].position : aliens[0].position
|
||||||
|
|
@ -204,14 +222,25 @@ update_game :: proc(state: ^GameState) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fire_bullet :: proc(state: ^GameState, shot_from_player := true) {
|
fire_bullet :: proc(
|
||||||
|
bullets: ^#soa[MAX_BULLETS]Bullet,
|
||||||
|
bullet_index: ^int,
|
||||||
|
shot_from_player := true,
|
||||||
|
alien: ^Alien = nil,
|
||||||
|
) {
|
||||||
using state
|
using state
|
||||||
|
|
||||||
bullet := &bullets[bullet_index];bullet_index = (bullet_index + 1) % MAX_BULLETS
|
bullet := &bullets[bullet_index];bullet_index = (bullet_index + 1) % MAX_BULLETS
|
||||||
bullet.alive = true
|
bullet.alive = true
|
||||||
bullet.player_bullet = true
|
if shot_from_player {
|
||||||
bullet.position = player_pos
|
bullet.player_bullet = true
|
||||||
bullet.position.y = bullet.position.y - ((PLAYER_RECT.y / 2) + BULLET_RECT.y / 2.0)
|
bullet.position = player_pos
|
||||||
|
bullet.position.y = bullet.position.y - ((PLAYER_RECT.y / 2) + BULLET_RECT.y / 2)
|
||||||
|
} else if alien != nil {
|
||||||
|
bullet.player_bullet = false
|
||||||
|
bullet.position = alien.position
|
||||||
|
bullet.position.y = bullet.position.y + ((ALIEN_RECT.y / 2) + ALIEN_RECT.y / 2)
|
||||||
|
}
|
||||||
log.info("Fired bullet: ", bullet)
|
log.info("Fired bullet: ", bullet)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,10 @@ main :: proc() {
|
||||||
rl.InitWindow(state.screen_width, state.screen_height, state.title)
|
rl.InitWindow(state.screen_width, state.screen_height, state.title)
|
||||||
defer rl.CloseWindow()
|
defer rl.CloseWindow()
|
||||||
|
|
||||||
|
if !ODIN_DEBUG {
|
||||||
|
rl.SetExitKey(nil)
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
rl.UnloadImage(texture_atlas_image)
|
rl.UnloadImage(texture_atlas_image)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue