diff options
author | altaf-creator <dev@altafcreator.com> | 2025-10-20 01:43:48 +0800 |
---|---|---|
committer | altaf-creator <dev@altafcreator.com> | 2025-10-20 01:43:48 +0800 |
commit | 466bec0b724632f6dd2e1555a7bd58ffc1dd0458 (patch) | |
tree | d6645ea11914edeec645299fa497a9e542dbaec7 /Scripts/Weapons |
Jam version.
Diffstat (limited to 'Scripts/Weapons')
-rw-r--r-- | Scripts/Weapons/Bow.gd | 22 | ||||
-rw-r--r-- | Scripts/Weapons/Bow.gd.uid | 1 | ||||
-rw-r--r-- | Scripts/Weapons/Melee.gd | 35 | ||||
-rw-r--r-- | Scripts/Weapons/Melee.gd.uid | 1 | ||||
-rw-r--r-- | Scripts/Weapons/Projectile.gd | 19 | ||||
-rw-r--r-- | Scripts/Weapons/Projectile.gd.uid | 1 |
6 files changed, 79 insertions, 0 deletions
diff --git a/Scripts/Weapons/Bow.gd b/Scripts/Weapons/Bow.gd new file mode 100644 index 0000000..09ffa3c --- /dev/null +++ b/Scripts/Weapons/Bow.gd @@ -0,0 +1,22 @@ +extends Node2D + +@export var arrow : PackedScene +@export var speed : float + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass + +func action() -> void: + var pivot = get_node("../../") + var new = arrow.instantiate() + new.init_vel = Vector2.DOWN.rotated(pivot.rotation) * speed + new.global_position = global_position + var normalised = new.init_vel.normalized() + new.sprite.rotation = atan2(normalised.y, normalised.x) + get_tree().get_root().get_node("Node2D").add_child(new) diff --git a/Scripts/Weapons/Bow.gd.uid b/Scripts/Weapons/Bow.gd.uid new file mode 100644 index 0000000..07daad8 --- /dev/null +++ b/Scripts/Weapons/Bow.gd.uid @@ -0,0 +1 @@ +uid://bfmc8st4ss7om diff --git a/Scripts/Weapons/Melee.gd b/Scripts/Weapons/Melee.gd new file mode 100644 index 0000000..33f2807 --- /dev/null +++ b/Scripts/Weapons/Melee.gd @@ -0,0 +1,35 @@ +extends Node2D + +@export var animator : AnimationPlayer +@export var atk : int +@export var area : Area2D +@export var knock : Vector2 = Vector2(700, -300) +@export_flags_2d_physics var mask +@export var disable_aft_atk : bool = false + +func _ready() -> void: + area.collision_mask = mask + +#func _process(_delta: float) -> void: +# if area.monitoring: +# modulate = Color.GREEN +# else: +# modulate = Color.WHITE + +func action() -> void: + if animator.is_playing(): + return + + area.monitoring = true + + if scale.x < 0: + animator.play("swing_flip") + else: + animator.play("swing") + +func _on_area_2d_body_entered(body:Node2D) -> void: + if body is Entity: + body.damage(atk) + if disable_aft_atk: area.set_deferred("monitoring", false) + if scale.x < 0: body.knockback = Vector2(-knock.x, knock.y) + else: body.knockback = knock diff --git a/Scripts/Weapons/Melee.gd.uid b/Scripts/Weapons/Melee.gd.uid new file mode 100644 index 0000000..7b405a9 --- /dev/null +++ b/Scripts/Weapons/Melee.gd.uid @@ -0,0 +1 @@ +uid://ckd00ra2lp1xo diff --git a/Scripts/Weapons/Projectile.gd b/Scripts/Weapons/Projectile.gd new file mode 100644 index 0000000..fa13c70 --- /dev/null +++ b/Scripts/Weapons/Projectile.gd @@ -0,0 +1,19 @@ +extends RigidBody2D + +@export var init_vel : Vector2 +@export var sprite : Node2D +@export var atk : int + +func _ready() -> void: + linear_velocity = init_vel + print(linear_velocity.normalized()) + +func _process(delta: float) -> void: + var normalised = linear_velocity.normalized() + sprite.rotation = atan2(normalised.y, normalised.x) + +func _on_area_2d_body_entered(body:Node2D) -> void: + print(body) + if body is Entity: + body.damage(atk) + queue_free() diff --git a/Scripts/Weapons/Projectile.gd.uid b/Scripts/Weapons/Projectile.gd.uid new file mode 100644 index 0000000..9bc33ba --- /dev/null +++ b/Scripts/Weapons/Projectile.gd.uid @@ -0,0 +1 @@ +uid://i4wpiugtk5qi |