1
Fork 0
mirror of https://github.com/RYGhub/the-cold-night.git synced 2024-11-21 20:24:20 +00:00

Create player scene and basic player movement

This commit is contained in:
Steffo 2022-04-02 21:38:43 +02:00
parent 185eb7a7fa
commit 639db9cf24
Signed by: steffo
GPG key ID: 6965406171929D01
5 changed files with 82 additions and 11 deletions

View file

@ -8,16 +8,6 @@
config_version=4
_global_script_classes=[ {
"base": "Sprite",
"class": "Fire",
"language": "GDScript",
"path": "res://src/Fire.gd"
} ]
_global_script_class_icons={
"Fire": ""
}
[application]
config/name="LD50"
@ -29,6 +19,37 @@ window/size/width=1280
window/size/height=720
window/size/resizable=false
[input]
player_move_up={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
]
}
player_move_down={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, 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":1,"axis_value":1.0,"script":null)
]
}
player_move_left={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"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)
]
}
player_move_right={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"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)
]
}
[physics]
common/enable_pause_aware_picking=true

View file

@ -1,8 +1,9 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=5 format=2]
[ext_resource path="res://src/Background.tscn" type="PackedScene" id=1]
[ext_resource path="res://src/Darkness.tscn" type="PackedScene" id=2]
[ext_resource path="res://src/Fire.tscn" type="PackedScene" id=3]
[ext_resource path="res://src/Player.tscn" type="PackedScene" id=4]
[node name="Game" type="Node2D"]
@ -14,3 +15,7 @@ position = Vector2( 553, 296 )
[node name="Fire" parent="." instance=ExtResource( 3 )]
position = Vector2( 597, 323 )
intensity = 1.0
[node name="Player" parent="." instance=ExtResource( 4 )]
position = Vector2( 500, 438 )

18
src/Player.tscn Normal file
View file

@ -0,0 +1,18 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://src/White.png" type="Texture" id=1]
[ext_resource path="res://src/PlayerMovement.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 16, 16 )
[node name="Player" type="KinematicBody2D"]
[node name="PlayerMovement" type="Node" parent="."]
script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 )
[node name="Shape" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )

21
src/PlayerMovement.gd Normal file
View file

@ -0,0 +1,21 @@
extends Node
export var movement_per_second: float = 96.0
onready var target: KinematicBody2D = get_parent()
func _physics_process(_delta):
var total_input = Vector2.ZERO
total_input += Input.get_action_strength("player_move_up") * Vector2.UP
total_input += Input.get_action_strength("player_move_down") * Vector2.DOWN
total_input += Input.get_action_strength("player_move_left") * Vector2.LEFT
total_input += Input.get_action_strength("player_move_right") * Vector2.RIGHT
# If using a controller, allow going slower than the default speed, but not faster
# Basically, "cap" movement at 1
if total_input.length() > 1:
total_input.normalized()
var _motion: Vector2 = target.move_and_slide(total_input * movement_per_second, Vector2.ZERO)

6
src/PlayerMovement.tscn Normal file
View file

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://src/PlayerMovement.gd" type="Script" id=1]
[node name="PlayerMovement" type="Node"]
script = ExtResource( 1 )