ArcherTower and Arrows
This commit is contained in:
85
Game/Towers/archer_tower.tscn
Normal file
85
Game/Towers/archer_tower.tscn
Normal file
@ -0,0 +1,85 @@
|
||||
[gd_scene load_steps=12 format=3 uid="uid://brugqnquwjrkt"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://fxf6wd4317fb" path="res://Assets/Towers/4.png" id="1_1544k"]
|
||||
[ext_resource type="Script" uid="uid://dil41a1ymo0ua" path="res://Game/Towers/towers.gd" id="1_ssiuv"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ssiuv"]
|
||||
atlas = ExtResource("1_1544k")
|
||||
region = Rect2(0, 0, 70, 130)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_be2t6"]
|
||||
atlas = ExtResource("1_1544k")
|
||||
region = Rect2(70, 0, 70, 130)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ambw7"]
|
||||
atlas = ExtResource("1_1544k")
|
||||
region = Rect2(140, 0, 70, 130)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_mkf4u"]
|
||||
atlas = ExtResource("1_1544k")
|
||||
region = Rect2(210, 0, 70, 130)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_wwkyq"]
|
||||
atlas = ExtResource("1_1544k")
|
||||
region = Rect2(280, 0, 70, 130)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_e1la6"]
|
||||
atlas = ExtResource("1_1544k")
|
||||
region = Rect2(350, 0, 70, 130)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_xrf6u"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_ssiuv")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_be2t6")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_ambw7")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_mkf4u")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_wwkyq")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_e1la6")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"default",
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_ssiuv"]
|
||||
radius = 29.0
|
||||
height = 88.0
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_be2t6"]
|
||||
radius = 238.134
|
||||
|
||||
[node name="ArcherTower" type="Node2D"]
|
||||
script = ExtResource("1_ssiuv")
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="CharacterBody2D"]
|
||||
sprite_frames = SubResource("SpriteFrames_xrf6u")
|
||||
autoplay = "default"
|
||||
frame_progress = 0.157334
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
||||
position = Vector2(0, 17)
|
||||
shape = SubResource("CapsuleShape2D_ssiuv")
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="CharacterBody2D"]
|
||||
position = Vector2(2, 20)
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D/Area2D"]
|
||||
shape = SubResource("CircleShape2D_be2t6")
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
autostart = true
|
55
Game/Towers/towers.gd
Normal file
55
Game/Towers/towers.gd
Normal file
@ -0,0 +1,55 @@
|
||||
extends Node2D
|
||||
|
||||
var shootingTime = 0
|
||||
|
||||
var follower = false
|
||||
var target = null
|
||||
|
||||
const ARROW = preload("res://Game/Bullets/arrow.tscn")
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
follower = true
|
||||
get_node("CharacterBody2D/Area2D").connect("body_entered", Callable(self, "choose_target"))
|
||||
get_node("Timer").timeout.connect(shoot)
|
||||
set_process_input(true)
|
||||
set_properties()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if follower:
|
||||
position = get_viewport().get_mouse_position()
|
||||
if not target:
|
||||
if get_node("CharacterBody2D/Area2D").get_overlapping_bodies():
|
||||
choose_target(null)
|
||||
|
||||
func set_properties() -> void:
|
||||
if self.name.contains("ArcherTower"):
|
||||
get_node("Timer").wait_time = 0.8
|
||||
|
||||
|
||||
func get_if_moving_state():
|
||||
return follower
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
||||
if abs(position) <= get_viewport().get_mouse_position():
|
||||
follower = false
|
||||
|
||||
func choose_target(body : Node2D) -> void:
|
||||
var surroinding_enemies = get_node("CharacterBody2D/Area2D").get_overlapping_bodies()
|
||||
target = surroinding_enemies[0]
|
||||
for i in surroinding_enemies:
|
||||
if i.get_parent().get_progress() > target.get_parent().get_progress():
|
||||
target = i
|
||||
pass
|
||||
|
||||
func shoot() -> void:
|
||||
if target != null:
|
||||
if self.name.contains("ArcherTower"):
|
||||
var arrow = ARROW.instantiate()
|
||||
arrow.position = self.position
|
||||
arrow.set_speed(250)
|
||||
arrow.set_targe(target)
|
||||
arrow.set_hitpoint(50)
|
||||
get_parent().add_child(arrow)
|
||||
pass
|
1
Game/Towers/towers.gd.uid
Normal file
1
Game/Towers/towers.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://dil41a1ymo0ua
|
Reference in New Issue
Block a user