Files
grimm-odin/general/main.odin
T
2026-09-26 20:48:09 -07:00

101 lines
1.9 KiB
Odin

package main
import "core:fmt"
import rl "vendor:raylib"
World :: struct {
entities: map[rl.Vector2]Entity,
}
world: World
player: Player
enemy: Enemy
camera: rl.Camera2D
CELL_SIZE :: 20
main :: proc() {
fmt.println("hello world")
rl.InitWindow(800, 600, "grimm gameplay prototype")
defer rl.CloseWindow()
player = Player {
transform = Transform{position = {4, 8}},
camera = rl.Camera2D{target = {0, 0}, zoom = 1.5},
}
world.entities[player.transform.position] = player
enemy = Enemy {
transform = Transform{position = {8, 8}},
}
world.entities[enemy.transform.position] = enemy
for !rl.WindowShouldClose() {
update()
rl.BeginDrawing()
rl.ClearBackground(rl.PURPLE)
rl.BeginMode2D(player.camera)
draw()
rl.EndMode2D()
rl.EndDrawing()
}
}
update :: proc() {
if rl.IsKeyPressed(rl.KeyboardKey.W) {
move(&player.transform, 0, -1)
}
if rl.IsKeyPressed(rl.KeyboardKey.A) {
move(&player.transform, -1, 0)
}
if rl.IsKeyPressed(rl.KeyboardKey.S) {
move(&player.transform, 0, 1)
}
if rl.IsKeyPressed(rl.KeyboardKey.D) {
move(&player.transform, 1, 0)
}
if rl.IsKeyPressed(rl.KeyboardKey.SPACE) {
move(&enemy.transform, 1, 0)
}
run_timers()
}
draw :: proc() {
rl.DrawRectangle(
i32(player.transform.position.x * CELL_SIZE),
i32(player.transform.position.y * CELL_SIZE),
CELL_SIZE,
CELL_SIZE,
rl.WHITE,
)
rl.DrawRectangle(
i32(enemy.transform.position.x * CELL_SIZE),
i32(enemy.transform.position.y * CELL_SIZE),
CELL_SIZE,
CELL_SIZE,
rl.BLUE,
)
for x in 0 ..< 26 {
for y in 0 ..< 26 {
rl.DrawRectangleLines(
i32(x) * CELL_SIZE,
i32(y) * CELL_SIZE,
CELL_SIZE,
CELL_SIZE,
rl.BLANK,
)
}
}
if rl.IsMouseButtonPressed(rl.MouseButton.LEFT) {
pos := rl.GetScreenToWorld2D(rl.GetMousePosition(), player.camera)
pos_x := int(pos.x / CELL_SIZE) * CELL_SIZE
pos_y := int(pos.y / CELL_SIZE) * CELL_SIZE
shoot(player.transform, {f32(pos_x), f32(pos_y)})
}
run_particle_system()
}