diff --git a/project.godot b/project.godot index baf3966..93a79d9 100644 --- a/project.godot +++ b/project.godot @@ -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 diff --git a/src/Game.tscn b/src/Game.tscn index 06d1109..a477acc 100644 --- a/src/Game.tscn +++ b/src/Game.tscn @@ -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 ) diff --git a/src/Player.tscn b/src/Player.tscn new file mode 100644 index 0000000..3aa8ae6 --- /dev/null +++ b/src/Player.tscn @@ -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 ) diff --git a/src/PlayerMovement.gd b/src/PlayerMovement.gd new file mode 100644 index 0000000..188545f --- /dev/null +++ b/src/PlayerMovement.gd @@ -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) diff --git a/src/PlayerMovement.tscn b/src/PlayerMovement.tscn new file mode 100644 index 0000000..145aa85 --- /dev/null +++ b/src/PlayerMovement.tscn @@ -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 )