From b97916bedc2445c9e783dec0b1c329432850db25 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 8 Jan 2023 10:01:13 +0100 Subject: [PATCH] Start producing crops --- island/CropTile.gd | 5 +++++ island/CropTile.tscn | 7 ++++++- island/Island.tscn | 8 +------- island/MoveTowardsPlayer.gd | 1 - island/Pineapple.tscn | 2 +- island/Producer.gd | 18 ++++++++++++++++++ 6 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 island/Producer.gd diff --git a/island/CropTile.gd b/island/CropTile.gd index 16a3ce8..3537e6a 100644 --- a/island/CropTile.gd +++ b/island/CropTile.gd @@ -8,6 +8,10 @@ signal on_complete() @onready var growth_timer: Timer = $GrowthTimer @onready var sprout_mesh: MeshInstance3D = $Plant/Sprout @onready var pop_sound: AudioStreamPlayer3D = $Pop +@onready var producer: Node3D = $Producer + +@export var produce_scene: PackedScene = preload("res://island/Pineapple.tscn") + @export var debug_growth: bool = false @export var debug_growth_offset: float = 0.0; @@ -15,6 +19,7 @@ signal on_complete() func plant(): if growth_timer.is_stopped(): growth_timer.start() + producer.produce_with_random_force() emit_signal("on_planted") diff --git a/island/CropTile.tscn b/island/CropTile.tscn index c66f9d3..9c99eda 100644 --- a/island/CropTile.tscn +++ b/island/CropTile.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=7 format=3 uid="uid://cf35yl04qtru3"] +[gd_scene load_steps=8 format=3 uid="uid://cf35yl04qtru3"] [ext_resource type="Script" path="res://island/CropTile.gd" id="1_7lls2"] [ext_resource type="Material" uid="uid://w0ipvdnh4l8s" path="res://island/CropMaterial.tres" id="2_1oajr"] +[ext_resource type="Script" path="res://island/Producer.gd" id="2_jejoo"] [ext_resource type="AudioStream" uid="uid://lkftwgdun745" path="res://assets/pop.wav" id="3_gur2a"] [ext_resource type="Script" path="res://island/Pop.gd" id="4_5e7wk"] @@ -25,6 +26,10 @@ _surfaces = [{ [node name="CropTile" type="Node3D"] script = ExtResource("1_7lls2") +[node name="Producer" type="Node3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0, 0.5) +script = ExtResource("2_jejoo") + [node name="Plant" type="Area3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0, 0.5) diff --git a/island/Island.tscn b/island/Island.tscn index cc6caef..da04812 100644 --- a/island/Island.tscn +++ b/island/Island.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=16 format=3 uid="uid://bg88gc1w1gw5m"] +[gd_scene load_steps=15 format=3 uid="uid://bg88gc1w1gw5m"] [ext_resource type="Shader" path="res://island/Sea.gdshader" id="1_agjfy"] [ext_resource type="Texture2D" uid="uid://bdoifsf6k0qb8" path="res://assets/water_tile.png" id="1_w6ara"] @@ -9,7 +9,6 @@ [ext_resource type="PackedScene" uid="uid://bknwefv5ycc3u" path="res://island/PyramidSmolMesh.tscn" id="6_klmt8"] [ext_resource type="PackedScene" uid="uid://boxtb3trgcy8c" path="res://island/PillarMesh.tscn" id="7_grmwj"] [ext_resource type="PackedScene" uid="uid://cf35yl04qtru3" path="res://island/CropTile.tscn" id="8_4ooup"] -[ext_resource type="PackedScene" uid="uid://v7bv81krh12e" path="res://island/Pineapple.tscn" id="10_cvxfg"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_3uyyi"] render_priority = 0 @@ -96,8 +95,3 @@ debug_growth_offset = 0.5 transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 2, 8) debug_growth = true debug_growth_offset = 0.6 - -[node name="Pineapple" parent="." instance=ExtResource("10_cvxfg")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 4, 3, 31) - -[editable path="Pineapple"] diff --git a/island/MoveTowardsPlayer.gd b/island/MoveTowardsPlayer.gd index 6390c91..a09584f 100644 --- a/island/MoveTowardsPlayer.gd +++ b/island/MoveTowardsPlayer.gd @@ -19,7 +19,6 @@ func _physics_process(delta): if captured: var direction = player.position - parent.position var force = direction.normalized() * force_multiplier * delta - force.y = abs(force.y) parent.apply_force(force) diff --git a/island/Pineapple.tscn b/island/Pineapple.tscn index 5eedaf7..bbaa610 100644 --- a/island/Pineapple.tscn +++ b/island/Pineapple.tscn @@ -14,7 +14,7 @@ radius = 3.0 [node name="Pineapple" type="RigidBody3D"] collision_layer = 2 lock_rotation = true -linear_damp = 3.0 +linear_damp = 1.0 [node name="Shape" type="CollisionShape3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.45, 0) diff --git a/island/Producer.gd b/island/Producer.gd new file mode 100644 index 0000000..8bd6e16 --- /dev/null +++ b/island/Producer.gd @@ -0,0 +1,18 @@ +extends Node3D + + +@export var produce_scene: PackedScene = preload("res://island/Pineapple.tscn") + +var rng: RandomNumberGenerator + + +func _ready(): + rng = RandomNumberGenerator.new() + rng.randomize() + + +func produce_with_random_force(): + # TODO: Not sure it's a good idea attaching produce to the crop + var produce: RigidBody3D = produce_scene.instantiate() + add_child(produce) + produce.apply_impulse(Vector3.UP * rng.randf_range(15.0, 25.0))