diff --git a/codetower-20.blend b/codetower-20.blend new file mode 100644 index 0000000..1af5264 Binary files /dev/null and b/codetower-20.blend differ diff --git a/ct.py b/ct.py index 970069d..673cbc6 100644 --- a/ct.py +++ b/ct.py @@ -262,7 +262,7 @@ def terrain_init (cont): # Configuration du moteur de rendu eevee.use_eevee_smaa = False - if scene.objects['Terrain']['speed']<4: # smaa avec en vitesse 4 et 10 -> tendance au plantage + if scene.objects['Terrain']['speed']<10: # smaa avec en vitesse 4 et 10 -> tendance au plantage eevee.use_eevee_smaa = True # Recherche les tuiles non constructibles (chemin) @@ -298,7 +298,7 @@ def terrain_run (): obj_i.actuators['Steering'].velocity=0 # Run - else : + else : scene.objects['Terrain']['run']=True scene.objects['Run'].setVisible(False,False) scene.objects['Run-Hl'].setVisible(False,False) @@ -307,6 +307,8 @@ def terrain_run (): # Démarrage de la map if scene.objects['Terrain']['thread_run']==False: scene.objects['Stop'].setVisible(True,False) + runpy.run_module('ct_cmd', run_name='stop') # Stop du script utilisateur + ct_map.stop() # Stop du script des vagues # Mise à zéro des compteurs ct_map.map_reset() @@ -319,7 +321,7 @@ def terrain_run (): obj_i.endObject() scene.objects['Terrain']['scene_tile_tower']= [] - # Scripts utilisateur et vagues + # Scripts utilisateur et vagues scene.objects['Terrain']['map_run'] = True scene.objects['Terrain']['thread_run']=True scene.objects['Points']['time_begin']=time.localtime() @@ -346,8 +348,7 @@ def terrain_stop (): scene.objects['Terrain']['run']=False scene.objects['Terrain']['thread_run']=False scene.objects['Terrain']['map_run'] = False # Ne pas afficher la bannière de fin - runpy.run_module('ct_cmd', run_name='stop') # Execution du script utilisateur - # ct_cmd.stop() # Stop du script utilisateur + runpy.run_module('ct_cmd', run_name='stop') # Stop du script utilisateur ct_map.stop() # Stop du script des vagues # Supprimer les enemis @@ -384,7 +385,7 @@ def terrain_end (): scene.objects['Camera'].worldPosition.z = scene.objects['Camera']['init_lz'] # Wave - if scene.objects['Points']['wave']== scene.objects['Terrain']['nb_waves']: + if scene.objects['Points']['wave']== scene.objects['Terrain']['nb_waves'] and scene.objects['Points']['lifes'] > 0: scene.objects['Endbanner_wave']['Text']="Victory" else: scene.objects['Endbanner_wave']['Text']="Wave \n"+str(scene.objects['Points']['wave']) @@ -441,7 +442,7 @@ def terrain_speed (obj): obj_i.actuators['Steering'].velocity=obj_i['speed_base']*scene.objects['Terrain']['speed'] # Configuration du moteur de rendu - if scene.objects['Terrain']['speed']<4: # smaa avec en vitesse 4 et 10 -> tendance au plantage + if scene.objects['Terrain']['speed']<10: # smaa avec en vitesse 4 et 10 -> tendance au plantage eevee.use_eevee_smaa = True else: eevee.use_eevee_smaa = False diff --git a/ct_cmd-exemple.py b/ct_cmd-exemple.py new file mode 100644 index 0000000..e573df5 --- /dev/null +++ b/ct_cmd-exemple.py @@ -0,0 +1,97 @@ +import bge # Bibliothèque Blender Game Engine (UPBGE) +from ct_lib import * # Bibliothèque CodeTower + +############################################################################### +# ct_cmd.py +# @title: Commands for the CodeTower game +# @project: CodeTower +# @lang: fr,en +# @authors: Philippe Roy +# @copyright: Copyright (C) 2022 Philippe Roy +# @license: GNU GPL +# +# En: This game is a tower defense coding game. The towers are driven by Python code. +# Fr: Ce simulateur est un jeu du type tower defense où les tours sont à piloter par la programmation Python. +# +############################################################################### + +purple = (0.202, 0.114, 0.521,1) +turquoise = (0.051, 0.270, 0.279,1) +magenta = (0.799, 0.005, 0.314,1) +orange = (0.799, 0.130, 0.063,1) +yellow = (0.799, 0.617, 0.021, 1) +green = (0.246, 0.687, 0.078, 1) +red = (0.799, 0.031, 0.038, 1) +blue = (0.127, 0.456, 1.000, 1) + +############################################################################### +# En: Threads management << DONT CHANGE THIS SECTION >> +# Fr: Gestion des tâches (threads) << NE PAS MODIFIER CETTE SECTION >> +############################################################################### + +scene = bge.logic.getCurrentScene() + +def start(): + scene.objects['Terrain']['thread_cmd']=True + thread_cmd_start(commands) + +def stop(): + thread_cmd_stop() + +def end(): + ct_sleep (2) + print ("Commands thread is arrived.") + scene.objects['Terrain']['thread_cmd']=False + +############################################################################### +# En: Tower commands +# Fr: Commandes des tours +# +# Build a tower : ct_build (x, y, category, name, color, style) +# - x position (integer) +# - y position (integer) +# - category (string) : "Archer tower", "Mage tower" or "Barrack" (not implemented) +# - name (string) +# - color (RGB model) : purple, turquoise, magenta, orange, yellow, green, red or [R, G, B, 1] +# - style : square or round and version (A,B or C), exemple : 'square-A' +# - Return boolean flag +# - True : builded +# - False : not builded +# - Exemple : ct_build(1,1, "Archer tower", "Tower #1",yellow,"round-A") +# +# Remove a tower : ct_remove (x, y) +# - x position (integer) +# - y position (integer) +# +# Get your level : ct_level () +# - Return your level (integer) +# +# Time management (temporization) : ct_sleep (delay) +# - delay : delay in seconds (float) +# +############################################################################### + +def commands(): + while True: + if ct_level ()==1: + ct_build(4,5, "Archer tower", "Tower #1",yellow,"round-A") + + if ct_level ()==2: + ct_build(3,-1, "Archer tower", "Tower #2",red,"round-A") + + if ct_level ()==3: + ct_build(5,4, "Mage tower", "Tower #3",blue,"square-A") + + + + +############################################################################### +# En: Externals calls << DONT CHANGE THIS SECTION >> +# Fr: Appels externes << NE PAS MODIFIER CETTE SECTION >> +############################################################################### + +if __name__=='start': + start() +if __name__=='stop': + stop() + diff --git a/ct_cmd.py b/ct_cmd.py index db1604c..e796c6b 100644 --- a/ct_cmd.py +++ b/ct_cmd.py @@ -29,20 +29,18 @@ blue = (0.127, 0.456, 1.000, 1) # Fr: Gestion des tâches (threads) << NE PAS MODIFIER CETTE SECTION >> ############################################################################### -threads=[] scene = bge.logic.getCurrentScene() def start(): scene.objects['Terrain']['thread_cmd']=True - thread_start(threads, "commands", commands) - # scene.objects['Commands']['cmd_start']=False + thread_cmd_start(commands) def stop(): - thread_stop(threads, "commands") + thread_cmd_stop() def end(): ct_sleep (2) - print ("Threads commands #", len(threads)-1, "are arrived -> close them.") + print ("Commands thread is arrived.") scene.objects['Terrain']['thread_cmd']=False ############################################################################### @@ -59,13 +57,15 @@ def end(): # - Return boolean flag # - True : builded # - False : not builded -# -# - exemple : ct_build("archer tower", 4,5, "Tower #1",yellow,"round-A") +# - Exemple : ct_build(1,1, "Archer tower", "Tower #1",yellow,"round-A") # # Remove a tower : ct_remove (x, y) # - x position (integer) # - y position (integer) # +# Get your level : ct_level () +# - Return your level (integer) +# # Time management (temporization) : ct_sleep (delay) # - delay : delay in seconds (float) # @@ -77,20 +77,21 @@ def commands(): while True: - # if ct_level == 1: - # ct_build(4,5, "Archer tower", "Tower #1", blue, "square-A") - if ct_level() == 1: ct_build(4,5, "Archer tower", "Tower #1", blue, "square-A") - # if ct_level()==2: - # ct_build(4,-2, "Archer tower", "Tower #2", blue, "square-A") + if ct_level()==2: + ct_build(4,-2, "Archer tower", "Tower #2", blue, "square-A") - # if ct_level()==3: - # # ct_build(5,5, "Archer tower", "Tower #3", magenta, "square-B") - # ct_build(5,5, "Mage tower", "Tower #3", magenta, "square-B") + if ct_level()==3: + ct_build(5,4, "Mage tower", "Tower #3", magenta, "square-B") - end() # End of cycle << DONT CHANGE THIS LINE >> + + +############################################################################### +# En: Externals calls << DONT CHANGE THIS SECTION >> +# Fr: Appels externes << NE PAS MODIFIER CETTE SECTION >> +############################################################################### if __name__=='start': start() diff --git a/ct_lib.py b/ct_lib.py index 2d9d2e6..d962cba 100644 --- a/ct_lib.py +++ b/ct_lib.py @@ -62,6 +62,9 @@ sndbuff_mage = aud.Sound.cache(snd_mage) snd_life = aud.Sound('asset/sounds/life.ogg') sndbuff_life = aud.Sound.cache(snd_life) +threads_waves=[] +threads_cmd=[] + ############################################################################### # Données générales ############################################################################### @@ -72,9 +75,6 @@ def ct_level_current(): def ct_level(): return scene.objects['Points']['level_max'] -if __name__=='ct_level': - ct_level() - ############################################################################### # Méthode kill pour les tâches (threads) ############################################################################### @@ -141,6 +141,19 @@ def thread_stop(threads, type_txt): print ("There are zombies threads",type_txt, ".") return False +def thread_waves_start(fct): + thread_start(threads_waves, "waves", fct) + +def thread_waves_stop(): + thread_stop(threads_waves, "waves") + +def thread_cmd_start(fct): + thread_start(threads_cmd, "commands", fct) + +def thread_cmd_stop(): + thread_stop(threads_cmd, "commands") + + ############################################################################### # Vagues (minions) ############################################################################### @@ -196,7 +209,8 @@ def ct_minion_details(x,y,cat,level,body="Knight_m_A_common"): # Actuator Steering minion.actuators['Steering'].navmesh=scene.objects[scene.objects['Terrain']['navmesh']] minion.actuators['Steering'].target=scene.objects[scene.objects['Terrain']['endtile']] - minion.actuators['Steering'].distance=0.5 + minion.actuators['Steering'].distance=2 + # minion.actuators['Steering'].distance=0.5 minion.actuators['Steering'].velocity=minion['speed_base']*scene.objects['Terrain']['speed'] # Destruction d'un minion diff --git a/ct_map1.py b/ct_map1.py index 7fd4b30..27acb65 100644 --- a/ct_map1.py +++ b/ct_map1.py @@ -24,8 +24,6 @@ scene = bge.logic.getCurrentScene() # Fr: Gestion des tâches (threads) << NE PAS MODIFIER CETTE SECTION >> ############################################################################### -threads=[] - # waves_f={ # 1 : wave1(), # 2 :wave2(), @@ -34,22 +32,21 @@ threads=[] def start(wave): scene.objects['Terrain']['thread_wave']=True - # thread_start(threads, "waves", waves_f(wave)) if wave==1: - thread_start(threads, "waves", wave1) + thread_waves_start(wave1) if wave==2: - thread_start(threads, "waves", wave2) + thread_waves_start(wave2) if wave==3: - thread_start(threads, "waves", wave3) + thread_waves_start(wave3) if wave==4: - thread_start(threads, "waves", wave4) + thread_waves_start(wave4) def stop(): - thread_stop(threads, "waves") + thread_waves_stop() def end(): ct_sleep (2) - print ("Threads waves #", len(threads)-1, "are arrived -> close them.") + print ("Waves thread is arrived.") scene.objects['Terrain']['thread_wave']=False ############################################################################### @@ -158,11 +155,12 @@ def wave3(): # Wave 4 def wave4(): ct_map_text_wave(4) - for i in range (50): + for i in range (20): ct_minion(14,3,"Orc",1) + ct_minion(14,2.5,"Orc",1) # ct_minion_details(14,3,"Orc",1, "Orc_A_common") # ct_minion(14,3,"Knight",1) - ct_sleep (0.33) + ct_sleep (0.5) end()