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,
|
||||
position: glm.vec2,
|
||||
id: AlienKind,
|
||||
last_time_fired: f64,
|
||||
}
|
||||
|
||||
Bullet :: struct {
|
||||
|
|
@ -102,12 +103,7 @@ update_game :: proc(state: ^GameState) {
|
|||
|
||||
// Press space to change to fire
|
||||
if (rl.IsKeyPressed(rl.KeyboardKey.SPACE)) {
|
||||
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)
|
||||
fire_bullet(state, shot_from_player = true)
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
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...
|
||||
damage_alien :: proc(
|
||||
state: ^GameState,
|
||||
|
|
|
|||
49
main.odin
49
main.odin
|
|
@ -21,30 +21,31 @@ GameEndType :: enum {
|
|||
|
||||
GameState :: struct {
|
||||
// window
|
||||
target_fps: c.int,
|
||||
title: cstring,
|
||||
screen_width: c.int,
|
||||
screen_height: c.int,
|
||||
target_fps: c.int,
|
||||
title: cstring,
|
||||
screen_width: c.int,
|
||||
screen_height: c.int,
|
||||
// frame stats
|
||||
frame_counter: int,
|
||||
current_frame_time: f64,
|
||||
last_frame_time: f64,
|
||||
delta_time: f64,
|
||||
frame_counter: int,
|
||||
current_frame_time: f64,
|
||||
last_frame_time: f64,
|
||||
delta_time: f64,
|
||||
// game vars
|
||||
screen: GameScreen,
|
||||
previous_screen: GameScreen,
|
||||
last_frame_screen: GameScreen,
|
||||
game_end: GameEndType,
|
||||
reset_game: bool,
|
||||
aliens: #soa[ALIENS]Alien,
|
||||
bullets: #soa[MAX_BULLETS]Bullet,
|
||||
bullet_index: int,
|
||||
player_pos: glm.vec2,
|
||||
player_health: c.int,
|
||||
player_score: c.int,
|
||||
player_high_score: c.int,
|
||||
shuffle_dir: ShuffleDirection,
|
||||
last_shuffle_dir: ShuffleDirection,
|
||||
screen: GameScreen,
|
||||
previous_screen: GameScreen,
|
||||
last_frame_screen: GameScreen,
|
||||
game_end: GameEndType,
|
||||
reset_game: bool,
|
||||
aliens: #soa[ALIENS]Alien,
|
||||
bullets: #soa[MAX_BULLETS]Bullet,
|
||||
bullet_index: int,
|
||||
player_last_time_fired: f64,
|
||||
player_pos: glm.vec2,
|
||||
player_health: c.int,
|
||||
player_score: c.int,
|
||||
player_high_score: c.int,
|
||||
shuffle_dir: ShuffleDirection,
|
||||
last_shuffle_dir: ShuffleDirection,
|
||||
}
|
||||
state: GameState
|
||||
|
||||
|
|
@ -63,8 +64,8 @@ setup :: proc(state: ^GameState) {
|
|||
title = "Space Invaders (raylib+odin-lang edition)"
|
||||
|
||||
current_frame_time = rl.GetTime()
|
||||
previous_screen = .LOGO
|
||||
screen = .GAMEPLAY
|
||||
previous_screen = .TITLE
|
||||
screen = .TITLE
|
||||
|
||||
rl.SetTargetFPS(target_fps)
|
||||
}
|
||||
|
|
|
|||
46
screens.odin
46
screens.odin
|
|
@ -4,7 +4,6 @@ import "core:log"
|
|||
import rl "vendor:raylib"
|
||||
|
||||
GameScreen :: enum {
|
||||
LOGO,
|
||||
TITLE,
|
||||
GAMEPLAY,
|
||||
ENDING,
|
||||
|
|
@ -15,15 +14,6 @@ update_screen :: proc(state: ^GameState) {
|
|||
using state
|
||||
|
||||
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:
|
||||
{
|
||||
// Press enter to change to GAMEPLAY screen
|
||||
|
|
@ -56,24 +46,32 @@ update_screen :: proc(state: ^GameState) {
|
|||
}
|
||||
|
||||
draw_screen :: proc(state: ^GameState) {
|
||||
using state
|
||||
{
|
||||
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:
|
||||
{
|
||||
// TODO: Draw TITLE screen here!
|
||||
rl.DrawRectangle(0, 0, state.screen_width, state.screen_height, rl.GREEN)
|
||||
rl.DrawText("TITLE SCREEN", 20, 20, 40, rl.DARKGREEN)
|
||||
rl.DrawText(
|
||||
"PRESS ENTER or TAP to JUMP to GAMEPLAY SCREEN",
|
||||
120,
|
||||
220,
|
||||
rl.DrawRectangle(0, 0, state.screen_width, state.screen_height, rl.WHITE)
|
||||
|
||||
rl.DrawTexturePro(
|
||||
texture_atlas,
|
||||
{LOGO_TO[0].x, LOGO_TO[0].y, LOGO_TO[1].x, LOGO_TO[1].y},
|
||||
{
|
||||
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,
|
||||
rl.DARKGREEN,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package space_invaders
|
|||
|
||||
import glm "core:math/linalg/glsl"
|
||||
|
||||
LOGO_TO :: [2]glm.vec2{{0, 0}, {128-(SPRITE_CELL * 2), SPRITE_CELL * 2}}
|
||||
|
||||
GLOBAL_SPRITE_SCALE :: 2
|
||||
SPRITE_CELL :: 16
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue