From ef60fdd59f6edd55681bc6ecad5746a206dd3171 Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Fri, 7 Apr 2023 16:11:07 +0200 Subject: [PATCH] Fixing Strucuter and Cleaning Up --- Assets/Sprites/Jesus_Left_Idle.png | Bin 0 -> 641 bytes Assets/Sprites/Jesus_Left_Idle.png.import | 34 +++++++++++++ Player/player.gd | 59 ---------------------- Player/player.tscn | 16 ------ Scenes/Movement.tscn | 16 ------ Scenes/PlayerMovement.tscn | 22 ++++++++ Scripts/PlayerController.gd | 24 +++++++++ project.godot | 6 ++- 8 files changed, 85 insertions(+), 92 deletions(-) create mode 100644 Assets/Sprites/Jesus_Left_Idle.png create mode 100644 Assets/Sprites/Jesus_Left_Idle.png.import delete mode 100644 Player/player.gd delete mode 100644 Player/player.tscn delete mode 100644 Scenes/Movement.tscn create mode 100644 Scenes/PlayerMovement.tscn create mode 100644 Scripts/PlayerController.gd diff --git a/Assets/Sprites/Jesus_Left_Idle.png b/Assets/Sprites/Jesus_Left_Idle.png new file mode 100644 index 0000000000000000000000000000000000000000..4082dd7546dc404958a4d14a2c48f6658d2894b6 GIT binary patch literal 641 zcmV-{0)G98P)q+JLb0HuLPZfpq;o-(x=KeW)KNi1M<*Qw z7dID`%0Em=(t$c}^n?xXJ zQ5!OSHWN}|BHk4OCUm6)BII%;Y!=QfrM0o;vl@v|P<(zD7&GmC96E(EAaOIft{BOAd*PtgHJ?z7k3_9 zLxTg_$*|`<3Y>feqCu~|rdhpSZ^EUD?J%LL_97-0H~ss=`4(#NAowN}Jpg4e4G=R? zk>CVPNTpJ(HGBnl-G5`oh1yTYt7X_@rHUTcV#1Z6C@`MQXyY&>Knaowbw;uU%oq7y zfF_{I-Xt@W$5bLR0atKNAV>)m0h9SCpPV%TmuPFnr9zgK3e3+I(?-KUOM&&(Wv2`2 zd|-Vd5^*>+f{Ife+*<^8j!&7~io@=FfVuu#H32NRl%o67`2$qbVGwgtY>0NJRX bZDYRybItKwhRaT>00000NkvXXu0mjf7-bZy literal 0 HcmV?d00001 diff --git a/Assets/Sprites/Jesus_Left_Idle.png.import b/Assets/Sprites/Jesus_Left_Idle.png.import new file mode 100644 index 0000000..7e997b4 --- /dev/null +++ b/Assets/Sprites/Jesus_Left_Idle.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c6n0go8l4gaak" +path="res://.godot/imported/Jesus_Left_Idle.png-591d029c8d8b8b573a2665b70cf0e031.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Assets/Sprites/Jesus_Left_Idle.png" +dest_files=["res://.godot/imported/Jesus_Left_Idle.png-591d029c8d8b8b573a2665b70cf0e031.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Player/player.gd b/Player/player.gd deleted file mode 100644 index 99cc78b..0000000 --- a/Player/player.gd +++ /dev/null @@ -1,59 +0,0 @@ -extends CharacterBody2D - -# Serialized Variables ------------------ -@export var MAX_SPEED = 300 -@export var ACCELERATION = 1500 -@export var FRICTION = 1200 -# --------------------------------------- - - - -# Calculation Variables ----------------- -@onready var axis = Vector2.ZERO -# --------------------------------------- - - - -# Engine Callbacks ---------------------- -func _physics_process(delta): - move(delta) -# --------------------------------------- - - - -# Input --------------------------------- -func get_input(): - # Makes the function equivalent to unity's Input.GetAxis("Horizontal") - axis.x = int(Input.is_action_pressed("move_right")) - int(Input.is_action_pressed("move_left")) - # Makes the function equivalent to unity's Input.GetAxis("Vertical") - axis.y = int(Input.is_action_pressed("move_down")) - int(Input.is_action_pressed("move-up")) - - return axis.normalized() -# --------------------------------------- - - - -# Movement ------------------------------ -func move(delta): - axis = get_input() # Get the input - - # If player is not moving - if axis == Vector2.ZERO: - apply_friction(FRICTION * delta) - else : - apply_movement(axis * ACCELERATION * delta) - - move_and_slide() - - -func apply_movement(accel): - velocity += accel - velocity = velocity.limit_length(MAX_SPEED) - - -func apply_friction(amount): - if velocity.length() > amount : - velocity -= velocity.normalized() * amount - else : - velocity = Vector2.ZERO -# ---------------------------------------- diff --git a/Player/player.tscn b/Player/player.tscn deleted file mode 100644 index 4b2714d..0000000 --- a/Player/player.tscn +++ /dev/null @@ -1,16 +0,0 @@ -[gd_scene load_steps=4 format=3 uid="uid://btiw3mdue2ien"] - -[ext_resource type="Texture2D" uid="uid://futvep428rf0" path="res://icon.svg" id="1_1j8gw"] -[ext_resource type="Script" path="res://Player/player.gd" id="1_dl5xi"] - -[sub_resource type="CircleShape2D" id="CircleShape2D_rcutd"] -radius = 67.0 - -[node name="Player" type="CharacterBody2D"] -script = ExtResource("1_dl5xi") - -[node name="Sprite2D" type="Sprite2D" parent="."] -texture = ExtResource("1_1j8gw") - -[node name="CollisionShape2D" type="CollisionShape2D" parent="."] -shape = SubResource("CircleShape2D_rcutd") diff --git a/Scenes/Movement.tscn b/Scenes/Movement.tscn deleted file mode 100644 index 4529cb2..0000000 --- a/Scenes/Movement.tscn +++ /dev/null @@ -1,16 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://bu6iwskde5hn6"] - -[ext_resource type="PackedScene" uid="uid://btiw3mdue2ien" path="res://Player/player.tscn" id="1_62wcj"] - -[node name="Movement" type="Node2D"] - -[node name="Player" parent="." instance=ExtResource("1_62wcj")] -position = Vector2(561, 312) -MAX_SPEED = 350 -ACCELERATION = 2500 -FRICTION = 1500 - -[node name="StaticBody2D" type="StaticBody2D" parent="."] - -[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="StaticBody2D"] -polygon = PackedVector2Array(90, 68, 776, 70, 1086, 236, 924, 566, 704, 220, 262, 154, 174, 494, 34, 316) diff --git a/Scenes/PlayerMovement.tscn b/Scenes/PlayerMovement.tscn new file mode 100644 index 0000000..73f741f --- /dev/null +++ b/Scenes/PlayerMovement.tscn @@ -0,0 +1,22 @@ +[gd_scene load_steps=3 format=3 uid="uid://ccgpsim5nfxd6"] + +[ext_resource type="Script" path="res://Scripts/PlayerController.gd" id="1_x3102"] +[ext_resource type="Texture2D" uid="uid://c6n0go8l4gaak" path="res://Assets/Sprites/Jesus_Left_Idle.png" id="2_48vut"] + +[node name="Node2D" type="Node2D"] + +[node name="CharacterBody2D" type="CharacterBody2D" parent="."] +script = ExtResource("1_x3102") + +[node name="Sprite2D" type="Sprite2D" parent="CharacterBody2D"] +texture = ExtResource("2_48vut") + +[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="CharacterBody2D"] +polygon = PackedVector2Array(16, 32, -14, 32, -14, -22, 16, -22) + +[node name="Camera2D" type="Camera2D" parent="CharacterBody2D"] +position_smoothing_enabled = true +drag_horizontal_enabled = true +drag_vertical_enabled = true +editor_draw_limits = true +editor_draw_drag_margin = true diff --git a/Scripts/PlayerController.gd b/Scripts/PlayerController.gd new file mode 100644 index 0000000..f167eb8 --- /dev/null +++ b/Scripts/PlayerController.gd @@ -0,0 +1,24 @@ +extends CharacterBody2D + +@export var speed = 100 +@export_range(0, 1) var damping_factor := 0.6 + +func get_move_vector(): + var input_direction = Input.get_vector("move_left", "move_right", "move_up", "move_down").normalized() + return input_direction + +func move_player(delta : float): + if get_move_vector() == Vector2.ZERO: + # Damp Players Velocity if no Input + self.velocity = self.velocity * (1 - min(1, damping_factor * 60 * delta)) + else: + # Set Players Velocity to the Input Direction in the Players Speed + self.velocity = get_move_vector() * speed * delta * 60 + + # Update The Players Physics Calculations + self.move_and_slide() + pass + +func _physics_process(delta : float): + move_player(delta) + pass diff --git a/project.godot b/project.godot index b9f6a67..56d2078 100644 --- a/project.godot +++ b/project.godot @@ -25,24 +25,28 @@ move_left={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"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":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"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,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null) ] } move_right={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"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":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"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,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null) ] } -move-up={ +move_up={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"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":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"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,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null) ] } move_down={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null) ] }