bugfixing and cleaned up background code
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 4 Mar 2022 21:35:41 +0000 (15:35 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 4 Mar 2022 21:35:41 +0000 (15:35 -0600)
run_tree/scenes/level1.scene
run_tree/scenes/quick_save_new.scene
src/entity/components/background.onyx [new file with mode: 0644]
src/entity/editor.onyx
src/entity/schematics/background.onyx
src/game.onyx

index 20d7bc6c0a70f0ec207479eb1bc1584553fe94a3..c2d9a19317a125afe347639b644ad22756f90e9c 100644 (file)
@@ -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
index ec3f4eeffc722ec92ec941ea3cb89fe9f78c17ef..c2d9a19317a125afe347639b644ad22756f90e9c 100644 (file)
@@ -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 (file)
index 0000000..9473564
--- /dev/null
@@ -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
index 0fd955db4cda920346d93da78d9a490c66f9d017..e6c26d2f63d507a4ad2d494b9f7fb802d3248ddb 100644 (file)
@@ -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;
index e9f66d890dda374fefdcf560bd7ecaa464ccdb94..117d4123801dc5e85c32b110546a2601a24cc6b4 100644 (file)
@@ -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
index b15a23a0e0a3b3f92f095174bf8741c981879d72..a56acb981072bcace2c84e843833e744a8d25e71 100644 (file)
@@ -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;