ArcherTower and Arrows
This commit is contained in:
BIN
Assets/Bullets/arrow.png
Normal file
BIN
Assets/Bullets/arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 970 B |
34
Assets/Bullets/arrow.png.import
Normal file
34
Assets/Bullets/arrow.png.import
Normal file
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bqdblby54pv2s"
|
||||
path="res://.godot/imported/arrow.png-356b4401c295e7e562eff933a2cd1c46.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Assets/Bullets/arrow.png"
|
||||
dest_files=["res://.godot/imported/arrow.png-356b4401c295e7e562eff933a2cd1c46.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
|
19
Game/Bullets/arrow.tscn
Normal file
19
Game/Bullets/arrow.tscn
Normal file
@ -0,0 +1,19 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://bjihbmnkq0n3b"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://bqdblby54pv2s" path="res://Assets/Bullets/arrow.png" id="1_v0wue"]
|
||||
[ext_resource type="Script" uid="uid://dqvdgdobuo2rf" path="res://Game/Bullets/bullet.gd" id="1_wft0c"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_wft0c"]
|
||||
size = Vector2(3, 16)
|
||||
|
||||
[node name="Arrow" type="Node2D"]
|
||||
script = ExtResource("1_wft0c")
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
||||
shape = SubResource("RectangleShape2D_wft0c")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="CharacterBody2D"]
|
||||
texture = ExtResource("1_v0wue")
|
35
Game/Bullets/bullet.gd
Normal file
35
Game/Bullets/bullet.gd
Normal file
@ -0,0 +1,35 @@
|
||||
extends Node2D
|
||||
|
||||
var target
|
||||
var speed
|
||||
var hitpoint
|
||||
|
||||
func set_targe(_target : Node2D) -> void:
|
||||
target = _target
|
||||
|
||||
func set_speed(_speed: int) -> void:
|
||||
speed = _speed
|
||||
|
||||
func set_hitpoint(_hitpoint: int) -> void:
|
||||
hitpoint = _hitpoint
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if target and speed > 0:
|
||||
# Get the direction vector from the bullet to the target
|
||||
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)
|
||||
|
||||
# Move the bullet towards the target
|
||||
position += direction * speed * delta
|
||||
|
||||
if position.distance_to(target.get_parent().get_parent().position) <= 5:
|
||||
target_reached()
|
||||
else:
|
||||
queue_free()
|
||||
|
||||
|
||||
func target_reached() -> void:
|
||||
target.get_parent().enemy_hurt(hitpoint)
|
||||
queue_free()
|
1
Game/Bullets/bullet.gd.uid
Normal file
1
Game/Bullets/bullet.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://dqvdgdobuo2rf
|
@ -8,7 +8,7 @@ const COBOLD = preload("res://Game/Mobs/cobold.tscn")
|
||||
|
||||
const enemies = [FORKMAN, COBOLD, ORK]
|
||||
|
||||
var lives = 2
|
||||
var lives = 20
|
||||
|
||||
func _ready() -> void:
|
||||
get_node("SidePanel").Update_Lives(lives)
|
||||
@ -27,7 +27,7 @@ func spawnMonster():
|
||||
func decrease_life(damage) -> void:
|
||||
lives -= damage
|
||||
get_node("SidePanel").Update_Lives(lives)
|
||||
if lives == 0:
|
||||
if lives <= 0:
|
||||
game_over()
|
||||
|
||||
func game_over()-> void:
|
||||
|
@ -195,6 +195,7 @@ corner_radius_bottom_left = 20
|
||||
script = ExtResource("1_ssdee")
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
|
||||
collision_layer = 3
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="CharacterBody2D"]
|
||||
position = Vector2(10, 0)
|
||||
|
@ -49,16 +49,19 @@ func move_character(delta: float) -> void:
|
||||
func set_character_data():
|
||||
match self.name:
|
||||
"Forkman":
|
||||
self.name = "Forkman-" + str(randi())
|
||||
speed = 120
|
||||
health = 100
|
||||
shield = 100
|
||||
damage = 2
|
||||
"Ork":
|
||||
self.name = "Ork-" + str(randi())
|
||||
speed = 80
|
||||
health = 150
|
||||
shield = 100
|
||||
damage = 5
|
||||
"Cobold":
|
||||
self.name = "Cobold-" + str(randi())
|
||||
speed = 200
|
||||
health = 50
|
||||
shield = 0
|
||||
@ -132,3 +135,7 @@ func Collision_Handler(body: Node2D):
|
||||
enemy_hurt(100)
|
||||
body.get_parent().Explode_Mine()
|
||||
|
||||
|
||||
func get_progress():
|
||||
return get_parent().get_progress()
|
||||
|
||||
|
@ -196,6 +196,7 @@ corner_radius_bottom_left = 20
|
||||
script = ExtResource("1_pq2md")
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
|
||||
collision_layer = 3
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
||||
scale = Vector2(0.5, 0.5)
|
||||
|
@ -195,6 +195,7 @@ corner_radius_bottom_left = 20
|
||||
script = ExtResource("1_1ecd4")
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
|
||||
collision_layer = 3
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="CharacterBody2D"]
|
||||
position = Vector2(10, 0)
|
||||
|
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
|
@ -8,9 +8,14 @@ const STICK_TRAP = preload("res://Game/Traps/stick_trap.tscn")
|
||||
@onready var minespawner: Button = $HBoxContainer4/HBoxContainer4/Button3
|
||||
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")
|
||||
|
||||
func _ready() -> void:
|
||||
stickspawner.connect("button_up", Spawn_Stick)
|
||||
minespawner.connect("button_up", Spawn_Mine)
|
||||
archertowerspawn.connect("button_down", Spawn_Archer)
|
||||
|
||||
func Update_Lives(lives) -> void:
|
||||
livelabel.text = "Lives: " + str(lives)
|
||||
@ -24,3 +29,9 @@ func Spawn_Mine() -> void:
|
||||
var mine = MINE.instantiate()
|
||||
mine.name = "Mine-" + str(randi())
|
||||
get_parent().add_child(mine)
|
||||
|
||||
func Spawn_Archer() -> void:
|
||||
var tower = ARCHER_TOWER.instantiate()
|
||||
tower.name = "ArcherTower-" + str(randi())
|
||||
get_parent().add_child(tower)
|
||||
pass
|
||||
|
Reference in New Issue
Block a user