diff --git a/general/components.odin b/general/components.odin index cd43803..c9350db 100644 --- a/general/components.odin +++ b/general/components.odin @@ -5,3 +5,9 @@ import rl "vendor:raylib" Transform :: struct { position: rl.Vector2, } + +Weapon :: struct { + dmg: i32, + rpm: f32, + cooldown: bool, +} diff --git a/general/entities.odin b/general/entities.odin index 5a6425a..097b079 100644 --- a/general/entities.odin +++ b/general/entities.odin @@ -11,6 +11,7 @@ Player :: struct { transform: Transform, sprite: rl.Texture2D, camera: rl.Camera2D, + weapon: Weapon, } Enemy :: struct { diff --git a/general/main.odin b/general/main.odin index 157e2fa..bb16f6d 100644 --- a/general/main.odin +++ b/general/main.odin @@ -21,6 +21,7 @@ main :: proc() { 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 { @@ -88,7 +89,7 @@ draw :: proc() { } } - if rl.IsMouseButtonPressed(rl.MouseButton.LEFT) { + 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 diff --git a/general/systems.odin b/general/systems.odin index 400aaca..f619693 100644 --- a/general/systems.odin +++ b/general/systems.odin @@ -1,6 +1,8 @@ package main import "core:fmt" +import "core:math" +import "core:math/rand" import rl "vendor:raylib" move :: proc(t: ^Transform, x, y: f32) { @@ -17,18 +19,21 @@ move :: proc(t: ^Transform, x, y: f32) { shoot :: proc(t: Transform, pos: rl.Vector2) { pos_centered := center_to_grid(pos) t_centered := center_to_grid(t.position) + spray: rl.Vector2 = { + pos.x + rand.float32_range(0, CELL_SIZE), + pos.y + rand.float32_range(0, CELL_SIZE), + } line_particle := LineParticle { pos1 = t.position * CELL_SIZE + 10, - pos2 = pos + 10, + pos2 = spray, tint = rl.WHITE, lifetime = 0.2, } - spawn_particle(line_particle) - start_timer(1, test_timer_callback) -} -test_timer_callback :: proc() { - fmt.println("timer finished") + if player.weapon.cooldown == true {return} + player.weapon.cooldown = true + start_timer(60 / player.weapon.rpm, proc() {player.weapon.cooldown = false}) + spawn_particle(line_particle) } center_to_grid :: proc(pos: rl.Vector2) -> rl.Vector2 {