75 lines
1.5 KiB
Odin
75 lines
1.5 KiB
Odin
package main
|
|
|
|
import "core:fmt"
|
|
import ecs "shoal/src"
|
|
import rl "vendor:raylib"
|
|
|
|
camera: rl.Camera2D
|
|
CELL_SIZE :: 20
|
|
|
|
app: ecs.App
|
|
|
|
main :: proc() {
|
|
ecs.add_plugin(&app, ecs.DefaultPlugin)
|
|
ecs.add_system(&app, ecs.STARTUP, setup_entities)
|
|
ecs.add_system(&app, ecs.UPDATE, player_move)
|
|
ecs.add_system(&app, ecs.UPDATE, run_particle_system)
|
|
ecs.add_system(&app, ecs.UPDATE, run_timers)
|
|
ecs.add_system(&app, ecs.DRAW, draw_player)
|
|
ecs.add_system(&app, ecs.UPDATE, update_grid_actor)
|
|
ecs.run(&app)
|
|
}
|
|
|
|
setup_entities :: proc() {
|
|
player := ecs.spawn_entity(&app)
|
|
ecs.add_component(player, &Player)
|
|
ecs.add_component(player, &Weapon)
|
|
ecs.add_component(player, &GridActor)
|
|
ecs.add_component(player, &ecs.Sprite)
|
|
ecs.add_component(player, &ecs.Transform)
|
|
}
|
|
|
|
player_move :: proc() {
|
|
e, player := ecs.single(&Player)
|
|
grid_actor := ecs.get_component(e, &GridActor)
|
|
|
|
if rl.IsKeyPressed(rl.KeyboardKey.W) {
|
|
move(grid_actor, 0, -1)
|
|
}
|
|
if rl.IsKeyPressed(rl.KeyboardKey.A) {
|
|
move(grid_actor, -1, 0)
|
|
}
|
|
if rl.IsKeyPressed(rl.KeyboardKey.S) {
|
|
move(grid_actor, 0, 1)
|
|
}
|
|
if rl.IsKeyPressed(rl.KeyboardKey.D) {
|
|
move(grid_actor, 1, 0)
|
|
}
|
|
}
|
|
|
|
draw_player :: proc() {
|
|
e, player := ecs.single(&Player)
|
|
transform := ecs.get_component(e, &ecs.Transform)
|
|
rl.DrawRectangle(
|
|
i32(transform.translation.x),
|
|
i32(transform.translation.y),
|
|
CELL_SIZE,
|
|
CELL_SIZE,
|
|
rl.WHITE,
|
|
)
|
|
}
|
|
|
|
draw_grid :: proc() {
|
|
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,
|
|
)
|
|
}
|
|
}
|
|
}
|