diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/assets.odin | 2 | ||||
| -rw-r--r-- | src/draw.odin | 12 | ||||
| -rw-r--r-- | src/input.odin | 2 | ||||
| -rw-r--r-- | src/main.odin | 22 | ||||
| -rw-r--r-- | src/phys/world.odin | 11 | ||||
| -rw-r--r-- | src/player.odin | 2 |
6 files changed, 48 insertions, 3 deletions
diff --git a/src/assets.odin b/src/assets.odin index b072805..0b6fcc9 100644 --- a/src/assets.odin +++ b/src/assets.odin @@ -49,7 +49,7 @@ images: [Image_Id]Image_Resource = { animations: [Animation_Id]Animation_Resource = { .NONE = {frame_count=1, frame_durations={100}, tags={}}, - .PLAYER = {frame_count = 23, frame_durations = {100, 100, 100, 100, 100, 100, 75, 75, 75, 75, 75, 75, 75, 75, 100, 100, 100, 100, 100, 100, 100, 100, 100}, tags = {"idle"={from = 0, to = 5}, "jump_trans"={from = 16, to = 16}, "run"={from = 6, to = 13}, "jump_down"={from = 17, to = 18}, "jump_up"={from = 14, to = 15}, "sleep"={from = 19, to = 22}}}, + .PLAYER = {frame_count = 23, frame_durations = {100, 100, 100, 100, 100, 100, 75, 75, 75, 75, 75, 75, 75, 75, 100, 100, 100, 100, 100, 100, 100, 100, 100}, tags = {"jump_up"={from = 14, to = 15}, "run"={from = 6, to = 13}, "jump_trans"={from = 16, to = 16}, "jump_down"={from = 17, to = 18}, "idle"={from = 0, to = 5}, "sleep"={from = 19, to = 22}}}, } rooms: [Room_Id]Room_Resource = { diff --git a/src/draw.odin b/src/draw.odin index 2aa1257..e51e0ae 100644 --- a/src/draw.odin +++ b/src/draw.odin @@ -76,6 +76,18 @@ draw_rect :: proc(rect: Rect) { ) } +draw_linerect :: proc(rect: Rect) { + assert(rect.size.x > 0 && rect.size.y > 0) + + rl.DrawRectangleLines( + c.int(rect.start.x), + c.int(rect.start.y), + c.int(rect.size.x), + c.int(rect.size.y), + _color_to_rl(renderer.tint), + ) +} + draw_texture :: proc { draw_texture_full, draw_texture_quad, diff --git a/src/input.odin b/src/input.odin index 0b1d56e..1513c33 100644 --- a/src/input.odin +++ b/src/input.odin @@ -19,6 +19,7 @@ actions: struct { jump: Keybind, dash: Keybind, shoot: Keybind, + toggle_debug_mode: Keybind, } init_keybinds :: proc() { @@ -27,6 +28,7 @@ init_keybinds :: proc() { actions.jump.input = .SPACE actions.dash.input = .LEFT_SHIFT actions.shoot.input = rl.MouseButton.LEFT + actions.toggle_debug_mode.input = .GRAVE } is_keybind_down :: proc(keybind: Keybind) -> bool { diff --git a/src/main.odin b/src/main.odin index 1e3f8ba..969c25b 100644 --- a/src/main.odin +++ b/src/main.odin @@ -21,6 +21,7 @@ Rect :: struct { } state: struct { + debug_mode: bool, camera: rl.Camera2D, platform_list: Entity_List(Platform), bullet_list: Entity_List(Bullet), @@ -65,6 +66,10 @@ init :: proc() { } frame :: proc() { + if is_keybind_just_down(actions.toggle_debug_mode) { + state.debug_mode = !state.debug_mode + } + update_player(rl.GetFrameTime()) update_bullets(rl.GetFrameTime()) @@ -75,7 +80,18 @@ frame :: proc() { draw_player() draw_room(current_room.id) draw_bullets() - // draw_platforms() + + if state.debug_mode { + // Draw all collisions + body_it: int + renderer.tint = {1, 0.25, 0.5, 0.5} + for body in phys.iterate_bodies(&body_it) { + rect := phys.get_rect(body) + rect.start += phys.get_position(body) + draw_linerect(transmute(Rect)rect) + } + renderer.tint = {1, 1, 1, 1} + } rl.EndMode2D() @@ -86,6 +102,10 @@ frame :: proc() { ) rl.DrawText(fps_text, 5, 5, 8, rl.GREEN) + if state.debug_mode { + rl.DrawText("Debug Mode", 5, 5 + 8, 8, rl.YELLOW) + } + draw_end_frame() } diff --git a/src/phys/world.odin b/src/phys/world.odin index 189f0b0..15e7826 100644 --- a/src/phys/world.odin +++ b/src/phys/world.odin @@ -110,6 +110,17 @@ _get_body :: proc(h: Body_Handle, location := #caller_location) -> ^Body { return &world.bodies[h.idx] } +iterate_bodies :: proc(it: ^int) -> (Body_Handle, bool) { + for it^ < len(world.bodies) { + if world.bodies[it^].handle.uses > 0 { + it^ += 1 + return world.bodies[it^ - 1].handle, true + } + it^ += 1 + } + return {}, false +} + add_body :: proc(b: Body) -> Body_Handle { handle: Body_Handle diff --git a/src/player.odin b/src/player.odin index abed174..497407c 100644 --- a/src/player.odin +++ b/src/player.odin @@ -124,7 +124,7 @@ _default_state :: proc(dt: f32) { rel_mouse_pos := get_mouse_pos() - pos if is_keybind_just_down(actions.shoot) { - mouse_dir := linalg.normalize0(rel_mouse_pos) + mouse_dir := linalg.normalize0(rel_mouse_pos + {0, PLAYER_GUN_HEIGHT}) bullet_pos := pos bullet_pos.y -= PLAYER_GUN_HEIGHT |
