Cleaned up comments + split level logic.
This commit is contained in:
+9
-65
@@ -8,7 +8,8 @@ Scene :: union {
|
||||
}
|
||||
|
||||
Scene_Menu :: struct {
|
||||
selected_option: int,
|
||||
// Ui_Canvas
|
||||
// as in a struct so that we cleanly have either Level or Ui_Canvas
|
||||
}
|
||||
|
||||
Scene_Gameplay :: struct {
|
||||
@@ -66,7 +67,7 @@ update_gameplay :: proc(scene: ^Scene_Gameplay, game: ^Game, input: Input_Event,
|
||||
}
|
||||
|
||||
render_gameplay :: proc(scene: Scene_Gameplay, viewport_texture: rl.RenderTexture2D, is_paused: bool) {
|
||||
// Offscreen Pass: Render all game objects at low/fixed virtual resolution (1280x720)
|
||||
// Offscreen Pass: Render all game objects at low/fixed virtual resolution
|
||||
rl.BeginTextureMode(viewport_texture)
|
||||
rl.ClearBackground(rl.BLACK)
|
||||
|
||||
@@ -74,9 +75,9 @@ render_gameplay :: proc(scene: Scene_Gameplay, viewport_texture: rl.RenderTextur
|
||||
|
||||
if is_paused {
|
||||
// UI coordinates aligned relative to internal 1280x720 viewport space
|
||||
rl.DrawRectangleRec(rl.Rectangle{0,0, VIEWPORT_WIDTH, VIEWPORT_HEIGHT}, rl.Color{0,0,0,140})
|
||||
rl.DrawText("PAUSED", VIEWPORT_WIDTH / 2 - 80, VIEWPORT_HEIGHT / 2 - 40, 40, rl.WHITE)
|
||||
rl.DrawText("Press Q to Quit to Menu", VIEWPORT_WIDTH / 2 - 110, VIEWPORT_HEIGHT / 2 + 10, 20, rl.LIGHTGRAY)
|
||||
rl.DrawRectangleRec(rl.Rectangle{0,0, VIEWPORT_W, VIEWPORT_H}, rl.Color{0,0,0,140})
|
||||
rl.DrawText("PAUSED", VIEWPORT_W / 2 - 80, VIEWPORT_H / 2 - 40, 40, rl.WHITE)
|
||||
rl.DrawText("Press Q to Quit to Menu", VIEWPORT_W / 2 - 110, VIEWPORT_H / 2 + 10, 20, rl.LIGHTGRAY)
|
||||
}
|
||||
rl.EndTextureMode()
|
||||
|
||||
@@ -87,69 +88,12 @@ render_gameplay :: proc(scene: Scene_Gameplay, viewport_texture: rl.RenderTextur
|
||||
render_game_to_window :: proc(texture: rl.Texture) {
|
||||
rl.DrawTexturePro(
|
||||
texture,
|
||||
// Source rect: OpenGL render targets have inverted Y coordinates (-height flips it right side up)
|
||||
// src: OpenGL render targets have inverted Y coordinates (-height flips it)
|
||||
rl.Rectangle{0, 0, f32(texture.width), -f32(texture.height)},
|
||||
// Dest rect: Scales 1280x720 canvas to fill window resolution (2560x1440)
|
||||
rl.Rectangle{0, 0, f32(WINDOW_WIDTH), f32(WINDOW_HEIGHT)},
|
||||
// dst: Scales viewport canvas to fill window res (WINDOW_WIDTHxWINDOW_HEIGHT)
|
||||
rl.Rectangle{0, 0, f32(WINDOW_W), f32(WINDOW_H)},
|
||||
rl.Vector2{},
|
||||
0,
|
||||
rl.WHITE
|
||||
)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// LEVEL specifics
|
||||
// ------------------------------------------------------------------------------
|
||||
Level :: struct {
|
||||
field_bounds: rl.Rectangle,
|
||||
player: Entity,
|
||||
enemy: Entity,
|
||||
ball: Entity,
|
||||
}
|
||||
|
||||
init_level :: proc() -> Level {
|
||||
// Positioning based strictly on internal viewport resolution, independent of target display size
|
||||
pad_x := f32(VIEWPORT_WIDTH) * 0.10
|
||||
pad_y := f32(VIEWPORT_HEIGHT) * 0.10
|
||||
|
||||
bounds := rl.Rectangle{
|
||||
x = pad_x,
|
||||
y = pad_y,
|
||||
width = f32(VIEWPORT_WIDTH) - (pad_x * 2),
|
||||
height = f32(VIEWPORT_HEIGHT) - (pad_y * 2),
|
||||
}
|
||||
|
||||
player_ent := init_player()
|
||||
player_ent.pos.x = bounds.x + 3
|
||||
player_ent.pos.y = bounds.y + (bounds.height / 2) - (player_ent.size.y / 2)
|
||||
|
||||
enemy_ent := init_enemy()
|
||||
enemy_ent.pos.x = (bounds.x + bounds.width) - (enemy_ent.size.x) - 3
|
||||
enemy_ent.pos.y = bounds.y + (bounds.height / 2) - (enemy_ent.size.y / 2)
|
||||
|
||||
return Level{
|
||||
field_bounds = bounds,
|
||||
player = player_ent,
|
||||
enemy = enemy_ent,
|
||||
ball = init_ball(),
|
||||
}
|
||||
}
|
||||
|
||||
update_level :: proc(level: ^Level, input: Input_Event, dt: f32) {
|
||||
update_player(&level.player, input, level.field_bounds, dt)
|
||||
update_ball(&level.ball, level.field_bounds, dt)
|
||||
}
|
||||
|
||||
render_level :: proc(level: Level) {
|
||||
rl.DrawRectangleRec(level.field_bounds, rl.DARKGRAY)
|
||||
rl.DrawRectangleLinesEx(level.field_bounds, 3, rl.RAYWHITE)
|
||||
|
||||
center_x := f32(VIEWPORT_WIDTH) / 2.0
|
||||
start_pos := rl.Vector2{center_x, level.field_bounds.y + 3}
|
||||
end_pos := rl.Vector2{center_x, level.field_bounds.y + level.field_bounds.height - 3}
|
||||
rl.DrawLineEx(start_pos, end_pos, 3.0, rl.WHITE)
|
||||
|
||||
render_player(level.player, level.field_bounds)
|
||||
render_enemy(level.enemy, level.field_bounds)
|
||||
render_ball(level.ball, level.field_bounds)
|
||||
}
|
||||
Reference in New Issue
Block a user