From 9c2a01f8a18af0353af1095530caa958f21ec72f Mon Sep 17 00:00:00 2001 From: Jakob Feldmann Date: Mon, 23 May 2022 16:19:32 +0200 Subject: [PATCH] Renamed Areas and Bodies, slight restructure, preliminary spring --- project.godot | 2 +- src/Actors/{Player => Blobby}/Blobby.gd | 50 +++++++++++-------- src/Actors/{Player => Blobby}/Blobby.tscn | 42 +++++++--------- src/Actors/{Player => Blobby}/Camera2D.gd | 0 src/Actors/Enemy/Enemy.gd | 10 ++-- src/Actors/Enemy/Enemy.tscn | 21 ++++---- src/Actors/{Player => }/Player.gd | 2 +- src/Actors/{Player => }/PlayerStateMachine.gd | 14 +++--- src/Contraptions/Platform/Spring.gd | 11 ++++ src/Contraptions/Platform/Spring.tscn | 24 +++++++-- src/Levels/Level02.tscn | 2 +- src/Levels/Level03.tscn | 39 +++------------ src/Levels/LevelTemplate.tscn | 2 +- src/Levels/Plattforms Level.tscn | 20 +------- src/Levels/Simple Level.tscn | 2 +- src/Utilities/Physic/PhysicsFunc.gd | 6 +++ 16 files changed, 120 insertions(+), 127 deletions(-) rename src/Actors/{Player => Blobby}/Blobby.gd (83%) rename src/Actors/{Player => Blobby}/Blobby.tscn (69%) rename src/Actors/{Player => Blobby}/Camera2D.gd (100%) rename src/Actors/{Player => }/Player.gd (96%) rename src/Actors/{Player => }/PlayerStateMachine.gd (94%) diff --git a/project.godot b/project.godot index 0073310..23cdb09 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ _global_script_classes=[ { "base": "KinematicBody2D", "class": "Player", "language": "GDScript", -"path": "res://src/Actors/Player/Player.gd" +"path": "res://src/Actors/Player.gd" }, { "base": "Line2D", "class": "RayCastDebugLines", diff --git a/src/Actors/Player/Blobby.gd b/src/Actors/Blobby/Blobby.gd similarity index 83% rename from src/Actors/Player/Blobby.gd rename to src/Actors/Blobby/Blobby.gd index 87568ab..601a446 100644 --- a/src/Actors/Player/Blobby.gd +++ b/src/Actors/Blobby/Blobby.gd @@ -15,14 +15,20 @@ onready var camera = $Camera2D # TODO Too much speed reduction on landings # TODO Too much speed through midair boosting # TODO Mini hopping through jump buffer(rare wallslide) +# TODO Think about how each component and feature would scale in the future -func _on_EnemyDetector_area_entered(area: Area2D) -> void: - _velocity = calculate_stomp_velocity(_velocity, stomp_feedback) +# TODO This is the worst thing since... you know +# When the Enemy stomp AREA enters the enemy collision area -> stomp +func _on_Skin_area_entered(area: Area2D) -> void: + if area.name == "StompDetector": + velocity = calculate_stomp_velocity(velocity, stomp_feedback) -func _on_EnemyDetector_body_entered(body: Node) -> void: - die() +# When the Enemy collision BODY enters the enemy collision area -> die +func _on_Skin_body_entered(body: Node) -> void: + if body.name == "EnemyBody": + die() func _on_JumpBufferTimer_timeout() -> void: @@ -30,19 +36,19 @@ func _on_JumpBufferTimer_timeout() -> void: func handle_grounded_movement(delta: float, direction: Vector2) -> Vector2: - return calculate_grounded_velocity(_velocity, delta, direction) + return calculate_grounded_velocity(velocity, delta, direction) func handle_jump_movement(delta: float, direction: Vector2) -> Vector2: - return calculate_jump_velocity(_velocity, delta, direction) + return calculate_jump_velocity(velocity, delta, direction) func handle_fall_movement(delta: float, direction: Vector2) -> Vector2: - return calculate_fall_velocity(_velocity, delta, direction) + return calculate_fall_velocity(velocity, delta, direction) func handle_wallslide_movement(delta: float, direction: Vector2) -> Vector2: - return calculate_wallslide_velocity(_velocity, delta, direction) + return calculate_wallslide_velocity(velocity, delta, direction) func calculate_grounded_velocity( @@ -51,7 +57,7 @@ func calculate_grounded_velocity( var state = player_state_machine.state var out_vel := linear_velocity var velocity_direction = 1.0 - if _velocity.x < 0: + if velocity.x < 0: velocity_direction = -1.0 # Stopping movement @@ -61,7 +67,7 @@ func calculate_grounded_velocity( ) # Translates velocity back to force and subtracts deceleration force var result_force = ( - abs(PhysicsFunc.convert_velocity_to_force(_velocity.x, mass, delta)) + abs(PhysicsFunc.convert_velocity_to_force(velocity.x, mass, delta)) - deceleration_force ) if result_force <= 0: @@ -85,7 +91,7 @@ func calculate_grounded_velocity( * velocity_direction ) # Normal movement - if abs(_velocity.x) < max_velocity[state]: + if abs(velocity.x) < max_velocity[state]: out_vel.x += ( delta * ( @@ -106,7 +112,7 @@ func calculate_grounded_velocity( out_vel.x = max_velocity[state] * direction.x # Jumping when grounded or jump is buffered if Input.is_action_just_pressed("jump") || jump_buffer_filled: - return calculate_jump_velocity(_velocity, delta, direction) + return calculate_jump_velocity(velocity, delta, direction) elif player_state_machine.coyote_hanging: out_vel.y = 0 @@ -119,8 +125,8 @@ func calculate_grounded_velocity( func is_reversing_horizontal_movement(direction: Vector2) -> bool: return ( - (direction.x > 0 && _velocity.x < 0) - || (direction.x < 0 && _velocity.x >= 0) + (direction.x > 0 && velocity.x < 0) + || (direction.x < 0 && velocity.x >= 0) ) @@ -179,7 +185,7 @@ func calculate_jump_velocity( ): var additive_jump_force = ( velocity_jump_boost_ratio - * abs(_velocity.x) + * abs(velocity.x) * mass ) linear_velocity.y = ( @@ -195,7 +201,7 @@ func calculate_jump_velocity( if !Input.is_action_pressed("jump"): # TODO This is so good not gonna lie - if _velocity.y > _gravity * delta * 10: + if velocity.y > _gravity * delta * 10: linear_velocity.y += _gravity * delta * 10 else: linear_velocity.y += ( @@ -207,7 +213,7 @@ func calculate_jump_velocity( linear_velocity.y += _gravity * delta # TODO Dis shizzle buggy - if _velocity.x == 0: + if velocity.x == 0: linear_velocity.x += inair_velocity * direction.x if is_correct_airstrafe_input() && !walljumping: @@ -222,11 +228,11 @@ func calculate_jump_velocity( func calculate_fall_velocity( linear_velocity: Vector2, delta: float, direction: Vector2 ) -> Vector2: - if _velocity.y < max_velocity["fall"]: + if velocity.y < max_velocity["fall"]: linear_velocity.y += _gravity * delta else: linear_velocity.y = max_velocity["fall"] - if _velocity.x == 0: + if velocity.x == 0: # TODO this is weird linear_velocity.x += inair_velocity * direction.x if Input.is_action_just_pressed("jump"): @@ -243,7 +249,7 @@ func calculate_wallslide_velocity( # Walljump mechanics if is_correct_walljump_input(direction): # TODO This +0.01 indicates a larger problem with division through possible 0 values!! - var multiplicator = max(min(1, 1000 / (_velocity.y + 0.01)), 0.9) + var multiplicator = max(min(1, 1000 / (velocity.y + 0.01)), 0.9) linear_velocity.y += ( (acceleration_force["walljump"].y / mass) * -1 @@ -264,8 +270,8 @@ func calculate_stomp_velocity( return out -func execute_movement(direction) -> void: - _velocity = move_and_slide(_velocity, FLOOR_NORMAL) +func execute_movement() -> void: + velocity = move_and_slide(velocity, FLOOR_NORMAL) func die() -> void: diff --git a/src/Actors/Player/Blobby.tscn b/src/Actors/Blobby/Blobby.tscn similarity index 69% rename from src/Actors/Player/Blobby.tscn rename to src/Actors/Blobby/Blobby.tscn index b905091..5b6873b 100644 --- a/src/Actors/Player/Blobby.tscn +++ b/src/Actors/Blobby/Blobby.tscn @@ -1,17 +1,14 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://assets/blobby/blobby1.png" type="Texture" id=1] -[ext_resource path="res://src/Actors/Player/PlayerStateMachine.gd" type="Script" id=2] -[ext_resource path="res://assets/meta/new_dynamicfont.tres" type="DynamicFont" id=3] -[ext_resource path="res://src/Actors/Player/Blobby.gd" type="Script" id=5] -[ext_resource path="res://src/Actors/Player/Camera2D.gd" type="Script" id=6] - -[sub_resource type="RectangleShape2D" id=2] -extents = Vector2( 4.60652, 5.57253 ) +[ext_resource path="res://src/Actors/Blobby/Camera2D.gd" type="Script" id=2] +[ext_resource path="res://src/Actors/PlayerStateMachine.gd" type="Script" id=3] +[ext_resource path="res://src/Actors/Blobby/Blobby.gd" type="Script" id=4] +[ext_resource path="res://assets/meta/new_dynamicfont.tres" type="DynamicFont" id=5] [node name="Blobby" type="KinematicBody2D"] collision_mask = 120 -script = ExtResource( 5 ) +script = ExtResource( 4 ) [node name="Player" type="Sprite" parent="."] position = Vector2( -0.00490093, 0.00763269 ) @@ -20,8 +17,8 @@ texture = ExtResource( 1 ) [node name="AnimationPlayer" type="AnimationPlayer" parent="Player"] -[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."] -polygon = PoolVector2Array( -6.76445, -3.27282, -2.676, -7.3, 3.939, -7.3, 7.45577, -2.58186, 7.97746, -1.86331, 8.02357, 4.91157, 4.944, 8.5, -4.213, 8.5, -6.67105, 6.08934 ) +[node name="BlobbyBody" type="CollisionPolygon2D" parent="."] +polygon = PoolVector2Array( -6.7, -3.273, -2.676, -7.3, 3.939, -7.3, 8, -1.768, 8, 4.912, 4.944, 8.5, -1.03623, 8.5, -4.213, 8.5, -6.7, 6.089 ) [node name="Camera2D" type="Camera2D" parent="."] position = Vector2( 80, 0 ) @@ -38,20 +35,19 @@ drag_margin_right = 0.08 drag_margin_bottom = 0.07 editor_draw_limits = true editor_draw_drag_margin = true -script = ExtResource( 6 ) +script = ExtResource( 2 ) [node name="ShiftTween" type="Tween" parent="Camera2D"] -[node name="EnemyDetector" type="Area2D" parent="."] -collision_mask = 2 -monitorable = false +[node name="Skin" type="Area2D" parent="."] +collision_mask = 126 -[node name="CollisionShape2D" type="CollisionShape2D" parent="EnemyDetector"] -modulate = Color( 0.2, 0, 0.494118, 1 ) -shape = SubResource( 2 ) +[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Skin"] +scale = Vector2( 1.03, 1.03 ) +polygon = PoolVector2Array( -6.7, -3.311, -2.676, -7.3, 3.939, -7.3, 8, -1.863, 8, 4.912, 4.944, 8.5, -1.03623, 8.5, -4.213, 8.5, -6.7, 6.089 ) [node name="PlayerStateMachine" type="Node" parent="."] -script = ExtResource( 2 ) +script = ExtResource( 3 ) [node name="JumpBufferTimer" type="Timer" parent="PlayerStateMachine"] wait_time = 0.034 @@ -67,7 +63,7 @@ margin_top = -34.2836 margin_right = 25.6614 margin_bottom = -20.2836 custom_colors/font_color = Color( 0, 0, 0, 1 ) -custom_fonts/font = ExtResource( 3 ) +custom_fonts/font = ExtResource( 5 ) text = "Ihre Werbung" align = 1 valign = 1 @@ -75,7 +71,7 @@ valign = 1 [node name="WallRaycasts" type="Node2D" parent="."] [node name="LeftWallRaycast" type="Node2D" parent="WallRaycasts"] -position = Vector2( 3.95827, 5.64054 ) +position = Vector2( 3.86988, 6.34765 ) [node name="Left_Wallcast1" type="RayCast2D" parent="WallRaycasts/LeftWallRaycast"] position = Vector2( -10.706, -8.03844 ) @@ -103,6 +99,6 @@ enabled = true cast_to = Vector2( 2, 0 ) collision_mask = 9 -[connection signal="area_entered" from="EnemyDetector" to="." method="_on_EnemyDetector_area_entered"] -[connection signal="body_entered" from="EnemyDetector" to="." method="_on_EnemyDetector_body_entered"] +[connection signal="area_entered" from="Skin" to="." method="_on_Skin_area_entered"] +[connection signal="body_entered" from="Skin" to="." method="_on_Skin_body_entered"] [connection signal="timeout" from="PlayerStateMachine/JumpBufferTimer" to="." method="_on_JumpBufferTimer_timeout"] diff --git a/src/Actors/Player/Camera2D.gd b/src/Actors/Blobby/Camera2D.gd similarity index 100% rename from src/Actors/Player/Camera2D.gd rename to src/Actors/Blobby/Camera2D.gd diff --git a/src/Actors/Enemy/Enemy.gd b/src/Actors/Enemy/Enemy.gd index 6d4e8a6..da4fba4 100644 --- a/src/Actors/Enemy/Enemy.gd +++ b/src/Actors/Enemy/Enemy.gd @@ -5,21 +5,21 @@ export var score := 100 func _ready() -> void: set_physics_process(false) - _velocity.x = -300 + velocity.x = -30 func _on_StompDetector_body_entered(body: Node) -> void: if body.global_position.y > get_node("StompDetector").global_position.y: return - get_node("CollisionShape2D").disabled = true + get_node("EnemyShape").disabled = true die() func _physics_process(delta: float) -> void: - _velocity.y += _gravity * delta + velocity.y += _gravity * delta if is_on_wall(): - _velocity.x *= -1.0 - _velocity.y = move_and_slide(_velocity, FLOOR_NORMAL).y + velocity.x *= -1.0 + velocity.y = move_and_slide(velocity, FLOOR_NORMAL).y func die() -> void: diff --git a/src/Actors/Enemy/Enemy.tscn b/src/Actors/Enemy/Enemy.tscn index bdad37d..3d60e4a 100644 --- a/src/Actors/Enemy/Enemy.tscn +++ b/src/Actors/Enemy/Enemy.tscn @@ -4,10 +4,10 @@ [ext_resource path="res://src/Actors/Enemy/Enemy.gd" type="Script" id=2] [sub_resource type="RectangleShape2D" id=1] -extents = Vector2( 8.68243, 5.8581 ) +extents = Vector2( 2.72463, 1.17848 ) [sub_resource type="RectangleShape2D" id=2] -extents = Vector2( 45, 14 ) +extents = Vector2( 15.4794, 6.68174 ) [node name="Enemy" type="KinematicBody2D"] collision_layer = 2 @@ -15,28 +15,29 @@ collision_mask = 9 script = ExtResource( 2 ) [node name="enemy" type="Sprite" parent="."] -position = Vector2( 0, -48 ) +position = Vector2( 0, -1.90735e-06 ) +scale = Vector2( 0.286789, 0.276348 ) texture = ExtResource( 1 ) [node name="VisibilityEnabler2D" type="VisibilityEnabler2D" parent="."] -position = Vector2( 3895.22, -31 ) -scale = Vector2( 44.2501, 3.1 ) +position = Vector2( 1362.81, -0.138177 ) +scale = Vector2( 15.4865, 1.28502 ) rect = Rect2( -89, -10, 2, 20 ) process_parent = true physics_process_parent = true -[node name="CollisionShape2D" type="CollisionShape2D" parent="."] -position = Vector2( -0.445457, -31.2227 ) +[node name="EnemyBody" type="CollisionShape2D" parent="."] +position = Vector2( 0, 6.48802 ) scale = Vector2( 5.68128, 5.29182 ) shape = SubResource( 1 ) [node name="StompDetector" type="Area2D" parent="."] modulate = Color( 0, 0.0392157, 1, 1 ) -position = Vector2( 0, -62 ) +position = Vector2( 0, -6.44095 ) collision_layer = 2 +input_pickable = false -[node name="CollisionShape2D2" type="CollisionShape2D" parent="StompDetector"] -position = Vector2( 0.44545, -13 ) +[node name="CollisionShape2D" type="CollisionShape2D" parent="StompDetector"] shape = SubResource( 2 ) [connection signal="body_entered" from="StompDetector" to="." method="_on_StompDetector_body_entered"] diff --git a/src/Actors/Player/Player.gd b/src/Actors/Player.gd similarity index 96% rename from src/Actors/Player/Player.gd rename to src/Actors/Player.gd index 754dcce..418d85f 100644 --- a/src/Actors/Player/Player.gd +++ b/src/Actors/Player.gd @@ -28,6 +28,6 @@ var _gravity: float = PhysicsConst.gravity # Kilograms var mass := 6.5 -var _velocity := Vector2.ZERO +var velocity := Vector2.ZERO var air_strafe_charges := 1 diff --git a/src/Actors/Player/PlayerStateMachine.gd b/src/Actors/PlayerStateMachine.gd similarity index 94% rename from src/Actors/Player/PlayerStateMachine.gd rename to src/Actors/PlayerStateMachine.gd index a4545fd..1b93c52 100644 --- a/src/Actors/Player/PlayerStateMachine.gd +++ b/src/Actors/PlayerStateMachine.gd @@ -50,8 +50,8 @@ func _state_logic(delta): var direction = get_horizontal_direction() - parent._velocity = handle_input_ref.call_func(delta, direction) - parent.execute_movement(direction) + parent.velocity = handle_input_ref.call_func(delta, direction) + parent.execute_movement() func handle_idle_input(delta, direction) -> Vector2: @@ -102,18 +102,18 @@ func _get_transition(delta): parent.get_node("StateLabel").text = ( self.state + " x vel:" - + String(round(parent._velocity.x)) + + String(round(parent.velocity.x)) ) var new_state if !parent.is_on_floor(): - if parent._velocity.y < 0: + if parent.velocity.y < 0: new_state = states.jump - if parent._velocity.y >= 0: + if parent.velocity.y >= 0: new_state = states.fall if ( parent.is_touching_wall_completely() - && parent._velocity.y <= parent.wallslide_threshold + && parent.velocity.y <= parent.wallslide_threshold ): # TODO Wallslide might be too long # TODO Player is stuck to the wall @@ -134,7 +134,7 @@ func _get_transition(delta): if coyote_hanging: new_state = self.state - elif parent._velocity.x != 0: + elif parent.velocity.x != 0: if Input.is_action_pressed("boost_move"): new_state = states.run else: diff --git a/src/Contraptions/Platform/Spring.gd b/src/Contraptions/Platform/Spring.gd index baf0d80..cea14bc 100644 --- a/src/Contraptions/Platform/Spring.gd +++ b/src/Contraptions/Platform/Spring.gd @@ -30,3 +30,14 @@ func _physics_process(delta: float) -> void: y_velocity *= friction self.position.y += y_velocity * delta + + +func _on_Area2D_area_entered(area: Area2D) -> void: + var area_parent = area.get_parent() + var a_velocity = area_parent.velocity.y + var a_mass = area_parent.mass + var b_velocity = y_velocity + var b_mass = mass + y_velocity += PhysicsFunc.complete_unelastic_shock( + a_velocity, b_velocity, a_mass, b_mass + ) diff --git a/src/Contraptions/Platform/Spring.tscn b/src/Contraptions/Platform/Spring.tscn index 420d2fc..2535cec 100644 --- a/src/Contraptions/Platform/Spring.tscn +++ b/src/Contraptions/Platform/Spring.tscn @@ -1,10 +1,13 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://src/Contraptions/Platform/Spring.gd" type="Script" id=1] [ext_resource path="res://assets/environment/blocks/Basic stone block.png" type="Texture" id=2] [sub_resource type="RectangleShape2D" id=1] -extents = Vector2( 11.8807, 1.59654 ) +extents = Vector2( 11.913, 1.58343 ) + +[sub_resource type="RectangleShape2D" id=2] +extents = Vector2( 11.8988, 1.56963 ) [node name="Spring" type="Node2D"] script = ExtResource( 1 ) @@ -14,11 +17,22 @@ collision_layer = 32 collision_mask = 41 [node name="Sprite" type="Sprite" parent="StaticBody2D"] -position = Vector2( -7.80793, -0.67961 ) +position = Vector2( -11.9516, -1.58488 ) scale = Vector2( 1.48986, 0.197785 ) texture = ExtResource( 2 ) centered = false -[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"] -position = Vector2( 4.1428, 0.903461 ) +[node name="SpringBody" type="CollisionShape2D" parent="StaticBody2D"] +position = Vector2( -0.0323062, -0.0131137 ) shape = SubResource( 1 ) + +[node name="Spring" type="Area2D" parent="StaticBody2D"] +position = Vector2( -0.0323062, -0.0131137 ) +collision_layer = 32 +collision_mask = 3 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D/Spring"] +position = Vector2( 0.0323062, 0.0137925 ) +shape = SubResource( 2 ) + +[connection signal="area_entered" from="StaticBody2D/Spring" to="." method="_on_Area2D_area_entered"] diff --git a/src/Levels/Level02.tscn b/src/Levels/Level02.tscn index 53c892f..2881065 100644 --- a/src/Levels/Level02.tscn +++ b/src/Levels/Level02.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=8 format=2] -[ext_resource path="res://src/Actors/Player/Blobby.tscn" type="PackedScene" id=1] +[ext_resource path="res://src/Actors/Blobby/Blobby.tscn" type="PackedScene" id=1] [ext_resource path="res://assets/meta/tileset.png" type="Texture" id=2] [ext_resource path="res://src/Actors/Enemy/Enemy.tscn" type="PackedScene" id=3] [ext_resource path="res://assets/environment/background/background.png" type="Texture" id=4] diff --git a/src/Levels/Level03.tscn b/src/Levels/Level03.tscn index 5cdbd42..ba0f854 100644 --- a/src/Levels/Level03.tscn +++ b/src/Levels/Level03.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=8 format=2] -[ext_resource path="res://src/Actors/Player/Blobby.tscn" type="PackedScene" id=1] +[ext_resource path="res://src/Actors/Blobby/Blobby.tscn" type="PackedScene" id=1] [ext_resource path="res://assets/meta/tileset.tres" type="TileSet" id=2] [ext_resource path="res://src/Actors/Enemy/Enemy.tscn" type="PackedScene" id=3] [ext_resource path="res://assets/environment/background/background.png" type="Texture" id=4] @@ -34,38 +34,13 @@ format = 1 tile_data = PoolIntArray( -1048576, 0, 0, -1048564, 0, 0, -983040, 0, 0, -983028, 0, 0, -917504, 0, 0, -917492, 0, 0, -851968, 0, 0, -851956, 0, 0, -786432, 0, 0, -786420, 0, 0, -720896, 0, 0, -720884, 0, 0, -655360, 0, 0, -655348, 0, 0, -589824, 0, 0, -589812, 0, 0, -524288, 0, 0, -524276, 0, 0, -458752, 0, 0, -458740, 0, 0, -393216, 0, 0, -393215, 0, 0, -393214, 0, 0, -393213, 0, 0, -393204, 0, 0, -327680, 0, 0, -327668, 0, 0, -262144, 0, 0, -262132, 0, 0, -196608, 0, 0, -196607, 0, 0, -196606, 0, 0, -196605, 0, 0, -196596, 0, 0, -131072, 0, 0, -131060, 0, 0, -65536, 0, 0, -65524, 0, 0, 0, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 12, 0, 0, 65536, 0, 0, 65544, 0, 0, 65548, 0, 0, 131072, 0, 0, 131084, 0, 0, 196608, 0, 0, 196620, 0, 0, 262144, 0, 0, 262149, 0, 0, 262154, 0, 0, 262155, 0, 0, 262156, 0, 0, 327680, 0, 0, 327681, 0, 0, 327692, 0, 0, 393216, 0, 0, 393228, 0, 0, 458752, 0, 0, 458753, 0, 0, 458754, 0, 0, 458755, 0, 0, 458756, 0, 0, 458757, 0, 0, 458758, 0, 0, 458759, 0, 0, 458760, 0, 0, 458761, 0, 0, 458762, 0, 0, 458763, 0, 0, 458764, 0, 0, 524288, 0, 0, 524289, 0, 0, 524290, 0, 0, 524291, 0, 0, 524292, 0, 0, 524293, 0, 0, 524294, 0, 0, 524295, 0, 0, 524296, 0, 0, 524297, 0, 0, 524298, 0, 0, 524299, 0, 0, 524300, 0, 0, 589824, 0, 0, 589825, 0, 0, 589826, 0, 0, 589827, 0, 0, 589828, 0, 0, 589829, 0, 0, 589830, 0, 0, 589831, 0, 0, 589832, 0, 0, 589833, 0, 0, 589834, 0, 0, 589835, 0, 0, 589836, 0, 0 ) [node name="Blobby" parent="." instance=ExtResource( 1 )] -position = Vector2( 131, 560 ) - -[node name="Player" parent="Blobby" index="0"] -position = Vector2( -0.476822, -29.8424 ) - -[node name="CollisionPolygon2D" parent="Blobby" index="1"] -position = Vector2( -1.16798, -29.1162 ) - -[node name="Camera2D" parent="Blobby" index="2"] -position = Vector2( 390.714, -75 ) -limit_top = -10000 -limit_right = 1040 -limit_bottom = 700 -drag_margin_h_enabled = false - -[node name="EnemyDetector" parent="Blobby" index="3"] -position = Vector2( 14.6832, -44.0497 ) - -[node name="CollisionShape2D" parent="Blobby/EnemyDetector" index="0"] -position = Vector2( -15.3507, 14.3845 ) - -[node name="StateLabel" parent="Blobby" index="5"] -margin_left = -38.6708 -margin_top = -73.3364 -margin_right = 48.3292 -margin_bottom = -59.3364 - -[node name="WallRaycasts" parent="Blobby" index="6"] -position = Vector2( -0.589935, -29.85 ) +position = Vector2( 156.988, 538.998 ) [node name="Enemy" parent="." instance=ExtResource( 3 )] -position = Vector2( 715.5, 560 ) +position = Vector2( 718.871, 527.037 ) + +[node name="VisibilityEnabler2D" parent="Enemy" index="1"] +position = Vector2( 1363.25, -11.7006 ) [node name="Coin" parent="." instance=ExtResource( 5 )] position = Vector2( 592, 352 ) @@ -82,5 +57,5 @@ position = Vector2( 749, 274 ) [node name="Portal" parent="." instance=ExtResource( 8 )] position = Vector2( 130.332, -461.479 ) -[editable path="Blobby"] +[editable path="Enemy"] [editable path="Coin"] diff --git a/src/Levels/LevelTemplate.tscn b/src/Levels/LevelTemplate.tscn index f78da47..3dd9997 100644 --- a/src/Levels/LevelTemplate.tscn +++ b/src/Levels/LevelTemplate.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=13 format=2] -[ext_resource path="res://src/Actors/Player/Blobby.tscn" type="PackedScene" id=1] +[ext_resource path="res://src/Actors/Blobby/Blobby.tscn" type="PackedScene" id=1] [ext_resource path="res://assets/meta/tileset.png" type="Texture" id=2] [ext_resource path="res://src/Actors/Enemy/Enemy.tscn" type="PackedScene" id=3] [ext_resource path="res://assets/environment/background/background.png" type="Texture" id=4] diff --git a/src/Levels/Plattforms Level.tscn b/src/Levels/Plattforms Level.tscn index e402164..a862c63 100644 --- a/src/Levels/Plattforms Level.tscn +++ b/src/Levels/Plattforms Level.tscn @@ -1,6 +1,6 @@ -[gd_scene load_steps=10 format=2] +[gd_scene load_steps=9 format=2] -[ext_resource path="res://src/Actors/Player/Blobby.tscn" type="PackedScene" id=1] +[ext_resource path="res://src/Actors/Blobby/Blobby.tscn" type="PackedScene" id=1] [ext_resource path="res://assets/environment/blocks/Basic stone block.png" type="Texture" id=2] [ext_resource path="res://src/Contraptions/Platform/Spring.tscn" type="PackedScene" id=3] [ext_resource path="res://src/Environment/Background.tscn" type="PackedScene" id=4] @@ -40,9 +40,6 @@ points = PoolVector2Array( 16, 16, 0, 16, 0, 0, 16, 0 ) } ] 0/z_index = 0 -[sub_resource type="RectangleShape2D" id=5] -extents = Vector2( 8, 8 ) - [node name="LevelTemplate" type="Node2D"] __meta__ = { "_edit_horizontal_guides_": [ 464.0 ], @@ -67,16 +64,3 @@ position = Vector2( 206.918, 601.665 ) [node name="Blobby" parent="." instance=ExtResource( 1 )] position = Vector2( 50.7867, 604.063 ) - -[node name="RigidBody2D" type="RigidBody2D" parent="."] -position = Vector2( -104.184, -29.293 ) -collision_layer = 64 -collision_mask = 8 - -[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"] -position = Vector2( 130.787, 601.665 ) -shape = SubResource( 5 ) - -[node name="Sprite" type="Sprite" parent="RigidBody2D/CollisionShape2D"] -position = Vector2( 0, -0.000244141 ) -texture = ExtResource( 2 ) diff --git a/src/Levels/Simple Level.tscn b/src/Levels/Simple Level.tscn index a70f49f..94c38a4 100644 --- a/src/Levels/Simple Level.tscn +++ b/src/Levels/Simple Level.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=10 format=2] -[ext_resource path="res://src/Actors/Player/Blobby.tscn" type="PackedScene" id=1] +[ext_resource path="res://src/Actors/Blobby/Blobby.tscn" type="PackedScene" id=1] [ext_resource path="res://assets/environment/blocks/Basic stone block.png" type="Texture" id=2] [ext_resource path="res://src/Contraptions/Platform/Track.tscn" type="PackedScene" id=3] [ext_resource path="res://assets/environment/background/background.png" type="Texture" id=4] diff --git a/src/Utilities/Physic/PhysicsFunc.gd b/src/Utilities/Physic/PhysicsFunc.gd index b667336..c7ff0a5 100644 --- a/src/Utilities/Physic/PhysicsFunc.gd +++ b/src/Utilities/Physic/PhysicsFunc.gd @@ -4,3 +4,9 @@ static func convert_velocity_to_force(velocity, mass, delta) -> float: static func convert_force_to_velocity(force, mass, delta) -> float: return (force / mass) * delta + + +static func complete_unelastic_shock( + v1: float, v2: float, m1: float, m2: float +) -> float: + return (m1 * v1 + m2 * v2) / (m1 + m2)