Chests and strafing speed

This commit is contained in:
Marco 2025-01-28 14:05:38 +01:00
commit b645e1724e
17 changed files with 286 additions and 21 deletions

View file

@ -0,0 +1,8 @@
[gd_resource type="Resource" script_class="LootItem" load_steps=2 format=3 uid="uid://dibquna7fww7t"]
[ext_resource type="Script" path="res://Scripts/Resources/LootItem.cs" id="1_istlt"]
[resource]
script = ExtResource("1_istlt")
Item = 0
Amount = 1

View file

@ -0,0 +1,108 @@
[gd_scene load_steps=15 format=3 uid="uid://djf0y08ix66fn"]
[ext_resource type="Script" path="res://Scenes/Interactable.cs" id="1_4p5d3"]
[ext_resource type="Texture2D" uid="uid://qeh4ai8h6sw5" path="res://Sprites/Chest.png" id="2_w7a1a"]
[ext_resource type="Script" path="res://Scripts/Pickupper.cs" id="3_qro6k"]
[ext_resource type="Script" path="res://Scripts/Resources/LootItem.cs" id="4_rcd61"]
[sub_resource type="AtlasTexture" id="AtlasTexture_elja3"]
atlas = ExtResource("2_w7a1a")
region = Rect2(0, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_nyoe2"]
atlas = ExtResource("2_w7a1a")
region = Rect2(16, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_f10r8"]
atlas = ExtResource("2_w7a1a")
region = Rect2(0, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_faho7"]
atlas = ExtResource("2_w7a1a")
region = Rect2(16, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_yfpr1"]
atlas = ExtResource("2_w7a1a")
region = Rect2(0, 0, 16, 16)
[sub_resource type="AtlasTexture" id="AtlasTexture_x1bfm"]
atlas = ExtResource("2_w7a1a")
region = Rect2(16, 0, 16, 16)
[sub_resource type="SpriteFrames" id="SpriteFrames_cirgn"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_elja3")
}],
"loop": true,
"name": &"Closed",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_nyoe2")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_f10r8")
}],
"loop": true,
"name": &"Closing",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_faho7")
}],
"loop": true,
"name": &"Open",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_yfpr1")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_x1bfm")
}],
"loop": true,
"name": &"Opening",
"speed": 5.0
}]
[sub_resource type="CircleShape2D" id="CircleShape2D_ihal6"]
radius = 16.0
[sub_resource type="RectangleShape2D" id="RectangleShape2D_isrvb"]
size = Vector2(12, 10)
[sub_resource type="Resource" id="Resource_0qq1f"]
script = ExtResource("4_rcd61")
Item = 3
Amount = 10
[node name="Chest" type="Node2D"]
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_cirgn")
animation = &"Closed"
[node name="Interactable" type="Area2D" parent="." node_paths=PackedStringArray("Target") groups=["Interactable"]]
script = ExtResource("1_4p5d3")
Target = NodePath("../Pickupper")
[node name="CollisionShape2D" type="CollisionShape2D" parent="Interactable"]
shape = SubResource("CircleShape2D_ihal6")
[node name="RigidBody2D" type="RigidBody2D" parent="."]
collision_layer = 64
collision_mask = 10
gravity_scale = 0.0
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"]
position = Vector2(0, -3)
shape = SubResource("RectangleShape2D_isrvb")
[node name="Pickupper" type="Node2D" parent="."]
script = ExtResource("3_qro6k")
LootTable = [SubResource("Resource_0qq1f")]

View file

@ -3,7 +3,7 @@
[ext_resource type="Script" path="res://Scenes/Interactable.cs" id="1_g3j01"]
[ext_resource type="Texture2D" uid="uid://d24g1qb40t72l" path="res://Sprites/Button_Small.png" id="2_7m30w"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_x0adl"]
[sub_resource type="CircleShape2D" id="CircleShape2D_vvpve"]
[node name="ControlPad" type="Area2D" groups=["Interactable"]]
collision_layer = 4
@ -11,7 +11,7 @@ collision_mask = 2
script = ExtResource("1_g3j01")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_x0adl")
shape = SubResource("CircleShape2D_vvpve")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("2_7m30w")

View file

@ -3,7 +3,8 @@
[ext_resource type="Script" path="res://Scenes/Interactable.cs" id="1_q256v"]
[ext_resource type="Texture2D" uid="uid://ch6nbhxgxxtf" path="res://Sprites/Red_Card_Reader.png" id="2_xidhq"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_x0adl"]
[sub_resource type="CircleShape2D" id="CircleShape2D_hhoab"]
radius = 12.0
[node name="KeycardPad" type="Area2D" groups=["Interactable"]]
collision_layer = 4
@ -12,7 +13,7 @@ script = ExtResource("1_q256v")
RequiresKeycard = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_x0adl")
shape = SubResource("CircleShape2D_hhoab")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("2_xidhq")

View file

@ -1,8 +1,9 @@
[gd_scene load_steps=5 format=3 uid="uid://dxs3ks2ucaxl4"]
[gd_scene load_steps=6 format=3 uid="uid://dxs3ks2ucaxl4"]
[ext_resource type="Script" path="res://Scenes/Interactable.cs" id="1_8ev2v"]
[ext_resource type="Texture2D" uid="uid://c53bchw2krocb" path="res://Sprites/Red_Keycard.png" id="2_onmup"]
[ext_resource type="Script" path="res://Scripts/Pickupper.cs" id="3_t6rqq"]
[ext_resource type="Resource" uid="uid://dibquna7fww7t" path="res://Resources/Items/Red_Keycard.tres" id="4_4o8tc"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_x0adl"]
@ -20,3 +21,4 @@ texture = ExtResource("2_onmup")
[node name="Pickupper" type="Node2D" parent="."]
script = ExtResource("3_t6rqq")
LootTable = [ExtResource("4_4o8tc")]

View file

@ -146,7 +146,8 @@ radius = 1.0
collision_layer = 2
collision_mask = 99
script = ExtResource("1_m27vu")
Speed = 2500
Speed = 3000
StrafeSpeed = 2500
CrosshairDistance = 20.0
SelectorScene = ExtResource("3_8wt6s")
GameOverScene = "res://Scenes/GameOver.tscn"

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=38 format=4 uid="uid://bv451a8wgty4u"]
[gd_scene load_steps=39 format=4 uid="uid://bv451a8wgty4u"]
[ext_resource type="Script" path="res://Scripts/GameManager.cs" id="1_8tmoj"]
[ext_resource type="PackedScene" uid="uid://bghghp5ep4w2j" path="res://Scenes/player.tscn" id="2_8mh54"]
@ -24,6 +24,7 @@
[ext_resource type="PackedScene" uid="uid://cymtsmui4yo17" path="res://Scenes/Keycard_Pad.tscn" id="20_0aphx"]
[ext_resource type="PackedScene" uid="uid://dkwi1hu1bixoe" path="res://Scenes/HUD/HUD.tscn" id="22_krk0o"]
[ext_resource type="Script" path="res://Scenes/CameraTarget.gd" id="24_0c2yt"]
[ext_resource type="PackedScene" uid="uid://djf0y08ix66fn" path="res://Scenes/Interactable/Chest.tscn" id="25_4b2ed"]
[sub_resource type="NavigationPolygon" id="NavigationPolygon_lnwgu"]
vertices = PackedVector2Array(8, 8, -8, 8, -8, -8, 8, -8)
@ -431,3 +432,6 @@ script = ExtResource("24_0c2yt")
[node name="PlayerStartPosition" type="Marker2D" parent="."]
position = Vector2(-779, -160)
[node name="Chest" parent="." instance=ExtResource("25_4b2ed")]
position = Vector2(-760, -169)

18
Scripts/Chest.cs Normal file
View file

@ -0,0 +1,18 @@
namespace Cirno.Scripts;
public partial class Chest : Activable
{
private InventoryManager inventoryManager;
public override void _Ready()
{
inventoryManager = GetNode<InventoryManager>("/root/GameScene/InventoryManager");
}
public override void Activate()
{
inventoryManager.AddRedKeycard();
GetParent().QueueFree();
}
}

View file

@ -1,5 +1,6 @@
using Godot;
using System;
using Cirno.Scripts;
public partial class InventoryManager : Node2D
{
@ -15,6 +16,45 @@ public partial class InventoryManager : Node2D
{
}
public bool AddItem(ItemTypes type, int amount = 1)
{
switch (type)
{
case ItemTypes.KeycardRed:
RedKeycard = true;
GD.Print($"Red Keycard x{amount}");
break;
case ItemTypes.KeycardBlue:
GD.Print($"Blue Keycard x{amount}");
break;
case ItemTypes.KeycardGreen:
GD.Print($"Green Keycard x{amount}");
break;
case ItemTypes.Ammo:
GD.Print($"Ammo x{amount}");
break;
case ItemTypes.Medkit:
GD.Print($"Medkit x{amount}");
break;
case ItemTypes.CrabBomb:
GD.Print($"CrabBomb x{amount}");
break;
case ItemTypes.Bomb:
GD.Print($"Bomb x{amount}");
break;
case ItemTypes.Mine:
GD.Print($"Mine x{amount}");
break;
case ItemTypes.Battery:
GD.Print($"Battery x{amount}");
break;
default:
return false;
}
return true; // TODO: Return false if could not be added
}
public void AddRedKeycard()
{
RedKeycard = true;

14
Scripts/ItemTypes.cs Normal file
View file

@ -0,0 +1,14 @@
namespace Cirno.Scripts;
public enum ItemTypes
{
KeycardRed,
KeycardBlue,
KeycardGreen,
Ammo,
Medkit,
CrabBomb,
Bomb,
Mine,
Battery
}

View file

@ -1,19 +1,29 @@
using Godot;
using System;
using System.Collections.Generic;
using Cirno.Scripts;
using Cirno.Scripts.Resources;
using Godot.Collections;
public partial class Pickupper : Activable
{
private InventoryManager _inventoryManager;
private InventoryManager inventoryManager;
[Export] public Array<LootItem> LootTable = new Array<LootItem>();
public override void _Ready()
{
inventoryManager = GetNode<InventoryManager>("/root/GameScene/InventoryManager");
}
public override void Activate()
{
inventoryManager.AddRedKeycard();
GetParent().QueueFree();
}
}
public override void _Ready()
{
_inventoryManager = GetNode<InventoryManager>("/root/GameScene/InventoryManager");
}
public override void Activate()
{
foreach (var item in LootTable)
{
_inventoryManager.AddItem(item.Item, item.Amount);
}
//inventoryManager.AddRedKeycard();
GetParent().QueueFree(); // TODO: send a signal instead
}
}

View file

@ -7,6 +7,11 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
{
[Export]
public int Speed { get; set; } = 400;
[Export]
public int StrafeSpeed { get; set; } = 200;
public int MovementSpeed => _isStrafing ? StrafeSpeed : Speed;
[Export]
public float CrosshairDistance { get; set; } = 10f;
@ -237,7 +242,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
// {
// _facingDirection = _movementDirection;
// }
Velocity = _movementDirection * (float)(Speed * delta);
Velocity = _movementDirection * (float)( MovementSpeed * delta);
MoveAndSlide();
@ -246,7 +251,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
//FindInteractable();
}
private void _on_interaction_controller_area_entered(Area2D area)
{
// Replace with function body.

View file

@ -0,0 +1,10 @@
using Godot;
namespace Cirno.Scripts.Resources;
[GlobalClass]
public partial class LootItem : Resource
{
[Export] public ItemTypes Item;
[Export] public int Amount;
}

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

Binary file not shown.

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

Binary file not shown.

34
Sprites/Chest.png.import Normal file
View file

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

@ -47,6 +47,10 @@ project/assembly_name="Cirno"
enabled=PackedStringArray("res://addons/ButtonLink/plugin.cfg", "res://addons/DebugGUI/plugin.cfg", "res://addons/smoothing/plugin.cfg")
[global_group]
Interactable=""
[input]
left={