2024-01-27 23:55:20 +01:00
|
|
|
extends Control
|
2024-01-28 02:34:46 +01:00
|
|
|
var ads_scene = []
|
|
|
|
var ads = []
|
2024-01-28 21:53:02 +01:00
|
|
|
var level = [10, 15, 25]
|
|
|
|
var nlevel = 0
|
|
|
|
var nb = 10
|
2024-01-27 23:55:20 +01:00
|
|
|
|
|
|
|
func new_ads():
|
2024-01-28 02:34:46 +01:00
|
|
|
print("her")
|
|
|
|
randomize()
|
2024-01-28 22:30:48 +01:00
|
|
|
var _range = randi_range(0, ads_scene.size() - 1)
|
2024-01-28 21:53:02 +01:00
|
|
|
print(_range)
|
2024-01-28 02:34:46 +01:00
|
|
|
var instance = ads_scene[_range].instantiate()
|
2024-01-28 22:30:48 +01:00
|
|
|
$GamesAreUnderThisNode.add_sibling(instance)
|
|
|
|
var _scale = Vector2(0.5, 0.5)
|
2024-01-28 02:34:46 +01:00
|
|
|
instance.scale = _scale
|
|
|
|
var _size = instance.get_size() * _scale
|
|
|
|
print(_size)
|
|
|
|
instance.position.x = randf_range(1, get_viewport_rect().size.x - (_size.x))
|
2024-01-28 22:30:48 +01:00
|
|
|
instance.position.y = randf_range(1, get_viewport_rect().size.y - (_size.y * 1.5))
|
2024-01-28 02:34:46 +01:00
|
|
|
ads.push_back(instance)
|
|
|
|
print(instance.position)
|
2024-01-27 23:55:20 +01:00
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
2024-01-28 02:34:46 +01:00
|
|
|
func load_scene():
|
2024-01-28 22:30:48 +01:00
|
|
|
for scene in [ "res://scenes/game/ads/ads_music.tscn"
|
|
|
|
, "res://scenes/game/ads/ads_normal.tscn"
|
|
|
|
, "res://scenes/game/ads/ads_operation.tscn"
|
|
|
|
, "res://scenes/game/ads/ads_pair.tscn"
|
|
|
|
, "res://scenes/game/ads/ads_roll.tscn"
|
|
|
|
, "res://scenes/game/ads/ads_sexy_robot.tscn"
|
|
|
|
, "res://scenes/game/ads/ads_weather.tscn" ]:
|
2024-01-28 02:34:46 +01:00
|
|
|
ads_scene.push_back(load(scene))
|
2024-01-27 23:55:20 +01:00
|
|
|
|
2024-01-28 19:43:27 +01:00
|
|
|
func _input(event):
|
|
|
|
if event.is_action_pressed("ui_cancel"):
|
2024-01-28 22:30:48 +01:00
|
|
|
if ($Rules.visible):
|
|
|
|
$Rules.set_visible(false)
|
|
|
|
$Timer.start()
|
|
|
|
else:
|
|
|
|
$Rules.set_visible(true)
|
|
|
|
$Timer.stop()
|
2024-01-28 21:53:02 +01:00
|
|
|
|
|
|
|
func newLevel():
|
|
|
|
for n in nb:
|
|
|
|
new_ads()
|
|
|
|
Reset_Timer()
|
|
|
|
$Timer.start()
|
2024-01-27 23:55:20 +01:00
|
|
|
|
2024-01-28 02:34:46 +01:00
|
|
|
func _ready():
|
|
|
|
load_scene()
|
|
|
|
print(ads_scene)
|
2024-01-28 21:53:02 +01:00
|
|
|
|
|
|
|
if Global.mode == 1 :
|
|
|
|
nb = level[nlevel]
|
|
|
|
|
|
|
|
if Global.mode == 2 :
|
|
|
|
pass
|
|
|
|
newLevel()
|
|
|
|
|
2024-01-28 22:30:48 +01:00
|
|
|
var seconds := 0
|
|
|
|
var Dsecond := 45
|
2024-01-28 21:53:02 +01:00
|
|
|
|
2024-01-28 02:34:46 +01:00
|
|
|
func win():
|
|
|
|
for ad in ads:
|
|
|
|
if ad.visible == true :
|
|
|
|
return false
|
2024-01-28 21:53:02 +01:00
|
|
|
if Global.mode == 1 :
|
|
|
|
nlevel +=1
|
|
|
|
if nlevel < 3:
|
|
|
|
nb = level[nlevel]
|
|
|
|
newLevel()
|
|
|
|
return false
|
2024-01-28 02:34:46 +01:00
|
|
|
return true
|
2024-01-27 23:55:20 +01:00
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
2024-01-28 21:53:02 +01:00
|
|
|
func lose():
|
|
|
|
return seconds == 0
|
|
|
|
|
2024-01-28 02:34:46 +01:00
|
|
|
func _process(_delta):
|
2024-01-28 21:53:02 +01:00
|
|
|
if lose():
|
|
|
|
$Timer.stop()
|
|
|
|
get_tree().change_scene_to_file("res://scenes/game/defeat.tscn")
|
2024-01-28 02:34:46 +01:00
|
|
|
if win():
|
2024-01-28 21:53:02 +01:00
|
|
|
if Global.mode == 1 :
|
|
|
|
$Timer.stop()
|
|
|
|
get_tree().change_scene_to_file("res://scenes/game/victory.tscn")
|
|
|
|
if Global.mode == 2 :
|
|
|
|
nb +=5
|
|
|
|
newLevel()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_timer_timeout():
|
|
|
|
$Label.text = str(seconds)
|
|
|
|
seconds -=1
|
|
|
|
|
|
|
|
func Reset_Timer():
|
|
|
|
seconds=Dsecond
|
|
|
|
|