diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2025-03-10 18:22:09 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2025-03-10 18:22:09 +0100 |
commit | 440020e642f539079867577435a9f8b02075699b (patch) | |
tree | 99acccfc1574a8ffc656d6f64ff934949edb1f52 /player |
Diffstat (limited to 'player')
-rw-r--r-- | player/assets/player-portait.kra | bin | 0 -> 35136 bytes | |||
-rw-r--r-- | player/assets/player-portait.kra~ | bin | 0 -> 35051 bytes | |||
-rw-r--r-- | player/assets/player-portait.png | bin | 0 -> 1139 bytes | |||
-rw-r--r-- | player/assets/player-portait.png.import | 34 | ||||
-rw-r--r-- | player/assets/sprites.kra | bin | 0 -> 52323 bytes | |||
-rw-r--r-- | player/assets/sprites.kra~ | bin | 0 -> 39750 bytes | |||
-rw-r--r-- | player/assets/sprites.png | bin | 0 -> 5690 bytes | |||
-rw-r--r-- | player/assets/sprites.png.import | 34 | ||||
-rw-r--r-- | player/assets/sprites.png~ | bin | 0 -> 5446 bytes | |||
-rw-r--r-- | player/player.gd | 41 | ||||
-rw-r--r-- | player/player.gd.uid | 1 | ||||
-rw-r--r-- | player/player.tscn | 241 | ||||
-rw-r--r-- | player/player_state.gd | 12 | ||||
-rw-r--r-- | player/player_state.gd.uid | 1 | ||||
-rw-r--r-- | player/state_idle.gd | 30 | ||||
-rw-r--r-- | player/state_idle.gd.uid | 1 | ||||
-rw-r--r-- | player/state_moving.gd | 52 | ||||
-rw-r--r-- | player/state_moving.gd.uid | 1 |
18 files changed, 448 insertions, 0 deletions
diff --git a/player/assets/player-portait.kra b/player/assets/player-portait.kra Binary files differnew file mode 100644 index 0000000..5349a47 --- /dev/null +++ b/player/assets/player-portait.kra diff --git a/player/assets/player-portait.kra~ b/player/assets/player-portait.kra~ Binary files differnew file mode 100644 index 0000000..0ccc59d --- /dev/null +++ b/player/assets/player-portait.kra~ diff --git a/player/assets/player-portait.png b/player/assets/player-portait.png Binary files differnew file mode 100644 index 0000000..e6d194d --- /dev/null +++ b/player/assets/player-portait.png diff --git a/player/assets/player-portait.png.import b/player/assets/player-portait.png.import new file mode 100644 index 0000000..b03e109 --- /dev/null +++ b/player/assets/player-portait.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cowq84cvepbp7" +path="res://.godot/imported/player-portait.png-bf1e6df8e8b036df7a685ef1e4ec3bb9.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://player/assets/player-portait.png" +dest_files=["res://.godot/imported/player-portait.png-bf1e6df8e8b036df7a685ef1e4ec3bb9.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 diff --git a/player/assets/sprites.kra b/player/assets/sprites.kra Binary files differnew file mode 100644 index 0000000..967a244 --- /dev/null +++ b/player/assets/sprites.kra diff --git a/player/assets/sprites.kra~ b/player/assets/sprites.kra~ Binary files differnew file mode 100644 index 0000000..e91e2c9 --- /dev/null +++ b/player/assets/sprites.kra~ diff --git a/player/assets/sprites.png b/player/assets/sprites.png Binary files differnew file mode 100644 index 0000000..f635426 --- /dev/null +++ b/player/assets/sprites.png diff --git a/player/assets/sprites.png.import b/player/assets/sprites.png.import new file mode 100644 index 0000000..4201dd1 --- /dev/null +++ b/player/assets/sprites.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c5tjx8m8m7xv1" +path="res://.godot/imported/sprites.png-aaa6d29875ac017efefb9605184986f9.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://player/assets/sprites.png" +dest_files=["res://.godot/imported/sprites.png-aaa6d29875ac017efefb9605184986f9.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 diff --git a/player/assets/sprites.png~ b/player/assets/sprites.png~ Binary files differnew file mode 100644 index 0000000..6d07776 --- /dev/null +++ b/player/assets/sprites.png~ diff --git a/player/player.gd b/player/player.gd new file mode 100644 index 0000000..93920c6 --- /dev/null +++ b/player/player.gd @@ -0,0 +1,41 @@ +class_name Player +extends CharacterBody2D + + +var current_state: PlayerState: + set = set_state + +var current_direction: Vector2: + set = set_direction + +var current_speed := 150.0 + +@onready var state_idle: PlayerStateIdle = %StateIdle +@onready var state_moving: PlayerStateMoving = %StateMoving + +@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D + +@onready var ray_cast_up: RayCast2D = $RayCastUp +@onready var ray_cast_down: RayCast2D = $RayCastDown +@onready var ray_cast_left: RayCast2D = $RayCastLeft +@onready var ray_cast_right: RayCast2D = $RayCastRight + + +func _ready() -> void: + current_state = $States/StateIdle + + +func set_state(value: PlayerState) -> void: + if current_state: + current_state._state_exit() + current_state.process_mode = Node.PROCESS_MODE_DISABLED + + current_state = value + + current_state.process_mode = Node.PROCESS_MODE_INHERIT + current_state._state_enter() + + +func set_direction(value: Vector2) -> void: + current_direction = value + Game.current_direction = value diff --git a/player/player.gd.uid b/player/player.gd.uid new file mode 100644 index 0000000..1e3d033 --- /dev/null +++ b/player/player.gd.uid @@ -0,0 +1 @@ +uid://dl3t07nx8ts2a diff --git a/player/player.tscn b/player/player.tscn new file mode 100644 index 0000000..e956bad --- /dev/null +++ b/player/player.tscn @@ -0,0 +1,241 @@ +[gd_scene load_steps=28 format=3 uid="uid://lpmvfkid4uqc"] + +[ext_resource type="Script" uid="uid://dl3t07nx8ts2a" path="res://player/player.gd" id="1_rkbax"] +[ext_resource type="Texture2D" uid="uid://c1dljohon2jfp" path="res://icon.svg" id="2_qjkh3"] +[ext_resource type="Texture2D" uid="uid://c5tjx8m8m7xv1" path="res://player/assets/sprites.png" id="2_rkbax"] +[ext_resource type="Script" uid="uid://bo75eq57ifvga" path="res://player/state_idle.gd" id="3_g1dw6"] +[ext_resource type="Script" uid="uid://btr1v8motp2lb" path="res://player/state_moving.gd" id="4_yw30f"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_g1dw6"] +atlas = ExtResource("2_rkbax") +region = Rect2(0, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_tqiix"] +atlas = ExtResource("2_rkbax") +region = Rect2(0, 48, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ebec5"] +atlas = ExtResource("2_rkbax") +region = Rect2(0, 32, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_rkbax"] +atlas = ExtResource("2_rkbax") +region = Rect2(0, 16, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_yw30f"] +atlas = ExtResource("2_rkbax") +region = Rect2(16, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_qjkh3"] +atlas = ExtResource("2_rkbax") +region = Rect2(0, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_g6k8r"] +atlas = ExtResource("2_rkbax") +region = Rect2(32, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_boad6"] +atlas = ExtResource("2_rkbax") +region = Rect2(0, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_e7oew"] +atlas = ExtResource("2_rkbax") +region = Rect2(16, 48, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_c35mf"] +atlas = ExtResource("2_rkbax") +region = Rect2(0, 48, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_65viv"] +atlas = ExtResource("2_rkbax") +region = Rect2(32, 48, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_x7c3f"] +atlas = ExtResource("2_rkbax") +region = Rect2(0, 48, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_yllr7"] +atlas = ExtResource("2_rkbax") +region = Rect2(16, 32, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_kb6p2"] +atlas = ExtResource("2_rkbax") +region = Rect2(0, 32, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_wodsf"] +atlas = ExtResource("2_rkbax") +region = Rect2(32, 32, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_32hag"] +atlas = ExtResource("2_rkbax") +region = Rect2(0, 32, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_rgyib"] +atlas = ExtResource("2_rkbax") +region = Rect2(16, 16, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_hg6s5"] +atlas = ExtResource("2_rkbax") +region = Rect2(0, 16, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_8t03j"] +atlas = ExtResource("2_rkbax") +region = Rect2(32, 16, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_2ieo8"] +atlas = ExtResource("2_rkbax") +region = Rect2(0, 16, 16, 16) + +[sub_resource type="SpriteFrames" id="SpriteFrames_yd4wl"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_g1dw6") +}], +"loop": true, +"name": &"idle_down", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_tqiix") +}], +"loop": true, +"name": &"idle_left", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_ebec5") +}], +"loop": true, +"name": &"idle_right", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_rkbax") +}], +"loop": true, +"name": &"idle_up", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_yw30f") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_qjkh3") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_g6k8r") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_boad6") +}], +"loop": true, +"name": &"walk_down", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_e7oew") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_c35mf") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_65viv") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_x7c3f") +}], +"loop": true, +"name": &"walk_left", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_yllr7") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_kb6p2") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_wodsf") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_32hag") +}], +"loop": true, +"name": &"walk_right", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_rgyib") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_hg6s5") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_8t03j") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_2ieo8") +}], +"loop": true, +"name": &"walk_up", +"speed": 5.0 +}] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_rkbax"] +size = Vector2(14, 14) + +[node name="Player" type="CharacterBody2D" groups=["player"]] +script = ExtResource("1_rkbax") + +[node name="Shadow" type="Sprite2D" parent="."] +position = Vector2(-4, 5) +scale = Vector2(0.0625, 0.0234375) +texture = ExtResource("2_qjkh3") +centered = false + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] +sprite_frames = SubResource("SpriteFrames_yd4wl") +animation = &"idle_down" +centered = false +offset = Vector2(-8, -8) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("RectangleShape2D_rkbax") + +[node name="RayCastUp" type="RayCast2D" parent="."] +target_position = Vector2(0, -23) +collision_mask = 2 + +[node name="RayCastDown" type="RayCast2D" parent="."] +target_position = Vector2(0, 23) +collision_mask = 2 + +[node name="RayCastLeft" type="RayCast2D" parent="."] +target_position = Vector2(-23, 0) +collision_mask = 2 + +[node name="RayCastRight" type="RayCast2D" parent="."] +target_position = Vector2(23, 0) +collision_mask = 2 + +[node name="States" type="Node2D" parent="."] + +[node name="StateIdle" type="Node2D" parent="States" node_paths=PackedStringArray("player")] +unique_name_in_owner = true +process_mode = 4 +script = ExtResource("3_g1dw6") +player = NodePath("../..") + +[node name="StateMoving" type="Node2D" parent="States" node_paths=PackedStringArray("player")] +unique_name_in_owner = true +process_mode = 4 +script = ExtResource("4_yw30f") +player = NodePath("../..") diff --git a/player/player_state.gd b/player/player_state.gd new file mode 100644 index 0000000..ccbca65 --- /dev/null +++ b/player/player_state.gd @@ -0,0 +1,12 @@ +class_name PlayerState +extends Node2D + + +@export var player: Player + + +func _state_enter() -> void: + pass + +func _state_exit() -> void: + pass diff --git a/player/player_state.gd.uid b/player/player_state.gd.uid new file mode 100644 index 0000000..0ce67b7 --- /dev/null +++ b/player/player_state.gd.uid @@ -0,0 +1 @@ +uid://bdflh40t2hmjl diff --git a/player/state_idle.gd b/player/state_idle.gd new file mode 100644 index 0000000..78f7af5 --- /dev/null +++ b/player/state_idle.gd @@ -0,0 +1,30 @@ +class_name PlayerStateIdle +extends PlayerState + + +func _state_enter() -> void: + get_viewport().get_camera_2d().global_position = player.global_position + + if player.current_direction == Vector2.UP: + player.sprite.play("idle_up") + elif player.current_direction == Vector2.DOWN: + player.sprite.play("idle_down") + elif player.current_direction == Vector2.LEFT: + player.sprite.play("idle_left") + elif player.current_direction == Vector2.RIGHT: + player.sprite.play("idle_right") + + +func _physics_process(_delta: float) -> void: + if Input.is_action_just_pressed("ui_up"): + player.current_direction = Vector2.UP + player.set_state(player.state_moving) + elif Input.is_action_just_pressed("ui_down"): + player.current_direction = Vector2.DOWN + player.set_state(player.state_moving) + elif Input.is_action_just_pressed("ui_left"): + player.current_direction = Vector2.LEFT + player.set_state(player.state_moving) + elif Input.is_action_just_pressed("ui_right"): + player.current_direction = Vector2.RIGHT + player.set_state(player.state_moving) diff --git a/player/state_idle.gd.uid b/player/state_idle.gd.uid new file mode 100644 index 0000000..17fe1df --- /dev/null +++ b/player/state_idle.gd.uid @@ -0,0 +1 @@ +uid://bo75eq57ifvga diff --git a/player/state_moving.gd b/player/state_moving.gd new file mode 100644 index 0000000..0be777f --- /dev/null +++ b/player/state_moving.gd @@ -0,0 +1,52 @@ +class_name PlayerStateMoving +extends PlayerState + + +var is_moving := false +var target_position: Vector2 + + +func _state_enter() -> void: + is_moving = false + + +func _state_exit() -> void: + is_moving = false + + +func _physics_process(delta: float) -> void: + var map: TileMapLayer = Game.world.get_current_map().get_node("TileMapLayer") + + if not is_moving: + if Input.is_action_pressed("ui_up") and not player.ray_cast_up.is_colliding(): + is_moving = true + player.current_direction = Vector2.UP + player.sprite.play("walk_up") + elif Input.is_action_pressed("ui_down") and not player.ray_cast_down.is_colliding(): + is_moving = true + player.current_direction = Vector2.DOWN + player.sprite.play("walk_down") + elif Input.is_action_pressed("ui_left") and not player.ray_cast_left.is_colliding(): + is_moving = true + player.current_direction = Vector2.LEFT + player.sprite.play("walk_left") + elif Input.is_action_pressed("ui_right") and not player.ray_cast_right.is_colliding(): + is_moving = true + player.current_direction = Vector2.RIGHT + player.sprite.play("walk_right") + else: + player.set_state(player.state_idle) + + var target_tile := map.local_to_map(player.global_position) + Vector2i(player.current_direction) + target_position = map.map_to_local(target_tile) + + if is_moving: + player.global_position = player.global_position.move_toward( + target_position, + delta * player.current_speed + ) + + get_viewport().get_camera_2d().global_position = player.global_position + + if player.global_position == target_position: + is_moving = false diff --git a/player/state_moving.gd.uid b/player/state_moving.gd.uid new file mode 100644 index 0000000..f05ec9a --- /dev/null +++ b/player/state_moving.gd.uid @@ -0,0 +1 @@ +uid://btr1v8motp2lb |