-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using `tween.tween_method` for axe object periodic rotation
- Loading branch information
1 parent
f9ac782
commit d042371
Showing
8 changed files
with
165 additions
and
2 deletions.
There are no files selected for viewing
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
34
2d-survivors-course/scenes/ability/axe_ability/axe.png.import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
2d-survivors-course/scenes/ability/axe_ability/axe_ability.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
62
2d-survivors-course/scenes/ability/axe_ability/axe_ability.tscn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
26 changes: 26 additions & 0 deletions
26
2d-survivors-course/scenes/ability/axe_ability_controller/axe_ability_controller.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
12 changes: 12 additions & 0 deletions
12
2d-survivors-course/scenes/ability/axe_ability_controller/axe_ability_controller.tscn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters