From 3ba9afd2be0eeeb86f1cfd28f381ccf2b1f2e36c Mon Sep 17 00:00:00 2001 From: Haze Weathers Date: Wed, 10 May 2023 18:25:26 -0400 Subject: [PATCH] sg pushin' shovin' squishin' some snails n' skeles with rocks --- objects/environment/rock/rock.gd | 22 ++++----- objects/environment/rock/rock.tscn | 5 +- objects/player/player_scholar.gd | 32 ++++++++++++- objects/player/player_scholar.tscn | 75 +++++++++++++++++++++++++++++- 4 files changed, 117 insertions(+), 17 deletions(-) diff --git a/objects/environment/rock/rock.gd b/objects/environment/rock/rock.gd index d7f33ae..a60b1ab 100644 --- a/objects/environment/rock/rock.gd +++ b/objects/environment/rock/rock.gd @@ -1,23 +1,23 @@ extends KinematicBody2D -var velocity = Vector2.ZERO -onready var bottom = $Bottom + +var velocity: Vector2 = Vector2.ZERO func _physics_process(delta): - if !is_on_floor(): + if not is_on_floor(): #Gravity - velocity.y = 100 - velocity.x = 0 + velocity.y = 100.0 + velocity.x = 0.0 else: - velocity.y = 0 + velocity.y = 0.0 move_and_slide(velocity,Vector2.UP) - velocity.x = 0 + velocity.x = 0.0 -func push(direction): - velocity -= direction * 32 +func push(amount: float): + velocity.x = amount func _on_Hitbox_area_entered(area): # do not squish if in "blocks_squash" group - if area.is_in_group("enemy_hitbox") && !area.is_in_group("blocks_squash"): + if area.is_in_group("enemy_hitbox") and not area.is_in_group("blocks_squash"): var enemy = area.get_parent() - if enemy.global_position.y > global_position.y && velocity.y > 0: + if enemy.global_position.y > global_position.y and velocity.y > 0: enemy.die() diff --git a/objects/environment/rock/rock.tscn b/objects/environment/rock/rock.tscn index 484d58a..b5d0562 100644 --- a/objects/environment/rock/rock.tscn +++ b/objects/environment/rock/rock.tscn @@ -10,7 +10,7 @@ shader_param/border_color = Color( 0, 0, 0, 1 ) shader_param/border_corners = false [sub_resource type="RectangleShape2D" id=2] -extents = Vector2( 3.7, 4 ) +extents = Vector2( 3.75, 4 ) [sub_resource type="RectangleShape2D" id=3] extents = Vector2( 4, 4 ) @@ -37,7 +37,4 @@ collision_layer = 5 position = Vector2( 5, 4 ) shape = SubResource( 3 ) -[node name="Bottom" type="Position2D" parent="."] -position = Vector2( 4, 8 ) - [connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"] diff --git a/objects/player/player_scholar.gd b/objects/player/player_scholar.gd index 96cc6fb..082c844 100644 --- a/objects/player/player_scholar.gd +++ b/objects/player/player_scholar.gd @@ -10,6 +10,8 @@ const DeathSplatter = preload("res://objects/player/player_death_particles.tscn" # EXPORTS # ## horizontal movement speed export var walk_speed: float = 50.0 +## speed to push pushable objects at +export var push_speed: float = 25.0 ## climbing speed export var climb_speed: float = 39.0 ## gravity force @@ -43,15 +45,22 @@ onready var grounded_shape: CollisionShape2D = $"%GroundedShape" onready var airborne_shape: CollisionShape2D = $"%AirborneShape" onready var ladder_detector: RayCast2D = $"%LadderDetector" onready var death_splatter_position: Position2D = $"%DeathSplatterPosition" +onready var pushable_detector: RayCast2D = $"%PushableDetector" # OVERRIDES # func _ready() -> void: + # death handling Game.respawn_point = global_position connect("died", Game, "_on_player_died") + # to detect floor on first frame move_and_slide(Vector2(0.0, 1.0), Vector2.UP) + # make certain pushable detector will not detect player + pushable_detector.add_exception(self) + # set up state chart state_chart.initialize() state_chart.set_guard_property("can_respawn", true) + # state chart debug $StateDebugLayer/StateChartDebug.target = state_chart func _physics_process(delta: float) -> void: @@ -103,6 +112,9 @@ func _on_Grounded_state_entered() -> void: snap.y = 2.5 # snap when in grounded state velocity.y = 1.0 +func _on_Pushing_state_entered() -> void: + animation_player.play("push") + func _on_Airborne_state_entered() -> void: grounded_shape.disabled = true airborne_shape.disabled = false @@ -208,6 +220,21 @@ func _process_can_walk(delta: float) -> void: else: animation_player.play("idle") +## rubbing up against a wall or pushing an object +func _process_pushing(delta: float) -> void: + if not is_on_wall(): + state_chart.send_event("push_stop") + var input_dir = sign(Input.get_axis("ui_left", "ui_right")) + if input_dir != 0.0: + pushable_detector.force_raycast_update() + if pushable_detector.is_colliding(): + var col = pushable_detector.get_collider() + if col.is_in_group("pushable"): + col.push(input_dir * push_speed) + velocity.x = input_dir * push_speed * 2.0 + else: + state_chart.send_event("push_stop") + ## climbing on ladders func _process_climbing(delta: float) -> void: # climbing movement @@ -271,10 +298,13 @@ func _process_movement(delta: float) -> void: if col != null: if col.remainder.y >= 1.0 and col.normal.y == 0.0: position.x += col.normal.x * 0.001 + + # check for wall + if is_on_wall(): + state_chart.send_event("push_start") # COLLISION CALLBACKS # func _on_Hitbox_body_entered(body: Node) -> void: if body.is_in_group("death"): die() - diff --git a/objects/player/player_scholar.tscn b/objects/player/player_scholar.tscn index 73f1aaf..f937a81 100644 --- a/objects/player/player_scholar.tscn +++ b/objects/player/player_scholar.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=37 format=2] +[gd_scene load_steps=39 format=2] [ext_resource path="res://objects/player/player_scholar.gd" type="Script" id=1] [ext_resource path="res://graphics/player/pal_purplearmor.png" type="Texture" id=2] @@ -20,6 +20,7 @@ [ext_resource path="res://graphics/particles/dust.png" type="Texture" id=18] [ext_resource path="res://graphics/player/sg_fall_scared.png" type="Texture" id=19] [ext_resource path="res://graphics/player/sg_fall.png" type="Texture" id=20] +[ext_resource path="res://graphics/player/sg_push.png" type="Texture" id=21] [sub_resource type="ShaderMaterial" id=1] shader = ExtResource( 3 ) @@ -407,6 +408,59 @@ tracks/3/keys = { "values": [ 0.0 ] } +[sub_resource type="Animation" id=17] +resource_name = "push" +length = 0.8 +loop = true +tracks/0/type = "value" +tracks/0/path = NodePath("Graphics/Sprite:texture") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0 ), +"transitions": PoolRealArray( 1 ), +"update": 1, +"values": [ ExtResource( 21 ) ] +} +tracks/1/type = "value" +tracks/1/path = NodePath("Graphics/Sprite:hframes") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/keys = { +"times": PoolRealArray( 0 ), +"transitions": PoolRealArray( 1 ), +"update": 1, +"values": [ 4 ] +} +tracks/2/type = "value" +tracks/2/path = NodePath("Graphics/Sprite:frame") +tracks/2/interp = 1 +tracks/2/loop_wrap = true +tracks/2/imported = false +tracks/2/enabled = true +tracks/2/keys = { +"times": PoolRealArray( 0, 0.2, 0.4, 0.6 ), +"transitions": PoolRealArray( 1, 1, 1, 1 ), +"update": 1, +"values": [ 0, 1, 2, 3 ] +} +tracks/3/type = "value" +tracks/3/path = NodePath("Graphics/Sprite:rotation_degrees") +tracks/3/interp = 1 +tracks/3/loop_wrap = true +tracks/3/imported = false +tracks/3/enabled = true +tracks/3/keys = { +"times": PoolRealArray( 0 ), +"transitions": PoolRealArray( 1 ), +"update": 0, +"values": [ 0.0 ] +} + [sub_resource type="Animation" id=11] resource_name = "shoot_airborne" length = 0.001 @@ -650,6 +704,12 @@ scale_amount = 0.25 scale_amount_random = 0.5 scale_amount_curve = SubResource( 13 ) +[node name="PushableDetector" type="RayCast2D" parent="Graphics"] +unique_name_in_owner = true +position = Vector2( 3, -4 ) +cast_to = Vector2( 1, 0 ) +collision_mask = 4 + [node name="BodyShape" type="CollisionShape2D" parent="."] position = Vector2( 0.5, -5 ) shape = SubResource( 2 ) @@ -685,6 +745,7 @@ anims/fall = SubResource( 15 ) anims/fall_scared = SubResource( 14 ) anims/idle = SubResource( 6 ) anims/jump = SubResource( 8 ) +anims/push = SubResource( 17 ) anims/shoot_airborne = SubResource( 11 ) anims/shoot_grounded = SubResource( 10 ) anims/walk = SubResource( 7 ) @@ -749,6 +810,11 @@ to = NodePath("../../Shooting") event = "shoot" guard_expression = "can_shoot" +[node name="On PushStart" type="Node" parent="StateChart/Root/Movement/Grounded/CanWalk"] +script = ExtResource( 10 ) +to = NodePath("../../Pushing") +event = "push_start" + [node name="Shooting" type="Node" parent="StateChart/Root/Movement/Grounded"] script = ExtResource( 11 ) consumed_events = [ "jump" ] @@ -761,6 +827,11 @@ event = "shoot_end" [node name="Pushing" type="Node" parent="StateChart/Root/Movement/Grounded"] script = ExtResource( 11 ) +[node name="On PushStop" type="Node" parent="StateChart/Root/Movement/Grounded/Pushing"] +script = ExtResource( 10 ) +to = NodePath("../../CanWalk") +event = "push_stop" + [node name="Airborne" type="Node" parent="StateChart/Root/Movement"] process_priority = 5 script = ExtResource( 9 ) @@ -934,6 +1005,8 @@ script = ExtResource( 8 ) [connection signal="state_physics_processing" from="StateChart/Root/Movement/Grounded/CanWalk" to="." method="_process_horizontal_movement"] [connection signal="state_physics_processing" from="StateChart/Root/Movement/Grounded/CanWalk" to="." method="_process_can_walk"] [connection signal="state_entered" from="StateChart/Root/Movement/Grounded/Shooting" to="." method="_on_Shooting_state_entered"] +[connection signal="state_entered" from="StateChart/Root/Movement/Grounded/Pushing" to="." method="_on_Pushing_state_entered"] +[connection signal="state_physics_processing" from="StateChart/Root/Movement/Grounded/Pushing" to="." method="_process_pushing"] [connection signal="state_entered" from="StateChart/Root/Movement/Airborne" to="." method="_on_Airborne_state_entered"] [connection signal="state_physics_processing" from="StateChart/Root/Movement/Airborne" to="." method="_process_gravity"] [connection signal="state_physics_processing" from="StateChart/Root/Movement/Airborne/Jump" to="." method="_process_jump"]