Teleport works, item pickup is broken

This commit is contained in:
2024-09-07 14:00:40 -07:00
parent 4c2731bc7b
commit fbaf698852
28 changed files with 314 additions and 229 deletions

View File

@@ -4,6 +4,8 @@ using Chickensoft.AutoInject;
using Chickensoft.GodotNodeInterfaces;
using Chickensoft.Introspection;
using Godot;
using System.Collections.Generic;
using System.Linq;
public interface IGame : IProvide<IGameRepo>, INode3D;
@@ -14,6 +16,8 @@ public partial class Game : Node3D, IGame
IGameRepo IProvide<IGameRepo>.Value() => GameRepo;
public IInstantiator Instantiator { get; set; } = default!;
public IGameLogic GameLogic { get; set; } = default!;
public IGameRepo GameRepo { get; set; } = default!;
@@ -28,21 +32,57 @@ public partial class Game : Node3D, IGame
[Node] public NavigationRegion3D NavigationRegion { get; set; } = default!;
[Node] public Area3D Teleport { get; set; } = default!;
[Node] public IDungeonFloor Overworld { get; set; } = default!;
[Node] public IDungeonFloor Floor1 { get; set; } = default!;
[Node] public IDungeonFloor Floor2 { get; set; } = default!;
[Node] public IDungeonFloor Floor3 { get; set; } = default!;
[Node] public AnimationPlayer AnimationPlayer { get; set; } = default!;
private List<IDungeonFloor> Floors;
private int _currentFloor = -1;
public void Setup()
{
GameRepo = new GameRepo();
GameLogic = new GameLogic();
GameLogic.Set(GameRepo);
GameLogic.Set(AppRepo);
Instantiator = new Instantiator(GetTree());
Floors = new List<IDungeonFloor> { Overworld, Floor1, Floor2, Floor3 };
Teleport.BodyEntered += OnTeleportEntered;
}
private void OnTeleportEntered(Node3D body)
{
GameLogic.Input(new GameLogic.Input.LoadNextFloor());
}
public void OnResolved()
{
GameBinding = GameLogic.Bind();
GameBinding
.Handle((in GameLogic.Output.StartGame _) => { })
.Handle((in GameLogic.Output.SetPauseMode output) => { CallDeferred(nameof(SetPauseMode), output.IsPaused); })
.Handle((in GameLogic.Output.StartGame _) =>
{
})
.Handle((in GameLogic.Output.LoadNextFloor _) =>
{
SetPauseMode(true);
AnimationPlayer.Play("wait_and_load");
var currentFloor = Floors.ElementAt(_currentFloor);
currentFloor.CallDeferred(MethodName.QueueFree, []);
})
.Handle((in GameLogic.Output.SetPauseMode output) =>
{
CallDeferred(nameof(SetPauseMode), output.IsPaused);
})
.Handle((in GameLogic.Output.SetInventoryMode _) => { InventoryMenu.PopulateItems(_.Inventory); InventoryMenu.Show(); })
.Handle((in GameLogic.Output.HideInventory _) => { InventoryMenu.Hide(); InventoryMenu.ClearItems(); })
.Handle((in GameLogic.Output.ShowMiniMap _) => { MiniMap.Show(); })
@@ -51,10 +91,31 @@ public partial class Game : Node3D, IGame
GameLogic.Start();
GameLogic.Input(new GameLogic.Input.Initialize());
AnimationPlayer.AnimationStarted += AnimationPlayer_AnimationStarted;
AnimationPlayer.AnimationFinished += AnimationPlayer_AnimationFinished;
AnimationPlayer.Play("wait_and_load");
this.Provide();
}
private void AnimationPlayer_AnimationStarted(StringName animName)
{
SetPauseMode(true);
var newFloor = Floors.ElementAt(_currentFloor + 1);
newFloor.CallDeferred(nameof(newFloor.InitializeDungeon), []);
newFloor.Show();
}
private void AnimationPlayer_AnimationFinished(StringName animName)
{
var spawnPoints = GetTree().GetNodesInGroup("Exit").OfType<Marker3D>();
Teleport.GlobalPosition = spawnPoints.Last().GlobalPosition;
_currentFloor++;
SetPauseMode(false);
}
public override void _Process(double delta)
{
if (Input.IsActionJustPressed(GameInputs.Inventory))

View File

@@ -1,15 +1,72 @@
[gd_scene load_steps=8 format=3 uid="uid://33ek675mfb5n"]
[gd_scene load_steps=16 format=3 uid="uid://33ek675mfb5n"]
[ext_resource type="Script" path="res://src/game/Game.cs" id="1_ytcii"]
[ext_resource type="PackedScene" uid="uid://cfecvvav8kkp6" path="res://src/player/Player.tscn" id="3_kk6ly"]
[ext_resource type="PackedScene" uid="uid://dlj8qdg1c5048" path="res://src/inventory_menu/InventoryMenu.tscn" id="4_wk8gw"]
[ext_resource type="PackedScene" uid="uid://dvnc26rebk6o0" path="res://src/map/Overworld.tscn" id="5_4hqe8"]
[ext_resource type="PackedScene" uid="uid://u1e5ae7whhxg" path="res://src/map/dungeon/floors/Floor1.tscn" id="6_75lk5"]
[ext_resource type="PackedScene" uid="uid://bwbofurcvf3yh" path="res://src/minimap/Minimap.tscn" id="6_owlf4"]
[ext_resource type="PackedScene" uid="uid://b3r0r22kc67bl" path="res://src/map/dungeon/floors/Floor2.tscn" id="7_1sm5s"]
[ext_resource type="PackedScene" uid="uid://b40sstnic41dw" path="res://src/map/dungeon/floors/Floor3.tscn" id="8_87yk1"]
[ext_resource type="PackedScene" uid="uid://c3ek5i43cl0r5" path="res://src/map/Teleport.tscn" id="9_nwu7r"]
[sub_resource type="Environment" id="Environment_fke5g"]
[sub_resource type="NavigationMesh" id="NavigationMesh_xligp"]
[sub_resource type="Animation" id="Animation_wewlr"]
resource_name = "load"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("LoadScreen:color")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 1),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(0, 0.486275, 1, 1), Color(0, 0.486275, 1, 0)]
}
[sub_resource type="Animation" id="Animation_nc1gg"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("LoadScreen:color")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 1, 1, 0)]
}
[sub_resource type="Animation" id="Animation_ovny8"]
resource_name = "wait_and_load"
length = 3.0
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("LoadScreen:color")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 1.96667, 2.96667),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [Color(0, 0.486275, 1, 1), Color(0, 0.486275, 1, 1), Color(0, 0.486275, 1, 0)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_opfbx"]
_data = {
"RESET": SubResource("Animation_nc1gg"),
"load": SubResource("Animation_wewlr"),
"wait_and_load": SubResource("Animation_ovny8")
}
[node name="Game" type="Node3D"]
process_mode = 3
script = ExtResource("1_ytcii")
@@ -19,7 +76,7 @@ environment = SubResource("Environment_fke5g")
[node name="Player" parent="." instance=ExtResource("3_kk6ly")]
process_mode = 1
transform = Transform3D(0.0871905, 0, -0.996192, 0, 1, 0, 0.996192, 0, 0.0871905, -5.335, -4.70883, -0.527107)
transform = Transform3D(0.0871905, 0, -0.996192, 0, 1, 0, 0.996192, 0, 0.0871905, -11.0585, -2.7998, -6.0685)
MoveSpeed = 8.0
Acceleration = 4.0
@@ -42,4 +99,39 @@ unique_name_in_owner = true
navigation_mesh = SubResource("NavigationMesh_xligp")
[node name="Overworld" parent="." instance=ExtResource("5_4hqe8")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.510071, -5.13176)
unique_name_in_owner = true
visible = false
[node name="Floor1" parent="." instance=ExtResource("6_75lk5")]
unique_name_in_owner = true
visible = false
[node name="Floor2" parent="." instance=ExtResource("7_1sm5s")]
unique_name_in_owner = true
visible = false
[node name="Floor3" parent="." instance=ExtResource("8_87yk1")]
unique_name_in_owner = true
visible = false
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
unique_name_in_owner = true
libraries = {
"": SubResource("AnimationLibrary_opfbx")
}
[node name="LoadScreen" type="ColorRect" parent="."]
process_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(1, 1, 1, 0)
[node name="Teleport" parent="." instance=ExtResource("9_nwu7r")]
unique_name_in_owner = true
process_mode = 3
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 900, 900, 900)
disable_mode = 2
collision_layer = 2

View File

@@ -15,6 +15,8 @@
public readonly record struct MiniMapButtonReleased;
public readonly record struct GameOver;
public readonly record struct LoadNextFloor;
}
}
}

View File

@@ -19,6 +19,8 @@ namespace GameJamDungeon
public readonly record struct HideMiniMap();
public readonly record struct GameOver();
public readonly record struct LoadNextFloor;
}
}
}

View File

@@ -8,7 +8,7 @@ namespace GameJamDungeon
public partial record State
{
[Meta]
public partial record Playing : State, IGet<Input.InventoryMenuButtonPressed>, IGet<Input.MiniMapButtonPressed>, IGet<Input.GameOver>
public partial record Playing : State, IGet<Input.InventoryMenuButtonPressed>, IGet<Input.MiniMapButtonPressed>, IGet<Input.GameOver>, IGet<Input.LoadNextFloor>
{
public Playing()
{
@@ -28,6 +28,12 @@ namespace GameJamDungeon
{
return To<Quit>();
}
public Transition On(in Input.LoadNextFloor input)
{
Output(new Output.LoadNextFloor());
return ToSelf();
}
}
}
}