Conveyor belts

This commit is contained in:
Marco 2025-03-14 15:13:00 +01:00
commit 362ea29852
16 changed files with 371 additions and 15 deletions

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=58 format=3 uid="uid://c4pr2707hbeph"]
[gd_scene load_steps=60 format=3 uid="uid://c4pr2707hbeph"]
[ext_resource type="Script" uid="uid://d2ubk5gucny6s" path="res://Scripts/Components/FSM/PlayerFSMProxy.cs" id="1_g3wua"]
[ext_resource type="Script" uid="uid://bw2hakslndaxm" path="res://Scripts/Components/FSM/PlayerStateMachine.cs" id="1_mpmil"]
@ -31,6 +31,7 @@
[ext_resource type="Script" uid="uid://cem7a1agaqtrt" path="res://Scenes/InteractionController.cs" id="27_vwjki"]
[ext_resource type="Script" uid="uid://d0bebi2vn171l" path="res://Scripts/Components/FSM/Player/PlayerFSMItemUseModule.cs" id="29_m323t"]
[ext_resource type="Texture2D" uid="uid://ddwhrlrgj6i00" path="res://Sprites/Actors/Cirno.png" id="30_li0ug"]
[ext_resource type="Script" uid="uid://camgjo4302qmq" path="res://Scripts/Components/Actors/ConveyorBeltMover.cs" id="32_4f2wn"]
[sub_resource type="CircleShape2D" id="CircleShape2D_b3hxm"]
radius = 5.0
@ -224,10 +225,14 @@ _data = {
&"Walk_Up": SubResource("Animation_v2m0j")
}
[sub_resource type="CircleShape2D" id="CircleShape2D_fnw0c"]
radius = 2.05679
[node name="FSMPlayer" type="CharacterBody2D" node_paths=PackedStringArray("PlayerFSM", "InteractionController")]
process_mode = 1
collision_layer = 2
collision_mask = 97
platform_floor_layers = 4294967294
platform_wall_layers = 97
script = ExtResource("1_g3wua")
PlayerFSM = NodePath("StateMachine")
@ -251,7 +256,7 @@ _inputProvider = NodePath("../../InputProvider")
_damageReceiver = NodePath("../../DamageReceiver")
_activationProvider = NodePath("../../InteractionProvider")
_interactionController = NodePath("../../InteractionController")
_moduleNodes = [NodePath("../../InteractionController"), NodePath("../../ItemUser")]
_moduleNodes = [NodePath("../../InteractionController"), NodePath("../../ItemUser"), NodePath("../../ConveyorBeltMover")]
[node name="Cutscene" type="Node2D" parent="StateMachine" node_paths=PackedStringArray("_animationProvider")]
script = ExtResource("4_22ff8")
@ -285,10 +290,8 @@ shape = SubResource("CircleShape2D_b3hxm")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
material = ExtResource("4_5qlss")
sprite_frames = ExtResource("4_s0ir4")
animation = &"Drowning"
animation = &"idle"
autoplay = "idle"
frame = 15
frame_progress = 0.860925
[node name="WeaponProvider" type="Node2D" parent="."]
script = ExtResource("5_gp3hw")
@ -411,6 +414,17 @@ libraries = {
&"": SubResource("AnimationLibrary_nfrn8")
}
[node name="ConveyorBeltMover" type="Area2D" parent="."]
collision_layer = 2
collision_mask = 512
script = ExtResource("32_4f2wn")
[node name="CollisionShape2D" type="CollisionShape2D" parent="ConveyorBeltMover"]
position = Vector2(0, 6.48)
shape = SubResource("CircleShape2D_fnw0c")
[connection signal="area_entered" from="DamageReceiver" to="DamageReceiver" method="_on_damage_hitbox_area_entered"]
[connection signal="area_entered" from="InteractionProvider" to="InteractionProvider" method="_on_interaction_controller_area_entered"]
[connection signal="area_exited" from="InteractionProvider" to="InteractionProvider" method="_on_interaction_controller_area_exited"]
[connection signal="body_entered" from="ConveyorBeltMover" to="ConveyorBeltMover" method="OnBodyEntered"]
[connection signal="body_exited" from="ConveyorBeltMover" to="ConveyorBeltMover" method="OnBodyExited"]

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=20 format=3 uid="uid://5xajclchk3my"]
[gd_scene load_steps=22 format=3 uid="uid://5xajclchk3my"]
[ext_resource type="Script" uid="uid://dql102fvubniv" path="res://Scripts/MainMenu.cs" id="1_702nk"]
[ext_resource type="PackedScene" uid="uid://c84shrj84g4t2" path="res://Scenes/HUD/MusicRoom.tscn" id="2_if7li"]
@ -14,10 +14,15 @@
[ext_resource type="PackedScene" uid="uid://b3tyacxxw88lx" path="res://Scenes/Utils/StreamPlayerWithName.tscn" id="8_koqhg"]
[ext_resource type="PackedScene" uid="uid://bmj8t4pou6608" path="res://Scenes/HUD/TitleCrystal.tscn" id="8_riqfo"]
[ext_resource type="PackedScene" uid="uid://bemu3l6b1e84y" path="res://Scenes/HUD/debug_menu.tscn" id="9_nwlsr"]
[ext_resource type="Texture2D" uid="uid://p242xo3qxwve" path="res://Sprites/UI/Crystal3.png" id="9_riqfo"]
[ext_resource type="Texture2D" uid="uid://cv1fmski5dvhk" path="res://Sprites/Briefing/Intro/robot pov/l1_robot pov1.png" id="12_7467j"]
[ext_resource type="Resource" uid="uid://byo74ews118nl" path="res://Resources/Music/No_Reason.tres" id="13_fh7cp"]
[ext_resource type="FontFile" uid="uid://cyk27h5aox1n7" path="res://fonts/sector_034.ttf" id="14_yxkem"]
[sub_resource type="AtlasTexture" id="AtlasTexture_aoyqx"]
atlas = ExtResource("9_riqfo")
region = Rect2(320, 0, 32, 16)
[sub_resource type="Theme" id="Theme_c7h4d"]
[sub_resource type="LabelSettings" id="LabelSettings_htmja"]
@ -61,6 +66,7 @@ offset_top = 44.855
offset_right = 192.36
offset_bottom = 60.855
rotation = 3.14159
texture = SubResource("AtlasTexture_aoyqx")
[node name="MarginContainer" type="MarginContainer" parent="."]
anchors_preset = 15

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,103 @@
[gd_scene load_steps=11 format=3 uid="uid://bc4ffe8oscm6y"]
[ext_resource type="Texture2D" uid="uid://yi2nv5x10r2e" path="res://Sprites/Props/Conveyor_Horizontal.png" id="1_hb8qr"]
[sub_resource type="AtlasTexture" id="AtlasTexture_ysm5s"]
atlas = ExtResource("1_hb8qr")
region = Rect2(0, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_07rsj"]
atlas = ExtResource("1_hb8qr")
region = Rect2(16, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_mnaio"]
atlas = ExtResource("1_hb8qr")
region = Rect2(32, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_btv6n"]
atlas = ExtResource("1_hb8qr")
region = Rect2(48, 0, 16, 16)
[sub_resource type="SpriteFrames" id="SpriteFrames_g7o5d"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_ysm5s")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_07rsj")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_mnaio")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_btv6n")
}],
"loop": true,
"name": &"default",
"speed": 5.0
}]
[sub_resource type="Animation" id="Animation_hb8qr"]
resource_name = "Active"
length = 0.8
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.2, 0.4, 0.6),
"transitions": PackedFloat32Array(1, 1, 1, 1),
"update": 1,
"values": [0, 1, 2, 3]
}
[sub_resource type="Animation" id="Animation_ysm5s"]
length = 0.001
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="AnimationLibrary" id="AnimationLibrary_07rsj"]
_data = {
&"Active": SubResource("Animation_hb8qr"),
&"RESET": SubResource("Animation_ysm5s")
}
[sub_resource type="RectangleShape2D" id="RectangleShape2D_hb8qr"]
size = Vector2(16, 16)
[node name="ConveyorHorizontal" type="Area2D"]
metadata/_edit_group_ = true
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
visible = false
sprite_frames = SubResource("SpriteFrames_g7o5d")
autoplay = "default"
frame = 2
frame_progress = 0.48232
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("1_hb8qr")
hframes = 4
region_rect = Rect2(0, 0, 16, 16)
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
&"": SubResource("AnimationLibrary_07rsj")
}
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_hb8qr")

View file

@ -0,0 +1,79 @@
using Cirno.Scripts.Components.FSM;
using Godot;
namespace Cirno.Scripts.Components.Actors;
public partial class ConveyorBeltMover : PlayerArea2DModule
{
public bool Enabled { get; private set; } = false;
private Vector2 _velocity = Vector2.Zero;
private IStateMachine<PlayerState, CharacterBody2D> _machine;
public override void Init(IStateMachine<PlayerState, CharacterBody2D> machine)
{
base.Init(machine);
_machine = machine;
}
private void OnBodyEntered(Node2D body)
{
if (!Enabled) return;
if (body is not TileMapLayer tileMap) return;
GD.Print($"Entered {body.Name}");
// How do I get the actual coords of the cell at the collision point??
var localTilemapCoords = tileMap.ToLocal(this.GlobalPosition);
GD.Print($"Local tilemap coords: {localTilemapCoords}");
var coords = tileMap.LocalToMap(localTilemapCoords);
GD.Print($"Tilemap coords: {coords}");
var td = tileMap.GetCellTileData(coords);
if (td is null) return;
//tileMap.TileSet.physics
var vel = td.GetConstantLinearVelocity(2);
GD.Print($"velocity: {vel}");
var layerData = td.GetCustomDataByLayerId(0).As<Vector2>();
// I can do whatever I want with this
GD.Print($"Layer Data: {layerData}");
_velocity = vel;
}
private void OnBodyExited(Node2D body)
{
if (body is not TileMapLayer tileMap) return;
GD.Print($"Exited {body.Name}");
_velocity = Vector2.Zero;
}
public override void EnterState(PlayerState state)
{
Enabled = true;
GD.Print("Enabled conveyor");
}
public override void ExitState(PlayerState state)
{
Enabled = false;
GD.Print("Disabled conveyor");
}
public override void Process(double delta)
{
}
public override void PhysicsProcess(double delta)
{
if (Enabled && _velocity.Length() != 0)
{
CharacterBody.Velocity += _velocity;
//GD.Print($"Applying velocity {_velocity} {CharacterBody.Velocity} ");
}
}
}

View file

@ -0,0 +1 @@
uid://camgjo4302qmq

View file

@ -56,11 +56,19 @@ public abstract partial class BaseState<TKey, TType> : Node2D, IState<TKey, TTyp
public virtual void ProcessState(double delta)
{
_modules.ForEach(module => module.Process(delta));
foreach (var module in _modules)
{
module.Process(delta);
}
//_modules.ForEach(module => module.Process(delta));
}
public virtual void PhysicsProcessState(double delta)
{
_modules.ForEach(module => module.PhysicsProcess(delta));
foreach (var module in _modules)
{
module.PhysicsProcess(delta);
}
//_modules.ForEach(module => module.PhysicsProcess(delta));
}
}

View file

@ -103,13 +103,23 @@ public partial class Active : PlayerStateBase
public override void PhysicsProcessState(double delta)
{
MainObject.Velocity = _movementDirection * MovementSpeed;
// Reset at start of frame
MainObject.Velocity = Vector2.Zero;
// Process modules
base.PhysicsProcessState(delta);
MainObject.Velocity += _movementDirection * MovementSpeed;
MainObject.MoveAndSlide();
}
public override void ProcessState(double delta)
{
base.ProcessState(delta);
_movementDirection = _inputProvider.GetMovementInput().Normalized();
_isStrafing = _inputProvider.GetStrafePressed();
@ -152,6 +162,8 @@ public partial class Active : PlayerStateBase
//CallDeferred(MethodName.PauseDeferred);
PauseDeferred();
}
}
private void PauseDeferred()

BIN
Sprites/Props/Conveyor_Horizontal.aseprite (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Sprites/Props/Conveyor_Horizontal.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://yi2nv5x10r2e"
path="res://.godot/imported/Conveyor_Horizontal.png-f2402b0f14daf2a9a2cc94da9f77b145.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/Props/Conveyor_Horizontal.png"
dest_files=["res://.godot/imported/Conveyor_Horizontal.png-f2402b0f14daf2a9a2cc94da9f77b145.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

BIN
Tilesets/Conveyors.aseprite (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Tilesets/Conveyors.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c741ej5hhmpv4"
path="res://.godot/imported/Conveyors.png-301aad4bb1b642f4825b989b65691457.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Tilesets/Conveyors.png"
dest_files=["res://.godot/imported/Conveyors.png-301aad4bb1b642f4825b989b65691457.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

View file

@ -1,4 +1,4 @@
[gd_resource type="TileSet" load_steps=56 format=3 uid="uid://6k28roiljylj"]
[gd_resource type="TileSet" load_steps=58 format=3 uid="uid://6k28roiljylj"]
[ext_resource type="Texture2D" uid="uid://tphqodqyere1" path="res://Tilesets/factory.png" id="1_70kxh"]
[ext_resource type="PackedScene" uid="uid://bj28qiai2x2ar" path="res://Scenes/Props/Barrel.tscn" id="2_cxg4b"]
@ -20,6 +20,7 @@
[ext_resource type="PackedScene" uid="uid://e80xujqyjoh" path="res://Scenes/Props/Box_Vertical.tscn" id="10_hg2bp"]
[ext_resource type="Texture2D" uid="uid://df8t3kan5qgjb" path="res://Tilesets/Space.png" id="12_fb37q"]
[ext_resource type="Texture2D" uid="uid://v310x6wx801b" path="res://Tilesets/Beams2.png" id="19_hupu0"]
[ext_resource type="Texture2D" uid="uid://c741ej5hhmpv4" path="res://Tilesets/Conveyors.png" id="21_u4jco"]
[sub_resource type="NavigationPolygon" id="NavigationPolygon_l8pdw"]
vertices = PackedVector2Array(8, 8, -8, 8, -8, -8, 8, -8)
@ -1198,11 +1199,49 @@ texture = ExtResource("19_hupu0")
2:2/0 = 0
1:3/0 = 0
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_y1d7q"]
texture = ExtResource("21_u4jco")
0:0/animation_columns = 4
0:0/animation_frame_0/duration = 1.0
0:0/animation_frame_1/duration = 1.0
0:0/animation_frame_2/duration = 1.0
0:0/animation_frame_3/duration = 1.0
0:0/0 = 0
0:0/0/physics_layer_2/linear_velocity = Vector2(40, 0)
0:0/0/physics_layer_2/polygon_0/points = PackedVector2Array(-6, -6, 6, -6, 6, 6, -6, 6)
0:0/0/custom_data_0 = Vector2(20, 0)
0:1/animation_columns = 4
0:1/animation_frame_0/duration = 1.0
0:1/animation_frame_1/duration = 1.0
0:1/animation_frame_2/duration = 1.0
0:1/animation_frame_3/duration = 1.0
0:1/0 = 0
0:1/0/physics_layer_2/linear_velocity = Vector2(-40, 0)
0:1/0/physics_layer_2/polygon_0/points = PackedVector2Array(-6, -6, 6, -6, 6, 6, -6, 6)
0:2/animation_columns = 4
0:2/animation_frame_0/duration = 1.0
0:2/animation_frame_1/duration = 1.0
0:2/animation_frame_2/duration = 1.0
0:2/animation_frame_3/duration = 1.0
0:2/0 = 0
0:2/0/physics_layer_2/linear_velocity = Vector2(0, -40)
0:2/0/physics_layer_2/polygon_0/points = PackedVector2Array(-6, -6, 6, -6, 6, 6, -6, 6)
0:3/animation_columns = 4
0:3/animation_frame_0/duration = 1.0
0:3/animation_frame_1/duration = 1.0
0:3/animation_frame_2/duration = 1.0
0:3/animation_frame_3/duration = 1.0
0:3/0 = 0
0:3/0/physics_layer_2/linear_velocity = Vector2(0, 40)
0:3/0/physics_layer_2/polygon_0/points = PackedVector2Array(-6, -6, 6, -6, 6, 6, -6, 6)
[resource]
physics_layer_0/collision_layer = 1
physics_layer_0/collision_mask = 30
physics_layer_1/collision_layer = 32
physics_layer_1/collision_mask = 18
physics_layer_2/collision_layer = 512
physics_layer_2/collision_mask = 2
terrain_set_0/mode = 0
terrain_set_0/terrain_0/name = "Fence"
terrain_set_0/terrain_0/color = Color(0.5, 0.34375, 0.25, 1)
@ -1215,7 +1254,10 @@ terrain_set_0/terrain_3/color = Color(0.375, 0.5, 0.25, 1)
terrain_set_0/terrain_4/name = "SimpleFence"
terrain_set_0/terrain_4/color = Color(0.28125, 0.5, 0.25, 1)
navigation_layer_0/layers = 1
custom_data_layer_0/name = "Conveyor"
custom_data_layer_0/type = 5
sources/0 = SubResource("TileSetAtlasSource_jwf4b")
sources/1 = SubResource("TileSetScenesCollectionSource_qg3vu")
sources/2 = SubResource("TileSetAtlasSource_wgdjv")
sources/3 = SubResource("TileSetAtlasSource_7u0cp")
sources/4 = SubResource("TileSetAtlasSource_y1d7q")

View file

@ -293,6 +293,7 @@ inventory={
2d_physics/layer_7="solid-actors"
2d_physics/layer_8="EnemyBullets"
2d_physics/layer_9="Acid"
2d_physics/layer_10="Conveyor"
[physics]