Cheat Gun

This commit is contained in:
Marco 2025-02-15 17:51:06 +01:00
commit cb27f33a6d
21 changed files with 620 additions and 436 deletions

View file

@ -1,8 +1,16 @@
[gd_resource type="Resource" script_class="BossPhase" load_steps=5 format=3 uid="uid://da1vjfavqs7u2"] [gd_resource type="Resource" script_class="BossPhase" load_steps=7 format=3 uid="uid://da1vjfavqs7u2"]
[ext_resource type="PackedScene" uid="uid://c034favdy56p0" path="res://Scenes/Weapons/Bullets/enemyBullet_star_yellow.tscn" id="1_0bb8a"] [ext_resource type="PackedScene" uid="uid://c034favdy56p0" path="res://Scenes/Weapons/Bullets/enemyBullet_star_yellow.tscn" id="1_0bb8a"]
[ext_resource type="Script" path="res://Scripts/Resources/BossPhase.cs" id="1_7asq8"] [ext_resource type="Script" path="res://Scripts/Resources/BossPhase.cs" id="1_7asq8"]
[ext_resource type="Script" path="res://Scripts/AttackPatterns/SpiralPattern.cs" id="1_ys2v3"] [ext_resource type="Script" path="res://Scripts/AttackPatterns/SpiralPattern.cs" id="1_ys2v3"]
[ext_resource type="Script" path="res://Scripts/Resources/Modifiers/DelayedContinuousRotationModifier.cs" id="2_t0hje"]
[sub_resource type="Resource" id="Resource_n6wfp"]
script = ExtResource("2_t0hje")
TimeInSeconds = 0.0
ModifierType = 0
Value = 80.0
Continuous = false
[sub_resource type="Resource" id="Resource_q4pcc"] [sub_resource type="Resource" id="Resource_q4pcc"]
script = ExtResource("1_ys2v3") script = ExtResource("1_ys2v3")
@ -17,7 +25,7 @@ spread = 360.0
owner = 2 owner = 2
_damageType = 0 _damageType = 0
_bulletDamage = 1.0 _bulletDamage = 1.0
_timeModifiers = null _timeModifiers = Array[Object]([SubResource("Resource_n6wfp")])
_targetPlayer = false _targetPlayer = false
WaitForCompletion = true WaitForCompletion = true

View file

@ -0,0 +1,14 @@
[gd_resource type="Resource" script_class="BulletResource" load_steps=3 format=3 uid="uid://bopwqpmxoy1rd"]
[ext_resource type="PackedScene" uid="uid://b1qnfiuokpvsr" path="res://Scenes/Weapons/bullet.tscn" id="1_i4nah"]
[ext_resource type="Script" path="res://Scripts/Resources/BulletResource.cs" id="2_dbvc7"]
[resource]
script = ExtResource("2_dbvc7")
BulletScene = ExtResource("1_i4nah")
BulletSpeed = 100.0
BulletDamage = 50.0
LifeTime = 10.0
Owner = 1
DamageType = 0
TimeModifiers = null

View file

@ -0,0 +1,18 @@
[gd_resource type="Resource" script_class="LootItem" load_steps=4 format=3 uid="uid://cfq121rs3bsu8"]
[ext_resource type="PackedScene" uid="uid://pemr2lrv3ylk" path="res://Scenes/HUD/Items/ying_yang_gun_huditem.tscn" id="1_i6xgq"]
[ext_resource type="Resource" uid="uid://ckppo2seg313h" path="res://Resources/Weapons/Cheat_Gun.tres" id="2_0na1t"]
[ext_resource type="Script" path="res://Scripts/Resources/LootItem.cs" id="3_i0e51"]
[resource]
script = ExtResource("3_i0e51")
ItemName = "Cheat Gun"
ItemKey = "CheatGun"
Item = 9
WeaponData = ExtResource("2_0na1t")
Amount = 1
Max = 1
PickupIfMaxed = true
ConsumeOnUse = false
UiType = 1
HudItemScene = ExtResource("1_i6xgq")

View file

@ -0,0 +1,19 @@
[gd_resource type="Resource" script_class="WeaponResource" load_steps=3 format=3 uid="uid://ckppo2seg313h"]
[ext_resource type="Resource" uid="uid://bopwqpmxoy1rd" path="res://Resources/Bullets/cheat_bullet.tres" id="1_7fekn"]
[ext_resource type="Script" path="res://Scripts/Resources/WeaponResource.cs" id="1_d3tbp"]
[resource]
script = ExtResource("1_d3tbp")
Name = "Cheat Gun"
BulletData = ExtResource("1_7fekn")
RateOfFire = 0.4
BulletCapacity = 200
ReloadTime = 0.1
AutoReload = true
InfiniteAmmo = true
BulletsPerShot = 1
SpreadAngle = 0.0
RandomSpread = 0.0
AmmoKey = ""
_rotationOffset = 0.0

