added logo to main screen and set up the game to start from the logo screen
This commit is contained in:
parent
31de4ca06c
commit
78af71a33a
5 changed files with 66 additions and 54 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 1 KiB After Width: | Height: | Size: 1.5 KiB |
23
game.odin
23
game.odin
|
|
@ -28,6 +28,7 @@ Alien :: struct {
|
||||||
death_animation_index: int,
|
death_animation_index: int,
|
||||||
position: glm.vec2,
|
position: glm.vec2,
|
||||||
id: AlienKind,
|
id: AlienKind,
|
||||||
|
last_time_fired: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
Bullet :: struct {
|
Bullet :: struct {
|
||||||
|
|
@ -102,12 +103,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)) {
|
||||||
bullet := &bullets[bullet_index];bullet_index = (bullet_index + 1) % MAX_BULLETS
|
fire_bullet(state, shot_from_player = true)
|
||||||
bullet.alive = true
|
|
||||||
bullet.player_bullet = true
|
|
||||||
bullet.position = player_pos
|
|
||||||
bullet.position.y = bullet.position.y - ((PLAYER_RECT.y / 2) + BULLET_RECT.y / 2.0)
|
|
||||||
log.info("Fired bullet: ", bullet)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rl.IsKeyDown(rl.KeyboardKey.RIGHT)) {
|
if (rl.IsKeyDown(rl.KeyboardKey.RIGHT)) {
|
||||||
|
|
@ -149,6 +145,10 @@ update_game :: proc(state: ^GameState) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for alien_idx in 0..< ALIENS_PER_ROW {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
// Update bullets & aliens
|
// Update bullets & aliens
|
||||||
{
|
{
|
||||||
for &bullet, bi in bullets {
|
for &bullet, bi in bullets {
|
||||||
|
|
@ -204,6 +204,17 @@ update_game :: proc(state: ^GameState) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fire_bullet :: proc(state: ^GameState, shot_from_player := true) {
|
||||||
|
using state
|
||||||
|
|
||||||
|
bullet := &bullets[bullet_index];bullet_index = (bullet_index + 1) % MAX_BULLETS
|
||||||
|
bullet.alive = true
|
||||||
|
bullet.player_bullet = true
|
||||||
|
bullet.position = player_pos
|
||||||
|
bullet.position.y = bullet.position.y - ((PLAYER_RECT.y / 2) + BULLET_RECT.y / 2.0)
|
||||||
|
log.info("Fired bullet: ", bullet)
|
||||||
|
}
|
||||||
|
|
||||||
// Since I'm using a #soa array I can't directly modify the alien & bullet entities...
|
// Since I'm using a #soa array I can't directly modify the alien & bullet entities...
|
||||||
damage_alien :: proc(
|
damage_alien :: proc(
|
||||||
state: ^GameState,
|
state: ^GameState,
|
||||||
|
|
|
||||||
49
main.odin
49
main.odin
|
|
@ -21,30 +21,31 @@ GameEndType :: enum {
|
||||||
|
|
||||||
GameState :: struct {
|
GameState :: struct {
|
||||||
// window
|
// window
|
||||||
target_fps: c.int,
|
target_fps: c.int,
|
||||||
title: cstring,
|
title: cstring,
|
||||||
screen_width: c.int,
|
screen_width: c.int,
|
||||||
screen_height: c.int,
|
screen_height: c.int,
|
||||||
// frame stats
|
// frame stats
|
||||||
frame_counter: int,
|
frame_counter: int,
|
||||||
current_frame_time: f64,
|
current_frame_time: f64,
|
||||||
last_frame_time: f64,
|
last_frame_time: f64,
|
||||||
delta_time: f64,
|
delta_time: f64,
|
||||||
// game vars
|
// game vars
|
||||||
screen: GameScreen,
|
screen: GameScreen,
|
||||||
previous_screen: GameScreen,
|
previous_screen: GameScreen,
|
||||||
last_frame_screen: GameScreen,
|
last_frame_screen: GameScreen,
|
||||||
game_end: GameEndType,
|
game_end: GameEndType,
|
||||||
reset_game: bool,
|
reset_game: bool,
|
||||||
aliens: #soa[ALIENS]Alien,
|
aliens: #soa[ALIENS]Alien,
|
||||||
bullets: #soa[MAX_BULLETS]Bullet,
|
bullets: #soa[MAX_BULLETS]Bullet,
|
||||||
bullet_index: int,
|
bullet_index: int,
|
||||||
player_pos: glm.vec2,
|
player_last_time_fired: f64,
|
||||||
player_health: c.int,
|
player_pos: glm.vec2,
|
||||||
player_score: c.int,
|
player_health: c.int,
|
||||||
player_high_score: c.int,
|
player_score: c.int,
|
||||||
shuffle_dir: ShuffleDirection,
|
player_high_score: c.int,
|
||||||
last_shuffle_dir: ShuffleDirection,
|
shuffle_dir: ShuffleDirection,
|
||||||
|
last_shuffle_dir: ShuffleDirection,
|
||||||
}
|
}
|
||||||
state: GameState
|
state: GameState
|
||||||
|
|
||||||
|
|
@ -63,8 +64,8 @@ setup :: proc(state: ^GameState) {
|
||||||
title = "Space Invaders (raylib+odin-lang edition)"
|
title = "Space Invaders (raylib+odin-lang edition)"
|
||||||
|
|
||||||
current_frame_time = rl.GetTime()
|
current_frame_time = rl.GetTime()
|
||||||
previous_screen = .LOGO
|
previous_screen = .TITLE
|
||||||
screen = .GAMEPLAY
|
screen = .TITLE
|
||||||
|
|
||||||
rl.SetTargetFPS(target_fps)
|
rl.SetTargetFPS(target_fps)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
46
screens.odin
46
screens.odin
|
|
@ -4,7 +4,6 @@ import "core:log"
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
GameScreen :: enum {
|
GameScreen :: enum {
|
||||||
LOGO,
|
|
||||||
TITLE,
|
TITLE,
|
||||||
GAMEPLAY,
|
GAMEPLAY,
|
||||||
ENDING,
|
ENDING,
|
||||||
|
|
@ -15,15 +14,6 @@ update_screen :: proc(state: ^GameState) {
|
||||||
using state
|
using state
|
||||||
|
|
||||||
switch screen {
|
switch screen {
|
||||||
case .LOGO:
|
|
||||||
{
|
|
||||||
// Wait for 2 seconds (120 frames) before jumping to TITLE screen
|
|
||||||
if (frame_counter > int(target_fps * 2)) {
|
|
||||||
previous_screen = screen
|
|
||||||
screen = .TITLE
|
|
||||||
log.info("Updated screen enum", screen)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case .TITLE:
|
case .TITLE:
|
||||||
{
|
{
|
||||||
// Press enter to change to GAMEPLAY screen
|
// Press enter to change to GAMEPLAY screen
|
||||||
|
|
@ -56,24 +46,32 @@ update_screen :: proc(state: ^GameState) {
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_screen :: proc(state: ^GameState) {
|
draw_screen :: proc(state: ^GameState) {
|
||||||
|
using state
|
||||||
{
|
{
|
||||||
switch state.screen {
|
switch state.screen {
|
||||||
case .LOGO:
|
|
||||||
{
|
|
||||||
// TODO: Draw LOGO screen here!
|
|
||||||
rl.DrawText("SPACE INVADERS", 220, 220, 40, rl.GREEN)
|
|
||||||
rl.DrawText("WAIT for 2 SECONDS...", 290, 400, 20, rl.GRAY)
|
|
||||||
|
|
||||||
}
|
|
||||||
case .TITLE:
|
case .TITLE:
|
||||||
{
|
{
|
||||||
// TODO: Draw TITLE screen here!
|
rl.DrawRectangle(0, 0, state.screen_width, state.screen_height, rl.WHITE)
|
||||||
rl.DrawRectangle(0, 0, state.screen_width, state.screen_height, rl.GREEN)
|
|
||||||
rl.DrawText("TITLE SCREEN", 20, 20, 40, rl.DARKGREEN)
|
rl.DrawTexturePro(
|
||||||
rl.DrawText(
|
texture_atlas,
|
||||||
"PRESS ENTER or TAP to JUMP to GAMEPLAY SCREEN",
|
{LOGO_TO[0].x, LOGO_TO[0].y, LOGO_TO[1].x, LOGO_TO[1].y},
|
||||||
120,
|
{
|
||||||
220,
|
f32(screen_width / GLOBAL_SPRITE_SCALE) / 2,
|
||||||
|
f32(screen_height / GLOBAL_SPRITE_SCALE) / 2,
|
||||||
|
LOGO_TO[1].x * 4,
|
||||||
|
LOGO_TO[1].y * 4,
|
||||||
|
},
|
||||||
|
{LOGO_TO[1].x * 2, LOGO_TO[1].y * 2},
|
||||||
|
0,
|
||||||
|
rl.GREEN,
|
||||||
|
)
|
||||||
|
text : cstring = "PRESS ENTER TO START GAME"
|
||||||
|
size := rl.MeasureText(text, 20)
|
||||||
|
rl.DrawText(
|
||||||
|
text,
|
||||||
|
(screen_width/4) - (size/2),
|
||||||
|
(screen_height / 2)- 20,
|
||||||
20,
|
20,
|
||||||
rl.DARKGREEN,
|
rl.DARKGREEN,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package space_invaders
|
||||||
|
|
||||||
import glm "core:math/linalg/glsl"
|
import glm "core:math/linalg/glsl"
|
||||||
|
|
||||||
|
LOGO_TO :: [2]glm.vec2{{0, 0}, {128-(SPRITE_CELL * 2), SPRITE_CELL * 2}}
|
||||||
|
|
||||||
GLOBAL_SPRITE_SCALE :: 2
|
GLOBAL_SPRITE_SCALE :: 2
|
||||||
SPRITE_CELL :: 16
|
SPRITE_CELL :: 16
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue