Game field, camera, first assets
This commit is contained in:
parent
85af303aa0
commit
af14f6cf8e
Binary file not shown.
After Width: | Height: | Size: 141 B |
Binary file not shown.
After Width: | Height: | Size: 268 B |
Binary file not shown.
After Width: | Height: | Size: 653 B |
Binary file not shown.
Binary file not shown.
Binary file not shown.
18
game.odin
18
game.odin
|
@ -1,8 +1,12 @@
|
|||
package main
|
||||
|
||||
import rl "vendor:raylib"
|
||||
import "vendor:raylib/rlgl"
|
||||
import "core:fmt"
|
||||
|
||||
// Virtual game field dimensions
|
||||
GameField := Vec2{800, 600}
|
||||
|
||||
|
||||
Pad :: struct {
|
||||
position: Vec2,
|
||||
|
@ -29,6 +33,7 @@ Game :: struct {
|
|||
pad: Pad,
|
||||
balls: [dynamic]Ball,
|
||||
bricks: [dynamic]Brick,
|
||||
camera: rl.Camera2D
|
||||
}
|
||||
|
||||
|
||||
|
@ -38,8 +43,12 @@ game_init :: proc() -> ^GameState {
|
|||
state.draw = game_draw
|
||||
state.update = game_update
|
||||
state.lives = 3
|
||||
state.camera = rl.Camera2D{
|
||||
zoom = 1,
|
||||
target = GameField / 2,
|
||||
}
|
||||
state.pad = Pad{
|
||||
position = {f32(WINDOW_WIDTH / 2), f32(WINDOW_HEIGHT - 40)},
|
||||
position = Vec2{GameField.x / 2, GameField.y - 40},
|
||||
size = {80, 10},
|
||||
}
|
||||
return state
|
||||
|
@ -58,6 +67,8 @@ game_update :: proc(state: ^GameState, delta: f32) {
|
|||
pad.position.x += 100 * delta
|
||||
}
|
||||
|
||||
game.camera.offset = WINDOWF / 2
|
||||
|
||||
}
|
||||
|
||||
game_draw :: proc(state: ^GameState) {
|
||||
|
@ -65,7 +76,12 @@ game_draw :: proc(state: ^GameState) {
|
|||
|
||||
using game
|
||||
|
||||
rl.BeginMode2D(camera)
|
||||
|
||||
rl.ClearBackground(rl.RAYWHITE)
|
||||
|
||||
|
||||
rl.DrawRectangleV({0, 0}, GameField, rl.RED)
|
||||
rl.DrawRectangleV(pad.position, pad.size, rl.GREEN)
|
||||
rl.EndMode2D()
|
||||
}
|
||||
|
|
20
main.odin
20
main.odin
|
@ -2,22 +2,25 @@ package main
|
|||
|
||||
import rl "vendor:raylib"
|
||||
import "core:slice"
|
||||
import "core:fmt"
|
||||
|
||||
Vec2 :: [2]f32
|
||||
Vec2i :: [2]i32
|
||||
|
||||
WINDOW_WIDTH : i32 = 800
|
||||
WINDOW_HEIGHT : i32 = 480
|
||||
WINDOW : Vec2i
|
||||
WINDOWF : Vec2
|
||||
|
||||
|
||||
main :: proc() {
|
||||
rl.SetConfigFlags(rl.ConfigFlags{.BORDERLESS_WINDOWED_MODE, .VSYNC_HINT, .WINDOW_RESIZABLE})
|
||||
rl.SetConfigFlags(rl.ConfigFlags{.FULLSCREEN_MODE, .VSYNC_HINT, .WINDOW_MAXIMIZED, .WINDOW_UNDECORATED})
|
||||
monitor := rl.GetCurrentMonitor()
|
||||
WINDOW_WIDTH = rl.GetMonitorWidth(monitor)
|
||||
WINDOW_HEIGHT = rl.GetMonitorHeight(monitor)
|
||||
rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "SinePong")
|
||||
rl.InitWindow(0, 0, "SinePong")
|
||||
rl.SetTargetFPS(9999)
|
||||
|
||||
WINDOW.x = rl.GetScreenWidth()
|
||||
WINDOW.y = rl.GetScreenHeight()
|
||||
WINDOWF = Vec2{f32(WINDOW.x), f32(WINDOW.y)}
|
||||
|
||||
stack_init()
|
||||
|
||||
defer {
|
||||
|
@ -31,8 +34,9 @@ main :: proc() {
|
|||
|
||||
for (!rl.WindowShouldClose()) {
|
||||
if rl.IsWindowResized() {
|
||||
WINDOW_WIDTH = rl.GetScreenWidth()
|
||||
WINDOW_HEIGHT = rl.GetScreenHeight()
|
||||
WINDOW.x = rl.GetScreenWidth()
|
||||
WINDOW.y = rl.GetScreenHeight()
|
||||
WINDOWF = Vec2{f32(WINDOW.x), f32(WINDOW.y)}
|
||||
}
|
||||
|
||||
current_state := state_stack[len(state_stack)-1]
|
||||
|
|
Binary file not shown.
|
@ -23,6 +23,7 @@ STACK_SIZE :: 16
|
|||
state_buf : [STACK_SIZE]^GameState
|
||||
state_stack : [dynamic]^GameState
|
||||
|
||||
|
||||
stack_init :: proc() {
|
||||
state_stack = slice.into_dynamic(state_buf[:])
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue