Basic Movement and Map Generation #22

Merged
Snoweuph merged 17 commits from dev-base into stable 2023-04-08 00:41:10 +00:00
4 changed files with 123 additions and 1 deletions
Showing only changes of commit 4b2d83a4c5 - Show all commits

59
Player/player.gd Normal file
View file

@ -0,0 +1,59 @@
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
# ----------------------------------------

16
Player/player.tscn Normal file
View file

@ -0,0 +1,16 @@
[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")

16
Scenes/Movement.tscn Normal file
View file

@ -0,0 +1,16 @@
[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)

View file

@ -11,10 +11,41 @@ config_version=5
[application] [application]
config/name="HoppyEaster" config/name="HoppyEaster"
run/main_scene="res://Scenes/Test.tscn" run/main_scene="res://Scenes/Movement.tscn"
config/features=PackedStringArray("4.0", "GL Compatibility") config/features=PackedStringArray("4.0", "GL Compatibility")
config/icon="res://icon.svg" config/icon="res://icon.svg"
[dotnet]
project/assembly_name="HoppyEaster"
[input]
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)
]
}
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)
]
}
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)
]
}
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)
]
}
[rendering] [rendering]
renderer/rendering_method="gl_compatibility" renderer/rendering_method="gl_compatibility"