mirror of
https://forge.apps.education.fr/phroy/codetower.git
synced 2024-01-27 11:35:17 +01:00
Bugfix : Arrêt des threads lors du stop
This commit is contained in:
parent
742c6088b5
commit
f459d7eb85
BIN
codetower-20.blend
Normal file
BIN
codetower-20.blend
Normal file
Binary file not shown.
11
ct.py
11
ct.py
@ -262,7 +262,7 @@ def terrain_init (cont):
|
|||||||
|
|
||||||
# Configuration du moteur de rendu
|
# Configuration du moteur de rendu
|
||||||
eevee.use_eevee_smaa = False
|
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
|
eevee.use_eevee_smaa = True
|
||||||
|
|
||||||
# Recherche les tuiles non constructibles (chemin)
|
# Recherche les tuiles non constructibles (chemin)
|
||||||
@ -307,6 +307,8 @@ def terrain_run ():
|
|||||||
# Démarrage de la map
|
# Démarrage de la map
|
||||||
if scene.objects['Terrain']['thread_run']==False:
|
if scene.objects['Terrain']['thread_run']==False:
|
||||||
scene.objects['Stop'].setVisible(True,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
|
# Mise à zéro des compteurs
|
||||||
ct_map.map_reset()
|
ct_map.map_reset()
|
||||||
@ -346,8 +348,7 @@ def terrain_stop ():
|
|||||||
scene.objects['Terrain']['run']=False
|
scene.objects['Terrain']['run']=False
|
||||||
scene.objects['Terrain']['thread_run']=False
|
scene.objects['Terrain']['thread_run']=False
|
||||||
scene.objects['Terrain']['map_run'] = False # Ne pas afficher la bannière de fin
|
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
|
runpy.run_module('ct_cmd', run_name='stop') # Stop du script utilisateur
|
||||||
# ct_cmd.stop() # Stop du script utilisateur
|
|
||||||
ct_map.stop() # Stop du script des vagues
|
ct_map.stop() # Stop du script des vagues
|
||||||
|
|
||||||
# Supprimer les enemis
|
# Supprimer les enemis
|
||||||
@ -384,7 +385,7 @@ def terrain_end ():
|
|||||||
scene.objects['Camera'].worldPosition.z = scene.objects['Camera']['init_lz']
|
scene.objects['Camera'].worldPosition.z = scene.objects['Camera']['init_lz']
|
||||||
|
|
||||||
# Wave
|
# 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"
|
scene.objects['Endbanner_wave']['Text']="Victory"
|
||||||
else:
|
else:
|
||||||
scene.objects['Endbanner_wave']['Text']="Wave \n"+str(scene.objects['Points']['wave'])
|
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']
|
obj_i.actuators['Steering'].velocity=obj_i['speed_base']*scene.objects['Terrain']['speed']
|
||||||
|
|
||||||
# Configuration du moteur de rendu
|
# 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
|
eevee.use_eevee_smaa = True
|
||||||
else:
|
else:
|
||||||
eevee.use_eevee_smaa = False
|
eevee.use_eevee_smaa = False
|
||||||
|
97
ct_cmd-exemple.py
Normal file
97
ct_cmd-exemple.py
Normal file
@ -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 <philippe.roy@ac-grenoble.fr>
|
||||||
|
# @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()
|
||||||
|
|
33
ct_cmd.py
33
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 >>
|
# Fr: Gestion des tâches (threads) << NE PAS MODIFIER CETTE SECTION >>
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
threads=[]
|
|
||||||
scene = bge.logic.getCurrentScene()
|
scene = bge.logic.getCurrentScene()
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
scene.objects['Terrain']['thread_cmd']=True
|
scene.objects['Terrain']['thread_cmd']=True
|
||||||
thread_start(threads, "commands", commands)
|
thread_cmd_start(commands)
|
||||||
# scene.objects['Commands']['cmd_start']=False
|
|
||||||
|
|
||||||
def stop():
|
def stop():
|
||||||
thread_stop(threads, "commands")
|
thread_cmd_stop()
|
||||||
|
|
||||||
def end():
|
def end():
|
||||||
ct_sleep (2)
|
ct_sleep (2)
|
||||||
print ("Threads commands #", len(threads)-1, "are arrived -> close them.")
|
print ("Commands thread is arrived.")
|
||||||
scene.objects['Terrain']['thread_cmd']=False
|
scene.objects['Terrain']['thread_cmd']=False
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -59,13 +57,15 @@ def end():
|
|||||||
# - Return boolean flag
|
# - Return boolean flag
|
||||||
# - True : builded
|
# - True : builded
|
||||||
# - False : not builded
|
# - False : not builded
|
||||||
#
|
# - Exemple : ct_build(1,1, "Archer tower", "Tower #1",yellow,"round-A")
|
||||||
# - exemple : ct_build("archer tower", 4,5, "Tower #1",yellow,"round-A")
|
|
||||||
#
|
#
|
||||||
# Remove a tower : ct_remove (x, y)
|
# Remove a tower : ct_remove (x, y)
|
||||||
# - x position (integer)
|
# - x position (integer)
|
||||||
# - y position (integer)
|
# - y position (integer)
|
||||||
#
|
#
|
||||||
|
# Get your level : ct_level ()
|
||||||
|
# - Return your level (integer)
|
||||||
|
#
|
||||||
# Time management (temporization) : ct_sleep (delay)
|
# Time management (temporization) : ct_sleep (delay)
|
||||||
# - delay : delay in seconds (float)
|
# - delay : delay in seconds (float)
|
||||||
#
|
#
|
||||||
@ -77,20 +77,21 @@ def commands():
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
# if ct_level == 1:
|
|
||||||
# ct_build(4,5, "Archer tower", "Tower #1", blue, "square-A")
|
|
||||||
|
|
||||||
if ct_level() == 1:
|
if ct_level() == 1:
|
||||||
ct_build(4,5, "Archer tower", "Tower #1", blue, "square-A")
|
ct_build(4,5, "Archer tower", "Tower #1", blue, "square-A")
|
||||||
|
|
||||||
# if ct_level()==2:
|
if ct_level()==2:
|
||||||
# ct_build(4,-2, "Archer tower", "Tower #2", blue, "square-A")
|
ct_build(4,-2, "Archer tower", "Tower #2", blue, "square-A")
|
||||||
|
|
||||||
# if ct_level()==3:
|
if ct_level()==3:
|
||||||
# # ct_build(5,5, "Archer tower", "Tower #3", magenta, "square-B")
|
ct_build(5,4, "Mage tower", "Tower #3", magenta, "square-B")
|
||||||
# ct_build(5,5, "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':
|
if __name__=='start':
|
||||||
start()
|
start()
|
||||||
|
22
ct_lib.py
22
ct_lib.py
@ -62,6 +62,9 @@ sndbuff_mage = aud.Sound.cache(snd_mage)
|
|||||||
snd_life = aud.Sound('asset/sounds/life.ogg')
|
snd_life = aud.Sound('asset/sounds/life.ogg')
|
||||||
sndbuff_life = aud.Sound.cache(snd_life)
|
sndbuff_life = aud.Sound.cache(snd_life)
|
||||||
|
|
||||||
|
threads_waves=[]
|
||||||
|
threads_cmd=[]
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Données générales
|
# Données générales
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -72,9 +75,6 @@ def ct_level_current():
|
|||||||
def ct_level():
|
def ct_level():
|
||||||
return scene.objects['Points']['level_max']
|
return scene.objects['Points']['level_max']
|
||||||
|
|
||||||
if __name__=='ct_level':
|
|
||||||
ct_level()
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Méthode kill pour les tâches (threads)
|
# 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, ".")
|
print ("There are zombies threads",type_txt, ".")
|
||||||
return False
|
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)
|
# Vagues (minions)
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -196,7 +209,8 @@ def ct_minion_details(x,y,cat,level,body="Knight_m_A_common"):
|
|||||||
# Actuator Steering
|
# Actuator Steering
|
||||||
minion.actuators['Steering'].navmesh=scene.objects[scene.objects['Terrain']['navmesh']]
|
minion.actuators['Steering'].navmesh=scene.objects[scene.objects['Terrain']['navmesh']]
|
||||||
minion.actuators['Steering'].target=scene.objects[scene.objects['Terrain']['endtile']]
|
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']
|
minion.actuators['Steering'].velocity=minion['speed_base']*scene.objects['Terrain']['speed']
|
||||||
|
|
||||||
# Destruction d'un minion
|
# Destruction d'un minion
|
||||||
|
20
ct_map1.py
20
ct_map1.py
@ -24,8 +24,6 @@ scene = bge.logic.getCurrentScene()
|
|||||||
# Fr: Gestion des tâches (threads) << NE PAS MODIFIER CETTE SECTION >>
|
# Fr: Gestion des tâches (threads) << NE PAS MODIFIER CETTE SECTION >>
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
threads=[]
|
|
||||||
|
|
||||||
# waves_f={
|
# waves_f={
|
||||||
# 1 : wave1(),
|
# 1 : wave1(),
|
||||||
# 2 :wave2(),
|
# 2 :wave2(),
|
||||||
@ -34,22 +32,21 @@ threads=[]
|
|||||||
|
|
||||||
def start(wave):
|
def start(wave):
|
||||||
scene.objects['Terrain']['thread_wave']=True
|
scene.objects['Terrain']['thread_wave']=True
|
||||||
# thread_start(threads, "waves", waves_f(wave))
|
|
||||||
if wave==1:
|
if wave==1:
|
||||||
thread_start(threads, "waves", wave1)
|
thread_waves_start(wave1)
|
||||||
if wave==2:
|
if wave==2:
|
||||||
thread_start(threads, "waves", wave2)
|
thread_waves_start(wave2)
|
||||||
if wave==3:
|
if wave==3:
|
||||||
thread_start(threads, "waves", wave3)
|
thread_waves_start(wave3)
|
||||||
if wave==4:
|
if wave==4:
|
||||||
thread_start(threads, "waves", wave4)
|
thread_waves_start(wave4)
|
||||||
|
|
||||||
def stop():
|
def stop():
|
||||||
thread_stop(threads, "waves")
|
thread_waves_stop()
|
||||||
|
|
||||||
def end():
|
def end():
|
||||||
ct_sleep (2)
|
ct_sleep (2)
|
||||||
print ("Threads waves #", len(threads)-1, "are arrived -> close them.")
|
print ("Waves thread is arrived.")
|
||||||
scene.objects['Terrain']['thread_wave']=False
|
scene.objects['Terrain']['thread_wave']=False
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -158,11 +155,12 @@ def wave3():
|
|||||||
# Wave 4
|
# Wave 4
|
||||||
def wave4():
|
def wave4():
|
||||||
ct_map_text_wave(4)
|
ct_map_text_wave(4)
|
||||||
for i in range (50):
|
for i in range (20):
|
||||||
ct_minion(14,3,"Orc",1)
|
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_details(14,3,"Orc",1, "Orc_A_common")
|
||||||
# ct_minion(14,3,"Knight",1)
|
# ct_minion(14,3,"Knight",1)
|
||||||
ct_sleep (0.33)
|
ct_sleep (0.5)
|
||||||
end()
|
end()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user