Added Wincondition and button to transition to winscreen, also changed spawnbehavior of new heroes

This commit is contained in:
Streamfire
2020-04-20 16:51:57 +02:00
parent 2fde998542
commit d0d5ded6f8
2 changed files with 47 additions and 5 deletions

View File

@@ -1,16 +1,38 @@
extends Node2D
export(int) var WinRounds= 10
export(PackedScene) var HeroTemplate
export(Vector2) var Spawnpoint=Vector2(344,125)
export(Vector2) var InitialSpawnPoint=Vector2(344,125)
export(Rect2) var SpawnBoxRange=Rect2(20,20,450,180)
export(float) var MinDistanceToBoss=100.0
var round_counter=0
var passed_final_Round=false
func _ready():
randomize()
spawn_new_hero(Spawnpoint.x,Spawnpoint.y)
pass # Replace with function body.
var point = determine_spawnpoint()
spawn_new_hero(point.x,point.y)
#spawn_new_hero(InitialSpawnPoint.x,InitialSpawnPoint.y)
func determine_spawnpoint():
var point = Vector2(rand_range(SpawnBoxRange.position.x,SpawnBoxRange.position.x+SpawnBoxRange.size.x),rand_range(SpawnBoxRange.position.y,SpawnBoxRange.position.y+SpawnBoxRange.size.y))
while(point.distance_to($YSort/SlimeBoss.position)<MinDistanceToBoss):
point = Vector2(rand_range(SpawnBoxRange.position.x,SpawnBoxRange.position.x+SpawnBoxRange.size.x),rand_range(SpawnBoxRange.position.y,SpawnBoxRange.position.y+SpawnBoxRange.size.y))
return point
func hero_has_died():
round_counter+=1
if (round_counter>=WinRounds and passed_final_Round ==false):
passed_final_Round=true
$CanvasLayer/Win.show()
Engine.time_scale=0
spawn_new_hero(Spawnpoint.x,Spawnpoint.y)
var point = determine_spawnpoint()
spawn_new_hero(point.x,point.y)
$CanvasLayer/SelectUpgradeUI.show()
@@ -18,3 +40,10 @@ func spawn_new_hero(x:float,y:float):
var hero = HeroTemplate.instance()
hero.position=Vector2(x,y)
$YSort.add_child(hero)
func _on_Win_pressed():
if passed_final_Round:
#TODO CHANGE SCENE TO WINSCREEN
pass
pass # Replace with function body.

View File

@@ -15,6 +15,11 @@
[node name="World" type="Node2D"]
pause_mode = 2
script = ExtResource( 2 )
__meta__ = {
"_edit_horizontal_guides_": [ ],
"_edit_vertical_guides_": [ ]
}
WinRounds = 5
HeroTemplate = ExtResource( 1 )
[node name="WallSprite" type="Sprite" parent="."]
@@ -26,7 +31,6 @@ region_rect = Rect2( 0, 0, 1280, 720 )
[node name="Background" parent="." instance=ExtResource( 7 )]
pause_mode = 1
frame = 17
[node name="FloorTileMap" type="TileMap" parent="."]
pause_mode = 1
@@ -65,3 +69,12 @@ visible = false
[node name="SelectUpgradeUI" parent="CanvasLayer" instance=ExtResource( 9 )]
visible = false
[node name="Win" type="Button" parent="CanvasLayer"]
visible = false
anchor_left = 1.0
anchor_right = 1.0
margin_left = -42.0
margin_bottom = 24.0
text = "Win"
[connection signal="pressed" from="CanvasLayer/Win" to="." method="_on_Win_pressed"]