Anri/AdBlockNot
Archived
1
0
Fork 0
This repository has been archived on 2024-01-28. You can view files and clone it, but cannot push or open issues or pull requests.
AdBlockNot/scripts/game.gd

70 lines
1.9 KiB
GDScript3
Raw Normal View History

2024-01-27 23:55:20 +01:00
extends Control
2024-01-28 02:34:46 +01:00
var ads_scene = []
var ads = []
"""
var ads_scene = [preload("res://scenes/game/ads/Ads_password.tscn"),
preload("res://scenes/game/ads/Ads_sudoku.tscn")]
"""
2024-01-27 23:55:20 +01:00
2024-01-28 02:34:46 +01:00
func getFilePathsByExtension(directoryPath: String, extension: String) -> Array:
var dir = DirAccess.open(directoryPath)
if !dir :
printerr("Warning: could not open directory: ", directoryPath)
return []
var filePaths := []
if dir:
dir.list_dir_begin()
var fileName = dir.get_next()
while fileName != "":
if dir.current_is_dir():
print("Found directory: " + fileName)
else:
print("Found file: " + fileName)
if fileName.get_extension() == extension:
var filePath = dir.get_current_dir() + "/" + fileName
filePaths.append(filePath)
fileName = dir.get_next()
else:
print("An error occurred when trying to access the path.")
return filePaths
2024-01-27 23:55:20 +01:00
func new_ads():
2024-01-28 02:34:46 +01:00
print("her")
randomize()
var _range = randi_range(0, ads_scene.size()-1)
var instance = ads_scene[_range].instantiate()
2024-01-27 23:55:20 +01:00
add_child(instance) # Replace with function body.
2024-01-28 02:34:46 +01:00
var _scale = Vector2(0.5,0.5)
instance.scale = _scale
var _size = instance.get_size() * _scale
print(_size)
instance.position.x = randf_range(1, get_viewport_rect().size.x - (_size.x))
instance.position.y = randf_range(1, get_viewport_rect().size.y - (_size.y*1.5))
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():
var _ads_scene = getFilePathsByExtension("res://scenes/game/ads", "tscn")
for scene in _ads_scene:
ads_scene.push_back(load(scene))
2024-01-27 23:55:20 +01:00
2024-01-28 02:34:46 +01:00
func _ready():
load_scene()
print(ads_scene)
for n in 15:
new_ads()
func win():
for ad in ads:
if ad.visible == true :
return false
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 02:34:46 +01:00
func _process(_delta):
if win():
pass
print("mettre écran victoire")