started testing furniture
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 1 Mar 2022 03:49:14 +0000 (21:49 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 1 Mar 2022 03:49:14 +0000 (21:49 -0600)
run_tree/assets/images/spritesheet.png
run_tree/scenes/quick_save_new.scene
src/entity/components/dispenser.onyx
src/entity/components/furniture.onyx [new file with mode: 0644]
src/entity/components/patron.onyx
src/entity/components/player.onyx
src/entity/manager.onyx
src/entity/schematics/furniture.onyx [new file with mode: 0644]
src/entity/schematics/patron.onyx

index 9ed43d4b3842502ca8cc177715dad9fdeac2662f..fc47fea25b02c9ca15249c7047f8d56f67f8a95a 100644 (file)
Binary files a/run_tree/assets/images/spritesheet.png and b/run_tree/assets/images/spritesheet.png differ
index 829da2f60f6c4776335f9e0c91b2646affe4867c..516a9a19df055ff771379329fe38df489bdfa9fe 100644 (file)
@@ -29,10 +29,10 @@ color.a = 1.0000
 [Player]
 id = 12
 flags = 2
-pos.x = 379.7973
-pos.y = 175.1558
-size.x = 32.0000
-size.y = 32.0000
+pos.x = 318.3422
+pos.y = 217.0257
+size.x = 16.0000
+size.y = 16.0000
 :MovementComponent
 controls.up = 87
 controls.down = 83
@@ -122,20 +122,18 @@ max_timeout = 2.0000
 [Patron]
 id = 22
 flags = 3
-pos.x = 388.6049
-pos.y = 284.5303
-size.x = 32.0000
-size.y = 32.0000
+pos.x = 392.0000
+pos.y = 408.0000
+size.x = 16.0000
+size.y = 16.0000
 :RenderComponent
-layer = 0
+layer = 5
 color.r = 1.0000
 color.g = 0.0000
 color.b = 0.0000
 color.a = 1.0000
 :PatronComponent
 state = 0
-seat_location.x = 400.0000
-seat_location.y = 400.0000
 order_item = "beer"
 order_show_animation = 0.0000
 holding = 0
@@ -197,6 +195,84 @@ color.g = 1.0000
 color.b = 1.0000
 color.a = 1.0000
 
+[Furniture]
+id = 30
+flags = 2
+pos.x = 136.0000
+pos.y = 256.0000
+size.x = 16.0000
+size.y = 32.0000
+:RenderComponent
+layer = 0
+color.r = 1.0000
+color.g = 1.0000
+color.b = 1.0000
+color.a = 1.0000
+:FurnitureComponent
+furniture_type = 0
+taken = false
+sprite.sheet = "./assets/images/spritesheet.png"
+sprite.pos.x = 32.0000
+sprite.pos.y = 32.0000
+sprite.size.x = 16.0000
+sprite.size.y = 32.0000
+sprite.color.r = 1.0000
+sprite.color.g = 1.0000
+sprite.color.b = 1.0000
+sprite.color.a = 1.0000
+
+[Furniture]
+id = 31
+flags = 2
+pos.x = 184.0000
+pos.y = 256.0000
+size.x = 16.0000
+size.y = 32.0000
+:RenderComponent
+layer = 0
+color.r = 1.0000
+color.g = 1.0000
+color.b = 1.0000
+color.a = 1.0000
+:FurnitureComponent
+furniture_type = 0
+taken = false
+sprite.sheet = "./assets/images/spritesheet.png"
+sprite.pos.x = 48.0000
+sprite.pos.y = 32.0000
+sprite.size.x = -16.0000
+sprite.size.y = 32.0000
+sprite.color.r = 1.0000
+sprite.color.g = 1.0000
+sprite.color.b = 1.0000
+sprite.color.a = 1.0000
+
+[Furniture]
+id = 32
+flags = 2
+pos.x = 160.0000
+pos.y = 256.0000
+size.x = 32.0000
+size.y = 32.0000
+:RenderComponent
+layer = 0
+color.r = 1.0000
+color.g = 1.0000
+color.b = 1.0000
+color.a = 1.0000
+:FurnitureComponent
+furniture_type = 1
+taken = false
+sprite.sheet = "./assets/images/spritesheet.png"
+sprite.pos.x = 48.0000
+sprite.pos.y = 32.0000
+sprite.size.x = 32.0000
+sprite.size.y = 32.0000
+sprite.color.r = 1.0000
+sprite.color.g = 1.0000
+sprite.color.b = 1.0000
+sprite.color.a = 1.0000
+
 [Tap]
 id = 14
 flags = 3
index 22c0e3c613de1e8e27770e2efba18bb806a6b435..2d3698b326efcec05808b3b47b276048affdd8de 100644 (file)
@@ -16,6 +16,8 @@ DispenserComponent :: struct {
     timeout := 0.0f;
 
     added :: (use this: ^DispenserComponent, entity: ^Entity) {
+        entity.flags |= .Interactable;
+
         if entity->has(InteractableComponent) {
             debug_log(.Error, "DispenserComponent expected entity to not have an InteractableComponent");
         }
diff --git a/src/entity/components/furniture.onyx b/src/entity/components/furniture.onyx
new file mode 100644 (file)
index 0000000..1fb10a5
--- /dev/null
@@ -0,0 +1,21 @@
+
+use package core
+
+#local Furniture_Type :: enum {
+    Seat;
+    Table;
+}
+
+FurnitureComponent :: struct {
+    use base: Component;
+
+    furniture_type: Furniture_Type;
+    taken := false;
+    sprite: Sprite;
+
+    init :: (use this: ^FurnitureComponent) {
+        sprite.pos = .{0, 32};
+        sprite.size = .{32, 32};
+        sprite.color = .{1, 1, 1};
+    }
+}
\ No newline at end of file
index 184f2a443560e7b861c2ecfa00d96040768d1209..b33004d7ed326fdcb079cf6b41eb93cf9835e187 100644 (file)
@@ -12,8 +12,8 @@ use package core
 PatronComponent :: struct {
     use component: Component;
 
-    state := Patron_State.Waiting_To_Place_Order;
-    seat_location: Vector2;
+    state: Patron_State;
+    seat: Entity_ID;
     order_item: str;
     order_show_animation: f32;
     holding: Entity_ID;
@@ -21,7 +21,6 @@ PatronComponent :: struct {
 
     init :: (use this: ^PatronComponent) {
         order_item = "beer";
-        seat_location = .{ 400, 400 };
     }
 
     added :: (use this: ^PatronComponent, entity: ^Entity) {
@@ -34,12 +33,28 @@ PatronComponent :: struct {
 
     update :: (use this: ^PatronComponent, entity: ^Entity, dt: f32) {
         if state == .Walking_To_Seat {
-            delta := Vector2.norm(seat_location - entity.pos) * 100;
-            entity.pos += delta * dt;
+            if seat == Entity_Nothing {
+                seats := scene->query_by_component(.{ 0, 0, 10000, 10000 }, FurnitureComponent);
+                defer memory.free_slice(^seats);
+
+                for seats {
+                    furniture := it->get(FurnitureComponent);
+                    if !furniture.taken && furniture.furniture_type == .Seat {
+                        furniture.taken = true;
+                        seat = it.id;
+                        break;
+                    }
+                }
+            }
 
+            seat_entity := scene->get(seat);
+            seat_location := seat_entity.pos;
             if Vector2.square_mag(seat_location - entity.pos) < 16 {
                 entity.pos = seat_location;
                 state = .Waiting_To_Place_Order;
+            } else {
+                delta := Vector2.norm(seat_location - entity.pos) * 100;
+                entity.pos += delta * dt;
             }
         }
 
index 3b62e949301a4fecc9ce8edbcbca605b89ded9ed..d3292a1e5eb18a585fbb36eab61969dd3c2448a6 100644 (file)
@@ -14,11 +14,11 @@ PlayerComponent :: struct {
         // Highlight the object that you are going to interact with
         {
             player.nearby_interact = Entity_Nothing;
-            area    := Rect.{pos.x - size.x, pos.y - size.y, size.x * 2, size.y * 2};
+            area    := Rect.{pos.x - size.x, pos.y - size.y, size.x * 4, size.y * 4};
             objects := scene->query_by_component(area, InteractableComponent);
             defer memory.free_slice(^objects);
 
-            dist := size.x * size.x + size.y * size.y;
+            dist := 4 * (size.x * size.x + size.y * size.y);
 
             for objects {
                 d := Vector2.square_mag(pos - it.pos);
@@ -31,7 +31,7 @@ PlayerComponent :: struct {
 
         {
             player.nearby_holding = Entity_Nothing;
-            area    := Rect.{pos.x - size.x, pos.y - size.y, size.x * 2, size.y * 2};
+            area    := Rect.{pos.x - size.x, pos.y - size.y, size.x * 4, size.y * 4};
             objects := scene->query_by_flags(area, .Carryable);
             defer memory.free_slice(^objects);
 
index 8ecd845bd039d6bf1264330d90b8977f09549399..c205a23b06d4fdc3d4031a104ee1fc8495001ba2 100644 (file)
@@ -380,3 +380,25 @@ entity_manager_query_by_flags :: (use this: ^Entity_Manager, area: Rect, flags:
     return ents;
 }
 
+
+
+
+
+@Relocate
+Sprite :: struct {
+    sheet: str;
+    pos:  Vector2;
+    size: Vector2;
+    color: Color;
+
+    render :: (use this: ^Sprite, r: Rect) {
+        texture, valid := texture_lookup(sheet);
+
+        immediate_set_color(color);
+        if !valid {
+            immediate_rectangle(r.x, r.y, r.w, r.h);
+        } else {
+            immediate_subimage(^texture, r.x, r.y, r.w, r.h, pos.x, pos.y, size.x, size.y);
+        }
+    }
+}
diff --git a/src/entity/schematics/furniture.onyx b/src/entity/schematics/furniture.onyx
new file mode 100644 (file)
index 0000000..058692f
--- /dev/null
@@ -0,0 +1,28 @@
+
+use package core
+
+Furniture :: struct {
+    #struct_tag Entity_Schematic.{
+        (scene) => Furniture.create(scene, .{0, 0})
+    }
+
+    create :: (scene: ^Entity_Manager, pos: Vector2) -> ^Entity {
+        this := scene->make();
+        this.pos = pos;
+        this.size = .{16, 16};
+        this.flags |= .Solid;
+
+        scene->create_and_add(this, RenderComponent) {
+            comp.func = render;
+        }
+
+        scene->create_and_add(this, FurnitureComponent) {}
+
+        return this;
+    }
+
+    render :: (entity: ^Entity) {
+        furniture := entity->get(FurnitureComponent);
+        furniture.sprite->render(entity->get_rect());
+    }
+}
\ No newline at end of file
index f2aa238f31a85ff4ebd53a57c7299506350ffdab..fd0dffd3986552268be5e00e2aa4c9820db7c4aa 100644 (file)
@@ -14,6 +14,7 @@ Patron :: struct {
 
         scene->create_and_add(this, RenderComponent) {
             comp.func = render;
+            comp.layer = 5;
             comp.color = .{1, 0, 0};
         }