Skip to content

Commit

Permalink
axe ability addition
Browse files Browse the repository at this point in the history
using `tween.tween_method` for axe object periodic rotation
  • Loading branch information
KartikWatts committed Jan 14, 2024
1 parent f9ac782 commit d042371
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 2 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions 2d-survivors-course/scenes/ability/axe_ability/axe.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://1xy63jrq5t73"
path="res://.godot/imported/axe.png-d9061886615e248b8d314bf004885af3.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://scenes/ability/axe_ability/axe.png"
dest_files=["res://.godot/imported/axe.png-d9061886615e248b8d314bf004885af3.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
27 changes: 27 additions & 0 deletions 2d-survivors-course/scenes/ability/axe_ability/axe_ability.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class_name AxeAbility
extends Node2D

const MAX_RADIUS = 100

var base_rotation = Vector2.RIGHT

@onready var hitbox_component = $HitBoxComponent as HitBoxComponent

func _ready():
base_rotation = Vector2.RIGHT.rotated(randf_range(0, TAU))

var tween = create_tween()
tween.tween_method(tween_method, 0.0, 2.0, 3)
tween.tween_callback(queue_free)


func tween_method(rotations: float):
var percent = rotations/2
var current_radius = percent * MAX_RADIUS
var current_direction = base_rotation.rotated(rotations * TAU)

var player = get_tree().get_first_node_in_group("player") as Node2D
if player == null:
return

global_position = player.global_position + (current_direction * current_radius)
62 changes: 62 additions & 0 deletions 2d-survivors-course/scenes/ability/axe_ability/axe_ability.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[gd_scene load_steps=8 format=3 uid="uid://cho20enadvyon"]

[ext_resource type="Script" path="res://scenes/ability/axe_ability/axe_ability.gd" id="1_1stjv"]
[ext_resource type="Texture2D" uid="uid://1xy63jrq5t73" path="res://scenes/ability/axe_ability/axe.png" id="1_bk8an"]
[ext_resource type="PackedScene" uid="uid://bknastfsr6crs" path="res://scenes/components/hit_box_component.tscn" id="3_nl63r"]

[sub_resource type="Animation" id="Animation_st3fe"]
resource_name = "default"
length = 0.5
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:rotation")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [0.0, 6.28319]
}

[sub_resource type="Animation" id="Animation_u3jpg"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:rotation")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [0.0]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_qh2gr"]
_data = {
"RESET": SubResource("Animation_u3jpg"),
"default": SubResource("Animation_st3fe")
}

[sub_resource type="CircleShape2D" id="CircleShape2D_dcqud"]

[node name="AxeAbility" type="Node2D"]
script = ExtResource("1_1stjv")

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_qh2gr")
}
autoplay = "default"

[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("1_bk8an")

[node name="HitBoxComponent" parent="." instance=ExtResource("3_nl63r")]

[node name="CollisionShape2D" type="CollisionShape2D" parent="HitBoxComponent"]
shape = SubResource("CircleShape2D_dcqud")
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
extends Node

@export var axe_ability_scene: PackedScene

@onready var _timer = $Timer as Timer

var damage = 10


func _ready():
_timer.timeout.connect(on_timer_timeout)


func on_timer_timeout():
var player = get_tree().get_first_node_in_group("player") as Node2D
if player == null:
return

var foreground = get_tree().get_first_node_in_group("foreground_layer") as Node2D
if foreground == null:
return

var axe_instance = axe_ability_scene.instantiate() as AxeAbility
foreground.add_child(axe_instance)
axe_instance.global_position = player.global_position
axe_instance.hitbox_component.damage = damage
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[gd_scene load_steps=3 format=3 uid="uid://boy7qngqg2m2i"]

[ext_resource type="Script" path="res://scenes/ability/axe_ability_controller/axe_ability_controller.gd" id="1_pv8qt"]
[ext_resource type="PackedScene" uid="uid://cho20enadvyon" path="res://scenes/ability/axe_ability/axe_ability.tscn" id="2_e7ppc"]

[node name="AxeAbilityController" type="Node"]
script = ExtResource("1_pv8qt")
axe_ability_scene = ExtResource("2_e7ppc")

[node name="Timer" type="Timer" parent="."]
wait_time = 2.0
autostart = true
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ extends Node
var damage = 5
var base_wait_time

# Called when the node enters the scene tree for the first time.
func _ready():
base_wait_time = timer.wait_time
#get_node("Timer")
Expand Down
5 changes: 4 additions & 1 deletion 2d-survivors-course/scenes/game_object/player/player.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[gd_scene load_steps=10 format=3 uid="uid://c2o7ggmbuyq3b"]
[gd_scene load_steps=11 format=3 uid="uid://c2o7ggmbuyq3b"]

[ext_resource type="Script" path="res://scenes/game_object/player/player.gd" id="1_6ggdr"]
[ext_resource type="Texture2D" uid="uid://c3oci8ridauxg" path="res://scenes/game_object/player/player.png" id="2_1v84t"]
[ext_resource type="Script" path="res://scenes/components/health_component.gd" id="2_lfgfj"]
[ext_resource type="PackedScene" uid="uid://crwtyhsq062wk" path="res://scenes/ability/sword_ability_controller/sword_ability_controller.tscn" id="2_moccb"]
[ext_resource type="PackedScene" uid="uid://boy7qngqg2m2i" path="res://scenes/ability/axe_ability_controller/axe_ability_controller.tscn" id="4_uqevh"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_bkthj"]
bg_color = Color(0.247059, 0.14902, 0.192157, 1)
Expand Down Expand Up @@ -37,6 +38,8 @@ script = ExtResource("2_lfgfj")

[node name="SwordAbilityController" parent="AbilityManager" instance=ExtResource("2_moccb")]

[node name="AxeAbilityController" parent="AbilityManager" instance=ExtResource("4_uqevh")]

[node name="DamageIntervalTimer" type="Timer" parent="."]
wait_time = 0.5
one_shot = true
Expand Down

0 comments on commit d042371

Please sign in to comment.