mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 08:55:35 +00:00
Hitbox visible
This commit is contained in:
parent
88fb08a451
commit
0ccc272ada
10 changed files with 141 additions and 17 deletions
|
|
@ -55,6 +55,8 @@ one_shot = true
|
|||
BulletScene = ExtResource("2_ogldd")
|
||||
BulletCapacity = 4
|
||||
BulletSpeed = 50.0
|
||||
BulletsPerShot = 3
|
||||
BulletsSpreadAngle = 40.0
|
||||
|
||||
[node name="NavigationAgent2D" type="NavigationAgent2D" parent="."]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=27 format=3 uid="uid://bghghp5ep4w2j"]
|
||||
[gd_scene load_steps=28 format=3 uid="uid://bghghp5ep4w2j"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/PlayerMovement.cs" id="1_m27vu"]
|
||||
[ext_resource type="Texture2D" uid="uid://la06powu57hu" path="res://Sprites/Cirno_Big.png" id="2_bwf6x"]
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
[ext_resource type="PackedScene" uid="uid://chkpk7erlqajg" path="res://Scenes/Selector.tscn" id="3_8wt6s"]
|
||||
[ext_resource type="Script" path="res://addons/smoothing/smoothing_2d.gd" id="4_j4xhu"]
|
||||
[ext_resource type="PackedScene" uid="uid://cfb3nsay84xdb" path="res://Scenes/Weapons/crosshair.tscn" id="6_l43rf"]
|
||||
[ext_resource type="Texture2D" uid="uid://bf37ce6jskdel" path="res://Sprites/SmallHitbox.png" id="7_msn8i"]
|
||||
[ext_resource type="Script" path="res://Scenes/InteractionController.cs" id="7_uvgjg"]
|
||||
[ext_resource type="PackedScene" uid="uid://crry0rgk7a8sm" path="res://Scenes/Weapons/BaseWeapon.tscn" id="9_wblq0"]
|
||||
|
||||
|
|
@ -139,9 +140,9 @@ animations = [{
|
|||
radius = 17.2627
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_e6woi"]
|
||||
radius = 1.41421
|
||||
radius = 1.0
|
||||
|
||||
[node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("Muzzle", "EquippedWeapon") groups=["Destroyable", "player"]]
|
||||
[node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("Muzzle", "EquippedWeapon", "HitboxSprite") groups=["Destroyable", "player"]]
|
||||
collision_layer = 2
|
||||
collision_mask = 99
|
||||
script = ExtResource("1_m27vu")
|
||||
|
|
@ -151,6 +152,7 @@ SelectorScene = ExtResource("3_8wt6s")
|
|||
GameOverScene = "res://Scenes/GameOver.tscn"
|
||||
Muzzle = NodePath("Muzzle")
|
||||
EquippedWeapon = NodePath("Weapon")
|
||||
HitboxSprite = NodePath("Smoothing2D/HitboxSprite")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
|
|
@ -181,7 +183,11 @@ animation = &"walk_left"
|
|||
|
||||
[node name="Crosshair" parent="Smoothing2D" instance=ExtResource("6_l43rf")]
|
||||
|
||||
[node name="HitboxSprite" type="Sprite2D" parent="Smoothing2D"]
|
||||
texture = ExtResource("7_msn8i")
|
||||
|
||||
[node name="InteractionController" type="Area2D" parent="."]
|
||||
visible = false
|
||||
collision_layer = 2
|
||||
collision_mask = 4
|
||||
script = ExtResource("7_uvgjg")
|
||||
|
|
|
|||
|
|
@ -44,6 +44,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
private GameManager _gameManager;
|
||||
|
||||
[Export] public Sprite2D HitboxSprite { get; set; }
|
||||
|
||||
private bool _isStrafing { get; set; }
|
||||
|
||||
[Signal]
|
||||
|
|
@ -192,10 +194,30 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
}
|
||||
|
||||
// public override void _Draw()
|
||||
// {
|
||||
// if (_isStrafing)
|
||||
// {
|
||||
// HitboxSprite.Visible = true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// HitboxSprite.Visible = false;
|
||||
// }
|
||||
// base._Draw();
|
||||
// }
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
_movementDirection = GetInput();
|
||||
|
||||
_isStrafing = Input.IsActionPressed("strafe");
|
||||
// Toggle visibility of the hitbox sprite based on strafing
|
||||
if (HitboxSprite != null)
|
||||
{
|
||||
HitboxSprite.Visible = _isStrafing;
|
||||
}
|
||||
|
||||
_rightStickInput = GetRightStickInput();
|
||||
|
||||
// Update Facing Direction
|
||||
|
|
|
|||
|
|
@ -23,6 +23,11 @@ public partial class Weapon : Node2D
|
|||
[Export] public bool AutoReload = true;
|
||||
|
||||
[Export] public bool InfiniteAmmo = true;
|
||||
|
||||
[Export] public int BulletsPerShot = 1;
|
||||
|
||||
[Export] public float BulletsSpreadAngle = 0f;
|
||||
|
||||
public int Ammo { get; set; } = 0;
|
||||
|
||||
public int LoadedAmmo { get; private set; }
|
||||
|
|
@ -80,23 +85,32 @@ public partial class Weapon : Node2D
|
|||
}
|
||||
|
||||
// TODO: Shoot at muzzle position, need to provide a way to turn it, on a radius?
|
||||
// TODO: Create not as child but as standalone
|
||||
|
||||
// if (BulletScene == null) return;
|
||||
//
|
||||
// var newInstance = BulletScene.Instantiate<Bullet>();
|
||||
// _gameManager.BulletsContainer.CallDeferred("add_child", newInstance);
|
||||
|
||||
var bullet = this.CreateChildOf<Bullet>(_gameManager.BulletsContainer, BulletScene, _muzzle.GlobalPosition);
|
||||
|
||||
if (bullet == null)
|
||||
{
|
||||
GD.PrintErr("Bullet is null, not shooting");
|
||||
return;
|
||||
};
|
||||
float halfSpread = BulletsSpreadAngle / 2f;
|
||||
float spreadStep = BulletsPerShot > 1 ? BulletsSpreadAngle / (BulletsPerShot - 1) : 0;
|
||||
|
||||
|
||||
bullet.SetDirection(ShootDirection);
|
||||
bullet.Speed = BulletSpeed;
|
||||
for (int i = 0; i < BulletsPerShot; i++)
|
||||
{
|
||||
// Calculate angle offset for this bullet
|
||||
float spreadOffset = -halfSpread + (spreadStep * i);
|
||||
|
||||
// Rotate the ShootDirection by the spread angle
|
||||
Vector2 spreadDirection = ShootDirection.Rotated(Mathf.DegToRad(spreadOffset));
|
||||
|
||||
|
||||
var bullet = this.CreateChildOf<Bullet>(_gameManager.BulletsContainer, BulletScene, _muzzle.GlobalPosition);
|
||||
|
||||
if (bullet == null)
|
||||
{
|
||||
GD.PrintErr("Bullet is null, not shooting");
|
||||
return;
|
||||
};
|
||||
|
||||
//bullet.SetDirection(ShootDirection);
|
||||
bullet.SetDirection(spreadDirection);
|
||||
bullet.Speed = BulletSpeed;
|
||||
}
|
||||
|
||||
LoadedAmmo -= 1;
|
||||
|
||||
|
|
|
|||
BIN
Sprites/Hitbox.aseprite
(Stored with Git LFS)
Normal file
BIN
Sprites/Hitbox.aseprite
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Sprites/Hitbox.png
(Stored with Git LFS)
Normal file
BIN
Sprites/Hitbox.png
(Stored with Git LFS)
Normal file
Binary file not shown.
34
Sprites/Hitbox.png.import
Normal file
34
Sprites/Hitbox.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://b6sx61lte2s8b"
|
||||
path="res://.godot/imported/Hitbox.png-f56dac3171bc251935bb76ec82c19051.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Sprites/Hitbox.png"
|
||||
dest_files=["res://.godot/imported/Hitbox.png-f56dac3171bc251935bb76ec82c19051.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
Sprites/SmallHitbox.aseprite
(Stored with Git LFS)
Normal file
BIN
Sprites/SmallHitbox.aseprite
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Sprites/SmallHitbox.png
(Stored with Git LFS)
Normal file
BIN
Sprites/SmallHitbox.png
(Stored with Git LFS)
Normal file
Binary file not shown.
34
Sprites/SmallHitbox.png.import
Normal file
34
Sprites/SmallHitbox.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bf37ce6jskdel"
|
||||
path="res://.godot/imported/SmallHitbox.png-03b8e18b0a68a463319a17855b03e809.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Sprites/SmallHitbox.png"
|
||||
dest_files=["res://.godot/imported/SmallHitbox.png-03b8e18b0a68a463319a17855b03e809.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
|
||||
Loading…
Add table
Add a link
Reference in a new issue