From: Brendan Hansen Date: Fri, 4 Mar 2022 21:35:41 +0000 (-0600) Subject: bugfixing and cleaned up background code X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=0c86cd3f2b2c5906d635c6ee9937ea83257bfe13;p=bar-game.git bugfixing and cleaned up background code --- diff --git a/run_tree/scenes/level1.scene b/run_tree/scenes/level1.scene index 20d7bc6..c2d9a19 100644 --- a/run_tree/scenes/level1.scene +++ b/run_tree/scenes/level1.scene @@ -1,10 +1,12 @@ [Background] id = 100 flags = 0 -pos.x = 0.0000 -pos.y = 0.0000 -size.x = 0.0000 -size.y = 0.0000 +pos.x = 404.0000 +pos.y = 310.5000 +size.x = 941.0000 +size.y = 751.0000 +:BackgroundComponent +texture_path = "./assets/images/background.png" :RenderComponent layer = 0 color.r = 1.0000 @@ -497,7 +499,7 @@ max_timeout = 2.0000 id = 152 flags = 2 pos.x = 276.7525 -pos.y = 229.4652 +pos.y = 229.4651 size.x = 16.0000 size.y = 32.0000 :MovementComponent @@ -509,7 +511,7 @@ controls.interact = 44 controls.pick_up = 46 facing = 1 velocity.x = 0.0000 -velocity.y = -0.0000 +velocity.y = 0.0000 :PlayerComponent holding = 155 :RenderComponent @@ -522,7 +524,7 @@ color.a = 1.0000 [Player] id = 12 flags = 2 -pos.x = 334.4180 +pos.x = 334.4179 pos.y = 246.6519 size.x = 16.0000 size.y = 32.0000 @@ -534,7 +536,7 @@ controls.right = 68 controls.interact = 70 controls.pick_up = 71 facing = 3 -velocity.x = -0.0000 +velocity.x = 0.0000 velocity.y = 0.0000 :PlayerComponent holding = 150 @@ -548,7 +550,7 @@ color.a = 1.0000 [Item_Entity] id = 150 flags = 6 -pos.x = 334.4180 +pos.x = 334.4179 pos.y = 222.6519 size.x = 16.0000 size.y = 16.0000 @@ -565,7 +567,7 @@ item = "burger" id = 155 flags = 0 pos.x = 276.7525 -pos.y = 205.4652 +pos.y = 205.4651 size.x = 16.0000 size.y = 16.0000 :RenderComponent diff --git a/run_tree/scenes/quick_save_new.scene b/run_tree/scenes/quick_save_new.scene index ec3f4ee..c2d9a19 100644 --- a/run_tree/scenes/quick_save_new.scene +++ b/run_tree/scenes/quick_save_new.scene @@ -1,10 +1,12 @@ [Background] id = 100 flags = 0 -pos.x = 0.0000 -pos.y = 0.0000 -size.x = 0.0000 -size.y = 0.0000 +pos.x = 404.0000 +pos.y = 310.5000 +size.x = 941.0000 +size.y = 751.0000 +:BackgroundComponent +texture_path = "./assets/images/background.png" :RenderComponent layer = 0 color.r = 1.0000 @@ -496,8 +498,8 @@ max_timeout = 2.0000 [Player] id = 152 flags = 2 -pos.x = 276.7493 -pos.y = 229.5119 +pos.x = 276.7525 +pos.y = 229.4651 size.x = 16.0000 size.y = 32.0000 :MovementComponent @@ -508,8 +510,8 @@ controls.right = 262 controls.interact = 44 controls.pick_up = 46 facing = 1 -velocity.x = 0.0268 -velocity.y = -0.3748 +velocity.x = 0.0000 +velocity.y = 0.0000 :PlayerComponent holding = 155 :RenderComponent @@ -522,8 +524,8 @@ color.a = 1.0000 [Player] id = 12 flags = 2 -pos.x = 334.4181 -pos.y = 246.6520 +pos.x = 334.4179 +pos.y = 246.6519 size.x = 16.0000 size.y = 32.0000 :MovementComponent @@ -534,8 +536,8 @@ controls.right = 68 controls.interact = 70 controls.pick_up = 71 facing = 3 -velocity.x = -0.0001 -velocity.y = -0.0000 +velocity.x = 0.0000 +velocity.y = 0.0000 :PlayerComponent holding = 150 :RenderComponent @@ -548,8 +550,8 @@ color.a = 1.0000 [Item_Entity] id = 150 flags = 6 -pos.x = 334.4181 -pos.y = 222.6520 +pos.x = 334.4179 +pos.y = 222.6519 size.x = 16.0000 size.y = 16.0000 :RenderComponent @@ -564,8 +566,8 @@ item = "burger" [Item_Entity] id = 155 flags = 0 -pos.x = 276.7484 -pos.y = 205.5248 +pos.x = 276.7525 +pos.y = 205.4651 size.x = 16.0000 size.y = 16.0000 :RenderComponent diff --git a/src/entity/components/background.onyx b/src/entity/components/background.onyx new file mode 100644 index 0000000..9473564 --- /dev/null +++ b/src/entity/components/background.onyx @@ -0,0 +1,23 @@ + +use package core + +BackgroundComponent :: struct { + use component: Component; + + texture_path: str; + + added :: (use this: ^BackgroundComponent, entity: ^Entity) { + scene->modify_component(entity, RenderComponent) { + comp.func = BackgroundComponent.render; + } + } + + render :: (entity: ^Entity) { + background_comp := entity->get(BackgroundComponent); + background_texture, _ := texture_lookup(background_comp.texture_path); + texture_wrap(^background_texture, .Repeat); + + r := entity->get_rect(); + immediate_subimage(^background_texture, r.x, r.y, r.w, r.h, 0, 0, r.w, r.h); + } +} \ No newline at end of file diff --git a/src/entity/editor.onyx b/src/entity/editor.onyx index 0fd955d..e6c26d2 100644 --- a/src/entity/editor.onyx +++ b/src/entity/editor.onyx @@ -60,9 +60,10 @@ editor_update :: (dt: f32) { #local handle_placing_entities :: () { if active_index < 0 do return; - mouse_pos := mouse_get_position_vector() - scene_render_offset; + mouse_raw := mouse_get_position_vector(); + mouse_pos := mouse_raw - scene_render_offset; - if is_button_just_up(GLFW_MOUSE_BUTTON_LEFT) && mouse_pos.x < ~~window_width - sidebar_width { + if is_button_just_up(GLFW_MOUSE_BUTTON_LEFT) && mouse_raw.x < ~~window_width - sidebar_width && mouse_raw.x >= 0 { schematic := scene.schematics.entries[active_index].value; entity := schematic.create(^scene); entity.schematic = schematic.type; @@ -75,9 +76,10 @@ editor_update :: (dt: f32) { } #local handle_entity_selction_and_dragging :: (dt: f32) { - mouse_pos := mouse_get_position_vector() - scene_render_offset; + mouse_raw := mouse_get_position_vector(); + mouse_pos := mouse_raw - scene_render_offset; - if mouse_pos.x < ~~window_width - sidebar_width { + if mouse_raw.x < ~~window_width - sidebar_width && mouse_pos.x >= 0 { if is_button_just_down(GLFW_MOUSE_BUTTON_LEFT) || is_button_just_down(GLFW_MOUSE_BUTTON_RIGHT) { if active_tab == .Edit do active_index = -1; selected_entity_id = Entity_Nothing; diff --git a/src/entity/schematics/background.onyx b/src/entity/schematics/background.onyx index e9f66d8..117d412 100644 --- a/src/entity/schematics/background.onyx +++ b/src/entity/schematics/background.onyx @@ -1,7 +1,7 @@ use package core -#local background_texture: Texture; +// #local background_texture: Texture; Background :: struct { #struct_tag Entity_Schematic.{ @@ -10,20 +10,11 @@ Background :: struct { this.pos = .{0, 0}; this.size = .{0, 0}; - scene->modify_component(this, RenderComponent) { - comp.func = Background.render; + scene->modify_component(this, BackgroundComponent) { + comp.texture_path = "./assets/images/background.png"; } - background_texture', _ := texture_lookup("./assets/images/background.png"); - texture_wrap(^background_texture, .Repeat); - return this; } } - - render :: (this: ^Entity) { - size :: 10000.0f - immediate_set_color(.{1, 1, 1}); - immediate_subimage(^background_texture, this.pos.x, this.pos.y, size, size, 0, 0, size / 2, size / 2); - } } \ No newline at end of file diff --git a/src/game.onyx b/src/game.onyx index b15a23a..a56acb9 100644 --- a/src/game.onyx +++ b/src/game.onyx @@ -86,6 +86,7 @@ game_draw :: () { if !editor_shown() { view_rect = Rect.{0, 0, ~~window_width, ~~window_height}; } else { + // view_rect.x = math.lerp(editor_open_percent(), cast(f32) ((window_width - scene_canvas.width) / 2), 0); view_rect.x = math.lerp(editor_open_percent(), cast(f32) ((window_width - scene_canvas.width) / 2), cast(f32) ((window_width - scene_canvas.width - 400) / 2)); view_rect.y = ~~ ((window_height - scene_canvas.height) / 2); view_rect.w = ~~ scene_canvas.width;