Added swinging

Still needs work

Signed-off-by: Ethan Wellenreiter <ewellenreiter@gmail.com>
This commit is contained in:
Ethan Wellenreiter 2025-01-03 03:41:29 -05:00
parent 99d09e2555
commit 0c726db9ea
6 changed files with 290 additions and 30 deletions

50
player/looking.gd Normal file
View File

@ -0,0 +1,50 @@
extends RayCast2D
@onready var player : Player = get_parent()
@onready var fire_range : float = player.ROPE_MAX_DISTANCE
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
var aim_dir : Vector2 = player.position
if player.MK:
aim_dir = get_global_mouse_position()
else:
# get the aim_dir based off of joystick
pass
#print("shooting_dir ", aim_dir.normalized())
look_at(aim_dir)
#if Input. # fire rope
if Input.is_action_just_pressed("fire"):
#print("hi")
if (not player.on_rope):
#fire rope
#vec2 aim_pos = get_global_mouse_position()
if is_colliding(): # process the swing
#print("shooting")
var col_point : Vector2 = get_collision_point()
var dist : float = player.position.distance_to(col_point)
print(col_point," ", dist," ", fire_range)
if dist < fire_range:
player.connection_points.append(col_point)
player.rope_length = dist
player.on_rope = true
# set the velocity accordingly since you can just float up otherwise
pass
elif player.on_rope:
print("was_on_rope")
player.on_rope = false
player.connection_points.clear()
# release rope
pass

View File

@ -2,35 +2,93 @@ extends CharacterBody2D
class_name Player
@export var SPEED = 300.0
@export var JUMP_VELOCITY = -400.0
@export var WALK_SPEED : float = 300.0
@export var SLOW_SPEED_MULTIPLIER : float = 3
@export var JUMP_VELOCITY : float = -500
@export var DASH_DISTANCE : float = 5
@export var DASH_TIME_LENGTH : float = 1
@export var SWING_SWAY : float = 100.0
@export var ROPE_MAX_DISTANCE : float = 10000
var connection_points : PackedVector2Array = PackedVector2Array()
var rope_length : float = -1
@export var DAMPENING : float = 0.8
var DASH_SPEED = DASH_DISTANCE/DASH_TIME_LENGTH
var MK : bool = true # mouse and keyboard or controller mode
var on_rope : bool = false
func add_gravity(delta: float) -> void:
velocity += get_gravity() * delta
func _physics_process(delta: float) -> void:
var vertically_held : bool = false
if is_on_floor():
vertically_held = true
# handle the stuff here with if it's hanging at the time
# Add the gravity.
if not vertically_held:
if not is_on_floor():
add_gravity(delta)
if on_rope: # handle the stuff here with if it's hanging at the time
#print("point: ", connection_points[-1], " ", position)
var conn_dir : Vector2 = connection_points[-1] - position
#var y_dir = self.up_direction * (1 if (self.up_direction.dot(conn_dir) > 0) else -1)
#var angle : float = y_dir.angle_to(connection_points[-1] - position)
var angle : float = (-self.up_direction).angle_to(conn_dir)
#print(angle)
#general tangential
var tangential_direction : Vector2 = Vector2(-conn_dir.y, conn_dir.x) # clockwise tangential
## tangential pointing down
#var tangential_direction : Vector2 = Vector2.ZERO
#if conn_dir.x > 0:
##print("c")
#tangential_direction = Vector2(-conn_dir.y, conn_dir.x) # clockwise tangential
#else:
##print("cc")
#tangential_direction = Vector2(conn_dir.y, -conn_dir.x) # counter-clockwise tangential
#tangential_direction = tangential_direction.normalized()
velocity = velocity.project(tangential_direction)
#print(tangential_direction)
#print(velocity)
#print(pow(DAMPENING, delta))
if velocity.dot(up_direction) > 0:
velocity *= pow(DAMPENING, delta)
var direction := Input.get_axis("move_left", "move_right") ## walking left and right
if direction:
#print("swaying")
velocity += delta*SWING_SWAY*(tangential_direction* (1 if direction > 0 else -1)).normalized()
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
pass
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("ui_left", "ui_right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
var direction := Input.get_axis("move_left", "move_right") ## walking left and right
if direction:
var acting_speed : float = WALK_SPEED
if direction * velocity.x < 0:
acting_speed *= SLOW_SPEED_MULTIPLIER
velocity.x = clamp(velocity.x + (direction*delta*acting_speed), -WALK_SPEED, WALK_SPEED)
else:
velocity.x = move_toward(velocity.x, 0, SLOW_SPEED_MULTIPLIER*WALK_SPEED*delta)
move_and_slide()
#print("v3: ", velocity)

View File

@ -1,7 +1,9 @@
[gd_scene load_steps=4 format=3 uid="uid://brhc07imuholv"]
[gd_scene load_steps=6 format=3 uid="uid://brhc07imuholv"]
[ext_resource type="Texture2D" uid="uid://tfyg7vamdt4q" path="res://assets/test_player.png" id="1_0ushe"]
[ext_resource type="Texture2D" uid="uid://87gegwimvax2" path="res://assets/test_player.png" id="1_0ushe"]
[ext_resource type="Script" path="res://player/player.gd" id="1_x227h"]
[ext_resource type="Script" path="res://player/looking.gd" id="3_n7yd4"]
[ext_resource type="Texture2D" uid="uid://ce2w78k77ugei" path="res://assets/pngtree-arrow-shape-red-simple-direction-png-image_5215909.png" id="4_3fyds"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_fbsbu"]
size = Vector2(96, 306)
@ -18,3 +20,13 @@ texture = ExtResource("1_0ushe")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(-2, 0)
shape = SubResource("RectangleShape2D_fbsbu")
[node name="RayCast2D" type="RayCast2D" parent="."]
target_position = Vector2(1e+06, 0)
collide_with_areas = true
script = ExtResource("3_n7yd4")
[node name="Sprite2D" type="Sprite2D" parent="RayCast2D"]
position = Vector2(83, 0)
scale = Vector2(0.266667, 0.266667)
texture = ExtResource("4_3fyds")

View File

@ -0,0 +1,40 @@
extends RayCast2D
class_name Rope
@onready var player : Player = get_parent()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta: float) -> void:
if player.on_rope:
var aim_dir : Vector2 = player.connection_points[-1]
#print("aim_dir ", aim_dir)
look_at(aim_dir)
if is_colliding(): # safety if statement. should always be true realistically
#print("passive")
var col_point : Vector2 = get_collision_point()
var dist : float = player.position.distance_to(col_point)
#print(col_point," ", player.connection_points[-1])
#if dist < fire_range:
#print(dist, " ", player.position.distance_to(player.connection_points[-1]))
#
while dist - player.position.distance_to(player.connection_points[-1]) > 10: #margin of 10
print("yowdy")
if (player.connection_points.size() > 1):
print(player.connection_points)
print("hi")
player.connection_points.remove_at(player.connection_points.size()-1)
player.rope_length = dist
print("bye")
else:
break
#while player.connection_points[-1].distance_to(col_point) > 5: # margin
#
if player.rope_length - dist > 10:
print("add")
player.connection_points.append(col_point)
player.rope_length = dist
pass

View File

@ -18,3 +18,58 @@ config/icon="res://icon.svg"
[autoload]
Universe="*res://world/universe/universe.gd"
[input]
ui_left={
"deadzone": 0.5,
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
]
}
fire={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":71,"key_label":0,"unicode":103,"location":0,"echo":false,"script":null)
]
}
move_right={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null)
]
}
move_left={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null)
]
}
jump={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
]
}
aim_up={
"deadzone": 0.5,
"events": []
}
aim_down={
"deadzone": 0.5,
"events": []
}
aim_left={
"deadzone": 0.5,
"events": []
}
aim_right={
"deadzone": 0.5,
"events": []
}

