Mortar first act
This commit is contained in:
@ -5,6 +5,19 @@ var speed
|
||||
var hitpoint
|
||||
var distancetaken = 0
|
||||
|
||||
#For the mortar, to create a nice bezier curve!
|
||||
var starterpos = 0
|
||||
var targetpos = 0
|
||||
var midpoint = 0
|
||||
var t = 0.0
|
||||
var duration = 0.5
|
||||
|
||||
func _ready() -> void:
|
||||
starterpos = global_position
|
||||
targetpos = target.global_position
|
||||
midpoint = (targetpos + starterpos) / 2
|
||||
midpoint.y -= 200 #height of the curve!
|
||||
|
||||
func set_targe(_target : Node2D) -> void:
|
||||
target = _target
|
||||
|
||||
@ -14,8 +27,15 @@ func set_speed(_speed: int) -> void:
|
||||
func set_hitpoint(_hitpoint: int) -> void:
|
||||
hitpoint = _hitpoint
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if target and speed > 0:
|
||||
if name.contains("Rock"):
|
||||
t += delta / duration
|
||||
position = bezier(t)
|
||||
if t >= 1.0:
|
||||
get_node("CharacterBody2D/AnimatedSprite2D").play("hit")
|
||||
set_process(false)
|
||||
elif 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()
|
||||
|
||||
@ -44,8 +64,17 @@ func target_reached() -> void:
|
||||
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()
|
||||
|
||||
|
||||
func bezier(t: float):
|
||||
var q0 = starterpos.lerp(midpoint, t)
|
||||
var q1 = midpoint.lerp(targetpos, t)
|
||||
return q0.lerp(q1, t)
|
||||
|
||||
|
||||
|
||||
func _on_animated_sprite_2d_animation_finished() -> void:
|
||||
queue_free()
|
||||
|
59
Game/Bullets/rock.tscn
Normal file
59
Game/Bullets/rock.tscn
Normal file
@ -0,0 +1,59 @@
|
||||
[gd_scene load_steps=10 format=3 uid="uid://cwcgq1vk643ha"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dqvdgdobuo2rf" path="res://Game/Bullets/bullet.gd" id="1_yml18"]
|
||||
[ext_resource type="Texture2D" uid="uid://t8y1d33eiffp" path="res://Assets/Bullets/mortarbullet (1).png" id="2_yml18"]
|
||||
[ext_resource type="Texture2D" uid="uid://cinql8footbvf" path="res://Assets/Bullets/mortarbullet (2).png" id="3_tjven"]
|
||||
[ext_resource type="Texture2D" uid="uid://xm4gs3h00bk1" path="res://Assets/Bullets/mortarbullet (3).png" id="4_av0br"]
|
||||
[ext_resource type="Texture2D" uid="uid://crf32to6tlkux" path="res://Assets/Bullets/mortarbullet (4).png" id="5_c612l"]
|
||||
[ext_resource type="Texture2D" uid="uid://bbu8u4h7vpqwa" path="res://Assets/Bullets/mortarbullet (5).png" id="6_m5188"]
|
||||
[ext_resource type="Texture2D" uid="uid://uc2ib201l7kd" path="res://Assets/Bullets/mortarbullet (6).png" id="7_lr72h"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_yml18"]
|
||||
size = Vector2(18, 16)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_yml18"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("2_yml18")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"default",
|
||||
"speed": 2.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("3_tjven")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("4_av0br")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("5_c612l")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("6_m5188")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("7_lr72h")
|
||||
}],
|
||||
"loop": false,
|
||||
"name": &"hit",
|
||||
"speed": 8.0
|
||||
}]
|
||||
|
||||
[node name="Rock" type="Node2D"]
|
||||
script = ExtResource("1_yml18")
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
||||
shape = SubResource("RectangleShape2D_yml18")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="CharacterBody2D"]
|
||||
scale = Vector2(0.4, 0.4)
|
||||
sprite_frames = SubResource("SpriteFrames_yml18")
|
||||
autoplay = "default"
|
||||
|
||||
[connection signal="animation_finished" from="CharacterBody2D/AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"]
|
48
Game/Towers/mortar_tower.tscn
Normal file
48
Game/Towers/mortar_tower.tscn
Normal file
@ -0,0 +1,48 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://uqxd2lii1xba"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dil41a1ymo0ua" path="res://Game/Towers/towers.gd" id="1_bhlym"]
|
||||
[ext_resource type="Texture2D" uid="uid://dkgih7tl654v1" path="res://Assets/Towers/Mortar part (3).png" id="1_sq58r"]
|
||||
[ext_resource type="Texture2D" uid="uid://cm33n3xc81rpj" path="res://Assets/Towers/Mortar part (2).png" id="2_bhlym"]
|
||||
[ext_resource type="Texture2D" uid="uid://cxtluaplpd8hg" path="res://Assets/Towers/Mortar part (1).png" id="3_82ftk"]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_cfdf4"]
|
||||
radius = 29.0
|
||||
height = 88.0
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_bhlym"]
|
||||
size = Vector2(367.125, 172.25)
|
||||
|
||||
[node name="MortarTower" type="Node2D"]
|
||||
script = ExtResource("1_bhlym")
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
||||
position = Vector2(0, 17)
|
||||
shape = SubResource("CapsuleShape2D_cfdf4")
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="CharacterBody2D"]
|
||||
position = Vector2(2, 20)
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D/Area2D"]
|
||||
position = Vector2(-1, -68)
|
||||
shape = SubResource("RectangleShape2D_bhlym")
|
||||
|
||||
[node name="MortarPart(3)" type="Sprite2D" parent="CharacterBody2D"]
|
||||
position = Vector2(0.800001, 18.6)
|
||||
scale = Vector2(0.4, 0.4)
|
||||
texture = ExtResource("1_sq58r")
|
||||
|
||||
[node name="MortarPart(2)" type="Sprite2D" parent="CharacterBody2D"]
|
||||
position = Vector2(4.40004, 18)
|
||||
scale = Vector2(0.4, 0.4)
|
||||
texture = ExtResource("2_bhlym")
|
||||
|
||||
[node name="MortarPart(1)" type="Sprite2D" parent="CharacterBody2D"]
|
||||
position = Vector2(0.800001, 31.6)
|
||||
scale = Vector2(0.4, 0.4)
|
||||
texture = ExtResource("3_82ftk")
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
autostart = true
|
@ -9,10 +9,11 @@ var target = null
|
||||
|
||||
const ARROW = preload("res://Game/Bullets/arrow.tscn")
|
||||
const MAGIC = preload("res://Game/Bullets/magic.tscn")
|
||||
const ROCK = preload("res://Game/Bullets/rock.tscn")
|
||||
|
||||
func _ready() -> void:
|
||||
follower = true
|
||||
get_node("CharacterBody2D/Area2D").connect("body_entered", Callable(self, "choose_target"))
|
||||
get_node("CharacterBody2D/Area2D").body_entered.connect(choose_target)
|
||||
get_node("Timer").timeout.connect(shoot)
|
||||
set_process_input(true)
|
||||
set_properties()
|
||||
@ -33,6 +34,9 @@ func set_properties() -> void:
|
||||
get_node("Timer").wait_time = 2.0
|
||||
bulletSpeed = 450
|
||||
hitpoint = 10
|
||||
if self.name.contains("MortarTower"): #??? not sure if necessary yet
|
||||
get_node("Timer").wait_time = 5
|
||||
hitpoint = 10
|
||||
|
||||
func get_if_moving_state():
|
||||
return follower
|
||||
@ -46,11 +50,11 @@ func choose_target(body : Node2D) -> void:
|
||||
if not follower:
|
||||
var surroinding_enemies = get_node("CharacterBody2D/Area2D").get_overlapping_bodies()
|
||||
target = surroinding_enemies[0]
|
||||
if self.name.contains("ArcherTower") or self.name.contains("BombTower"):
|
||||
if self.name.contains("ArcherTower"):
|
||||
for i in surroinding_enemies:
|
||||
if i.get_parent().get_progress() > target.get_parent().get_progress():
|
||||
target = i
|
||||
if self.name.contains("WizardTower"):
|
||||
if self.name.contains("WizardTower") or self.name.contains("MortarTower"):
|
||||
for i in surroinding_enemies:
|
||||
if i.get_parent().get_progress() < target.get_parent().get_progress():
|
||||
target = i
|
||||
@ -60,6 +64,7 @@ func shoot() -> void:
|
||||
if target != null:
|
||||
if self.name.contains("ArcherTower"):
|
||||
var arrow = ARROW.instantiate()
|
||||
arrow.name = "Arrow" + str(randi())
|
||||
arrow.position = self.position
|
||||
arrow.set_speed(bulletSpeed)
|
||||
arrow.set_targe(target)
|
||||
@ -68,9 +73,20 @@ func shoot() -> void:
|
||||
|
||||
if self.name.contains("WizardTower"):
|
||||
var magic = MAGIC.instantiate()
|
||||
magic.name = "Magic" + str(randi())
|
||||
magic.position = self.position
|
||||
magic.set_speed(bulletSpeed)
|
||||
magic.set_targe(target)
|
||||
magic.set_hitpoint(hitpoint)
|
||||
get_parent().add_child(magic)
|
||||
|
||||
if self.name.contains("MortarTower"):
|
||||
var rock = ROCK.instantiate()
|
||||
rock.name = "Rock" + str(randi())
|
||||
rock.position = self.position
|
||||
rock.set_speed(bulletSpeed)
|
||||
rock.set_targe(target)
|
||||
rock.set_hitpoint(hitpoint)
|
||||
get_parent().add_child(rock)
|
||||
|
||||
pass
|
||||
|
@ -17,6 +17,8 @@ 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")
|
||||
|
||||
@onready var mortartowerspawn: Button = $HBoxContainer4/HBoxContainer2/Button4
|
||||
const MORTAR_TOWER = preload("res://Game/Towers/mortar_tower.tscn")
|
||||
|
||||
@onready var delete_tower_button: Button = $HBoxContainer4/HBoxContainer5/Button4
|
||||
const DELETER = preload("res://Game/Accesories/deleter.tscn")
|
||||
@ -29,6 +31,7 @@ func _ready() -> void:
|
||||
wallspawner.connect("button_down", Spawn_Wall)
|
||||
archertowerspawn.connect("button_up", Spawn_Archer)
|
||||
wizardtowerspawn.connect("button_up", Spawn_wizard)
|
||||
mortartowerspawn.connect("button_up", Spawn_Mortar)
|
||||
delete_tower_button.connect("button_up", Spawn_Deleter)
|
||||
|
||||
func set_Lifes(amount) -> void:
|
||||
@ -71,6 +74,12 @@ func Spawn_wizard() -> void:
|
||||
tower.name = "WizardTower-" + str(randi())
|
||||
get_parent().add_child(tower)
|
||||
pass
|
||||
|
||||
func Spawn_Mortar() -> void:
|
||||
var tower = MORTAR_TOWER.instantiate()
|
||||
tower.name = "MortarTower-" + str(randi())
|
||||
get_parent().add_child(tower)
|
||||
pass
|
||||
|
||||
func Spawn_Deleter() -> void:
|
||||
var deleter = DELETER.instantiate()
|
||||
|
Reference in New Issue
Block a user