Wizard Tower and special effects
This commit is contained in:
@ -1,4 +0,0 @@
|
||||
extends Node2D
|
||||
|
||||
func _ready() -> void:
|
||||
print("ready")
|
@ -1 +0,0 @@
|
||||
uid://b3dcdgqfb5nf3
|
@ -3,6 +3,7 @@ extends Node2D
|
||||
var target
|
||||
var speed
|
||||
var hitpoint
|
||||
var distancetaken = 0
|
||||
|
||||
func set_targe(_target : Node2D) -> void:
|
||||
target = _target
|
||||
@ -19,17 +20,32 @@ func _process(delta: float) -> void:
|
||||
var direction = (target.get_parent().get_parent().get_position() - position).normalized()
|
||||
|
||||
# Rotate the bullet to face the target
|
||||
rotation = direction.angle() + deg_to_rad(90)
|
||||
if name.contains("Arrow"):
|
||||
rotation = direction.angle() + deg_to_rad(90)
|
||||
|
||||
# Move the bullet towards the target
|
||||
position += direction * speed * delta
|
||||
distancetaken += (direction * speed * delta).length()
|
||||
|
||||
if position.distance_to(target.get_parent().get_parent().position) <= 5:
|
||||
target_reached()
|
||||
if distancetaken > 250:
|
||||
queue_free()
|
||||
else:
|
||||
queue_free()
|
||||
|
||||
|
||||
|
||||
func target_reached() -> void:
|
||||
var chance = 0
|
||||
if name.contains("Arrow"): #special effects here!
|
||||
if randf() < 0.1:
|
||||
target.get_parent().set_speed(target.get_parent().get_speed() / 2)
|
||||
pass
|
||||
if name.contains("Magic"):
|
||||
if randf() < 0.5:
|
||||
target.get_parent().set_progress(max(target.get_parent().get_progress() - 60, 0))
|
||||
|
||||
|
||||
|
||||
target.get_parent().enemy_hurt(hitpoint)
|
||||
queue_free()
|
||||
|
68
Game/Bullets/magic.tscn
Normal file
68
Game/Bullets/magic.tscn
Normal file
@ -0,0 +1,68 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://caynrq7jnjlnx"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://mmrsjrjxv168" path="res://Assets/Bullets/magic.png" id="1_jjep1"]
|
||||
[ext_resource type="Script" uid="uid://dqvdgdobuo2rf" path="res://Game/Bullets/bullet.gd" id="1_lj5pp"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_lj5pp"]
|
||||
size = Vector2(18, 16)
|
||||
|
||||
[sub_resource type="Animation" id="Animation_lj5pp"]
|
||||
resource_name = "rotation"
|
||||
length = 0.5
|
||||
markers = [{
|
||||
"color": Color(1, 1, 1, 1),
|
||||
"name": &"new_marker",
|
||||
"time": 0.5
|
||||
}]
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:rotation")
|
||||
tracks/0/interp = 2
|
||||
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_0itbo"]
|
||||
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_55qby"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_0itbo"),
|
||||
&"rotation": SubResource("Animation_lj5pp")
|
||||
}
|
||||
|
||||
[node name="Magic" type="Node2D"]
|
||||
script = ExtResource("1_lj5pp")
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
||||
shape = SubResource("RectangleShape2D_lj5pp")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="CharacterBody2D"]
|
||||
libraries = {
|
||||
&"": SubResource("AnimationLibrary_55qby")
|
||||
}
|
||||
autoplay = "rotation"
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="CharacterBody2D"]
|
||||
scale = Vector2(3, 3)
|
||||
texture = ExtResource("1_jjep1")
|
@ -122,6 +122,7 @@ func AnimatedSprite2D_animation_finished() -> void:
|
||||
if animated_sprite.animation == "hurt":
|
||||
animated_sprite.play("walk")
|
||||
|
||||
|
||||
func Collision_Handler(body: Node2D):
|
||||
if body.get_parent().name.contains("StickTrap"):
|
||||
if not body.get_parent().get_if_moving_state():
|
||||
@ -140,3 +141,11 @@ func Collision_Handler(body: Node2D):
|
||||
func get_progress():
|
||||
return get_parent().get_progress()
|
||||
|
||||
func set_progress(amount) -> void:
|
||||
get_parent().set_progress(amount)
|
||||
|
||||
func get_speed():
|
||||
return speed
|
||||
|
||||
func set_speed(nspeed) -> void:
|
||||
speed = nspeed
|
||||
|
@ -8,7 +8,7 @@ var follower = false
|
||||
var target = null
|
||||
|
||||
const ARROW = preload("res://Game/Bullets/arrow.tscn")
|
||||
|
||||
const MAGIC = preload("res://Game/Bullets/magic.tscn")
|
||||
|
||||
func _ready() -> void:
|
||||
follower = true
|
||||
@ -26,10 +26,13 @@ func _process(delta: float) -> void:
|
||||
|
||||
func set_properties() -> void:
|
||||
if self.name.contains("ArcherTower"):
|
||||
get_node("Timer").wait_time = 0.8
|
||||
bulletSpeed = 400
|
||||
hitpoint = 50
|
||||
|
||||
get_node("Timer").wait_time = 0.5
|
||||
bulletSpeed = 600
|
||||
hitpoint = 25
|
||||
if self.name.contains("WizardTower"):
|
||||
get_node("Timer").wait_time = 2.0
|
||||
bulletSpeed = 450
|
||||
hitpoint = 10
|
||||
|
||||
func get_if_moving_state():
|
||||
return follower
|
||||
@ -43,9 +46,14 @@ func choose_target(body : Node2D) -> void:
|
||||
if not follower:
|
||||
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
|
||||
if self.name.contains("ArcherTower") or self.name.contains("BombTower"):
|
||||
for i in surroinding_enemies:
|
||||
if i.get_parent().get_progress() > target.get_parent().get_progress():
|
||||
target = i
|
||||
if self.name.contains("WizardTower"):
|
||||
for i in surroinding_enemies:
|
||||
if i.get_parent().get_progress() < target.get_parent().get_progress():
|
||||
target = i
|
||||
pass
|
||||
|
||||
func shoot() -> void:
|
||||
@ -57,4 +65,12 @@ func shoot() -> void:
|
||||
arrow.set_targe(target)
|
||||
arrow.set_hitpoint(hitpoint)
|
||||
get_parent().add_child(arrow)
|
||||
|
||||
if self.name.contains("WizardTower"):
|
||||
var magic = MAGIC.instantiate()
|
||||
magic.position = self.position
|
||||
magic.set_speed(bulletSpeed)
|
||||
magic.set_targe(target)
|
||||
magic.set_hitpoint(hitpoint)
|
||||
get_parent().add_child(magic)
|
||||
pass
|
||||
|
89
Game/Towers/wizard_tower.tscn
Normal file
89
Game/Towers/wizard_tower.tscn
Normal file
@ -0,0 +1,89 @@
|
||||
[gd_scene load_steps=12 format=3 uid="uid://b4e605q60lde4"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dil41a1ymo0ua" path="res://Game/Towers/towers.gd" id="1_grwc8"]
|
||||
[ext_resource type="Texture2D" uid="uid://dngrpwmj4oedg" path="res://Assets/Towers/S_Fly.png" id="2_grwc8"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_35u2c"]
|
||||
atlas = ExtResource("2_grwc8")
|
||||
region = Rect2(0, 0, 96, 96)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_fpdhp"]
|
||||
atlas = ExtResource("2_grwc8")
|
||||
region = Rect2(96, 0, 96, 96)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_mo8k5"]
|
||||
atlas = ExtResource("2_grwc8")
|
||||
region = Rect2(192, 0, 96, 96)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_uxuma"]
|
||||
atlas = ExtResource("2_grwc8")
|
||||
region = Rect2(288, 0, 96, 96)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_l7hme"]
|
||||
atlas = ExtResource("2_grwc8")
|
||||
region = Rect2(384, 0, 96, 96)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_pvyvx"]
|
||||
atlas = ExtResource("2_grwc8")
|
||||
region = Rect2(480, 0, 96, 96)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_pvyvx"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_35u2c")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_fpdhp")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_mo8k5")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_uxuma")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_l7hme")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_pvyvx")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"Default",
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_hcema"]
|
||||
radius = 29.0
|
||||
height = 88.0
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_c5q70"]
|
||||
radius = 183.044
|
||||
|
||||
[node name="WizardTower" type="Node2D"]
|
||||
script = ExtResource("1_grwc8")
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="CharacterBody2D"]
|
||||
position = Vector2(1, 13)
|
||||
scale = Vector2(1.5, 1.5)
|
||||
sprite_frames = SubResource("SpriteFrames_pvyvx")
|
||||
animation = &"Default"
|
||||
autoplay = "Default"
|
||||
frame_progress = 0.265757
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
||||
position = Vector2(0, 17)
|
||||
shape = SubResource("CapsuleShape2D_hcema")
|
||||
|
||||
[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_c5q70")
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
wait_time = 2.0
|
||||
autostart = true
|
@ -12,10 +12,14 @@ const MINE = preload("res://Game/Traps/mine.tscn")
|
||||
@onready var archertowerspawn: Button = $HBoxContainer4/HBoxContainer2/Button2
|
||||
const ARCHER_TOWER = preload("res://Game/Towers/archer_tower.tscn")
|
||||
|
||||
@onready var wizardtowerspawn: Button = $HBoxContainer4/HBoxContainer2/Button3
|
||||
const WIZARD_TOWER = preload("res://Game/Towers/wizard_tower.tscn")
|
||||
|
||||
func _ready() -> void:
|
||||
stickspawner.connect("button_up", Spawn_Stick)
|
||||
minespawner.connect("button_up", Spawn_Mine)
|
||||
archertowerspawn.connect("button_down", Spawn_Archer)
|
||||
archertowerspawn.connect("button_up", Spawn_Archer)
|
||||
wizardtowerspawn.connect("button_up", Spawn_wizard)
|
||||
|
||||
func Update_Lives(lives) -> void:
|
||||
livelabel.text = "Lives: " + str(lives)
|
||||
@ -35,3 +39,9 @@ func Spawn_Archer() -> void:
|
||||
tower.name = "ArcherTower-" + str(randi())
|
||||
get_parent().add_child(tower)
|
||||
pass
|
||||
|
||||
func Spawn_wizard() -> void:
|
||||
var tower = WIZARD_TOWER.instantiate()
|
||||
tower.name = "WizardTower-" + str(randi())
|
||||
get_parent().add_child(tower)
|
||||
pass
|
||||
|
Reference in New Issue
Block a user