First player iteration and functional grave puzzle

master
Wynd 2024-09-15 23:25:12 +03:00
parent 0df47e378d
commit 169fec61af
10 changed files with 186 additions and 18 deletions

View File

@ -0,0 +1,40 @@
extends CharacterBody2D
@export var speed: float = 400
@onready var raycast: RayCast2D = $RayCast2D
func _ready():
pass
func _process_movement():
velocity = Vector2.ZERO
if Input.is_action_pressed("move_up"):
velocity.y -= 1
elif Input.is_action_pressed("move_right"):
velocity.x += 1
elif Input.is_action_pressed("move_down"):
velocity.y += 1
elif Input.is_action_pressed("move_left"):
velocity.x -= 1
if velocity.length() > 0:
velocity = velocity.normalized() * speed
raycast.target_position = velocity.normalized() * 8
move_and_slide()
func _try_interact():
if Input.is_action_just_pressed("attack") and raycast.is_colliding():
var collision = raycast.get_collider()
if collision is PuzzleElement:
(collision as PuzzleElement).interact()
pass
pass
func _process(delta):
_try_interact()
pass
func _physics_process(delta):
_process_movement()

View File

@ -1,6 +1,71 @@
[gd_scene format=3 uid="uid://dpn82ibpmpb6u"]
[gd_scene load_steps=7 format=3 uid="uid://dpn82ibpmpb6u"]
[node name="Player" type="Node2D"]
position = Vector2(240, 72)
[ext_resource type="Script" path="res://entities/player/player.gd" id="1_jrd75"]
[ext_resource type="Texture2D" uid="uid://dxkxa6e6ue1b6" path="res://entities/assets/bat.png" id="1_qfnf0"]
[sub_resource type="Animation" id="Animation_ve5nf"]
resource_name = "RESET"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [0]
}
[sub_resource type="Animation" id="Animation_ab576"]
resource_name = "move"
length = 0.5
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.25),
"transitions": PackedFloat32Array(1, 1),
"update": 1,
"values": [0, 1]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_dx4e7"]
_data = {
"RESET": SubResource("Animation_ve5nf"),
"move": SubResource("Animation_ab576")
}
[sub_resource type="RectangleShape2D" id="RectangleShape2D_l7fhd"]
size = Vector2(8, 8)
[node name="Player" type="CharacterBody2D"]
z_index = 1
collision_mask = 3
script = ExtResource("1_jrd75")
speed = 40.0
[node name="Camera2D" type="Camera2D" parent="."]
[node name="Sprite2D" type="Sprite2D" parent="."]
texture_filter = 1
texture = ExtResource("1_qfnf0")
hframes = 2
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_dx4e7")
}
autoplay = "move"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_l7fhd")
[node name="RayCast2D" type="RayCast2D" parent="."]
target_position = Vector2(0, 8)
collision_mask = 2

View File

@ -20,6 +20,39 @@ window/size/viewport_width=160
window/size/viewport_height=144
window/stretch/mode="canvas_items"
[input]
move_up={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"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,"location":0,"echo":false,"script":null)
]
}
move_down={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"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,"location":0,"echo":false,"script":null)
]
}
move_left={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"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,"location":0,"echo":false,"script":null)
]
}
move_right={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"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,"location":0,"echo":false,"script":null)
]
}
attack={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":90,"key_label":0,"unicode":122,"location":0,"echo":false,"script":null)
]
}
jump={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
]
}
[rendering]
renderer/rendering_method="gl_compatibility"

View File

@ -1,11 +1,13 @@
class_name Grave
extends Node2D
extends PuzzleElement
@export var pair: Grave
@export var jingle: AudioStream
@export var id: int
@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var audio_player: AudioStreamPlayer2D = $AudioStreamPlayer2D
@onready var manager: GravePuzzle = $"../"
@export var test = false
var is_singing = false
@ -26,7 +28,10 @@ func _process(delta):
func _physics_process(delta):
pass
func interact():
manager.activate_grave(self)
func sing():
if is_finished:
return

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=3 uid="uid://chmxabjea27ay"]
[gd_scene load_steps=9 format=3 uid="uid://chmxabjea27ay"]
[ext_resource type="Script" path="res://puzzles/grave/grave.gd" id="1_ooabc"]
[ext_resource type="Texture2D" uid="uid://boii66my2eiqr" path="res://puzzles/assets/grave.png" id="1_wcgrd"]
@ -59,7 +59,11 @@ _data = {
[sub_resource type="AtlasTexture" id="AtlasTexture_h3pxl"]
atlas = ExtResource("1_wcgrd")
[node name="Grave" type="Node2D"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_smj88"]
size = Vector2(8, 8)
[node name="Grave" type="StaticBody2D"]
collision_layer = 2
script = ExtResource("1_ooabc")
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
@ -77,4 +81,7 @@ vframes = 2
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_smj88")
[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_animation_player_animation_finished"]

View File

@ -4,6 +4,8 @@ extends Puzzle
@export var graves: Array[Grave] = []
var _last_grave: Grave
func _process(delta):
var is_finished = true
for grave in graves:
@ -13,3 +15,12 @@ func _process(delta):
if is_finished:
complete()
func activate_grave(grave: Grave):
if _last_grave == grave.pair:
grave.complete()
grave.pair.complete()
return
grave.sing()
_last_grave = grave

View File

@ -0,0 +1,5 @@
class_name PuzzleElement
extends Node
func interact():
pass

View File

@ -3,7 +3,6 @@ extends PuzzleManager
#@onready var demo_puzzle = $DemoGravePuzzle1
@onready var next_room_fog = $NextRoomFog
func _process(delta):
if is_room_finished():
if next_room_fog != null:

View File

@ -6,15 +6,19 @@
texture = ExtResource("1_al8fb")
texture_region_size = Vector2i(8, 8)
0:0/0 = 0
0:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-4, -4, 4, -4, 4, 4, -4, 4)
1:0/0 = 0
4:0/0 = 0
5:0/0 = 0
6:0/0 = 0
6:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-4, -4, 4, -4, 4, 4, -4, 4)
4:1/0 = 0
5:1/0 = 0
6:1/0 = 0
6:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(-4, -4, 4, -4, 4, 4, -4, 4)
7:1/0 = 0
7:0/0 = 0
7:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-4, -4, 4, -4, 4, 4, -4, 4)
1:1/0 = 0
0:1/animation_columns = 1
0:1/animation_speed = 2.0
@ -33,4 +37,5 @@ texture_region_size = Vector2i(8, 8)
[resource]
tile_size = Vector2i(8, 8)
physics_layer_0/collision_layer = 1
sources/0 = SubResource("TileSetAtlasSource_m1u1u")

View File

@ -19,6 +19,7 @@ tile_map_data = PackedByteArray("AAAAAAAAAAAGAAAAAAABAAEAAAAFAAAAAAACAAIAAAAFAAA
tile_set = ExtResource("1_maeo5")
[node name="Player" parent="." instance=ExtResource("2_w5xov")]
position = Vector2(244, 68)
[node name="Box" parent="." instance=ExtResource("3_jiwuy")]
position = Vector2(204, 100)
@ -28,41 +29,38 @@ position = Vector2(292, 116)
[node name="RoomManager" parent="." node_paths=PackedStringArray("mandatory_puzzles") instance=ExtResource("7_8fiyl")]
script = ExtResource("8_53qtw")
mandatory_puzzles = [NodePath("DemoGravePuzzle1"), NodePath("DemoGravePuzzle2")]
mandatory_puzzles = [NodePath("DemoGravePuzzle1")]
[node name="DemoGravePuzzle1" type="Node2D" parent="RoomManager" node_paths=PackedStringArray("graves")]
script = ExtResource("8_sr3y5")
graves = [NodePath("Grave"), NodePath("Grave2")]
graves = [NodePath("Grave"), NodePath("Grave2"), NodePath("Grave3"), NodePath("Grave4")]
[node name="Grave" parent="RoomManager/DemoGravePuzzle1" node_paths=PackedStringArray("pair") instance=ExtResource("2_fe1sr")]
texture_filter = 1
position = Vector2(228, 20)
pair = NodePath("../Grave2")
jingle = ExtResource("3_v8h4p")
test = true
[node name="Grave2" parent="RoomManager/DemoGravePuzzle1" node_paths=PackedStringArray("pair") instance=ExtResource("2_fe1sr")]
texture_filter = 1
position = Vector2(196, 36)
pair = NodePath("../Grave")
jingle = ExtResource("3_v8h4p")
id = 1
[node name="DemoGravePuzzle2" type="Node2D" parent="RoomManager" node_paths=PackedStringArray("graves")]
script = ExtResource("8_sr3y5")
graves = [NodePath("Grave3"), NodePath("Grave4")]
[node name="Grave3" parent="RoomManager/DemoGravePuzzle2" node_paths=PackedStringArray("pair") instance=ExtResource("2_fe1sr")]
[node name="Grave3" parent="RoomManager/DemoGravePuzzle1" node_paths=PackedStringArray("pair") instance=ExtResource("2_fe1sr")]
texture_filter = 1
position = Vector2(244, 28)
pair = NodePath("../Grave4")
jingle = ExtResource("4_xmwgp")
id = 2
[node name="Grave4" parent="RoomManager/DemoGravePuzzle2" node_paths=PackedStringArray("pair") instance=ExtResource("2_fe1sr")]
[node name="Grave4" parent="RoomManager/DemoGravePuzzle1" node_paths=PackedStringArray("pair") instance=ExtResource("2_fe1sr")]
texture_filter = 1
position = Vector2(244, 44)
pair = NodePath("../Grave3")
jingle = ExtResource("4_xmwgp")
test = true
id = 3
last_used_tick = 240
[node name="NextRoomFog" type="TileMapLayer" parent="RoomManager"]