sync my shit
This commit is contained in:
+35
-62
@@ -1,82 +1,65 @@
|
||||
package main
|
||||
|
||||
import "core:fmt"
|
||||
import ecs "shoal/src"
|
||||
import rl "vendor:raylib"
|
||||
|
||||
World :: struct {
|
||||
entities: map[rl.Vector2]Entity,
|
||||
}
|
||||
|
||||
world: World
|
||||
player: Player
|
||||
enemy: Enemy
|
||||
camera: rl.Camera2D
|
||||
CELL_SIZE :: 20
|
||||
|
||||
app: ecs.App
|
||||
|
||||
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},
|
||||
weapon = Weapon{dmg = 1, rpm = 450, cooldown = false},
|
||||
}
|
||||
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()
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
update :: proc() {
|
||||
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(&player.transform, 0, -1)
|
||||
move(grid_actor, 0, -1)
|
||||
}
|
||||
if rl.IsKeyPressed(rl.KeyboardKey.A) {
|
||||
move(&player.transform, -1, 0)
|
||||
move(grid_actor, -1, 0)
|
||||
}
|
||||
if rl.IsKeyPressed(rl.KeyboardKey.S) {
|
||||
move(&player.transform, 0, 1)
|
||||
move(grid_actor, 0, 1)
|
||||
}
|
||||
if rl.IsKeyPressed(rl.KeyboardKey.D) {
|
||||
move(&player.transform, 1, 0)
|
||||
move(grid_actor, 1, 0)
|
||||
}
|
||||
|
||||
if rl.IsKeyPressed(rl.KeyboardKey.SPACE) {
|
||||
move(&enemy.transform, 1, 0)
|
||||
}
|
||||
|
||||
run_timers()
|
||||
}
|
||||
|
||||
draw :: proc() {
|
||||
draw_player :: proc() {
|
||||
e, player := ecs.single(&Player)
|
||||
transform := ecs.get_component(e, &ecs.Transform)
|
||||
rl.DrawRectangle(
|
||||
i32(player.transform.position.x * CELL_SIZE),
|
||||
i32(player.transform.position.y * CELL_SIZE),
|
||||
i32(transform.translation.x),
|
||||
i32(transform.translation.y),
|
||||
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,
|
||||
)
|
||||
}
|
||||
|
||||
draw_grid :: proc() {
|
||||
for x in 0 ..< 26 {
|
||||
for y in 0 ..< 26 {
|
||||
rl.DrawRectangleLines(
|
||||
@@ -88,14 +71,4 @@ draw :: proc() {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if rl.IsMouseButtonDown(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()
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user