tomato-dungeon

a game made in 1 day
git clone git://git.vgx.fr/tomato-dungeon
Log | Files | Refs | README

spawner.gd (775B)


      1 extends Position2D
      2 
      3 var max_wait = 20
      4 var target_max_wait = 7
      5 
      6 var max_monsters = 200
      7 
      8 export var prefered = -1
      9 export var bias = .5
     10 
     11 var monstres_scn
     12 
     13 # Called when the node enters the scene tree for the first time.
     14 func _ready():
     15 	monstres_scn = [
     16 		load("res://diable.tscn"),
     17 		load("res://golem.tscn"),
     18 		load("res://throw.tscn"),
     19 		load("res://serpent.tscn")
     20 	]
     21 
     22 
     23 func spawn_monster():
     24 	
     25 	var id = randi()%4
     26 	
     27 	if prefered != -1 and randf() < bias:
     28 		id = prefered
     29 	
     30 	var monster = monstres_scn[id].instance()
     31 	monster.position = position
     32 	
     33 	get_parent().add_child(monster)
     34 
     35 func _on_Timer_timeout():
     36 	if get_tree().get_nodes_in_group("monstres").size() < max_monsters:
     37 		spawn_monster()
     38 	if max_wait > target_max_wait:
     39 		max_wait -= 1
     40 	$Timer.start(randi() % max_wait)