Wave generation redesign
This commit is contained in:
14
Game/Maps/Map1_setup.gd
Normal file
14
Game/Maps/Map1_setup.gd
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
var waves = [
|
||||||
|
[
|
||||||
|
[10, 0.2, 0.8, 0.2, 0.0], #wave 1 #First path
|
||||||
|
[20, 0.4, 0.5, 0.5, 0.0], #wave 2
|
||||||
|
[30, 0.5, 0.4, 0.4, 0.1], #wave 3
|
||||||
|
[40, 0.8, 0.3, 0.2, 0.5], #wave 4
|
||||||
|
[50, 0.9, 0.1, 0.2, 0.7], #wave 5
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
var lives = 20
|
||||||
|
var coins = 500
|
1
Game/Maps/Map1_setup.gd.uid
Normal file
1
Game/Maps/Map1_setup.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://btn404qyu6kop
|
21
Game/Maps/Map2_setup.gd
Normal file
21
Game/Maps/Map2_setup.gd
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
var waves = [
|
||||||
|
[
|
||||||
|
[10, 0.2, 0.8, 0.2, 0.0], #wave 1 #First path
|
||||||
|
[20, 0.4, 0.5, 0.5, 0.0], #wave 2
|
||||||
|
[30, 0.5, 0.4, 0.4, 0.1], #wave 3
|
||||||
|
[40, 0.8, 0.3, 0.2, 0.5], #wave 4
|
||||||
|
[50, 0.9, 0.1, 0.2, 0.7], #wave 5
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[5, 0.1, 0.8, 0.2, 0.0], #wave 1 #Second Path
|
||||||
|
[10, 0.2, 0.5, 0.5, 0.0], #wave 2
|
||||||
|
[20, 0.3, 0.4, 0.4, 0.1], #wave 3
|
||||||
|
[30, 0.4, 0.3, 0.2, 0.5], #wave 4
|
||||||
|
[40, 0.7, 0.1, 0.2, 0.7], #wave 5
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
var lives = 20
|
||||||
|
var coins = 500
|
1
Game/Maps/Map2_setup.gd.uid
Normal file
1
Game/Maps/Map2_setup.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://dd08u1htj4jwb
|
@ -1,75 +0,0 @@
|
|||||||
extends Node2D
|
|
||||||
|
|
||||||
@onready var path_2d: Path2D = $Path2D
|
|
||||||
|
|
||||||
const FORKMAN = preload("res://Game/Mobs/forkman.tscn")
|
|
||||||
const ORK = preload("res://Game/Mobs/ork.tscn")
|
|
||||||
const COBOLD = preload("res://Game/Mobs/cobold.tscn")
|
|
||||||
|
|
||||||
const enemies = [FORKMAN, COBOLD, ORK]
|
|
||||||
|
|
||||||
var pause = 40
|
|
||||||
func _ready() -> void:
|
|
||||||
get_node("CanvasLayer/SidePanel").set_Lifes(20)
|
|
||||||
get_node("CanvasLayer/SidePanel").Update_Coins(250)
|
|
||||||
|
|
||||||
|
|
||||||
#the meaning of the columns inside my wave generation matris:
|
|
||||||
# Number of enemies need to be spawned, chance of spawn an enemy, chance of forkman, chance of gobline, chance of ork
|
|
||||||
var waves = [
|
|
||||||
[10, 0.2, 0.8, 0.2, 0.0], #wave 1
|
|
||||||
[20, 0.4, 0.5, 0.5, 0.0], #wave 2
|
|
||||||
[30, 0.5, 0.4, 0.4, 0.1], #wave 3
|
|
||||||
[40, 0.8, 0.3, 0.2, 0.5], #wave 4
|
|
||||||
[50, 0.9, 0.1, 0.2, 0.7], #wave 5
|
|
||||||
]
|
|
||||||
|
|
||||||
var currentwave = 0
|
|
||||||
var endwave = false
|
|
||||||
|
|
||||||
func _on_timer_timeout() -> void:
|
|
||||||
if pause <= 0:
|
|
||||||
if endwave:
|
|
||||||
if not get_node("Path2D").get_children():
|
|
||||||
endwave = false
|
|
||||||
get_node("CanvasLayer/SidePanel").Update_waves(currentwave + 1) #updating waves
|
|
||||||
if currentwave >= 4: #!!!!! CHECKS FOR THE LAST WAVE IF NEW WAVES ARE ADDED CHANGE ACCORDINGLY!!!
|
|
||||||
get_node("CanvasLayer/SidePanel").GameWon()
|
|
||||||
else:
|
|
||||||
spawnMonster()
|
|
||||||
else:
|
|
||||||
pause -= 1
|
|
||||||
|
|
||||||
func spawnMonster():
|
|
||||||
for w in waves:
|
|
||||||
if w[0] > 0:
|
|
||||||
if randf() < w[1]: #chance of generating any kind of enemy
|
|
||||||
w[0] -= 1
|
|
||||||
if w[0] <= 0:
|
|
||||||
endwave = true
|
|
||||||
currentwave += 1
|
|
||||||
var chosen = randf()
|
|
||||||
var sum = 0.0
|
|
||||||
for i in range(2,5):
|
|
||||||
sum += w[i]
|
|
||||||
if chosen < sum:
|
|
||||||
var monster = enemies[i-2].instantiate()
|
|
||||||
var path = PathFollow2D.new()
|
|
||||||
path.add_child(monster)
|
|
||||||
path_2d.add_child(path)
|
|
||||||
break
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
func decrease_life(damage) -> void:
|
|
||||||
get_node("CanvasLayer/SidePanel").Update_Lifes(-damage)
|
|
||||||
if get_node("CanvasLayer/SidePanel").get_Lifes() <= 0:
|
|
||||||
game_over()
|
|
||||||
|
|
||||||
|
|
||||||
func game_over()-> void:
|
|
||||||
get_node("Timer").stop()
|
|
||||||
var enemy = get_node("Path2D").get_children()
|
|
||||||
for i in enemy:
|
|
||||||
i.get_children()[0].set_process(false)
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
|||||||
[gd_scene load_steps=186 format=4 uid="uid://dql8q1od3r32h"]
|
[gd_scene load_steps=187 format=4 uid="uid://dql8q1od3r32h"]
|
||||||
|
|
||||||
[ext_resource type="Texture2D" uid="uid://f1npbjsw71nk" path="res://Assets/Tiles/Fields/FieldsTile_01.png" id="1_fdpq6"]
|
[ext_resource type="Texture2D" uid="uid://f1npbjsw71nk" path="res://Assets/Tiles/Fields/FieldsTile_01.png" id="1_fdpq6"]
|
||||||
[ext_resource type="Script" uid="uid://xo6vbicdva8d" path="res://Game/Maps/map_1.gd" id="1_rec5e"]
|
[ext_resource type="Script" uid="uid://xo6vbicdva8d" path="res://Game/Maps/map_managger.gd" id="1_rec5e"]
|
||||||
[ext_resource type="Texture2D" uid="uid://becu21re40tp3" path="res://Assets/Tiles/Fields/FieldsTile_02.png" id="2_cckt8"]
|
[ext_resource type="Texture2D" uid="uid://becu21re40tp3" path="res://Assets/Tiles/Fields/FieldsTile_02.png" id="2_cckt8"]
|
||||||
[ext_resource type="Texture2D" uid="uid://b1l385grogi2h" path="res://Assets/Decors/5 Grass/3.png" id="2_h3dak"]
|
[ext_resource type="Texture2D" uid="uid://b1l385grogi2h" path="res://Assets/Decors/5 Grass/3.png" id="2_h3dak"]
|
||||||
[ext_resource type="Texture2D" uid="uid://d31pjsbv4tdeo" path="res://Assets/Decors/4 Stone/6.png" id="2_rcusf"]
|
[ext_resource type="Texture2D" uid="uid://d31pjsbv4tdeo" path="res://Assets/Decors/4 Stone/6.png" id="2_rcusf"]
|
||||||
@ -112,6 +112,7 @@
|
|||||||
[ext_resource type="PackedScene" uid="uid://c5r8h61c73dwv" path="res://Game/music_player.tscn" id="68_hg5c4"]
|
[ext_resource type="PackedScene" uid="uid://c5r8h61c73dwv" path="res://Game/music_player.tscn" id="68_hg5c4"]
|
||||||
[ext_resource type="Texture2D" uid="uid://e1fkqo6mryto" path="res://Assets/Decors/4 Stone/8.png" id="111_xx2jp"]
|
[ext_resource type="Texture2D" uid="uid://e1fkqo6mryto" path="res://Assets/Decors/4 Stone/8.png" id="111_xx2jp"]
|
||||||
[ext_resource type="Texture2D" uid="uid://c5cshf3uwarcy" path="res://Assets/Decors/4 Stone/1.png" id="112_skmhh"]
|
[ext_resource type="Texture2D" uid="uid://c5cshf3uwarcy" path="res://Assets/Decors/4 Stone/1.png" id="112_skmhh"]
|
||||||
|
[ext_resource type="Script" uid="uid://btn404qyu6kop" path="res://Game/Maps/Map1_setup.gd" id="113_skmhh"]
|
||||||
|
|
||||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_3uxyt"]
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_3uxyt"]
|
||||||
texture = ExtResource("1_fdpq6")
|
texture = ExtResource("1_fdpq6")
|
||||||
@ -531,7 +532,6 @@ size = Vector2(163, 334)
|
|||||||
script = ExtResource("1_rec5e")
|
script = ExtResource("1_rec5e")
|
||||||
|
|
||||||
[node name="Decoration" type="Node2D" parent="."]
|
[node name="Decoration" type="Node2D" parent="."]
|
||||||
visible = false
|
|
||||||
|
|
||||||
[node name="6" type="Sprite2D" parent="Decoration"]
|
[node name="6" type="Sprite2D" parent="Decoration"]
|
||||||
position = Vector2(386, 348)
|
position = Vector2(386, 348)
|
||||||
@ -1599,4 +1599,7 @@ size_flags_horizontal = 6
|
|||||||
|
|
||||||
[node name="MusicPlayer" parent="." instance=ExtResource("68_hg5c4")]
|
[node name="MusicPlayer" parent="." instance=ExtResource("68_hg5c4")]
|
||||||
|
|
||||||
|
[node name="Setup" type="Node" parent="."]
|
||||||
|
script = ExtResource("113_skmhh")
|
||||||
|
|
||||||
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
|
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
|
||||||
|
1604
Game/Maps/map_1.tscn260300348.tmp
Normal file
1604
Game/Maps/map_1.tscn260300348.tmp
Normal file
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
|||||||
uid://cjoybvdfv0bk7
|
|
@ -1,6 +1,6 @@
|
|||||||
[gd_scene load_steps=185 format=4 uid="uid://bgme05i7taycc"]
|
[gd_scene load_steps=187 format=4 uid="uid://bgme05i7taycc"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://cjoybvdfv0bk7" path="res://Game/Maps/map_2.gd" id="1_qncs7"]
|
[ext_resource type="Script" uid="uid://xo6vbicdva8d" path="res://Game/Maps/map_managger.gd" id="1_qncs7"]
|
||||||
[ext_resource type="Texture2D" uid="uid://d31pjsbv4tdeo" path="res://Assets/Decors/4 Stone/6.png" id="2_djmha"]
|
[ext_resource type="Texture2D" uid="uid://d31pjsbv4tdeo" path="res://Assets/Decors/4 Stone/6.png" id="2_djmha"]
|
||||||
[ext_resource type="Texture2D" uid="uid://clpu8vcccw0n5" path="res://Assets/Decors/4 Stone/5.png" id="3_mb7u5"]
|
[ext_resource type="Texture2D" uid="uid://clpu8vcccw0n5" path="res://Assets/Decors/4 Stone/5.png" id="3_mb7u5"]
|
||||||
[ext_resource type="Texture2D" uid="uid://qq72i50enwfg" path="res://Assets/Decors/4 Stone/4.png" id="4_s0w1w"]
|
[ext_resource type="Texture2D" uid="uid://qq72i50enwfg" path="res://Assets/Decors/4 Stone/4.png" id="4_s0w1w"]
|
||||||
@ -109,6 +109,7 @@
|
|||||||
[ext_resource type="Texture2D" uid="uid://bof7eh3ttmi2f" path="res://Assets/Tiles/Fields/FieldsTile_64.png" id="109_jjtad"]
|
[ext_resource type="Texture2D" uid="uid://bof7eh3ttmi2f" path="res://Assets/Tiles/Fields/FieldsTile_64.png" id="109_jjtad"]
|
||||||
[ext_resource type="Texture2D" uid="uid://do3u4pgcgn7g3" path="res://Assets/Castles/Asset 27.png" id="110_fb8td"]
|
[ext_resource type="Texture2D" uid="uid://do3u4pgcgn7g3" path="res://Assets/Castles/Asset 27.png" id="110_fb8td"]
|
||||||
[ext_resource type="PackedScene" uid="uid://ddn64i6logtw0" path="res://Game/sidepanel.tscn" id="111_2ej3d"]
|
[ext_resource type="PackedScene" uid="uid://ddn64i6logtw0" path="res://Game/sidepanel.tscn" id="111_2ej3d"]
|
||||||
|
[ext_resource type="Script" uid="uid://dd08u1htj4jwb" path="res://Game/Maps/Map2_setup.gd" id="111_qncs7"]
|
||||||
[ext_resource type="PackedScene" uid="uid://c5r8h61c73dwv" path="res://Game/music_player.tscn" id="112_yc4f2"]
|
[ext_resource type="PackedScene" uid="uid://c5r8h61c73dwv" path="res://Game/music_player.tscn" id="112_yc4f2"]
|
||||||
|
|
||||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_3uxyt"]
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_3uxyt"]
|
||||||
@ -525,13 +526,16 @@ size = Vector2(1163, 13)
|
|||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_n3ya7"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_n3ya7"]
|
||||||
size = Vector2(915.093, 2.34375)
|
size = Vector2(915.093, 2.34375)
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_xfegu"]
|
||||||
|
size = Vector2(992, 0.656128)
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_4tlg5"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_4tlg5"]
|
||||||
size = Vector2(1161, 2)
|
size = Vector2(1161, 2)
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_sglle"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_sglle"]
|
||||||
size = Vector2(163, 153)
|
size = Vector2(163, 153)
|
||||||
|
|
||||||
[node name="Map1" type="Node2D"]
|
[node name="Map2" type="Node2D"]
|
||||||
script = ExtResource("1_qncs7")
|
script = ExtResource("1_qncs7")
|
||||||
|
|
||||||
[node name="Decoration" type="Node2D" parent="."]
|
[node name="Decoration" type="Node2D" parent="."]
|
||||||
@ -1607,8 +1611,8 @@ position = Vector2(350.453, 206)
|
|||||||
shape = SubResource("RectangleShape2D_n3ya7")
|
shape = SubResource("RectangleShape2D_n3ya7")
|
||||||
|
|
||||||
[node name="CollisionShape2D3" type="CollisionShape2D" parent="TowerArea"]
|
[node name="CollisionShape2D3" type="CollisionShape2D" parent="TowerArea"]
|
||||||
position = Vector2(639.969, 361.828)
|
position = Vector2(616, 360.328)
|
||||||
shape = SubResource("RectangleShape2D_n3ya7")
|
shape = SubResource("RectangleShape2D_xfegu")
|
||||||
|
|
||||||
[node name="CollisionShape2D4" type="CollisionShape2D" parent="TowerArea"]
|
[node name="CollisionShape2D4" type="CollisionShape2D" parent="TowerArea"]
|
||||||
position = Vector2(579, 521)
|
position = Vector2(579, 521)
|
||||||
@ -1625,4 +1629,7 @@ size_flags_horizontal = 6
|
|||||||
|
|
||||||
[node name="MusicPlayer" parent="." instance=ExtResource("112_yc4f2")]
|
[node name="MusicPlayer" parent="." instance=ExtResource("112_yc4f2")]
|
||||||
|
|
||||||
|
[node name="Setup" type="Node" parent="."]
|
||||||
|
script = ExtResource("111_qncs7")
|
||||||
|
|
||||||
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
|
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
@onready var path_2d: Path2D = $Path2D
|
var paths = []
|
||||||
@onready var path_2d_2: Path2D = $Path2D2
|
var waves = []
|
||||||
@onready var paths = [path_2d, path_2d_2]
|
|
||||||
|
|
||||||
const FORKMAN = preload("res://Game/Mobs/forkman.tscn")
|
const FORKMAN = preload("res://Game/Mobs/forkman.tscn")
|
||||||
const ORK = preload("res://Game/Mobs/ork.tscn")
|
const ORK = preload("res://Game/Mobs/ork.tscn")
|
||||||
@ -12,31 +11,22 @@ const enemies = [FORKMAN, COBOLD, ORK]
|
|||||||
|
|
||||||
var pause = 40
|
var pause = 40
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
get_node("CanvasLayer/SidePanel").set_Lifes(20)
|
get_node("CanvasLayer/SidePanel").set_Lifes(get_node("Setup").lives)
|
||||||
get_node("CanvasLayer/SidePanel").Update_Coins(500)
|
get_node("CanvasLayer/SidePanel").Update_Coins(get_node("Setup").coins)
|
||||||
|
for i in self.get_children():
|
||||||
|
if i.name.contains("Path2D"):
|
||||||
|
paths.append(i)
|
||||||
|
waves = get_node("Setup").waves
|
||||||
|
print(waves)
|
||||||
|
print(paths)
|
||||||
|
|
||||||
#the meaning of the columns inside my wave generation matris:
|
#the meaning of the columns inside my wave generation matris:
|
||||||
# Number of enemies need to be spawned, chance of spawn an enemy, chance of forkman, chance of gobline, chance of ork
|
# Number of enemies need to be spawned, chance of spawn an enemy, chance of forkman, chance of gobline, chance of ork
|
||||||
var waves = [
|
|
||||||
[
|
|
||||||
[10, 0.2, 0.8, 0.2, 0.0], #wave 1 #First path
|
|
||||||
[20, 0.4, 0.5, 0.5, 0.0], #wave 2
|
|
||||||
[30, 0.5, 0.4, 0.4, 0.1], #wave 3
|
|
||||||
[40, 0.8, 0.3, 0.2, 0.5], #wave 4
|
|
||||||
[50, 0.9, 0.1, 0.2, 0.7], #wave 5
|
|
||||||
],
|
|
||||||
[
|
|
||||||
[5, 0.1, 0.8, 0.2, 0.0], #wave 1 #Second Path
|
|
||||||
[10, 0.2, 0.5, 0.5, 0.0], #wave 2
|
|
||||||
[20, 0.3, 0.4, 0.4, 0.1], #wave 3
|
|
||||||
[30, 0.4, 0.3, 0.2, 0.5], #wave 4
|
|
||||||
[40, 0.7, 0.1, 0.2, 0.7], #wave 5
|
|
||||||
]
|
|
||||||
]
|
|
||||||
|
|
||||||
var currentwave = 0
|
var currentwave = 0
|
||||||
var endwave = false
|
var endwave = false
|
||||||
|
|
||||||
|
|
||||||
func _on_timer_timeout() -> void:
|
func _on_timer_timeout() -> void:
|
||||||
if pause <= 0:
|
if pause <= 0:
|
||||||
if endwave:
|
if endwave:
|
||||||
@ -44,10 +34,13 @@ func _on_timer_timeout() -> void:
|
|||||||
for i in paths:
|
for i in paths:
|
||||||
if not i.get_children():
|
if not i.get_children():
|
||||||
checkend = true
|
checkend = true
|
||||||
|
currentwave += 1
|
||||||
if checkend:
|
if checkend:
|
||||||
endwave = false
|
endwave = false
|
||||||
get_node("CanvasLayer/SidePanel").Update_waves(currentwave + 1) #updating waves
|
get_node("CanvasLayer/SidePanel").Update_waves(currentwave + 1) #updating waves
|
||||||
if currentwave >= 4: #!!!!! CHECKS FOR THE LAST WAVE IF NEW WAVES ARE ADDED CHANGE ACCORDINGLY!!!
|
if currentwave >= waves[0].size():
|
||||||
|
currentwave -= 1
|
||||||
|
get_node("Timer").stop()
|
||||||
get_node("CanvasLayer/SidePanel").GameWon()
|
get_node("CanvasLayer/SidePanel").GameWon()
|
||||||
else:
|
else:
|
||||||
spawnMonster()
|
spawnMonster()
|
||||||
@ -55,16 +48,17 @@ func _on_timer_timeout() -> void:
|
|||||||
pause -= 1
|
pause -= 1
|
||||||
|
|
||||||
func spawnMonster():
|
func spawnMonster():
|
||||||
for ROUTE in range(2):
|
for ROUTE in range(waves.size()):
|
||||||
for w in waves[ROUTE]:
|
var w = waves[ROUTE][currentwave]
|
||||||
|
print("Rout enumber: ",ROUTE," Array of wave: ",w, " Wave indexer: ", currentwave)
|
||||||
if w[0] > 0:
|
if w[0] > 0:
|
||||||
if randf() < w[1]: #chance of generating any kind of enemy
|
if randf() < w[1]: #chance of generating any kind of enemy
|
||||||
w[0] -= 1
|
w[0] -= 1
|
||||||
for i in waves:
|
for i in waves:
|
||||||
|
print("Check for wave ends: ",i[currentwave])
|
||||||
if i[currentwave][0] > 0:
|
if i[currentwave][0] > 0:
|
||||||
break
|
break
|
||||||
endwave = true
|
endwave = true
|
||||||
currentwave += 1
|
|
||||||
var chosen = randf()
|
var chosen = randf()
|
||||||
var sum = 0.0
|
var sum = 0.0
|
||||||
for i in range(2,5):
|
for i in range(2,5):
|
||||||
@ -75,7 +69,6 @@ func spawnMonster():
|
|||||||
path.add_child(monster)
|
path.add_child(monster)
|
||||||
paths[ROUTE].add_child(path)
|
paths[ROUTE].add_child(path)
|
||||||
break
|
break
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
func decrease_life(damage) -> void:
|
func decrease_life(damage) -> void:
|
Reference in New Issue
Block a user