Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
wave scene
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodre committed Jul 26, 2017
1 parent 49c459e commit 7ea5f54
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 92 deletions.
1 change: 1 addition & 0 deletions src/actors/enemy/enemy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var current_action = null
var dig_timestamp = 0
var attack_timestamp = 0


func _ready():
hp.connect("on_damage", self, "_handle_damage")

Expand Down
71 changes: 0 additions & 71 deletions src/gameflow/Rift.gd

This file was deleted.

140 changes: 140 additions & 0 deletions src/gameflow/rift.gd
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)
12 changes: 6 additions & 6 deletions src/gameflow/Rift.tscn → src/gameflow/rift.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_scene load_steps=5 format=1]

[ext_resource path="res://gameflow/rift.tex" type="Texture" id=1]
[ext_resource path="res://gameflow/Rift.gd" type="Script" id=2]
[ext_resource path="res://gameflow/rift.gd" type="Script" id=2]
[ext_resource path="res://utils/hp.tscn" type="PackedScene" id=3]

[sub_resource type="RectangleShape2D" id=1]
Expand All @@ -25,7 +25,7 @@ transform/pos = Vector2( 0.563454, 2.67066 )
transform/scale = Vector2( 2.47915, 1.93654 )
input/pickable = true
shapes/0/shape = SubResource( 1 )
shapes/0/transform = Matrix32( 2.69086, 0, 0, 2.89218, -0.442901, 1.06764 )
shapes/0/transform = Matrix32( 4.10913, 0, 0, 3.1931, -0.416451, 4.97957 )
shapes/0/trigger = true
gravity_vec = Vector2( 0, 1 )
gravity = 98.0
Expand All @@ -34,17 +34,17 @@ angular_damp = 1.0

[node name="CollisionShape2D" type="CollisionShape2D" parent="healing_area"]

transform/pos = Vector2( -0.442901, 1.06764 )
transform/scale = Vector2( 2.69086, 2.89218 )
transform/pos = Vector2( -0.416451, 4.97957 )
transform/scale = Vector2( 4.10913, 3.1931 )
shape = SubResource( 1 )
trigger = true
_update_shape_index = 0

[node name="Timer" type="Timer" parent="."]

process_mode = 1
wait_time = 5.0
wait_time = 1.0
one_shot = false
autostart = true
autostart = false


79 changes: 78 additions & 1 deletion src/gameflow/wave.gd
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")
9 changes: 9 additions & 0 deletions src/gameflow/wave.tscn
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 )


11 changes: 6 additions & 5 deletions src/levels/abstract_level.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[gd_scene load_steps=7 format=1]
[gd_scene load_steps=8 format=1]

[ext_resource path="res://levels/abstract_level.gd" type="Script" id=1]
[ext_resource path="res://musics/background_music.ogg" type="AudioStream" id=2]
[ext_resource path="res://hud/game_hud.tscn" type="PackedScene" id=3]
[ext_resource path="res://tilesets/tileset_background.tres" type="TileSet" id=4]
[ext_resource path="res://tilesets/solids_manager.tscn" type="PackedScene" id=5]
[ext_resource path="res://actors/hero/hero.tscn" type="PackedScene" id=6]
[ext_resource path="res://gameflow/wave.tscn" type="PackedScene" id=6]
[ext_resource path="res://actors/hero/hero.tscn" type="PackedScene" id=7]

[node name="root" type="Node"]

Expand Down Expand Up @@ -68,11 +69,11 @@ tile_data = IntArray( )

[node name="solids" parent="content" instance=ExtResource( 5 )]

[node name="entities" type="Node2D" parent="content"]
[node name="wave" parent="content" instance=ExtResource( 6 )]

[node name="hero" parent="content/entities" instance=ExtResource( 6 )]
[node name="entities" type="Node2D" parent="content"]

[node name="waves" type="Node" parent="content"]
[node name="hero" parent="content/entities" instance=ExtResource( 7 )]

[node name="topleft_level_area" type="Position2D" parent="."]

Expand Down
Loading

0 comments on commit 7ea5f54

Please sign in to comment.