This repository has been archived by the owner on Jul 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
248 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
extends Sprite | ||
|
||
# list of all the enemies | ||
var moles = [ | ||
preload("res://actors/enemy/enemy.tscn") | ||
] | ||
|
||
# list containing the number of mole in the garrison | ||
var garrison = [] | ||
var alive = false | ||
|
||
signal dead() | ||
|
||
# mole healed by the healing_area | ||
var healing_area | ||
var healed_mole = [] | ||
|
||
# management of the mole spawn | ||
var spawn_queue = [] | ||
var empty_queue = true | ||
var mole_count = 0 | ||
|
||
var timer | ||
|
||
# others | ||
var hp | ||
var solids_tilemaps | ||
|
||
func _ready(): | ||
solids_tilemaps = get_node("../../solids") | ||
healing_area = get_node("healing_area") | ||
|
||
|
||
timer = get_node("Timer") | ||
|
||
hp = get_node("hp") | ||
if (hp.invicible == false): | ||
set_modulate(Color(0.2,0.8,0.2)) | ||
|
||
initiate_garrison() | ||
|
||
healing_area.connect("body_enter",self,"heal_mole") | ||
healing_area.connect("body_exit",self,"stop_healing") | ||
timer.connect("timeout",self,"queue_spawn") | ||
|
||
create_rift_room() | ||
|
||
func _fixed_process(delta): | ||
|
||
for mole in healed_mole: | ||
var mole_hp = mole.hp.max_health | ||
mole.hp.restore_hp(0.01*mole_hp) | ||
|
||
|
||
# queue function ================== | ||
|
||
func queue_spawn(): # spawn the first mole in the queue | ||
var mole = spawn_queue[0].instance() | ||
mole.set_pos(get_pos() - Vector2(0,32)) | ||
get_node("../../entities").add_child(mole) | ||
mole.hp.connect("killed",self,"mole_number_update") | ||
|
||
spawn_queue.remove(0) | ||
mole_count += 1 | ||
|
||
if spawn_queue.size() == 0: | ||
change_queue_status() | ||
|
||
func add_to_queue(mole_idx, quantity): | ||
var mole_garrison = garrison[mole_idx] | ||
if mole_garrison >= quantity: | ||
for i in range(quantity): | ||
spawn_queue.append(moles[mole_idx]) | ||
garrison[mole_idx] -= quantity | ||
elif(mole_garrison != 0 and quantity >= mole_garrison): | ||
for i in range(mole_garrison): | ||
spawn_queue.append(moles[mole_idx]) | ||
garrison[mole_idx] = 0 | ||
|
||
print("[Warning] Attempt to spawn more units than available ones") | ||
else: | ||
print("[Warning] Attempt to spawn unavailable units") | ||
|
||
if empty_queue: # we stop the timer if there are no more enemies | ||
change_queue_status() | ||
|
||
func mole_number_update(): | ||
mole_count -= 1 | ||
if (mole_count == 0 and garrison_left() == 0): # a rift is dead if no moles are attached to it and no garrison | ||
alive = false | ||
set_fixed_process(false) | ||
emit_signal("dead") | ||
|
||
func change_queue_status(): | ||
if empty_queue: | ||
empty_queue = false | ||
timer.start() | ||
else: | ||
empty_queue = true | ||
timer.stop() | ||
|
||
# garrison functions ================ | ||
|
||
func add_to_garrison(mole_idx, quantity): | ||
garrison[mole_idx] += quantity | ||
alive = true | ||
set_fixed_process(true) | ||
|
||
func initiate_garrison(): | ||
for mole in moles: | ||
garrison.append(0) | ||
|
||
func garrison_left(): | ||
var S = 0 | ||
for moles in garrison: | ||
S += moles | ||
return S | ||
|
||
func empty_garrison(): | ||
for i in range(garrison.size()): | ||
garrison[i] = 0 | ||
|
||
# heal functions ================= | ||
func heal_mole(mole): | ||
if "creature" in mole.get_groups(): # checking if the mole is not a filthy tilemap | ||
if (mole.team == 2): # checking if the mole is not a rabbit | ||
healed_mole.append(mole) | ||
|
||
func stop_healing(mole): | ||
healed_mole.erase(mole) | ||
|
||
# ===== rift creation | ||
|
||
func create_rift_room(): | ||
var pos = get_pos() | ||
var tile_size = SolidTiles.TILE_SIZE | ||
|
||
for x in range(pos.x - 3*tile_size,pos.x + 3*tile_size, tile_size): | ||
for y in range(pos.y -2*tile_size, pos.y + 2*tile_size, tile_size): | ||
solids_tilemaps.set_cellv(solids_tilemaps.world_to_map(Vector2(x,y)),SolidTiles.TILE_EMPTY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,84 @@ | ||
extends Node | ||
|
||
# list of the enemies | ||
enum { | ||
ENEMY | ||
} | ||
|
||
# wave modes | ||
enum { | ||
GARRISON_EXHAUSTION, | ||
TIME_SURVIVAL | ||
} | ||
|
||
# list of the available enemies with the available number at the corresponding index | ||
var available_mole = [10] | ||
|
||
# wave | ||
var wave_number = 0 | ||
var wave_mode = GARRISON_EXHAUSTION | ||
|
||
# the rifts throughout the map | ||
var rifts | ||
var rift_scn = preload("./rift.tscn") | ||
|
||
var alive_rifts # number of rifts alive | ||
|
||
signal no_rift() # emitted when there are no rift alive | ||
|
||
|
||
func _ready(): | ||
rifts = get_childs() | ||
rifts = get_children() | ||
alive_rifts = rifts.size() | ||
|
||
for rift in rifts: | ||
rift.connect("dead",self,"dead_rift") | ||
|
||
connect("no_rift",self,"wave_end") | ||
|
||
# test | ||
add_garrison_to_rift(0,ENEMY,5) | ||
add_garrison_to_rift(1,ENEMY,5) | ||
spawn_from_rift(0,ENEMY,5) | ||
spawn_from_rift(1,ENEMY,5) | ||
|
||
# moles management | ||
func spawn_from_rift(rift_idx, mole_idx, quantity): # spawned units have to be in rift's garrison | ||
rifts[rift_idx].add_to_queue(mole_idx,quantity) | ||
|
||
func add_garrison_to_rift(rift_idx, mole_idx, quantity): | ||
var available_mole_bis = available_mole[mole_idx] | ||
if available_mole_bis >= quantity : | ||
rifts[rift_idx].add_to_garrison(mole_idx, quantity) | ||
|
||
available_mole[mole_idx] -= quantity | ||
elif(available_mole_bis != 0 and quantity >= available_mole_bis): | ||
rifts[rift_idx].add_to_garrison(mole_idx, available_mole_bis) | ||
|
||
available_mole[mole_idx] = 0 | ||
print("[Warning] Attempt to add more moles to garrison than available") | ||
else: | ||
print("[Warning] Attempt to add more moles to garrison when none available") | ||
|
||
# rift creation functions =================== | ||
func add_rift(pos): | ||
var new_rift = rift_scn.instance() | ||
new_rift.set_pos(pos) | ||
add_child(new_rift) | ||
|
||
rifts.append(new_rift) | ||
|
||
func add_damageable_rift(pos): | ||
var new_rift = rift_scn.instance() | ||
new_rift.hp.invicible = false | ||
new_rift.set_pos(pos) | ||
add_child(new_rift) | ||
|
||
|
||
func dead_rift(): | ||
alive_rifts -= 1 | ||
if alive_rifts == 0: | ||
emit_signal("no_rift") | ||
|
||
func wave_end(): | ||
print("The moles are vanquished!!! Praise the rabbit! Praise the carrot") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[gd_scene load_steps=2 format=1] | ||
|
||
[ext_resource path="res://gameflow/wave.gd" type="Script" id=1] | ||
|
||
[node name="wave" type="Node"] | ||
|
||
script/script = ExtResource( 1 ) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.