This commit is contained in:
2024-09-01 12:07:48 +02:00
parent a74dfd4527
commit 48158a1928
59 changed files with 1086 additions and 213 deletions

23
objects/Animal.tscn Normal file
View File

@@ -0,0 +1,23 @@
[gd_scene load_steps=4 format=3 uid="uid://cj457q2fx5mim"]
[ext_resource type="Script" path="res://scripts/animal.gd" id="1_bjim0"]
[ext_resource type="Texture2D" uid="uid://cxbv1inffa2bq" path="res://assets/plants/abre1.png" id="2_n8edq"]
[sub_resource type="CircleShape2D" id="CircleShape2D_5dvar"]
radius = 599.083
[node name="Animal" type="Node2D"]
script = ExtResource("1_bjim0")
[node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(0.3, 0.3)
texture = ExtResource("2_n8edq")
offset = Vector2(170, -550)
[node name="Area2D" type="Area2D" parent="."]
collision_layer = 2
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource("CircleShape2D_5dvar")
[connection signal="area_entered" from="Area2D" to="." method="_on_area_2d_area_entered"]

View File

@@ -1,166 +1,8 @@
[gd_scene load_steps=6 format=3 uid="uid://x4kv2y5f52cm"]
[ext_resource type="Script" path="res://scripts/plant.gd" id="1_drvq1"]
[ext_resource type="Texture2D" uid="uid://b3kjaw1hajc6s" path="res://assets/grille_seeds.png" id="1_n5onq"]
[sub_resource type="GDScript" id="GDScript_x3g5o"]
script/source = "class_name Plant
extends Node2D
enum PlantState { SAPLING, GROWN, DEAD}
signal grown
signal died
@onready var growing_timer: Timer = $Growing
@onready var need_checker: Timer = $NeedChecker
@onready var sapling_count_down: Timer = $SaplingCountDown
@onready var reproduction: Timer = $Reproduction
@onready var sprite_node: AnimatedSprite2D = $AnimatedSprite2D
const NEED_CHECK_PERIOD := 0.5
const SAPLING_LIFETIME_MULT := 2.0 # this multiplies the time to grow to tell the time it can stay as a sapling
const OFFSET_REPRODUCTION_PERCT_DIST := 0.5
var parameter: PlantType
var state := PlantState.SAPLING
var sapling_time_left: float
var can_grow := true
func init(plant_parameter: PlantType):
parameter = plant_parameter
sapling_count_down.start(SAPLING_LIFETIME_MULT * parameter.growing_time)
sprite_node.sprite_frames = parameter.sprite_frames
need_checker.start(NEED_CHECK_PERIOD)
func _on_need_checker_timeout() -> void:
can_grow = check_terrain_viability()
growing_timer.paused = not can_grow and state == PlantState.SAPLING
reproduction.paused = not can_grow
func check_terrain_viability() -> bool:
var water := GameTerrain.get_stat(position, GameTerrain.Stats.WATER)
if water < parameter.water_need[0] or water > parameter.water_need[1]:
return false
var fertility := GameTerrain.get_stat(position, GameTerrain.Stats.FERTILITY)
if fertility < parameter.fertility_need[0] or fertility > parameter.fertility_need[1]:
return false
var presence := GameTerrain.get_stat(position, GameTerrain.Stats.PRESENCE)
presence += GameTerrain.LEVELS_NUMBER / 2
if presence < parameter.presence_need[0] or presence > parameter.presence_need[1]:
return false
return true
func _on_growing_timeout() -> void:
if state == PlantState.SAPLING:
can_grow = check_terrain_viability()
if not can_grow:
growing_timer.start()
return
match state:
PlantState.SAPLING:
grow()
PlantState.GROWN:
die()
PlantState.DEAD:
remove()
func plant(new_position: Vector2):
position = new_position
state = PlantState.SAPLING
growing_timer.start(parameter.growing_time)
sprite_node.play(\"SAPLING\")
func grow():
if state != PlantState.SAPLING:
push_error(\"Tried to grow \" + parameter.type + \", but was not at sapling state\")
return
state = PlantState.GROWN
sapling_count_down.stop()
growing_timer.start(parameter.dying_time)
GameTerrain.modify_zone(position,
parameter.distance_prod,
GameTerrain.Stats.WATER,
parameter.water_prod)
GameTerrain.modify_zone(position,
parameter.distance_prod,
GameTerrain.Stats.FERTILITY,
parameter.fertility_prod)
GameTerrain.modify_zone(position,
parameter.distance_prod,
GameTerrain.Stats.PRESENCE,
parameter.presence_prod)
reproduction.start(parameter.dying_time / (parameter.offspring_per_lifetime + 1) + 0.1)
grown.emit()
sprite_node.play(\"GROWN\")
func die():
state = PlantState.DEAD
# remove alive prod and add dead prod
GameTerrain.modify_zone(position,
parameter.distance_prod,
GameTerrain.Stats.WATER,
-parameter.water_prod + parameter.dead_water_prod)
GameTerrain.modify_zone(position,
parameter.distance_prod,
GameTerrain.Stats.FERTILITY,
-parameter.fertility_prod + parameter.dead_fertility_prod)
GameTerrain.modify_zone(position,
parameter.distance_prod,
GameTerrain.Stats.PRESENCE,
-parameter.presence_prod)
growing_timer.start(parameter.dead_time)
died.emit()
sprite_node.play(\"DEAD\")
func remove(was_dead: bool = true):
if was_dead:
GameTerrain.modify_zone(position,
parameter.distance_prod,
GameTerrain.Stats.WATER,
-parameter.dead_water_prod)
GameTerrain.modify_zone(position,
parameter.distance_prod,
GameTerrain.Stats.FERTILITY,
-parameter.dead_fertility_prod)
queue_free()
func _on_sapling_count_down_timeout() -> void:
remove(false)
func _on_reproduction_timeout() -> void:
var min_dist := parameter.distance_prod - parameter.distance_prod * OFFSET_REPRODUCTION_PERCT_DIST
var max_dist := parameter.distance_prod + parameter.distance_prod * OFFSET_REPRODUCTION_PERCT_DIST
var plant_pos = position + (Vector2.RIGHT * randf_range(min_dist, max_dist)).rotated(randf_range(0, PI))
var space := get_world_2d().direct_space_state
var parameters = PhysicsPointQueryParameters2D.new()
parameters.position = plant_pos
parameters.collide_with_areas = true
parameters.collide_with_bodies = false
var result := space.intersect_point(parameters, 1)
if result.size() > 0:
return
var offspring = self.duplicate()
self.get_parent().add_child(offspring)
offspring.init(parameter)
offspring.plant(plant_pos)
"
[sub_resource type="AtlasTexture" id="AtlasTexture_5did5"]
atlas = ExtResource("1_n5onq")
region = Rect2(810, 540, 270, 270)
@@ -180,7 +22,7 @@ animations = [{
radius = 36.0
[node name="Plant" type="Node2D"]
script = SubResource("GDScript_x3g5o")
script = ExtResource("1_drvq1")
[node name="Growing" type="Timer" parent="."]
one_shot = true

View File

@@ -1,30 +1,20 @@
[gd_resource type="Resource" script_class="PlantType" load_steps=9 format=3 uid="uid://bgi2lo7kb3d2v"]
[gd_resource type="Resource" script_class="PlantType" load_steps=8 format=3 uid="uid://bgi2lo7kb3d2v"]
[ext_resource type="Script" path="res://scripts/plant_type.gd" id="1_i8xe4"]
[ext_resource type="Texture2D" uid="uid://b3kjaw1hajc6s" path="res://assets/grille_seeds.png" id="2_4rpny"]
[ext_resource type="Texture2D" uid="uid://r1bq2tgt1yxf" path="res://assets/gamejam_plantes_props1.png" id="2_gaemm"]
[ext_resource type="Texture2D" uid="uid://hkcjtfch0kub" path="res://assets/plants/evolution1.png" id="3_5jw8q"]
[ext_resource type="Texture2D" uid="uid://24ift4wt1h2h" path="res://assets/plants/evolution2.1.png" id="4_1u64t"]
[ext_resource type="Texture2D" uid="uid://d0xlqgttxwkgh" path="res://assets/plants/evolution2.png" id="5_2ybgr"]
[sub_resource type="AtlasTexture" id="AtlasTexture_1lwna"]
atlas = ExtResource("2_4rpny")
region = Rect2(0, 0, 270, 270)
[sub_resource type="AtlasTexture" id="AtlasTexture_fxqnu"]
atlas = ExtResource("2_gaemm")
region = Rect2(1920, 1620, 320, 540)
[sub_resource type="AtlasTexture" id="AtlasTexture_sjq1e"]
atlas = ExtResource("2_gaemm")
region = Rect2(320, 1080, 320, 540)
[sub_resource type="AtlasTexture" id="AtlasTexture_jsm3j"]
atlas = ExtResource("2_gaemm")
region = Rect2(0, 1080, 320, 540)
[sub_resource type="SpriteFrames" id="SpriteFrames_fxtnk"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_fxqnu")
"texture": ExtResource("3_5jw8q")
}],
"loop": true,
"name": &"DEAD",
@@ -32,7 +22,7 @@ animations = [{
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_sjq1e")
"texture": ExtResource("4_1u64t")
}],
"loop": true,
"name": &"GROWN",
@@ -40,7 +30,7 @@ animations = [{
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_jsm3j")
"texture": ExtResource("5_2ybgr")
}],
"loop": true,
"name": &"SAPLING",

View File

@@ -3,6 +3,8 @@
[ext_resource type="Script" path="res://scripts/plant_type.gd" id="1_meppe"]
[ext_resource type="Texture2D" uid="uid://r1bq2tgt1yxf" path="res://assets/gamejam_plantes_props1.png" id="2_jkmk8"]
[ext_resource type="Texture2D" uid="uid://b3kjaw1hajc6s" path="res://assets/grille_seeds.png" id="2_m81be"]
[ext_resource type="Texture2D" uid="uid://dwm660gppiset" path="res://assets/plants/abre2.png" id="4_1v11a"]
[ext_resource type="Texture2D" uid="uid://d02mdx460lfgm" path="res://assets/plants/evolution2.4.png" id="5_d75nd"]
[sub_resource type="AtlasTexture" id="AtlasTexture_bqj8q"]
atlas = ExtResource("2_m81be")
@@ -12,14 +14,6 @@ region = Rect2(270, 0, 270, 270)
atlas = ExtResource("2_jkmk8")
region = Rect2(2880, 1080, 320, 540)
[sub_resource type="AtlasTexture" id="AtlasTexture_7r8et"]
atlas = ExtResource("2_jkmk8")
region = Rect2(2880, 540, 320, 540)
[sub_resource type="AtlasTexture" id="AtlasTexture_oy8ng"]
atlas = ExtResource("2_jkmk8")
region = Rect2(3200, 0, 320, 540)
[sub_resource type="SpriteFrames" id="SpriteFrames_shufc"]
animations = [{
"frames": [{
@@ -32,7 +26,7 @@ animations = [{
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_7r8et")
"texture": ExtResource("4_1v11a")
}],
"loop": true,
"name": &"GROWN",
@@ -40,7 +34,7 @@ animations = [{
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_oy8ng")
"texture": ExtResource("5_d75nd")
}],
"loop": true,
"name": &"SAPLING",

View File

@@ -1,30 +1,20 @@
[gd_resource type="Resource" script_class="PlantType" load_steps=9 format=3 uid="uid://dnahox31xqy6l"]
[gd_resource type="Resource" script_class="PlantType" load_steps=8 format=3 uid="uid://dnahox31xqy6l"]
[ext_resource type="Script" path="res://scripts/plant_type.gd" id="1_mhtmv"]
[ext_resource type="Texture2D" uid="uid://r1bq2tgt1yxf" path="res://assets/gamejam_plantes_props1.png" id="2_gcjog"]
[ext_resource type="Texture2D" uid="uid://b3kjaw1hajc6s" path="res://assets/grille_seeds.png" id="2_od2qm"]
[ext_resource type="Texture2D" uid="uid://jmyn1g18nyql" path="res://assets/plants/evolution1.2.png" id="3_n58s0"]
[ext_resource type="Texture2D" uid="uid://br1olfut3p0tx" path="res://assets/plants/evolution1.1.png" id="4_ulvmw"]
[ext_resource type="Texture2D" uid="uid://hkcjtfch0kub" path="res://assets/plants/evolution1.png" id="5_6gtba"]
[sub_resource type="AtlasTexture" id="AtlasTexture_dkacp"]
atlas = ExtResource("2_od2qm")
region = Rect2(540, 0, 270, 270)
[sub_resource type="AtlasTexture" id="AtlasTexture_ncq3n"]
atlas = ExtResource("2_gcjog")
region = Rect2(0, 540, 320, 540)
[sub_resource type="AtlasTexture" id="AtlasTexture_slfxf"]
atlas = ExtResource("2_gcjog")
region = Rect2(1280, 1080, 320, 540)
[sub_resource type="AtlasTexture" id="AtlasTexture_gsxj4"]
atlas = ExtResource("2_gcjog")
region = Rect2(2240, 0, 320, 540)
[sub_resource type="SpriteFrames" id="SpriteFrames_d15np"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_ncq3n")
"texture": ExtResource("3_n58s0")
}],
"loop": true,
"name": &"DEAD",
@@ -32,7 +22,7 @@ animations = [{
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_slfxf")
"texture": ExtResource("4_ulvmw")
}],
"loop": true,
"name": &"GROWN",
@@ -40,7 +30,7 @@ animations = [{
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_gsxj4")
"texture": ExtResource("5_6gtba")
}],
"loop": true,
"name": &"SAPLING",