View File

@ -1,19 +1,25 @@
[gd_scene load_steps=5 format=3 uid="uid://dojvn2guqhhel"]
[gd_scene load_steps=7 format=3 uid="uid://dojvn2guqhhel"]
[ext_resource type="Texture2D" uid="uid://cs8xfi82lox77" path="res://assets/background.png" id="1_t0pgr"]
[ext_resource type="Texture2D" uid="uid://b48bhtfvrv7rc" path="res://assets/background.png" id="1_t0pgr"]
[ext_resource type="PackedScene" uid="uid://brhc07imuholv" path="res://player/player.tscn" id="2_fpbhy"]
[ext_resource type="Texture2D" uid="uid://cdr8heif70pkh" path="res://assets/ground.png" id="3_rvbjd"]
[ext_resource type="Texture2D" uid="uid://d0oq3rgb204fl" path="res://assets/ground.png" id="3_rvbjd"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ptfhu"]
size = Vector2(1158, 598)
size = Vector2(1980, 598)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_aqnnp"]
size = Vector2(1980, 621)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_1iolf"]
size = Vector2(1965, 598)
[node name="Level" type="Node2D"]
[node name="Background" type="TextureRect" parent="."]
offset_left = -31138.0
offset_top = -27910.0
offset_right = 92636.0
offset_bottom = 69138.0
offset_left = -28284.0
offset_top = -28611.0
offset_right = 95490.0
offset_bottom = 68437.0
scale = Vector2(0.5, 0.5)
texture = ExtResource("1_t0pgr")
stretch_mode = 1
@ -25,7 +31,7 @@ position = Vector2(397, -187)
position = Vector2(574.5, 200.5)
[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls_and_ground"]
position = Vector2(-5.5, 88.5)
position = Vector2(-44.5, 88.5)
shape = SubResource("RectangleShape2D_ptfhu")
[node name="TextureRect" type="TextureRect" parent="Walls_and_ground"]
@ -34,3 +40,42 @@ offset_top = -215.5
offset_right = 953.5
offset_bottom = -200.5
texture = ExtResource("3_rvbjd")
[node name="Walls_and_ground3" type="StaticBody2D" parent="."]
position = Vector2(574.5, 200.5)
[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls_and_ground3"]
position = Vector2(1526.5, -525)
shape = SubResource("RectangleShape2D_aqnnp")
[node name="TextureRect" type="TextureRect" parent="Walls_and_ground3"]
offset_left = 551.5
offset_top = -1475.5
offset_right = 2541.5
offset_bottom = -1460.5
rotation = 1.5708
texture = ExtResource("3_rvbjd")
[node name="Walls_and_ground2" type="StaticBody2D" parent="."]
position = Vector2(574.5, 200.5)
[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls_and_ground2"]
position = Vector2(-76, -1138.5)
shape = SubResource("RectangleShape2D_1iolf")
[node name="TextureRect" type="TextureRect" parent="Walls_and_ground2"]
offset_left = -1068.5
offset_top = -849.5
offset_right = 921.5
offset_bottom = -834.5
texture = ExtResource("3_rvbjd")
[node name="Walls_and_ground4" type="StaticBody2D" parent="."]
position = Vector2(-1062.73, -746.059)
[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls_and_ground4"]
shape = SubResource("RectangleShape2D_1iolf")
[node name="Sprite2D" type="Sprite2D" parent="Walls_and_ground4"]
position = Vector2(1.5, 290.5)
texture = ExtResource("3_rvbjd")