Attach momentum to elevator

This commit is contained in:
Layla 2020-06-01 05:32:07 -04:00
parent 1980139acb
commit 3dd00eabd3
No known key found for this signature in database
GPG Key ID: A494D9357BA1BE31
5 changed files with 43 additions and 2 deletions

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=8 format=2]
[ext_resource path="res://Assets/Art/Objects/elevator/elevator.png" type="Texture" id=1]
[ext_resource path="res://Scripts/Entities/Elevator.gd" type="Script" id=2]
[ext_resource path="res://Scripts/Component/ElevatorControls.gd" type="Script" id=3]
[ext_resource path="res://Scripts/Component/LandingArea.gd" type="Script" id=4]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 16, 2 )
@ -10,6 +11,9 @@ extents = Vector2( 16, 2 )
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 10, 16 )
[sub_resource type="RectangleShape2D" id=3]
extents = Vector2( 16, 1 )
[node name="Elevator" type="Node2D"]
script = ExtResource( 2 )
__meta__ = {
@ -40,3 +44,10 @@ script = ExtResource( 3 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="ElevatorControls"]
shape = SubResource( 2 )
[node name="LandingArea" type="Area2D" parent="."]
script = ExtResource( 4 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="LandingArea"]
position = Vector2( 0, 15 )
shape = SubResource( 3 )

View File

@ -40,7 +40,7 @@ reset_after_dialog = true
position = Vector2( 182.674, 166.939 )
[node name="Player" parent="." instance=ExtResource( 3 )]
position = Vector2( 32.6224, 160.876 )
position = Vector2( -418.613, 159.247 )
[node name="GUI" parent="." instance=ExtResource( 4 )]

View File

@ -0,0 +1,25 @@
extends Area2D
var player_node
func _ready():
connect("body_entered", self, "_on_body_enter")
connect("body_exited", self, "_on_body_exit")
set_process(false)
func _on_body_enter(body):
if body.has_method("user_input"):
player_node = body
set_process(true)
func _on_body_exit(body):
if body.has_method("user_input"):
body.floor_speed = Vector2.ZERO
set_process(false)
func _process(delta):
if get_parent().motion.y > 0:
player_node.floor_speed = get_parent().motion
else:
player_node.floor_speed = Vector2.ZERO

View File

@ -44,6 +44,8 @@ func start_moving(index):
func stop_moving():
emit_signal("elevator_stopped")
moving = false
motion = Vector2.ZERO
# Alert doors of updated elevator state
for door_path in doors:
get_node(door_path).on_elevator_stop(current_pos)
@ -54,6 +56,7 @@ func _physics_process(delta):
var target_pos = intial_pos + relative_positions[current_pos]
var angle = get_angle_to(target_pos)
var velocity = Vector2(cos(angle),sin(angle))
motion = velocity * elevator_speed
global_position += velocity * elevator_speed * delta
# Stop when elevator is at destination

View File

@ -14,6 +14,7 @@ var jumped = false
var moveMotion : float = 0 # Player Input ( <- & -> )
var motion : Vector2 = Vector2(0,0) # Player's current velocity
var floor_speed : Vector2 = Vector2.ZERO
var gui # Node representing GUI object
@ -104,6 +105,7 @@ func _physics_process(delta):
# Apply velocity to frame
motion.x = moveMotion
motion = motion + floor_speed
animation_manager(moveMotion)
move_and_slide(motion, Vector2(0,-1))