From 548e93e861aecfc3c682369552677afe29bc5a7b Mon Sep 17 00:00:00 2001 From: Luna Brovchuk Date: Sat, 30 Sep 2023 18:52:26 +0200 Subject: [PATCH] Add Player & Movement --- project.godot | 27 +++++++++++++++ src/models/player/Player.tscn | 18 ++++++++++ src/models/player/player.gd | 12 +++++++ src/models/player/sprite.png | Bin 0 -> 2131 bytes src/models/player/sprite.png.import | 35 ++++++++++++++++++++ src/scenes/game/Game.tscn | 49 +++++++++++++++++++++++++--- 6 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 src/models/player/Player.tscn create mode 100644 src/models/player/player.gd create mode 100644 src/models/player/sprite.png create mode 100644 src/models/player/sprite.png.import diff --git a/project.godot b/project.godot index f8a7d71..c79ad3a 100644 --- a/project.godot +++ b/project.godot @@ -54,6 +54,33 @@ blender=false common/drop_mouse_on_gui_input_disabled=true +[input] + +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":0,"physical_scancode":65,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":16777231,"unicode":0,"echo":false,"script":null) + ] +} +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":0,"physical_scancode":68,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":16777233,"unicode":0,"echo":false,"script":null) + ] +} +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":0,"physical_scancode":87,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":16777232,"unicode":0,"echo":false,"script":null) + ] +} +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":0,"physical_scancode":83,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":16777234,"unicode":0,"echo":false,"script":null) + ] +} + [physics] common/enable_pause_aware_picking=true diff --git a/src/models/player/Player.tscn b/src/models/player/Player.tscn new file mode 100644 index 0000000..6ae7ba3 --- /dev/null +++ b/src/models/player/Player.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://src/models/player/sprite.png" type="Texture" id=1] +[ext_resource path="res://src/models/player/player.gd" type="Script" id=2] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 7, 11 ) + +[node name="Player" type="KinematicBody2D"] +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +texture = ExtResource( 1 ) +centered = false + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2( 12, 12 ) +shape = SubResource( 1 ) diff --git a/src/models/player/player.gd b/src/models/player/player.gd new file mode 100644 index 0000000..0fc2b9e --- /dev/null +++ b/src/models/player/player.gd @@ -0,0 +1,12 @@ +extends KinematicBody2D + +var velocity = Vector2.ZERO +var speed = 120 + +func get_input(): + var input_direction = Input.get_vector("left", "right", "up", "down") + velocity = input_direction * speed + +func _physics_process(delta): + get_input() + move_and_slide(velocity) diff --git a/src/models/player/sprite.png b/src/models/player/sprite.png new file mode 100644 index 0000000000000000000000000000000000000000..ae4a661407030578f09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