From c6da8d31ea873a518fd361e0b41c436f7b303644 Mon Sep 17 00:00:00 2001 From: toasterpanic Date: Sat, 16 May 2026 17:22:56 -0400 Subject: [PATCH] Add handcannon; need inventory system and the like to get it working properly --- scenes/inhands/basic_handcannon.tscn | 15 +++++ scenes/projectiles/bullet.tscn | 15 +++++ scripts/global.gd | 14 ++++- scripts/player.gd | 55 ++++++++++-------- textures/weapons/inhands/basic_handcannon.png | Bin 0 -> 377 bytes .../inhands/basic_handcannon.png.import | 40 +++++++++++++ 6 files changed, 113 insertions(+), 26 deletions(-) create mode 100644 scenes/inhands/basic_handcannon.tscn create mode 100644 scenes/projectiles/bullet.tscn create mode 100644 textures/weapons/inhands/basic_handcannon.png create mode 100644 textures/weapons/inhands/basic_handcannon.png.import diff --git a/scenes/inhands/basic_handcannon.tscn b/scenes/inhands/basic_handcannon.tscn new file mode 100644 index 0000000..be16603 --- /dev/null +++ b/scenes/inhands/basic_handcannon.tscn @@ -0,0 +1,15 @@ +[gd_scene format=3 uid="uid://ckfc4q1dbtli8"] + +[ext_resource type="Texture2D" uid="uid://5mkyjoxmci5a" path="res://textures/weapons/inhands/basic_handcannon.png" id="1_fig3b"] + +[node name="Handcannon" type="Node3D" unique_id=523683834] +transform = Transform3D(1, -7.642742e-15, -8.7422784e-08, 0, 1, -8.742278e-08, 8.7422784e-08, 8.742278e-08, 1, 0, 0, 0) + +[node name="Handcannon" type="Sprite3D" parent="." unique_id=1764590626] +transform = Transform3D(4.3711374e-08, -1, 8.7422755e-08, -1, -4.371136e-08, 1.748456e-07, -1.7484558e-07, -8.742276e-08, -1, 0, 0, 0) +offset = Vector2(-6, 5) +pixel_size = 0.03 +shaded = true +alpha_cut = 2 +texture_filter = 0 +texture = ExtResource("1_fig3b") diff --git a/scenes/projectiles/bullet.tscn b/scenes/projectiles/bullet.tscn new file mode 100644 index 0000000..801fd0c --- /dev/null +++ b/scenes/projectiles/bullet.tscn @@ -0,0 +1,15 @@ +[gd_scene format=3 uid="uid://ufm8kssdh8vx"] + +[node name="Bullet" type="Node3D" unique_id=1536641450] + +[node name="MeshInstance3D" type="CSGCylinder3D" parent="." unique_id=1706082204] +transform = Transform3D(4.371139e-08, -1, 8.742278e-08, -1, -4.371139e-08, 0, 3.821371e-15, -8.742278e-08, -1, 0, 0, 0) +radius = 0.05 +sides = 5 +smooth_faces = false + +[node name="Hit" type="RayCast3D" parent="." unique_id=10285465] +transform = Transform3D(-4.371139e-08, 1, -2.9802322e-08, 0, 2.9802322e-08, 1, 1, 4.371139e-08, -1.3027009e-15, 0, 0, 0) +target_position = Vector3(0, -500, 0) +collision_mask = 19 +debug_shape_custom_color = Color(0, 1, 0, 1) diff --git a/scripts/global.gd b/scripts/global.gd index 40a5b32..5e879d6 100644 --- a/scripts/global.gd +++ b/scripts/global.gd @@ -76,13 +76,25 @@ const weapons = { "attack_swooshy": "pierce", "attack_swooshy_scale": Vector3(1.5, 1, 1), }, + "basic_handcannon": { + "ranged_weapon": true, + "damage": 100, + "max_pierces": 3, + "knockback": 2.5, + "recharge_time": 15, + "bullet": preload("res://scenes/projectiles/bullet.tscn"), + + "attack_swooshy": "pierce", + "attack_swooshy_scale": Vector3(1.5, 1, 1), + } } const inhands = { "basic_sword": preload("res://scenes/inhands/basic_sword.tscn"), "basic_hammer": preload("res://scenes/inhands/basic_hammer.tscn"), "basic_knife": preload("res://scenes/inhands/basic_knife.tscn"), - "basic_spear": preload("res://scenes/inhands/basic_spear.tscn") + "basic_spear": preload("res://scenes/inhands/basic_spear.tscn"), + "basic_handcannon": preload("res://scenes/inhands/basic_handcannon.tscn") } const effects = { diff --git a/scripts/player.gd b/scripts/player.gd index be0f55d..2ad1f4b 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -63,7 +63,9 @@ func set_weapon(weapon_name: String = "basic_sword") -> void: $DreamerBody.set_inhand(current_weapon) var range = get_weapon_info(current_weapon, "range") + if not range: range = 1 var width = get_weapon_info(current_weapon, "width") + if not width: width = 1 $HitCollision/Shape.shape.size = Vector3(range, 1.0, width) @@ -229,35 +231,38 @@ func _process(delta: float) -> void: combo_hits = 0 - for body in hits: - if body == self: continue - - if ("health" in body) and (body.health > 0): - body.health -= damage + if get_my_weapon_info("ranged_weapon"): + pass + else: + for body in hits: + if body == self: continue - var knockback_pos = global_position - knockback_pos.y = 0 - var knockback_body_pos = $HitCollision/Shape.global_position - knockback_body_pos.y = 0 - - body.position.y += 0.2 - body.velocity.y = 0.4 - body.velocity += knockback_pos.direction_to(knockback_body_pos) * knockback - - if body.velocity.length() > knockback: - body.velocity = body.velocity.normalized() * knockback + if ("health" in body) and (body.health > 0): + body.health -= damage - if "mid_knockback" in body: - body.mid_knockback = true + var knockback_pos = global_position + knockback_pos.y = 0 + var knockback_body_pos = $HitCollision/Shape.global_position + knockback_body_pos.y = 0 - if "on_knockback" in body: - body.on_knockback() + body.position.y += 0.2 + body.velocity.y = 0.4 + body.velocity += knockback_pos.direction_to(knockback_body_pos) * knockback - var damage_text = preload("res://scenes/effects/damage_text.tscn").instantiate() - game.add_child(damage_text) - damage_text.global_position = body.global_position - damage_text.get_node("Label").text = str(floor(damage)) - + if body.velocity.length() > knockback: + body.velocity = body.velocity.normalized() * knockback + + if "mid_knockback" in body: + body.mid_knockback = true + + if "on_knockback" in body: + body.on_knockback() + + var damage_text = preload("res://scenes/effects/damage_text.tscn").instantiate() + game.add_child(damage_text) + damage_text.global_position = body.global_position + damage_text.get_node("Label").text = str(floor(damage)) + var direction = (camera.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() if dodging and (knockback_time <= 0): velocity.x = dodge_direction.x * 6 diff --git a/textures/weapons/inhands/basic_handcannon.png b/textures/weapons/inhands/basic_handcannon.png new file mode 100644 index 0000000000000000000000000000000000000000..698c661f11cd658cfce4904282c8a91bf6c80c38 GIT binary patch literal 377 zcmV-<0fzpGP)Px$Gf6~2R5*>*lQB!fKorM+=P3vZkq*+(3?)!1A~?F1iXi=fv`WIP}l*$l7hgGQu(DFEMh4Kz|6@@3uuaNer`PTA83B{3oT-vg>OCA1b#%(%@g>M*+Jk(SW+P4F)|)wNr5E=hb0>s zk0I+3i*BBmUYLmda27T