From 69713fb7d11b7d5783761833a9bf63c184bc6833 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Tue, 10 Sep 2024 22:26:26 +0200 Subject: [PATCH] Very, very basic building stuff. --- assets/resources/fence_fortified.png | Bin 0 -> 5582 bytes assets/resources/fence_fortified.png.import | 34 ++++++++++++++++++ .../fence_fortified.tscn | 0 data/items/fence_fortified.tres | 12 +++++++ data/recipes/fence_fortified.tres | 12 +++++++ objects/player.gd | 5 +-- objects/player.tscn | 6 +++- scenes/game.tscn | 10 +++++- systems/BuildSystem.gd | 27 ++++++++++++-- 9 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 assets/resources/fence_fortified.png create mode 100644 assets/resources/fence_fortified.png.import rename assets/{scene_props => resources}/fence_fortified.tscn (100%) create mode 100644 data/items/fence_fortified.tres create mode 100644 data/recipes/fence_fortified.tres diff --git a/assets/resources/fence_fortified.png b/assets/resources/fence_fortified.png new file mode 100644 index 0000000000000000000000000000000000000000..72a9fa58c64dcc79c5ec353c27a462e57a99fc78 GIT binary patch literal 5582 zcmV;<6*20GP)EX>4Tx04R}tkv&MmKpe$iQ>9ue9qb^YkfAzR5ET(8twIqhgj%6h2a`)bgeDD1 zi;JV+T5#}VvFhOBtgC~oAP9bdI6F8gx=4xtOA0MwJUH&hyL*qjcYshYG0o~21vI^4 zrV?>6lU)%5ujob)VGLqgW|lE4NlAE)uY36TdKcqa-sk=tJ!;NkfKMczVTM^DUMHU1 ztQeg4i6g8itHkHTBPLyt_>t?1%Ws?u4huXpVy07b#1Ue#(8fv|v!baHPY_2{O{aVz z9iAZ2SAzwi_pa{~5T_TmEt#nEE8W z*3zO!KzJLtxNd369&ot>^gS7}DLay%rjXAA?`QN)S)lh82(G%lHTQA)0Hmp__CX>@2HM@dakSAh-}000xENklXzk4V$deY^YK^R@S0?=yd_z0W!K(%m$eDg*AW-S<@YKIg3GdEfVWKi0a& zi~RcNe|Y0t&phpFUhD*z**hM5^vRbz z_{d&1EzS{xoom=DfZqpR`~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8_24kwoLUy=6q+jI&OTDtBN=}`;lIu>nJ|pRqyRP2z z9sZeJ$0Q)hEswauxEgdP20LY{hzzQl1Kk0K`U9%kDeIb))OFYGNY?FLP?8JkGR$i-ixp{k)gI7zikigMhn& z1)Ky*1VJZn2F(3PcmT3xLuKL6X-;h{0!5g+@VPu+1p cFOuv312f!}gPu1wJpcdz07*qoM6N<$f*?)sumAu6 literal 0 HcmV?d00001 diff --git a/assets/resources/fence_fortified.png.import b/assets/resources/fence_fortified.png.import new file mode 100644 index 0000000..08653b0 --- /dev/null +++ b/assets/resources/fence_fortified.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cx3x4l20q17xh" +path="res://.godot/imported/fence_fortified.png-1ae65c603e478020bc26d4e987d66517.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/resources/fence_fortified.png" +dest_files=["res://.godot/imported/fence_fortified.png-1ae65c603e478020bc26d4e987d66517.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/assets/scene_props/fence_fortified.tscn b/assets/resources/fence_fortified.tscn similarity index 100% rename from assets/scene_props/fence_fortified.tscn rename to assets/resources/fence_fortified.tscn diff --git a/data/items/fence_fortified.tres b/data/items/fence_fortified.tres new file mode 100644 index 0000000..5d97213 --- /dev/null +++ b/data/items/fence_fortified.tres @@ -0,0 +1,12 @@ +[gd_resource type="Resource" script_class="Item" load_steps=4 format=3 uid="uid://c714vj3s6cnqg"] + +[ext_resource type="Texture2D" uid="uid://cx3x4l20q17xh" path="res://assets/resources/fence_fortified.png" id="1_hyv8l"] +[ext_resource type="Script" path="res://model/item.gd" id="1_u43c0"] +[ext_resource type="PackedScene" uid="uid://dv60qx8nqw3vg" path="res://assets/resources/fence_fortified.tscn" id="2_8ttdv"] + +[resource] +script = ExtResource("1_u43c0") +name = "" +scene = ExtResource("2_8ttdv") +icon = ExtResource("1_hyv8l") +max_stack_size = 64 diff --git a/data/recipes/fence_fortified.tres b/data/recipes/fence_fortified.tres new file mode 100644 index 0000000..761ed30 --- /dev/null +++ b/data/recipes/fence_fortified.tres @@ -0,0 +1,12 @@ +[gd_resource type="Resource" script_class="Recipe" load_steps=5 format=3 uid="uid://dtlb5wp5shlm3"] + +[ext_resource type="Script" path="res://model/recipe.gd" id="1_h0rj4"] +[ext_resource type="Resource" uid="uid://bn5j38jbwlj1f" path="res://data/items/stick.tres" id="1_i6g7d"] +[ext_resource type="Resource" uid="uid://dmjr6pmb17l2y" path="res://data/items/woodplanks.tres" id="2_d54b6"] +[ext_resource type="Resource" uid="uid://c714vj3s6cnqg" path="res://data/items/fence_fortified.tres" id="3_bsd6g"] + +[resource] +script = ExtResource("1_h0rj4") +name = "Fence Fortified" +ingredients = Array[Resource("res://model/item.gd")]([ExtResource("1_i6g7d"), ExtResource("1_i6g7d"), ExtResource("2_d54b6")]) +results = Array[Resource("res://model/item.gd")]([ExtResource("3_bsd6g")]) diff --git a/objects/player.gd b/objects/player.gd index 46280c8..f2552cd 100644 --- a/objects/player.gd +++ b/objects/player.gd @@ -1,12 +1,13 @@ class_name Player extends CharacterBody3D -const SPEED = 4.0 +const SPEED = 3.0 const JUMP_VELOCITY = 2.5 @onready var geometry:Node3D = %Geometry @onready var actionable_detector = %ActionableDetector @onready var animation_tree:AnimationTree = $Geometry/Rogue/AnimationTree +@onready var build_location:Node3D = %BuildLocation # Get the gravity from the project settings to be synced with RigidBody nodes. var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") @@ -65,7 +66,7 @@ func on_item_picked_up(item:Item): func get_actionable_global_transform() -> Vector3: - return actionable_detector.global_position + return build_location.global_position func _unhandled_input(_event: InputEvent) -> void: if Input.is_action_just_pressed("ui_accept"): diff --git a/objects/player.tscn b/objects/player.tscn index e513e79..185dd41 100644 --- a/objects/player.tscn +++ b/objects/player.tscn @@ -45,7 +45,11 @@ collision_mask = 16 [node name="CollisionShape3D" type="CollisionShape3D" parent="Geometry/ActionableDetector"] shape = SubResource("SphereShape3D_wrkyq") +[node name="BuildLocation" type="Node3D" parent="Geometry"] +unique_name_in_owner = true +transform = Transform3D(2.5, 0, 0, 0, 2.5, 0, 0, 0, 2.5, 0, 0, 2.4682) + [node name="Camera3D" type="Camera3D" parent="."] unique_name_in_owner = true -transform = Transform3D(1, 0, 0, 0, 0.460138, 0.887848, 0, -0.887848, 0.460138, 0, 2.91421, 1.186) +transform = Transform3D(1, 0, 0, 0, 0.639707, 0.768619, 0, -0.768619, 0.639707, 0, 2.23862, 1.4653) current = true diff --git a/scenes/game.tscn b/scenes/game.tscn index e3a6662..60d6ded 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=8 format=3 uid="uid://cqie4cy0uy1t0"] +[gd_scene load_steps=9 format=3 uid="uid://cqie4cy0uy1t0"] [ext_resource type="PackedScene" uid="uid://ch0s3dxx3rpir" path="res://objects/player.tscn" id="2_rjgxk"] [ext_resource type="Script" path="res://systems/QuestSystem.gd" id="4_8oxap"] [ext_resource type="Script" path="res://systems/BuildSystem.gd" id="4_iqdys"] +[ext_resource type="Resource" uid="uid://c714vj3s6cnqg" path="res://data/items/fence_fortified.tres" id="5_ii2f8"] [ext_resource type="PackedScene" uid="uid://dmagdl5pi6jdj" path="res://world/level.tscn" id="6_svjo8"] [sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_y65pc"] @@ -35,5 +36,12 @@ script = ExtResource("4_8oxap") [node name="BuildSystem" type="Node" parent="."] script = ExtResource("4_iqdys") +build_item = ExtResource("5_ii2f8") + +[node name="BuildPreview" type="Node3D" parent="BuildSystem"] +unique_name_in_owner = true + +[node name="BuiltStructures" type="Node" parent="BuildSystem"] +unique_name_in_owner = true [editable path="Player"] diff --git a/systems/BuildSystem.gd b/systems/BuildSystem.gd index b3e5ab1..f625599 100644 --- a/systems/BuildSystem.gd +++ b/systems/BuildSystem.gd @@ -1,14 +1,37 @@ class_name BuildSystem extends Node +@onready var build_preview = %BuildPreview @onready var player = %Player +@onready var built_structures = %BuiltStructures + +@export var build_item:Item = null # Called when the node enters the scene tree for the first time. func _ready(): pass # Replace with function body. +func update_build_preview_item() -> void: + for child in build_preview.get_children(): + if build_item == null or child.scene_file_path != build_item.scene.resource_path: + child.get_parent().remove_child(child) + child.queue_free() + + if build_preview.get_child_count() == 0 and build_item != null: + build_preview.add_child(build_item.scene.instantiate()) + # Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta): +func _physics_process(_delta): + update_build_preview_item() + var build_location:Vector3 = player.get_actionable_global_transform() - build_location = Vector3(roundf(build_location.x), build_location.y, roundf(build_location.z)) + build_location = Vector3(roundf(build_location.x * 2), build_location.y, roundf(build_location.z * 2)) * 0.5 + build_preview.global_position = build_location + + if build_item != null and Input.is_action_just_pressed("interaction"): + var new_structure:Node3D = build_item.scene.instantiate() + new_structure.transform = build_preview.transform + built_structures.add_child(new_structure) + get_viewport().set_input_as_handled() + return