From 7240d493ad003eee8d1489a4b201fe2e64a8a5f8 Mon Sep 17 00:00:00 2001 From: Josh Maggard Date: Sat, 13 Apr 2024 01:15:57 -0500 Subject: [PATCH] Add biomes --- Biome.gd | 9 ++ DebugLabel.gd | 4 + GameEvents.gd | 5 +- Water.gd | 38 +++++++++ biome.tscn | 10 +++ mai82AD.tmp | 227 ++++++++++++++++++++++++++++++++++++++++++++++++++ main.tscn | 115 ++++++++++++++++++++----- player.gd | 12 ++- player.tscn | 1 + 9 files changed, 397 insertions(+), 24 deletions(-) create mode 100644 Biome.gd create mode 100644 Water.gd create mode 100644 biome.tscn create mode 100644 mai82AD.tmp diff --git a/Biome.gd b/Biome.gd new file mode 100644 index 0000000..cacbe37 --- /dev/null +++ b/Biome.gd @@ -0,0 +1,9 @@ +class_name Biome +extends Area2D + +@export var water_bg_color: Color +@export var water_color: Color + +func _on_body_entered(body: Node2D) -> void: + if body is Player: + GameEvents.on_enter_new_biome.emit(self) diff --git a/DebugLabel.gd b/DebugLabel.gd index df50446..32fceb0 100644 --- a/DebugLabel.gd +++ b/DebugLabel.gd @@ -5,6 +5,10 @@ var values = {} func _ready() -> void: visible = false GameEvents.add_debug_obj.connect(add_debug_obj) + GameEvents.on_enter_new_biome.connect(_on_enter_new_biome) + +func _on_enter_new_biome(biome: Biome): + add_debug_obj("biome", biome.name) func _unhandled_input(event: InputEvent) -> void: if event.is_action_pressed("show_debug"): diff --git a/GameEvents.gd b/GameEvents.gd index 9bfc3fd..b0d9a8c 100644 --- a/GameEvents.gd +++ b/GameEvents.gd @@ -1,7 +1,8 @@ extends Node -signal add_debug_obj(key, value) -signal add_message(message) +signal add_debug_obj(key: String, value) +signal add_message(message: String) +signal on_enter_new_biome(biome: Biome) func add_message_emit(message): add_message.emit(message) diff --git a/Water.gd b/Water.gd new file mode 100644 index 0000000..872a789 --- /dev/null +++ b/Water.gd @@ -0,0 +1,38 @@ +extends Polygon2D + +@export var default_biome: Biome +@export var biome_transition_time: float = 1.0 +@export var biome_transition_curve: Curve +@onready var water_bg: Polygon2D = $WaterBG + + +var current_biome: Biome +var previous_water_color: Color +var previous_water_bg_color: Color + +var count = 0.0 +func _ready(): + GameEvents.on_enter_new_biome.connect(on_enter_new_biome) + color = default_biome.water_color + water_bg.color = default_biome.water_bg_color + current_biome = default_biome + +func on_enter_new_biome(new_biome: Biome): + print(new_biome) + if new_biome == current_biome: + return + count = biome_transition_time + current_biome = new_biome + previous_water_bg_color = water_bg.color + previous_water_color = color + + +func _process(delta: float) -> void: + if count <= 0: + return + + count -= delta + var t = 1 - (count/biome_transition_time) + var sample = biome_transition_curve.sample(t) + color = lerp(previous_water_color, current_biome.water_color, sample) + water_bg.color = lerp(previous_water_bg_color, current_biome.water_bg_color, sample) diff --git a/biome.tscn b/biome.tscn new file mode 100644 index 0000000..e96fd67 --- /dev/null +++ b/biome.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=2 format=3 uid="uid://b1tw6cgdbe6r7"] + +[ext_resource type="Script" path="res://Biome.gd" id="1_nuv4q"] + +[node name="Biome" type="Area2D"] +script = ExtResource("1_nuv4q") +water_bg_color = Color(0.356863, 0.431373, 0.882353, 1) +water_color = Color(0.262745, 0.317647, 0.768627, 0.501961) + +[connection signal="body_entered" from="." to="." method="_on_body_entered"] diff --git a/mai82AD.tmp b/mai82AD.tmp new file mode 100644 index 0000000..feb53e4 --- /dev/null +++ b/mai82AD.tmp @@ -0,0 +1,227 @@ +[gd_scene load_steps=11 format=3 uid="uid://c1e2254bs6m3e"] + +[ext_resource type="PackedScene" uid="uid://mnaxd41w2loc" path="res://player.tscn" id="1_rotku"] +[ext_resource type="Script" path="res://Water.gd" id="2_imxiw"] +[ext_resource type="PackedScene" uid="uid://cjiok5o0qam3w" path="res://ui.tscn" id="3_0cdyn"] +[ext_resource type="Script" path="res://WaterArea.gd" id="3_58cow"] +[ext_resource type="Script" path="res://Biome.gd" id="5_hobyo"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_sylxd"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_mb8yo"] +size = Vector2(7897, 3751) + +[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_t5me4"] +size = Vector2(16, 16) + +[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_mk1d2"] +size = Vector2(80, 16) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_as6lo"] +size = Vector2(4246, 659) + +[node name="Main" type="Node2D"] + +[node name="UI" parent="." instance=ExtResource("3_0cdyn")] + +[node name="Water" type="Polygon2D" parent="."] +modulate = Color(0.356863, 0.431373, 0.882353, 0.498039) +z_index = 1 +material = SubResource("ShaderMaterial_sylxd") +polygon = PackedVector2Array(4050, 0, -2686, 0, -3110, 3000, 4967, 3000) +script = ExtResource("2_imxiw") + +[node name="WaterBG" type="Polygon2D" parent="Water"] +z_index = -1 +material = SubResource("ShaderMaterial_sylxd") +color = Color(0.356863, 0.431373, 0.882353, 1) +polygon = PackedVector2Array(4050, 0, -2686, 0, -3110, 3000, 4967, 3000) + +[node name="Player" parent="." instance=ExtResource("1_rotku")] +position = Vector2(-129, -48) + +[node name="WaterArea" type="Area2D" parent="."] +gravity_space_override = 2 +gravity_point_center = Vector2(0, 0) +gravity_direction = Vector2(0, 0) +linear_damp_space_override = 2 +linear_damp = 0.5 +script = ExtResource("3_58cow") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="WaterArea"] +position = Vector2(1978.5, 1882.5) +shape = SubResource("RectangleShape2D_mb8yo") + +[node name="Placeholder Sprites" type="Node2D" parent="."] + +[node name="Sprite2D" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-234, 25) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D2" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-209, 72) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D3" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(2, 60) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D4" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-3, 12) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D5" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-285, 94) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D6" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-303, -1) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D7" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(183, 151) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D8" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(208, 198) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D9" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(419, 186) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D10" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(414, 138) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D11" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(132, 220) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D12" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(114, 125) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D13" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-51, 84) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D14" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-26, 131) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D15" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(185, 119) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D16" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(180, 71) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D17" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-102, 153) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D18" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-120, 58) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D19" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-522, 58) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D20" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-497, 105) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D21" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-286, 93) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D22" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-291, 45) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D23" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-573, 127) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D24" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-591, 32) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D25" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-348, 277) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D26" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-323, 324) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D27" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-112, 312) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D28" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-117, 264) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D29" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-399, 346) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="Sprite2D30" type="Sprite2D" parent="Placeholder Sprites"] +position = Vector2(-417, 251) +texture = SubResource("PlaceholderTexture2D_t5me4") + +[node name="StaticBody2D" type="StaticBody2D" parent="."] +position = Vector2(-110, -8) + +[node name="Sprite2D" type="Sprite2D" parent="StaticBody2D"] +texture = SubResource("PlaceholderTexture2D_mk1d2") + +[node name="Polygon2D" type="Polygon2D" parent="StaticBody2D"] +color = Color(0.321569, 0.192157, 0, 1) +polygon = PackedVector2Array(39, -8, 64, 11, 91, 47, 84, 77, 42, 79, -31, 57, -62, 95, -13, 233, -131, 779, -357, 968, -323, 1727, -908, 2114, -786, 5, -695, -463, -372, -460, -288, -73, -192, -2, -101, -8, -39, -8) + +[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="StaticBody2D"] +visible = false +polygon = PackedVector2Array(39, -8, 64, 11, 91, 47, 84, 77, 42, 79, -31, 57, -62, 95, -13, 233, -131, 779, -357, 968, -323, 1727, -908, 2114, -786, 5, -695, -463, -372, -460, -288, -73, -192, -2, -101, -8, -39, -8) + +[node name="StaticBody2D3" type="StaticBody2D" parent="."] +position = Vector2(2240, 2) + +[node name="Sprite2D" type="Sprite2D" parent="StaticBody2D3"] +texture = SubResource("PlaceholderTexture2D_mk1d2") + +[node name="Polygon2D" type="Polygon2D" parent="StaticBody2D3"] +color = Color(0.321569, 0.192157, 0, 1) +polygon = PackedVector2Array(-677, -104, -783, -1932, -1047, -1962, -1017, -112, -1387, 107, -1349, 560, -1047, 832, -919, 1157, -889, 1504, -972, 1814, -1221, 2108, -1160, 2350, -934, 2463, -405, 2342, 55, 2123, 86, 1610, -88, 1421, -315, 1270, -428, 968, -443, 628, -405, 432, -473, 130) + +[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="StaticBody2D3"] +polygon = PackedVector2Array(-677, -104, -783, -1932, -1047, -1962, -1017, -112, -1387, 107, -1349, 560, -1047, 832, -919, 1157, -889, 1504, -972, 1814, -1221, 2108, -1160, 2350, -934, 2463, -405, 2342, 55, 2123, 86, 1610, -88, 1421, -315, 1270, -428, 968, -443, 628, -405, 432, -473, 130) + +[node name="StaticBody2D2" type="StaticBody2D" parent="."] +position = Vector2(-1647, 2848) + +[node name="Sprite2D" type="Sprite2D" parent="StaticBody2D2"] +texture = SubResource("PlaceholderTexture2D_mk1d2") + +[node name="Polygon2D" type="Polygon2D" parent="StaticBody2D2"] +color = Color(0.321569, 0.192157, 0, 1) +polygon = PackedVector2Array(808, -4029, 778, -238, 6109, -117, 5384, -2715, 6305, -5010, 10941, 170, 5928, 2662, -1246, 2435, -2484, -4436) + +[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="StaticBody2D2"] +visible = false +polygon = PackedVector2Array(808, -4029, 778, -238, 6109, -117, 5384, -2715, 6305, -5010, 10941, 170, 5928, 2662, -1246, 2435, -2484, -4436) + +[node name="NormalBiome" type="Area2D" parent="."] +script = ExtResource("5_hobyo") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="NormalBiome"] +position = Vector2(1826, 329.5) +shape = SubResource("RectangleShape2D_as6lo") +debug_color = Color(0.666667, 0.933333, 1, 0.419608) + +[connection signal="body_entered" from="WaterArea" to="WaterArea" method="_on_body_entered"] +[connection signal="body_exited" from="WaterArea" to="WaterArea" method="_on_body_exited"] diff --git a/main.tscn b/main.tscn index 1ef7fbe..ed720ef 100644 --- a/main.tscn +++ b/main.tscn @@ -1,13 +1,31 @@ -[gd_scene load_steps=8 format=3 uid="uid://c1e2254bs6m3e"] +[gd_scene load_steps=15 format=3 uid="uid://c1e2254bs6m3e"] [ext_resource type="PackedScene" uid="uid://mnaxd41w2loc" path="res://player.tscn" id="1_rotku"] +[ext_resource type="Script" path="res://Water.gd" id="2_imxiw"] [ext_resource type="PackedScene" uid="uid://cjiok5o0qam3w" path="res://ui.tscn" id="3_0cdyn"] [ext_resource type="Script" path="res://WaterArea.gd" id="3_58cow"] +[ext_resource type="PackedScene" uid="uid://b1tw6cgdbe6r7" path="res://biome.tscn" id="5_18gyt"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_as6lo"] +size = Vector2(4246, 378) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_hxn7y"] +size = Vector2(5651, 898) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_t2dco"] +size = Vector2(5782.5, 1362) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_wau00"] +size = Vector2(787, 626) [sub_resource type="ShaderMaterial" id="ShaderMaterial_sylxd"] +[sub_resource type="Curve" id="Curve_0m4yk"] +_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(1, 1), 0.0, 0.0, 0, 0] +point_count = 2 + [sub_resource type="RectangleShape2D" id="RectangleShape2D_mb8yo"] -size = Vector2(7897, 3751) +size = Vector2(20240, 7052) [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_t5me4"] size = Vector2(16, 16) @@ -17,21 +35,66 @@ size = Vector2(80, 16) [node name="Main" type="Node2D"] -[node name="Water" type="Polygon2D" parent="."] -modulate = Color(0.356863, 0.431373, 0.882353, 0.498039) +[node name="Biomes" type="Node2D" parent="."] +z_index = 1 + +[node name="NormalBiome" parent="Biomes" instance=ExtResource("5_18gyt")] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Biomes/NormalBiome"] +position = Vector2(1826, 189) +shape = SubResource("RectangleShape2D_as6lo") +debug_color = Color(0.666667, 0.933333, 1, 0.419608) + +[node name="DarkBiome" parent="Biomes" instance=ExtResource("5_18gyt")] +position = Vector2(-282, 917) +water_bg_color = Color(0.235294, 0.290196, 0.721569, 1) +water_color = Color(0.184314, 0.223529, 0.592157, 0.682353) + +[node name="CollisionShape2D2" type="CollisionShape2D" parent="Biomes/DarkBiome"] +position = Vector2(2036.5, 9) +shape = SubResource("RectangleShape2D_hxn7y") +debug_color = Color(0.666667, 0.933333, 1, 0.419608) + +[node name="DarkBiome2" parent="Biomes" instance=ExtResource("5_18gyt")] +position = Vector2(-282, 917) +water_bg_color = Color(0.160784, 0.2, 0.537255, 1) +water_color = Color(0.12549, 0.152941, 0.435294, 0.784314) + +[node name="CollisionShape2D2" type="CollisionShape2D" parent="Biomes/DarkBiome2"] +position = Vector2(1921.25, 1274) +shape = SubResource("RectangleShape2D_t2dco") +debug_color = Color(0.666667, 0.933333, 1, 0.419608) + +[node name="SecretBiome1" parent="Biomes" instance=ExtResource("5_18gyt")] +position = Vector2(-1769, 2007) +water_bg_color = Color(0.0980392, 0.529412, 0.396078, 1) +water_color = Color(0.054902, 0.403922, 0.352941, 0.662745) + +[node name="CollisionShape2D2" type="CollisionShape2D" parent="Biomes/SecretBiome1"] +position = Vector2(-226.5, 37) +shape = SubResource("RectangleShape2D_wau00") +debug_color = Color(0.666667, 0.933333, 1, 0.419608) + +[node name="UI" parent="." instance=ExtResource("3_0cdyn")] + +[node name="Water" type="Polygon2D" parent="." node_paths=PackedStringArray("default_biome")] z_index = 1 material = SubResource("ShaderMaterial_sylxd") -color = Color(0.356863, 0.431373, 0.882353, 1) +color = Color(0.262745, 0.317647, 0.768627, 0.501961) polygon = PackedVector2Array(4050, 0, -2686, 0, -3110, 3000, 4967, 3000) +script = ExtResource("2_imxiw") +default_biome = NodePath("../Biomes/NormalBiome") +biome_transition_time = 3.0 +biome_transition_curve = SubResource("Curve_0m4yk") -[node name="WaterBG" type="Polygon2D" parent="."] +[node name="WaterBG" type="Polygon2D" parent="Water"] z_index = -1 material = SubResource("ShaderMaterial_sylxd") color = Color(0.356863, 0.431373, 0.882353, 1) polygon = PackedVector2Array(4050, 0, -2686, 0, -3110, 3000, 4967, 3000) [node name="Player" parent="." instance=ExtResource("1_rotku")] -position = Vector2(-129, -48) +position = Vector2(-1186, 2333) [node name="WaterArea" type="Area2D" parent="."] gravity_space_override = 2 @@ -42,11 +105,9 @@ linear_damp = 0.5 script = ExtResource("3_58cow") [node name="CollisionShape2D" type="CollisionShape2D" parent="WaterArea"] -position = Vector2(1978.5, 1882.5) +position = Vector2(2428, 3533) shape = SubResource("RectangleShape2D_mb8yo") -[node name="UI" parent="." instance=ExtResource("3_0cdyn")] - [node name="Placeholder Sprites" type="Node2D" parent="."] [node name="Sprite2D" type="Sprite2D" parent="Placeholder Sprites"] @@ -169,33 +230,45 @@ texture = SubResource("PlaceholderTexture2D_t5me4") position = Vector2(-417, 251) texture = SubResource("PlaceholderTexture2D_t5me4") -[node name="StaticBody2D" type="StaticBody2D" parent="."] +[node name="StartingIsland" type="StaticBody2D" parent="."] position = Vector2(-110, -8) -[node name="Sprite2D" type="Sprite2D" parent="StaticBody2D"] +[node name="Sprite2D" type="Sprite2D" parent="StartingIsland"] texture = SubResource("PlaceholderTexture2D_mk1d2") -[node name="Polygon2D" type="Polygon2D" parent="StaticBody2D"] +[node name="Polygon2D" type="Polygon2D" parent="StartingIsland"] color = Color(0.321569, 0.192157, 0, 1) polygon = PackedVector2Array(39, -8, 64, 11, 91, 47, 84, 77, 42, 79, -31, 57, -62, 95, -13, 233, -131, 779, -357, 968, -323, 1727, -908, 2114, -786, 5, -695, -463, -372, -460, -288, -73, -192, -2, -101, -8, -39, -8) -[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="StaticBody2D"] +[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="StartingIsland"] visible = false polygon = PackedVector2Array(39, -8, 64, 11, 91, 47, 84, 77, 42, 79, -31, 57, -62, 95, -13, 233, -131, 779, -357, 968, -323, 1727, -908, 2114, -786, 5, -695, -463, -372, -460, -288, -73, -192, -2, -101, -8, -39, -8) -[node name="StaticBody2D2" type="StaticBody2D" parent="."] +[node name="MiddleSeparator" type="StaticBody2D" parent="."] +position = Vector2(2240, 2) + +[node name="Sprite2D" type="Sprite2D" parent="MiddleSeparator"] +texture = SubResource("PlaceholderTexture2D_mk1d2") + +[node name="Polygon2D" type="Polygon2D" parent="MiddleSeparator"] +color = Color(0.321569, 0.192157, 0, 1) +polygon = PackedVector2Array(-677, -104, -783, -1932, -1047, -1962, -1017, -112, -1387, 107, -1349, 560, -1047, 832, -919, 1157, -889, 1504, -972, 1814, -1221, 2108, -1160, 2350, -934, 2463, -405, 2342, 55, 2123, 86, 1610, -88, 1421, -315, 1270, -428, 968, -443, 628, -405, 432, -473, 130) + +[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="MiddleSeparator"] +polygon = PackedVector2Array(-677, -104, -783, -1932, -1047, -1962, -1017, -112, -1387, 107, -1349, 560, -1047, 832, -919, 1157, -889, 1504, -972, 1814, -1221, 2108, -1160, 2350, -934, 2463, -405, 2342, 55, 2123, 86, 1610, -88, 1421, -315, 1270, -428, 968, -443, 628, -405, 432, -473, 130) + +[node name="OOB" type="StaticBody2D" parent="."] position = Vector2(-1647, 2848) -[node name="Sprite2D" type="Sprite2D" parent="StaticBody2D2"] +[node name="Sprite2D" type="Sprite2D" parent="OOB"] texture = SubResource("PlaceholderTexture2D_mk1d2") -[node name="Polygon2D" type="Polygon2D" parent="StaticBody2D2"] +[node name="Polygon2D" type="Polygon2D" parent="OOB"] color = Color(0.321569, 0.192157, 0, 1) -polygon = PackedVector2Array(808, -4029, 778, -238, 6109, -117, 5384, -2715, 6305, -5010, 10941, 170, 5928, 2662, -1246, 2435, -2484, -4436) +polygon = PackedVector2Array(808, -4029, 646, -752, -112, -636, -399, -924, 456, -1587, 365, -2017, -70, -2215, -676, -2090, -693, -1179, -472, -557, 727, -25, 2729, 11, 6109, -117, 5384, -2715, 6305, -5010, 10941, 170, 5928, 2662, -1246, 2435, -2484, -4436) -[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="StaticBody2D2"] -visible = false -polygon = PackedVector2Array(808, -4029, 778, -238, 6109, -117, 5384, -2715, 6305, -5010, 10941, 170, 5928, 2662, -1246, 2435, -2484, -4436) +[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="OOB"] +polygon = PackedVector2Array(808, -4029, 646, -752, -112, -636, -399, -924, 456, -1587, 365, -2017, -70, -2215, -676, -2090, -693, -1179, -472, -557, 727, -25, 2729, 11, 6109, -117, 5384, -2715, 6305, -5010, 10941, 170, 5928, 2662, -1246, 2435, -2484, -4436) [connection signal="body_entered" from="WaterArea" to="WaterArea" method="_on_body_entered"] [connection signal="body_exited" from="WaterArea" to="WaterArea" method="_on_body_exited"] diff --git a/player.gd b/player.gd index b84e08d..bcf9f04 100644 --- a/player.gd +++ b/player.gd @@ -29,10 +29,14 @@ var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") var is_in_water: bool = false func enter_water(): + motion_mode = CharacterBody2D.MOTION_MODE_FLOATING + floor_constant_speed = false is_in_water = true velocity.y *= .5 func exit_water(): + motion_mode = CharacterBody2D.MOTION_MODE_GROUNDED + floor_constant_speed = true is_in_water = false velocity.y *= 2 @@ -97,5 +101,11 @@ func _physics_process(delta): sprite.flip_h = false GameEvents.add_debug_obj.emit("disp", sprite.position) GameEvents.add_debug_obj.emit("velocity", velocity) - move_and_slide() + if move_and_slide(): + if is_in_water: + var collision_data: KinematicCollision2D = get_last_slide_collision() + GameEvents.add_debug_obj.emit("norm", collision_data.get_normal()) + velocity = velocity.bounce(collision_data.get_normal()) * .8 + + GameEvents.add_debug_obj.emit("post-velocity", velocity) diff --git a/player.tscn b/player.tscn index 1662850..ddcd92d 100644 --- a/player.tscn +++ b/player.tscn @@ -16,6 +16,7 @@ radius = 7.0 [node name="Player" type="CharacterBody2D"] position = Vector2(-112, -37) +wall_min_slide_angle = 0.0174533 floor_constant_speed = true floor_max_angle = 0.872665 floor_snap_length = 2.0