View file

@ -1,16 +1,12 @@
[gd_resource type="Resource" script_class="WeaponResource" load_steps=5 format=3 uid="uid://b8apu0l5fm4k"] [gd_resource type="Resource" script_class="WeaponResource" load_steps=3 format=3 uid="uid://b8apu0l5fm4k"]
[ext_resource type="Resource" uid="uid://eu6n6c5175y8" path="res://Resources/Bullets/simple_ice_bullet.tres" id="1_85ef1"] [ext_resource type="Resource" uid="uid://eu6n6c5175y8" path="res://Resources/Bullets/simple_ice_bullet.tres" id="1_85ef1"]
[ext_resource type="PackedScene" uid="uid://b1qnfiuokpvsr" path="res://Scenes/Weapons/bullet.tscn" id="1_yby7n"]
[ext_resource type="PackedScene" uid="uid://dfbmny3s4rili" path="res://Scenes/Particles/IceBulletParticle.tscn" id="2_icuny"]
[ext_resource type="Script" path="res://Scripts/Resources/WeaponResource.cs" id="2_m8dps"] [ext_resource type="Script" path="res://Scripts/Resources/WeaponResource.cs" id="2_m8dps"]
[resource] [resource]
script = ExtResource("2_m8dps") script = ExtResource("2_m8dps")
Name = "Icicle Gun" Name = "Icicle Gun"
BulletData = ExtResource("1_85ef1") BulletData = ExtResource("1_85ef1")
BulletScene = ExtResource("1_yby7n")
DestructionParticlesScene = ExtResource("2_icuny")
RateOfFire = 0.1 RateOfFire = 0.1
BulletCapacity = 4 BulletCapacity = 4
ReloadTime = 0.2 ReloadTime = 0.2
@ -20,10 +16,4 @@ BulletsPerShot = 1
SpreadAngle = 0.0 SpreadAngle = 0.0
RandomSpread = 0.0 RandomSpread = 0.0
AmmoKey = "" AmmoKey = ""
BulletSpeed = 300.0
BulletDamage = 1.0
LifeTime = 10.0
_rotationOffset = 0.0 _rotationOffset = 0.0
owner = 1
_damageType = 0
_timeModifiers = null

View file

@ -17,6 +17,8 @@ public partial class Barrel : Area2D, IDestructible
[Export] public PackedScene ExplosionParticles { get; set; } [Export] public PackedScene ExplosionParticles { get; set; }
[Export] public BulletResource ExplosionData { get; set; } [Export] public BulletResource ExplosionData { get; set; }
[Export] public BulletOwner BulletGroup { get; set; } = BulletOwner.None;
private GameManager _gameManager; private GameManager _gameManager;
private float _currentHealth = 0f; private float _currentHealth = 0f;

View file

@ -48,10 +48,10 @@ func smooth_damp(current: float, target: float, current_velocity: float, smooth_
return [output, current_velocity] return [output, current_velocity]
func _unhandled_input(_event: InputEvent) -> void: func _unhandled_input(_event: InputEvent) -> void:
if Input.is_key_pressed(KEY_1): if Input.is_action_just_pressed("debug_camera_1"):
pixel_snap = not pixel_snap pixel_snap = not pixel_snap
print("Camera pixel snap: ", pixel_snap) print("Camera pixel snap: ", pixel_snap)
if Input.is_key_pressed(KEY_2): if Input.is_action_just_pressed("debug_camera_2"):
enable_smoothing = not enable_smoothing enable_smoothing = not enable_smoothing
print("Camera smoothing: ", enable_smoothing) print("Camera smoothing: ", enable_smoothing)

View file

@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3 uid="uid://pemr2lrv3ylk"]
[ext_resource type="Texture2D" uid="uid://61kfxc7k3do" path="res://Sprites/Items/Ying_Yang_Gun.png" id="1_l8amd"]
[node name="YingYangGun" type="TextureRect"]
texture = ExtResource("1_l8amd")
stretch_mode = 2

View file

@ -0,0 +1,19 @@
[gd_scene load_steps=5 format=3 uid="uid://4q82gggqax87"]
[ext_resource type="Script" path="res://Scripts/Interactables/ItemPickup.cs" id="1_vx8ix"]
[ext_resource type="Resource" uid="uid://cfq121rs3bsu8" path="res://Resources/Items/Cheat_Gun_Item.tres" id="2_si1ac"]
[ext_resource type="Texture2D" uid="uid://61kfxc7k3do" path="res://Sprites/Items/Ying_Yang_Gun.png" id="4_pj6iu"]
[sub_resource type="CircleShape2D" id="CircleShape2D_jtwy2"]
[node name="CheaetGun" type="Area2D" groups=["Interactable"]]
collision_layer = 4
collision_mask = 2
script = ExtResource("1_vx8ix")
LootTable = [ExtResource("2_si1ac")]
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("4_pj6iu")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_jtwy2")

View file

@ -0,0 +1,19 @@
[gd_scene load_steps=5 format=3 uid="uid://ddwcib46ttlrp"]
[ext_resource type="Script" path="res://Scripts/Interactables/ItemPickup.cs" id="1_gpoff"]
[ext_resource type="Resource" uid="uid://dau0s8ob7qnpc" path="res://Resources/Items/IceShotgun.tres" id="2_l5f4t"]
[ext_resource type="Texture2D" uid="uid://b46usr10jhmev" path="res://Sprites/Items/Ice_Shotgun.png" id="3_w7kfy"]
[sub_resource type="CircleShape2D" id="CircleShape2D_jtwy2"]
[node name="IceShotgun" type="Area2D" groups=["Interactable"]]
collision_layer = 4
collision_mask = 2
script = ExtResource("1_gpoff")
LootTable = [ExtResource("2_l5f4t")]
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("3_w7kfy")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_jtwy2")

View file

@ -6,7 +6,9 @@
[sub_resource type="CircleShape2D" id="CircleShape2D_jtwy2"] [sub_resource type="CircleShape2D" id="CircleShape2D_jtwy2"]
[node name="IcicleGun" type="Area2D"] [node name="IcicleGun" type="Area2D" groups=["Interactable"]]
collision_layer = 4
collision_mask = 2
script = ExtResource("1_rdvi1") script = ExtResource("1_rdvi1")
LootTable = [ExtResource("2_6qt07")] LootTable = [ExtResource("2_6qt07")]

View file

@ -7,11 +7,10 @@
radius = 4.0 radius = 4.0
[node name="Bullet" type="Area2D" groups=["bullets"]] [node name="Bullet" type="Area2D" groups=["bullets"]]
collision_layer = 128 collision_layer = 136
collision_mask = 71 collision_mask = 87
script = ExtResource("1_w5w28") script = ExtResource("1_w5w28")
Speed = 200.0 Speed = 200.0
Owner = 2
metadata/_edit_group_ = true metadata/_edit_group_ = true
[node name="Sprite2D" type="Sprite2D" parent="."] [node name="Sprite2D" type="Sprite2D" parent="."]

View file

@ -11,7 +11,6 @@ collision_layer = 8
collision_mask = 85 collision_mask = 85
script = ExtResource("1_jvxw3") script = ExtResource("1_jvxw3")
Speed = 200.0 Speed = 200.0
Owner = 1
metadata/_edit_group_ = true metadata/_edit_group_ = true
[node name="Sprite2D" type="Sprite2D" parent="."] [node name="Sprite2D" type="Sprite2D" parent="."]

File diff suppressed because one or more lines are too long

View file

@ -9,204 +9,223 @@ using Cirno.Scripts.Resources;
public partial class Bullet : Area2D public partial class Bullet : Area2D
{ {
[Export] [Export] public float Speed = 1900f;
public float Speed = 1900f;
public BulletOwner BulletOwner => _bulletInfo?.Owner ?? BulletOwner.None; public BulletOwner BulletOwner => _bulletInfo?.Owner ?? BulletOwner.None;
public float Damage => _bulletInfo?.Damage ?? 1; public float Damage => _bulletInfo?.Damage ?? 1;
public DamageType DamageType => _bulletInfo?.DamageType ?? DamageType.Neutral; public DamageType DamageType => _bulletInfo?.DamageType ?? DamageType.Neutral;
protected Vector2 _direction = Vector2.Right; protected Vector2 _direction = Vector2.Right;
private double _elapsedTime = 0f; private double _elapsedTime = 0f;
private BulletInfo _bulletInfo; private BulletInfo _bulletInfo;
public BulletInfo BulletInfo => _bulletInfo; public BulletInfo BulletInfo => _bulletInfo;
private List<ModifierWrapper> _modifiers = new(); private List<ModifierWrapper> _modifiers = new();
private GameManager _gameManager; private GameManager _gameManager;
public void Initialize(BulletInfo bulletInfo, GameManager gameManager) public void Initialize(BulletInfo bulletInfo, GameManager gameManager)
{ {
_bulletInfo = bulletInfo; _bulletInfo = bulletInfo;
_gameManager = gameManager; _gameManager = gameManager;
// Need to clone them here // Need to clone them here
// _modifiers = _bulletInfo.TimeModifiers.Select(x => x.MakeClone()).ToList(); // _modifiers = _bulletInfo.TimeModifiers.Select(x => x.MakeClone()).ToList();
// var clonedModifiers = _bulletInfo.TimeModifiers.Select(x => x.MakeClone()); // var clonedModifiers = _bulletInfo.TimeModifiers.Select(x => x.MakeClone());
// _modifiers = clonedModifiers.ToList(); // _modifiers = clonedModifiers.ToList();
// Ugly hack to make instances unique // Ugly hack to make instances unique
_modifiers = _bulletInfo.TimeModifiers.Select(x => x.Wrap()).ToList(); _modifiers = _bulletInfo.TimeModifiers.Select(x => x.Wrap()).ToList();
}
} private void ApplyTimeModifiers(double delta)
{
foreach (var modifier in _modifiers)
{
if (_elapsedTime >= modifier.TimeModifier.TimeInSeconds)
{
if (!modifier.Applied)
{
modifier.Applied = true;
modifier.TimeModifier.Start(this);
}
private void ApplyTimeModifiers(double delta) modifier.TimeModifier.Update(this, delta);
{
foreach (var modifier in _modifiers)
{
if (_elapsedTime >= modifier.TimeModifier.TimeInSeconds)
{
if (!modifier.Applied)
{
modifier.Applied = true;
modifier.TimeModifier.Start(this);
}
modifier.TimeModifier.Update(this, delta); // switch (modifier.ModifierType)
// {
// case TimeModifierType.SpeedChange:
// //_bulletInfo.Speed += modifier.Value;
// Speed = modifier.Value;
// break;
// case TimeModifierType.RotationChange:
// RotateBullet(modifier.Value);
// //Rotation += Mathf.DegToRad(modifier.Value);
// break;
// case TimeModifierType.FacePlayer:
// FacePlayer();
// break;
// }
// switch (modifier.ModifierType) // if (!modifier.Continuous)
// { // {
// case TimeModifierType.SpeedChange: // modifier.Applied = true;
// //_bulletInfo.Speed += modifier.Value; // }
// Speed = modifier.Value; }
// break; }
// case TimeModifierType.RotationChange: }
// RotateBullet(modifier.Value);
// //Rotation += Mathf.DegToRad(modifier.Value);
// break;
// case TimeModifierType.FacePlayer:
// FacePlayer();
// break;
// }
// if (!modifier.Continuous) public virtual void RotateBullet(float degrees)
// { {
// modifier.Applied = true; float radians = Mathf.DegToRad(degrees);
// } _direction = _direction.Rotated(radians).Normalized(); // Rotate direction
} SetRotation(Rotation + radians);
} //Rotation = radians;
} }
public virtual void RotateBullet(float degrees) public virtual void RotateSpriteDegrees(float degrees)
{ {
float radians = Mathf.DegToRad(degrees); SetRotationDegrees(RotationDegrees + degrees);
_direction = _direction.Rotated(radians).Normalized(); // Rotate direction }
SetRotation(Rotation + radians);
//Rotation = radians;
}
public void FacePlayer() public virtual void RotateSprite(float radians)
{ {
if (_gameManager.Player != null) SetRotation(Rotation + radians);
{ }
_direction = (_gameManager.Player.GlobalPosition - this.GlobalPosition).Normalized();
RotateBullet(0); // quick hack to rotate lasers public void FacePlayer()
//LookAt(player.GlobalPosition); {
} if (_gameManager.Player != null)
} {
_direction = (_gameManager.Player.GlobalPosition - this.GlobalPosition).Normalized();
RotateBullet(0); // quick hack to rotate lasers
//LookAt(player.GlobalPosition);
}
}
//private void OnBodyEntered(Node body) //private void OnBodyEntered(Node body)
//{ //{
// When a body is entered, invoke the event and pass the collided body // When a body is entered, invoke the event and pass the collided body
// BulletHit?.Invoke(body); // BulletHit?.Invoke(body);
// Then remove the bullet // Then remove the bullet
// QueueFree(); // QueueFree();
//} //}
public void SetDirection(Vector2 direction) public void SetDirection(Vector2 direction)
{ {
var normalized = direction.Normalized(); var normalized = direction.Normalized();
_direction = normalized; _direction = normalized;
SetRotation(Mathf.Atan2(normalized.Y,normalized.X) + Mathf.Pi / 2); SetRotation(Mathf.Atan2(normalized.Y, normalized.X) + Mathf.Pi / 2);
//Debug.WriteLine($"Bullet Shot at direction {direction.X} {direction.Y}"); //Debug.WriteLine($"Bullet Shot at direction {direction.X} {direction.Y}");
} }
// Called every frame. 'delta' is the elapsed time since the previous frame. // Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta) public override void _Process(double delta)
{ {
_elapsedTime += delta; _elapsedTime += delta;
}
} public override void _PhysicsProcess(double delta)
{
if (_bulletInfo != null)
{
ApplyTimeModifiers(delta);
}
public override void _PhysicsProcess(double delta) this.Position += ((float)(Speed * delta) * _direction);
{ }
if (_bulletInfo != null)
{
ApplyTimeModifiers(delta);
}
this.Position += ((float)(Speed * delta) * _direction); private void _on_visible_on_screen_notifier_2d_screen_exited()
} {
//Debug.WriteLine("Destroy bullet out of screen");
Destroy();
}
private void _on_visible_on_screen_notifier_2d_screen_exited() private void _on_body_entered(Node2D body)
{ {
//Debug.WriteLine("Destroy bullet out of screen"); if (body.IsInGroup("Solid"))
Destroy(); {
} //Debug.WriteLine("Collision");
Destroy();
}
//// Do not Collide with body for purpose of destroying bullets
// else if (body.IsInGroup("Destroyable"))
// {
// Debug.WriteLine("Collision with destroyable object body");
// QueueFree();
// }
}
private void _on_body_entered(Node2D body) private void _on_area_entered(Area2D area)
{ {
if (body.IsInGroup("Solid")) if (area.IsInGroup("Solid"))
{ {
//Debug.WriteLine("Collision"); Destroy();
Destroy(); return;
} }
//// Do not Collide with body for purpose of destroying bullets
// else if (body.IsInGroup("Destroyable"))
// {
// Debug.WriteLine("Collision with destroyable object body");
// QueueFree();
// }
} if (area.IsInGroup("Destroyable") && area is IDestructible destructible &&
CanHit(BulletOwner, destructible.BulletGroup))
{
// hit
destructible.Hit(Damage, DamageType);
private void _on_area_entered(Area2D area) Destroy();
{ }
if (area.IsInGroup("Solid")) }
{
Destroy();
return;
}
if (area.IsInGroup("Destroyable") && area is IDestructible destructible) public bool CanHit(BulletOwner bulletOwner, BulletOwner targetGroup)
{ {
//Debug.WriteLine("Collision with destroyable object area"); // If either is None, it always hits
if (bulletOwner == BulletOwner.None || targetGroup == BulletOwner.None)
{
return true;
}
destructible.Hit(Damage, DamageType); // Otherwise, it hits only if they are different groups
return bulletOwner != targetGroup;
}
Destroy();
}
}
public void Destroy() public void Destroy()
{ {
if (_bulletInfo?.DestructionParticlesScene != null) if (_bulletInfo?.DestructionParticlesScene != null)
{ {
var particle = this.CreateSibling<AutodeleteParticle>(_bulletInfo.DestructionParticlesScene); var particle = this.CreateSibling<AutodeleteParticle>(_bulletInfo.DestructionParticlesScene);
particle.Init(); particle.Init();
} }
QueueFree(); QueueFree();
} }
} }
public enum BulletOwner public enum BulletOwner
{ {
None, None,
Player, Player,
Enemy Enemy
} }
public enum DamageType public enum DamageType
{ {
Neutral, Neutral,
Ballistic, Ballistic,
Fire, Fire,
Ice, Ice,
Explosive, Explosive,
Acid Acid
} }

View file

@ -8,217 +8,243 @@ using Godot.Collections;
public partial class GameManager : Node2D public partial class GameManager : Node2D
{ {
private Hud _hud; private Hud _hud;
private PlayerMovement _player; private PlayerMovement _player;
public GameState GameState { get; private set; } public GameState GameState { get; private set; }
public PlayerMovement Player => _player; public PlayerMovement Player => _player;
private Node2D _cameraTarget; private Node2D _cameraTarget;
public Vector2? PlayerPosition => _player?.GlobalPosition ?? null; public Vector2? PlayerPosition => _player?.GlobalPosition ?? null;
[Export] [Export] public PackedScene PlayerTemplate { get; set; }
public PackedScene PlayerTemplate { get; set; }
[Export] [Export] public Marker2D PlayerSpawnMarker { get; set; }
public Marker2D PlayerSpawnMarker { get; set; }
[Export] public PackedScene WeaponTemplate { get; private set; } [Export] public PackedScene WeaponTemplate { get; private set; }
[Export] public Array<LootItem> StartingEquipment { get; private set; } [Export] public Array<LootItem> StartingEquipment { get; private set; }
private InventoryManager _inventoryManager { get; set; } private InventoryManager _inventoryManager { get; set; }
//private AlarmManager _alarmManager { get; set; } //private AlarmManager _alarmManager { get; set; }
//public InventoryManager Inventory => _inventoryManager; //public InventoryManager Inventory => _inventoryManager;
//public AlarmManager AlarmManager => _alarmManager; //public AlarmManager AlarmManager => _alarmManager;
private Node2D _bulletsContainer; private Node2D _bulletsContainer;
public Node2D BulletsContainer => _bulletsContainer; public Node2D BulletsContainer => _bulletsContainer;
[Signal] [Signal]
public delegate void GameStateChangeEventHandler(GameState state); public delegate void GameStateChangeEventHandler(GameState state);
// Called when the node enters the scene tree for the first time. // Called when the node enters the scene tree for the first time.
public override void _Ready() public override void _Ready()
{ {
_hud = GetNodeOrNull<Hud>("HUD"); _hud = GetNodeOrNull<Hud>("HUD");
if (_hud == null) GD.Print("No HUD in scene."); if (_hud == null) GD.Print("No HUD in scene.");
_cameraTarget = GetNodeOrNull<Node2D>("CameraTarget"); _cameraTarget = GetNodeOrNull<Node2D>("CameraTarget");
if (_cameraTarget == null) GD.Print("No camera target in scene."); if (_cameraTarget == null) GD.Print("No camera target in scene.");
_inventoryManager = GetNodeOrNull<InventoryManager>("InventoryManager"); _inventoryManager = GetNodeOrNull<InventoryManager>("InventoryManager");
if (_inventoryManager == null) GD.Print("No inventory manager in scene."); if (_inventoryManager == null) GD.Print("No inventory manager in scene.");
//_alarmManager = GetNode<AlarmManager>("AlarmManager"); //_alarmManager = GetNode<AlarmManager>("AlarmManager");
SpawnBulletsContainer(); SpawnBulletsContainer();
if (_inventoryManager != null && _hud != null) if (_inventoryManager != null && _hud != null)
{ {
_inventoryManager.ItemAdded += (item, currentAmount) => _hud.AddInventoryItem(item, currentAmount); _inventoryManager.ItemAdded += (item, currentAmount) => _hud.AddInventoryItem(item, currentAmount);
_inventoryManager.ItemRemoved += (item, currentAmount) => _hud.RemoveInventoryItem(item, currentAmount); _inventoryManager.ItemRemoved += (item, currentAmount) => _hud.RemoveInventoryItem(item, currentAmount);
} }
GameState = GameState.Playing; GameState = GameState.Playing;
_ = DelayPlayerSpawn(); _ = DelayPlayerSpawn();
} }
// Called every frame. 'delta' is the elapsed time since the previous frame. // Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta) public override void _Process(double delta)
{ {
if (Input.IsActionJustPressed("pause")) if (Input.IsActionJustPressed("pause"))
{ {
TogglePause(); TogglePause();
} }
} }
private async Task DelayPlayerSpawn() private async Task DelayPlayerSpawn()
{ {
await Task.Delay(500); await Task.Delay(500);
if (PlayerSpawnMarker != null) if (PlayerSpawnMarker != null)
{ {
SpawnPlayer(); SpawnPlayer();
}
else
{
GD.Print("No player spawn marker in scene.");
return;
}
SpawnWeapons(); if (_player != null && _hud != null)
} {
_player.HealthChanged += (newHealth, maxHealth) => _hud.UpdateHealth(newHealth, maxHealth);
if (_player != null && _hud != null) _player.ShieldChanged += (newShield, maxShield) => _hud.UpdateShield(newShield, maxShield);
{
_player.HealthChanged += (newHealth, maxHealth) => _hud.UpdateHealth(newHealth, maxHealth);
_player.ShieldChanged += (newShield, maxShield) => _hud.UpdateShield(newShield, maxShield); _player.InteractableAreaEntered += (interactable) => _hud.UpdateInteractable(interactable);
}
else
{
GD.Print("No player and hud in scene");
return;
}
_player.InteractableAreaEntered += (interactable) => _hud.UpdateInteractable(interactable); if (_inventoryManager is not null)
} {
} _inventoryManager.ItemAdded += (LootItem item, int amount) =>
{
if (item.Item == ItemTypes.Weapon)
{
SpawnPlayerWeapon(item);
}
};
}
public void SpawnPlayer() SpawnWeapons();
{ }
if (_player != null) return;
//_player = this.CreateChild<PlayerMovement>(PlayerTemplate, PlayerSpawnMarker.Position );
_player = PlayerTemplate.Instantiate<PlayerMovement>();
this.CallDeferred("add_child", _player); public void SpawnPlayer()
_player.Transform = this.GlobalTransform; {
if (_player != null) return;
//_player = this.CreateChild<PlayerMovement>(PlayerTemplate, PlayerSpawnMarker.Position );
_player = PlayerTemplate.Instantiate<PlayerMovement>();
_player.GlobalPosition = PlayerSpawnMarker.Position; this.CallDeferred("add_child", _player);
_player.Transform = this.GlobalTransform;
CameraTargetPlayer(); _player.GlobalPosition = PlayerSpawnMarker.Position;
//
// if (_cameraTarget != null)
// {
// _cameraTarget.Reparent(_player, true);
// _cameraTarget.GlobalPosition = _player.Position;
// }
}
public void CameraTargetPlayer() CameraTargetPlayer();
{ //
if (_player is null) return; // if (_cameraTarget != null)
CameraTargetObject(_player); // {
} // _cameraTarget.Reparent(_player, true);
// _cameraTarget.GlobalPosition = _player.Position;
// }
}
public void CameraTargetObject(Node2D target) public void CameraTargetPlayer()
{ {
if (_cameraTarget is null) return; if (_player is null) return;
_cameraTarget.Reparent(target, true); CameraTargetObject(_player);
_cameraTarget.GlobalPosition = target.GlobalPosition; }
}
private void SpawnWeapons() public void CameraTargetObject(Node2D target)
{ {
if (!StartingEquipment.Any()) if (_cameraTarget is null) return;
{ _cameraTarget.Reparent(target, true);
GD.Print("No items to spawn on Player"); _cameraTarget.GlobalPosition = target.GlobalPosition;
return; }
}
foreach (var startingItem in StartingEquipment) private void SpawnWeapons()
{ {
switch (startingItem.Item) if (!StartingEquipment.Any())
{ {
case ItemTypes.Weapon: GD.Print("No items to spawn on Player");
if (WeaponTemplate == null) return;
{ }
GD.Print("Could not spawn weapon because template is null");
break;
}
var weapon = _player.CreateChild<Weapon>(WeaponTemplate);
weapon.WeaponData = startingItem.WeaponData;
_player.AddWeapon(weapon); foreach (var startingItem in StartingEquipment)
{
// Now automatically taken care of by the event
// switch (startingItem.Item)
// {
// case ItemTypes.Weapon:
// SpawnPlayerWeapon(startingItem);
//
// //_player.EquippedWeapon ??= weapon;
// break;
// }
if (_player.EquippedWeapon == null) _inventoryManager.AddItem(startingItem);
{ }
_player.EquipWeapon(weapon); }
}
//_player.EquippedWeapon ??= weapon; private void SpawnPlayerWeapon(LootItem startingItem)
break; {
} if (WeaponTemplate == null)
{
GD.Print("Could not spawn weapon because template is null");
return;
}
_inventoryManager.AddItem(startingItem); var weapon = _player.CreateChild<Weapon>(WeaponTemplate);
} weapon.WeaponData = startingItem.WeaponData;
}
private void SpawnBulletsContainer() _player.AddWeapon(weapon);
{
_bulletsContainer = new Node2D();
_bulletsContainer.Name = "BulletsContainer";
AddChild(_bulletsContainer); if (_player.EquippedWeapon == null)
} {
_player.EquipWeapon(weapon);
}
}
public void TogglePause() private void SpawnBulletsContainer()
{ {
if (GameState == GameState.Paused) _bulletsContainer = new Node2D();
{ _bulletsContainer.Name = "BulletsContainer";
Unpause();
}
else if (GameState == GameState.Playing)
{
Pause();
}
}
public void Pause() AddChild(_bulletsContainer);
{ }
if (GameState == GameState.Playing)
{
ChangeState(GameState.Paused);
}
}
public void Unpause() public void TogglePause()
{ {
if (GameState == GameState.Paused) if (GameState == GameState.Paused)
{ {
ChangeState(GameState.Playing); Unpause();
} }
} else if (GameState == GameState.Playing)
{
Pause();
}
}
public void ChangeState(GameState state) public void Pause()
{ {
if (state == GameState) return; if (GameState == GameState.Playing)
GameState = state; {
EmitSignal(nameof(GameStateChange), (int)GameState); ChangeState(GameState.Paused);
GD.Print($"Game state changed to {state}"); }
} }
public void Unpause()
{
if (GameState == GameState.Paused)
{
ChangeState(GameState.Playing);
}
}
public void ChangeState(GameState state)
{
if (state == GameState) return;
GameState = state;
EmitSignal(nameof(GameStateChange), (int)GameState);
GD.Print($"Game state changed to {state}");
}
} }
public enum GameState public enum GameState
{ {
Menu, Menu,
Paused, Paused,
Playing, Playing,
Dialogue Dialogue
} }

View file

@ -1,6 +1,7 @@
public interface IDestructible public interface IDestructible
{ {
public BulletOwner BulletGroup { get; set; }
public void Hit(float damage, DamageType type = DamageType.Neutral); public void Hit(float damage, DamageType type = DamageType.Neutral);
public bool IsDestroyed(); public bool IsDestroyed();
} }

View file

@ -60,7 +60,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
private InventoryManager _inventoryManager; private InventoryManager _inventoryManager;
[Export] public Sprite2D HitboxSprite { get; set; } [Export] public Sprite2D HitboxSprite { get; set; }
[Export] public BulletOwner BulletGroup { get; set; } = BulletOwner.Player;
private bool _isStrafing { get; set; } private bool _isStrafing { get; set; }
private bool _canMove = true; private bool _canMove = true;
@ -179,6 +179,16 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
} }
}*/ }*/
// public void ItemAdded(LootItem item, int amount)
// {
// switch (item.Item)
// {
// case ItemTypes.Weapon:
// AddWeapon(item.WeaponData);
// break;
// }
// }
public void AddWeapon(Weapon weapon) public void AddWeapon(Weapon weapon)
{ {
EquippedWeapons.Add(weapon); EquippedWeapons.Add(weapon);
@ -443,7 +453,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
private void _on_damage_hit_box_area_entered(Area2D area) private void _on_damage_hit_box_area_entered(Area2D area)
{ {
if (!_canMove) return; if (!_canMove) return;
if (area is Bullet bullet && bullet.BulletOwner != BulletOwner.Player) if (area is Bullet bullet && bullet.BulletOwner != BulletGroup)
{ {
this.Hit(bullet.Damage, bullet.DamageType); this.Hit(bullet.Damage, bullet.DamageType);
bullet.QueueFree(); bullet.QueueFree();

View file

@ -0,0 +1,12 @@
using Godot;
namespace Cirno.Scripts.Resources.Modifiers;
[GlobalClass]
public partial class DelayedContinuousRotationModifier : TimeModifier
{
public override void Update(Bullet bullet, double delta)
{
bullet.RotateSpriteDegrees((float)(Value * delta));
}
}

View file

@ -89,10 +89,11 @@ texture = ExtResource("1_70kxh")
4:0/0 = 0 4:0/0 = 0
5:0/0 = 0 5:0/0 = 0
6:0/0 = 0 6:0/0 = 0
6:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(8, -6, -6, -6, -6, 2, 8, 2) 6:0/0/physics_layer_1/polygon_0/points = PackedVector2Array(-6, -6, -6, 2, 8, 2, 8, -6)
7:0/0 = 0 7:0/0 = 0
7:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -6, 6, -6, 6, 2, -8, 2) 7:0/0/physics_layer_1/polygon_0/points = PackedVector2Array(-8, -6, -8, 2, 6, 2, 6, -6)
8:0/0 = 0 8:0/0 = 0
8:0/0/physics_layer_1/polygon_0/points = PackedVector2Array(-4, -6, -4, 8, 4, 8, 4, -6)
9:0/0 = 0 9:0/0 = 0
0:1/0 = 0 0:1/0 = 0
0:1/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_l8pdw") 0:1/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_l8pdw")
@ -110,6 +111,7 @@ texture = ExtResource("1_70kxh")
6:1/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_uanwu") 6:1/0/navigation_layer_0/polygon = SubResource("NavigationPolygon_uanwu")
7:1/0 = 0 7:1/0 = 0
8:1/0 = 0 8:1/0 = 0
8:1/0/physics_layer_1/polygon_0/points = PackedVector2Array(-4, -8, -4, 2, 4, 2, 4, -8)
9:1/0 = 0 9:1/0 = 0
0:2/animation_columns = 2 0:2/animation_columns = 2
0:2/animation_frame_0/duration = 1.0 0:2/animation_frame_0/duration = 1.0

View file

@ -223,6 +223,16 @@ use_item={
"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":85,"key_label":0,"unicode":117,"location":0,"echo":false,"script":null) "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":85,"key_label":0,"unicode":117,"location":0,"echo":false,"script":null)
] ]
} }
debug_camera_1={
"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":4194336,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
debug_camera_2={
"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":4194337,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
[layer_names] [layer_names]