Basic Movement and Map Generation #22
8 changed files with 85 additions and 92 deletions
BIN
Assets/Sprites/Jesus_Left_Idle.png
Normal file
BIN
Assets/Sprites/Jesus_Left_Idle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 641 B |
34
Assets/Sprites/Jesus_Left_Idle.png.import
Normal file
34
Assets/Sprites/Jesus_Left_Idle.png.import
Normal file
|
@ -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
|
|
@ -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
|
|
||||||
# ----------------------------------------
|
|
|
@ -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")
|
|
|
@ -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)
|
|
22
Scenes/PlayerMovement.tscn
Normal file
22
Scenes/PlayerMovement.tscn
Normal file
|
@ -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
|
24
Scripts/PlayerController.gd
Normal file
24
Scripts/PlayerController.gd
Normal file
|
@ -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
|
|
@ -25,24 +25,28 @@ move_left={
|
||||||
"deadzone": 0.5,
|
"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)
|
"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(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={
|
move_right={
|
||||||
"deadzone": 0.5,
|
"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)
|
"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(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,
|
"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)
|
"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(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={
|
move_down={
|
||||||
"deadzone": 0.5,
|
"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)
|
"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(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)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue