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="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/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"]
script = ExtResource("1_ys2v3")
@ -17,7 +25,7 @@ spread = 360.0
owner = 2
_damageType = 0
_bulletDamage = 1.0
_timeModifiers = null
_timeModifiers = Array[Object]([SubResource("Resource_n6wfp")])
_targetPlayer = false
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="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"]
[resource]
script = ExtResource("2_m8dps")
Name = "Icicle Gun"
BulletData = ExtResource("1_85ef1")
BulletScene = ExtResource("1_yby7n")
DestructionParticlesScene = ExtResource("2_icuny")
RateOfFire = 0.1
BulletCapacity = 4
ReloadTime = 0.2
@ -20,10 +16,4 @@ BulletsPerShot = 1
SpreadAngle = 0.0
RandomSpread = 0.0
AmmoKey = ""
BulletSpeed = 300.0
BulletDamage = 1.0
LifeTime = 10.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 BulletResource ExplosionData { get; set; }
[Export] public BulletOwner BulletGroup { get; set; } = BulletOwner.None;
private GameManager _gameManager;
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]
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
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
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"]
[node name="IcicleGun" type="Area2D"]
[node name="IcicleGun" type="Area2D" groups=["Interactable"]]
collision_layer = 4
collision_mask = 2
script = ExtResource("1_rdvi1")
LootTable = [ExtResource("2_6qt07")]

View file

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

View file

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

View file

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

View file

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

View file

@ -59,8 +59,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
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 _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)
{
EquippedWeapons.Add(weapon);
@ -443,7 +453,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
private void _on_damage_hit_box_area_entered(Area2D area)
{
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);
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
5: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/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/physics_layer_1/polygon_0/points = PackedVector2Array(-4, -6, -4, 8, 4, 8, 4, -6)
9:0/0 = 0
0:1/0 = 0
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")
7: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
0:2/animation_columns = 2
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)
]
}
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]