Tower bullet with 3d object but without physic

This commit is contained in:
Philippe Roy 2022-07-20 05:03:56 +02:00
parent c8bc8c9859
commit 3783722d19
4 changed files with 280 additions and 215 deletions

BIN
codetower-35.blend Normal file

Binary file not shown.

137
ct.py
View File

@ -1,8 +1,8 @@
# import importlib # import importlib
# import imp # import imp
import bge # Blender Game Engine (UPBGE) import bge # Blender Game Engine (UPBGE)
import bpy # Blender import bpy # Blender
import aud # Sounds import aud # Sounds
import math import math
import mathutils import mathutils
import time import time
@ -90,11 +90,14 @@ JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED
ACTIVATE = bge.logic.KX_INPUT_ACTIVE ACTIVATE = bge.logic.KX_INPUT_ACTIVE
# JUST_DEACTIVATED = bge.logic.KX_SENSOR_JUST_DEACTIVATED # JUST_DEACTIVATED = bge.logic.KX_SENSOR_JUST_DEACTIVATED
############################################################################### ###############################################################################
# Tour # Tour
############################################################################### ###############################################################################
##
# Commande pour afficher la position de la tour de construction # Commande pour afficher la position de la tour de construction
##
def cmd_tower_construct(cont): def cmd_tower_construct(cont):
obj = cont.owner obj = cont.owner
obj_Hl= scene.objects[obj.name+"-Hl"] obj_Hl= scene.objects[obj.name+"-Hl"]
@ -120,11 +123,14 @@ def cmd_tower_construct(cont):
text_info ("Tower position : ") text_info ("Tower position : ")
scene.objects['Cmd-text']['Text']= "" scene.objects['Cmd-text']['Text']= ""
############################################################################### ###############################################################################
# User interface : texte info et compteurs # User interface : texte info et compteurs
############################################################################### ###############################################################################
##
# Affichage sur la boite de texte sur 6 lignes # Affichage sur la boite de texte sur 6 lignes
##
def text_info (text): def text_info (text):
if text=="": if text=="":
scene.objects['Info-1-text'].setVisible(False,False) scene.objects['Info-1-text'].setVisible(False,False)
@ -138,7 +144,10 @@ def text_info (text):
scene.objects['Info-1-text']['Text']=lines_txt[0]+"\n"+lines_txt[1]+"\n"+lines_txt[2] scene.objects['Info-1-text']['Text']=lines_txt[0]+"\n"+lines_txt[1]+"\n"+lines_txt[2]
scene.objects['Info-2-text']['Text']=lines_txt[3]+"\n"+lines_txt[4]+"\n"+lines_txt[5] scene.objects['Info-2-text']['Text']=lines_txt[3]+"\n"+lines_txt[4]+"\n"+lines_txt[5]
##
# Mise à jour de l'affichage des compteurs # Mise à jour de l'affichage des compteurs
##
def points_maj (cont): def points_maj (cont):
global fps_time global fps_time
@ -176,7 +185,7 @@ def points_maj (cont):
if milliseconds != fps_time: if milliseconds != fps_time:
fps = int(1000/(milliseconds-fps_time)) fps = int(1000/(milliseconds-fps_time))
else: else:
fps= "----" fps = "----"
print ("Durée entre deux tics (16 ms), fps (60), coins :", milliseconds-fps_time, fps, str(scene.objects['Points']['coins'])) print ("Durée entre deux tics (16 ms), fps (60), coins :", milliseconds-fps_time, fps, str(scene.objects['Points']['coins']))
fps_time = milliseconds fps_time = milliseconds
@ -224,11 +233,14 @@ def points_maj (cont):
scene.objects['Points']['wave'] +=1 scene.objects['Points']['wave'] +=1
ct_map.start(scene.objects['Points']['wave']) # Lancement du script de la vague ct_map.start(scene.objects['Points']['wave']) # Lancement du script de la vague
############################################################################### ###############################################################################
# Terrain # Terrain
############################################################################### ###############################################################################
##
# Mouse over du terrain # Mouse over du terrain
##
def scn_terrain_mo (cont): def scn_terrain_mo (cont):
# Affiche la position de la tour de construction # Affiche la position de la tour de construction
@ -261,7 +273,10 @@ def scn_terrain_mo (cont):
else: else:
text_info ("") text_info ("")
##
# Initialisation lors du chargement du terrain # Initialisation lors du chargement du terrain
##
def terrain_init (): def terrain_init ():
# Cacher les fenêtres # Cacher les fenêtres
@ -306,7 +321,10 @@ def terrain_init ():
ct_map.map_reset() ct_map.map_reset()
scene.objects['Points-Level-text'].color = color_text scene.objects['Points-Level-text'].color = color_text
##
# Mise en route et pause du cycle # Mise en route et pause du cycle
##
def terrain_run (): def terrain_run ():
sound_play (sndbuff_click) sound_play (sndbuff_click)
@ -374,7 +392,10 @@ def terrain_run ():
if "type_minion" in obj_i.getPropertyNames(): if "type_minion" in obj_i.getPropertyNames():
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']
##
# Arrêt et réinitialisation du cycle # Arrêt et réinitialisation du cycle
##
def terrain_stop (): def terrain_stop ():
sound_play (sndbuff_click) sound_play (sndbuff_click)
@ -403,7 +424,10 @@ def terrain_stop ():
scene.objects['Stop-Hl'].setVisible(False,False) scene.objects['Stop-Hl'].setVisible(False,False)
scene.objects['Cmd-text'].setVisible(False,False) scene.objects['Cmd-text'].setVisible(False,False)
##
# Fin de la map # Fin de la map
##
def terrain_end (): def terrain_end ():
scene.objects['Terrain']['run']=False scene.objects['Terrain']['run']=False
scene.objects['Terrain']['thread_run']=False scene.objects['Terrain']['thread_run']=False
@ -460,7 +484,10 @@ def terrain_end ():
if scene.objects['End']['timer']== 40: if scene.objects['End']['timer']== 40:
scene.objects['Terrain']['map_run'] = False scene.objects['Terrain']['map_run'] = False
##
# Vitesse du jeu # Vitesse du jeu
##
def terrain_speed (obj): def terrain_speed (obj):
sound_play (sndbuff_click) sound_play (sndbuff_click)
speed_mode=[0.25, 0.5, 1,2,4,10] speed_mode=[0.25, 0.5, 1,2,4,10]
@ -495,7 +522,10 @@ def terrain_speed (obj):
with open("ct_config.xml", "wb") as f: with open("ct_config.xml", "wb") as f:
f.write(buffer_xml) f.write(buffer_xml)
##
# Highlight de la page de fin # Highlight de la page de fin
##
def endbanner_hl(cont): def endbanner_hl(cont):
if cont.sensors['MO'].status == JUST_ACTIVATED: if cont.sensors['MO'].status == JUST_ACTIVATED:
if scene.objects['Mouse_main']['mouse_graphic']: if scene.objects['Mouse_main']['mouse_graphic']:
@ -512,7 +542,10 @@ def endbanner_hl(cont):
scene.objects['Endbanner_points'].color = color_black scene.objects['Endbanner_points'].color = color_black
scene.objects['Endbanner_ok'].color = color_black scene.objects['Endbanner_ok'].color = color_black
##
# Fermer la page de fin # Fermer la page de fin
##
def endbanner_close(): def endbanner_close():
sound_play (sndbuff_click) sound_play (sndbuff_click)
scene.objects['Terrain']['manip_mode']=0 scene.objects['Terrain']['manip_mode']=0
@ -528,7 +561,7 @@ def endbanner_close_click(cont):
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive : if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
endbanner_close() endbanner_close()
############################################################################### ###############################################################################
# Sons # Sons
############################################################################### ###############################################################################
@ -568,14 +601,17 @@ def sound_unset ():
with open("ct_config.xml", "wb") as f: with open("ct_config.xml", "wb") as f:
f.write(buffer_xml) f.write(buffer_xml)
############################################################################### ###############################################################################
# Commandes # Commandes
############################################################################### ###############################################################################
color_cmd = (0.8, 0.8, 0.8, 1) # Blanc color_cmd = (0.8, 0.8, 0.8, 1) # Blanc
color_cmd_hl = (0.8, 0.619, 0.021, 1) # Jaune color_cmd_hl = (0.8, 0.619, 0.021, 1) # Jaune
##
# Init # Init
##
def cmd_init(): def cmd_init():
# UI : Commands # UI : Commands
@ -632,7 +668,10 @@ def cmd_init():
i=speed_mode.index(scene.objects['Terrain']['speed']) i=speed_mode.index(scene.objects['Terrain']['speed'])
scene.objects['Text_speed']['Text']=speed_mode_txt[i] scene.objects['Text_speed']['Text']=speed_mode_txt[i]
##
# Highlight des commandes # Highlight des commandes
##
def cmd_hl(cont): def cmd_hl(cont):
obj = cont.owner obj = cont.owner
@ -720,7 +759,10 @@ def cmd_hl(cont):
scene.objects[obj.name].setVisible(False,True) scene.objects[obj.name].setVisible(False,True)
scene.objects['Cmd-text'].setVisible(False,False) scene.objects['Cmd-text'].setVisible(False,False)
##
# Click sur les commandes # Click sur les commandes
##
def cmd_click (cont): def cmd_click (cont):
obj = cont.owner obj = cont.owner
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Terrain']['manip_mode']==0: if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Terrain']['manip_mode']==0:
@ -740,15 +782,18 @@ def cmd_click (cont):
about_open () about_open ()
############################################################################### ###############################################################################
# Gestion du clavier # Gestion du clavier
############################################################################### ###############################################################################
# Mode : ##
# Mode
#
# 0 : rien (par défaut) # 0 : rien (par défaut)
# 1 : Pan avec Shift # 1 : Pan avec Shift
# 2 : Zoom avec Ctrl # 2 : Zoom avec Ctrl
# 9 : Fenêtre modale # 9 : Fenêtre modal
##
def mode(cont): def mode(cont):
obj = cont.owner obj = cont.owner
@ -821,11 +866,14 @@ def mode(cont):
if JUST_ACTIVATED in keyboard.inputs[bge.events.PADMINUS].queue: if JUST_ACTIVATED in keyboard.inputs[bge.events.PADMINUS].queue:
terrain_speed (scene.objects['Speed_down']) terrain_speed (scene.objects['Speed_down'])
############################################################################### ###############################################################################
# Manipulation 3D de la scène # Manipulation 3D de la scène
############################################################################### ###############################################################################
##
# Mémorisation de la position et orientation initiales du modèle 3D et de la caméra # Mémorisation de la position et orientation initiales du modèle 3D et de la caméra
##
def manip_init(cont): def manip_init(cont):
scene.objects['Camera']['init_lx']=scene.objects['Camera'].worldPosition.x scene.objects['Camera']['init_lx']=scene.objects['Camera'].worldPosition.x
scene.objects['Camera']['init_ly']=scene.objects['Camera'].worldPosition.y scene.objects['Camera']['init_ly']=scene.objects['Camera'].worldPosition.y
@ -843,7 +891,10 @@ def manip_init(cont):
scene.objects['Points-Map-text']['init_relativ_ly']=scene.objects['Points-Map-text'].worldPosition.y-scene.objects['Points'].worldPosition.y scene.objects['Points-Map-text']['init_relativ_ly']=scene.objects['Points-Map-text'].worldPosition.y-scene.objects['Points'].worldPosition.y
scene.objects['Points-Map-text']['init_relativ_lz']=scene.objects['Points-Map-text'].worldPosition.z-scene.objects['Points'].worldPosition.z scene.objects['Points-Map-text']['init_relativ_lz']=scene.objects['Points-Map-text'].worldPosition.z-scene.objects['Points'].worldPosition.z
##
# Atteindre une orientation (bas niveau) # Atteindre une orientation (bas niveau)
##
def applyRotationTo(obj, rx=None, ry=None, rz=None, Local=True): def applyRotationTo(obj, rx=None, ry=None, rz=None, Local=True):
rres=0.001 # resolution rotation rres=0.001 # resolution rotation
@ -874,7 +925,10 @@ def applyRotationTo(obj, rx=None, ry=None, rz=None, Local=True):
obj.applyRotation((0, 0, rres), Local) obj.applyRotation((0, 0, rres), Local)
# print ("delta z ",rz-obj.worldOrientation.to_euler().z) # print ("delta z ",rz-obj.worldOrientation.to_euler().z)
##
# Reset de la manipulation de la vue # Reset de la manipulation de la vue
##
def manip_reset(): def manip_reset():
scene.objects['Camera'].worldPosition.x = scene.objects['Camera']['init_lx'] scene.objects['Camera'].worldPosition.x = scene.objects['Camera']['init_lx']
scene.objects['Camera'].worldPosition.y = scene.objects['Camera']['init_ly'] scene.objects['Camera'].worldPosition.y = scene.objects['Camera']['init_ly']
@ -882,19 +936,28 @@ def manip_reset():
applyRotationTo(scene.objects['Terrain'], 0, 0, 0) applyRotationTo(scene.objects['Terrain'], 0, 0, 0)
scene.objects['Cmd-text']['Text']= "" scene.objects['Cmd-text']['Text']= ""
##
# Position de départ pour la manipulation de la vue # Position de départ pour la manipulation de la vue
##
def manip_start(cont): def manip_start(cont):
if scene.objects['Terrain']['manip_mode']!=9: if scene.objects['Terrain']['manip_mode']!=9:
obj = cont.owner obj = cont.owner
obj['click_x']=cont.sensors['ClickM'].position[0] obj['click_x']=cont.sensors['ClickM'].position[0]
obj['click_y']=cont.sensors['ClickM'].position[1] obj['click_y']=cont.sensors['ClickM'].position[1]
##
# Cacher le cercle de la manipulation Orbit # Cacher le cercle de la manipulation Orbit
##
def manip_stop(cont): def manip_stop(cont):
# scene.objects['Orbit'].setVisible(False,False) # scene.objects['Orbit'].setVisible(False,False)
pass pass
##
# Manipulation du modèle ou de la caméra # Manipulation du modèle ou de la caméra
##
def manip(cont): def manip(cont):
obj = cont.owner obj = cont.owner
sensibilite_orbit=0.00005 # Base : 0.0005 sensibilite_orbit=0.00005 # Base : 0.0005
@ -929,7 +992,10 @@ def manip(cont):
scene.objects['Camera']['past_ly']=scene.objects['Camera'].worldPosition.y scene.objects['Camera']['past_ly']=scene.objects['Camera'].worldPosition.y
scene.objects['Camera']['past_lz']=scene.objects['Camera'].worldPosition.z scene.objects['Camera']['past_lz']=scene.objects['Camera'].worldPosition.z
##
# Manipulation du modèle ou de la caméra # Manipulation du modèle ou de la caméra
##
def manip_wheel(cont): def manip_wheel(cont):
if scene.objects['Terrain']['manip_mode']!=9: # Fenêtre modale if scene.objects['Terrain']['manip_mode']!=9: # Fenêtre modale
obj = cont.owner obj = cont.owner
@ -958,7 +1024,10 @@ def manip_wheel(cont):
else: else:
return return
##
# Icone de la souris # Icone de la souris
##
def mouse(cont): def mouse(cont):
if scene.objects['Mouse_main']['mouse_graphic']==False: if scene.objects['Mouse_main']['mouse_graphic']==False:
return return
@ -1001,7 +1070,10 @@ def mouse(cont):
obj['past_x']=cont.sensors["Mouse"].position[0] obj['past_x']=cont.sensors["Mouse"].position[0]
obj['past_y']=cont.sensors["Mouse"].position[1] obj['past_y']=cont.sensors["Mouse"].position[1]
##
# Mise en avant de la souris # Mise en avant de la souris
##
def mouse_up(): def mouse_up():
scene.objects['Mouse_main']['mouse_up']+=1 scene.objects['Mouse_main']['mouse_up']+=1
if scene.objects['Mouse_main']['mouse_up'] == 1: if scene.objects['Mouse_main']['mouse_up'] == 1:
@ -1015,7 +1087,10 @@ def mouse_up():
scene.objects['Mouse_main'].worldScale *= (dist/dist_past) *size_scale scene.objects['Mouse_main'].worldScale *= (dist/dist_past) *size_scale
scene.objects['Mouse_main'].worldScale=[8, 8, 8] scene.objects['Mouse_main'].worldScale=[8, 8, 8]
##
# Mise en arrière de la souris # Mise en arrière de la souris
##
def mouse_down(): def mouse_down():
scene.objects['Mouse_main']['mouse_up']-=1 scene.objects['Mouse_main']['mouse_up']-=1
if scene.objects['Mouse_main']['mouse_up'] == 0: if scene.objects['Mouse_main']['mouse_up'] == 0:
@ -1038,7 +1113,10 @@ color_doc_fct = (0.326, 0.101, 0.0592, 1) # BrownDark
color_doc_hl = (0.13, 0.254, 0.407, 1) # BlueDark color_doc_hl = (0.13, 0.254, 0.407, 1) # BlueDark
color_doc_activate = (1.0, 0.025, 0.116, 1) # Red color_doc_activate = (1.0, 0.025, 0.116, 1) # Red
##
# Ouvrir le livre # Ouvrir le livre
##
def doc (cont): def doc (cont):
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Terrain']['manip_mode']==0: if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Terrain']['manip_mode']==0:
scene.objects['Terrain']['manip_mode']=9 # Fenêtre modale scene.objects['Terrain']['manip_mode']=9 # Fenêtre modale
@ -1086,7 +1164,10 @@ def doc (cont):
scene.objects['Book_page_screen'].worldPosition = scene.objects['Book'].worldPosition scene.objects['Book_page_screen'].worldPosition = scene.objects['Book'].worldPosition
scene.objects['Book_page_screen'].setVisible(True,True) scene.objects['Book_page_screen'].setVisible(True,True)
##
# Fermer le livre # Fermer le livre
##
def doc_close (): def doc_close ():
sound_play (sndbuff_book_close) sound_play (sndbuff_book_close)
scene.objects['Terrain']['manip_mode']=0 # Fenêtre modale scene.objects['Terrain']['manip_mode']=0 # Fenêtre modale
@ -1107,12 +1188,18 @@ def doc_close ():
scene.objects['Book-cmd-underlay'].setVisible(False,False) scene.objects['Book-cmd-underlay'].setVisible(False,False)
scene.objects['Construc-underlay'].setVisible(False,False) scene.objects['Construc-underlay'].setVisible(False,False)
##
# Click pour fermer le livre # Click pour fermer le livre
def doc_close_click (cont): ##
def doc_close_click(cont):
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive : if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
doc_close() doc_close()
##
# Highlight du livre # Highlight du livre
##
def doc_hl (cont): def doc_hl (cont):
if cont.sensors['MO'].status == JUST_ACTIVATED : if cont.sensors['MO'].status == JUST_ACTIVATED :
obj = cont.owner obj = cont.owner
@ -1133,14 +1220,17 @@ def doc_hl (cont):
else: else:
scene.objects[name].color = color_doc_fct scene.objects[name].color = color_doc_fct
############################################################################### ###############################################################################
# About # About
############################################################################### ###############################################################################
color_link = (0.799, 0.617, 0.021, 1) # Jaune color_link = (0.799, 0.617, 0.021, 1) # Jaune
color_link_hl = (0.8, 0.8, 0.8, 1) # Blanc color_link_hl = (0.8, 0.8, 0.8, 1) # Blanc
##
# Ouvrir le about # Ouvrir le about
##
def about_open(): def about_open():
scene.objects['Terrain']['manip_mode']=9 # Fenêtre modale scene.objects['Terrain']['manip_mode']=9 # Fenêtre modale
manip_reset() manip_reset()
@ -1158,7 +1248,10 @@ def about_open():
scene.objects['About']['timer'] = 0 scene.objects['About']['timer'] = 0
scene.objects['About']['anim'] = True scene.objects['About']['anim'] = True
##
# Animation du about # Animation du about
##
def about_open_anim(): def about_open_anim():
pas=0.5 pas=0.5
scene.objects['About'].localPosition.y -= pas scene.objects['About'].localPosition.y -= pas
@ -1169,7 +1262,10 @@ def about_open_anim():
if scene.objects['About']['timer']== 40: if scene.objects['About']['timer']== 40:
scene.objects['About']['anim'] = False scene.objects['About']['anim'] = False
##
# Highlight du about # Highlight du about
##
def about_hl(cont): def about_hl(cont):
# decal = 18 # decal = 18
# size_scale = 0.2 # size_scale = 0.2
@ -1204,7 +1300,10 @@ def about_hl(cont):
# scene.objects['Mouse_main'].worldScale=[30, 30, 30] # scene.objects['Mouse_main'].worldScale=[30, 30, 30]
# print("about_hl R après", scene.objects['Mouse_main'].worldPosition) # print("about_hl R après", scene.objects['Mouse_main'].worldPosition)
##
# Fermer le about # Fermer le about
##
def about_close(): def about_close():
sound_play (sndbuff_click) sound_play (sndbuff_click)
scene.objects['Terrain']['manip_mode']=0 scene.objects['Terrain']['manip_mode']=0
@ -1213,12 +1312,18 @@ def about_close():
scene.objects['Aboutbanner'].color = [0.592, 0.68, 0.407, 1] scene.objects['Aboutbanner'].color = [0.592, 0.68, 0.407, 1]
scene.objects['About']['timer']= 0 scene.objects['About']['timer']= 0
##
# Click pour fermer le about # Click pour fermer le about
##
def about_close_click(cont): def about_close_click(cont):
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive : if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
about_close() about_close()
##
# Liens du about # Liens du about
##
def about_link(cont): def about_link(cont):
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive : if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
obj = cont.owner obj = cont.owner
@ -1232,7 +1337,7 @@ def about_link(cont):
'About_link-kenney' : 'https://www.kenney.nl'} 'About_link-kenney' : 'https://www.kenney.nl'}
webbrowser.open(link [name]) webbrowser.open(link [name])
# FIXME: souris graphique trop compliqué # FIXME: souris graphique trop compliqué
def about_link_hl(cont): def about_link_hl(cont):
decal = 15 decal = 15
if cont.sensors['MO'].status == JUST_ACTIVATED : if cont.sensors['MO'].status == JUST_ACTIVATED :

347
ct_lib.py
View File

@ -1,5 +1,5 @@
import bge # Blender Game Engine (UPBGE) import bge # Blender Game Engine (UPBGE)
import aud # Sounds import aud # Sounds
import threading # Multithreading import threading # Multithreading
import trace import trace
import sys import sys
@ -24,7 +24,7 @@ import random
# Commands trigged by 3D scene objects : scn_* # Commands trigged by 3D scene objects : scn_*
# Commands trigged by user (student or map designer) : ct_* # Commands trigged by user (student or map designer) : ct_*
# 3D scene manipulation : manip_* # 3D scene manipulation : manip_*
# #
############################################################################### ###############################################################################
scene = bge.logic.getCurrentScene() scene = bge.logic.getCurrentScene()
@ -71,7 +71,7 @@ JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED
ACTIVATE = bge.logic.KX_INPUT_ACTIVE ACTIVATE = bge.logic.KX_INPUT_ACTIVE
# JUST_DEACTIVATED = bge.logic.KX_SENSOR_JUST_DEACTIVATED # JUST_DEACTIVATED = bge.logic.KX_SENSOR_JUST_DEACTIVATED
############################################################################### ###############################################################################
# Données générales # Données générales
############################################################################### ###############################################################################
@ -81,7 +81,7 @@ def ct_level_current():
def ct_level(): def ct_level():
return scene.objects['Points']['level_max'] return scene.objects['Points']['level_max']
############################################################################### ###############################################################################
# Méthode kill pour les tâches (threads) # Méthode kill pour les tâches (threads)
############################################################################### ###############################################################################
@ -89,33 +89,33 @@ class thread_with_trace(threading.Thread):
def __init__(self, *args, **keywords): def __init__(self, *args, **keywords):
threading.Thread.__init__(self, *args, **keywords) threading.Thread.__init__(self, *args, **keywords)
self.killed = False self.killed = False
def start(self): def start(self):
self.__run_backup = self.run self.__run_backup = self.run
self.run = self.__run self.run = self.__run
threading.Thread.start(self) threading.Thread.start(self)
def __run(self): def __run(self):
sys.settrace(self.globaltrace) sys.settrace(self.globaltrace)
self.__run_backup() self.__run_backup()
self.run = self.__run_backup self.run = self.__run_backup
def globaltrace(self, frame, event, arg): def globaltrace(self, frame, event, arg):
if event == 'call': if event == 'call':
return self.localtrace return self.localtrace
else: else:
return None return None
def localtrace(self, frame, event, arg): def localtrace(self, frame, event, arg):
if self.killed: if self.killed:
if event == 'line': if event == 'line':
raise SystemExit() raise SystemExit()
return self.localtrace return self.localtrace
def kill(self): def kill(self):
self.killed = True self.killed = True
############################################################################### ###############################################################################
# Start et stop des tâches (threads) # Start et stop des tâches (threads)
############################################################################### ###############################################################################
@ -159,7 +159,7 @@ def thread_cmd_start(fct):
def thread_cmd_stop(): def thread_cmd_stop():
thread_stop(threads_cmd, "commands") thread_stop(threads_cmd, "commands")
############################################################################### ###############################################################################
# Sounds # Sounds
############################################################################### ###############################################################################
@ -168,14 +168,17 @@ def sound_play (sound):
if scene.objects['Commands']['sound'] and sys.platform!="win32": if scene.objects['Commands']['sound'] and sys.platform!="win32":
audiodev.play(sound) audiodev.play(sound)
############################################################################### ###############################################################################
# Waves (minions) # Waves (minions)
############################################################################### ###############################################################################
##
# Création d'un minion
#
# Minion caracteristics : category (class), level, hp, speed, armor, bounty, lifes_damage # Minion caracteristics : category (class), level, hp, speed, armor, bounty, lifes_damage
# Minion 3d body : body (male,female,old, ...), variante (A,B,C,D, ...), level # Minion 3d body : body (male,female,old, ...), variante (A,B,C,D, ...), level
##
# Création d'un minion
def ct_minion_create(x,y,cat,level): def ct_minion_create(x,y,cat,level):
category=cat+"-lv"+str(level) category=cat+"-lv"+str(level)
minion_3d= scene.objects['Terrain']['minion_3d'] minion_3d= scene.objects['Terrain']['minion_3d']
@ -241,13 +244,19 @@ def ct_minion_create_details(x,y,cat,level,body="Knight_m_A_common"):
scene.objects['Terrain']['thread_cmd_lock'] = False scene.objects['Terrain']['thread_cmd_lock'] = False
return minion.name return minion.name
##
# Activation du minion (steering) # Activation du minion (steering)
##
def ct_minion_go(minion_name): def ct_minion_go(minion_name):
minion=scene.objects[minion_name] minion=scene.objects[minion_name]
minion.restorePhysics() minion.restorePhysics()
minion.setVisible(True) minion.setVisible(True)
##
# Destruction d'un minion # Destruction d'un minion
##
def scn_minion_dead(cont): def scn_minion_dead(cont):
obj = cont.owner obj = cont.owner
scene.objects['Points']['minions'] -=1 scene.objects['Points']['minions'] -=1
@ -256,11 +265,14 @@ def scn_minion_dead(cont):
scene.objects['Points']['coins']= scene.objects['Points']['coins']+obj['bounty'] scene.objects['Points']['coins']= scene.objects['Points']['coins']+obj['bounty']
obj.endObject() obj.endObject()
############################################################################### ###############################################################################
# Spells / Casts # Spells / Casts
############################################################################### ###############################################################################
##
# Buff/debuff Minion # Buff/debuff Minion
##
def scn_minion_affect(cont): def scn_minion_affect(cont):
if scene.objects['Terrain']['run'] == False: # Pause if scene.objects['Terrain']['run'] == False: # Pause
return return
@ -276,7 +288,7 @@ def scn_minion_affect(cont):
# Lod # Lod
# print(obj.currentLodLevel) # print(obj.currentLodLevel)
# Etats actif # Etats actif
for debuff_i in obj['buff']: for debuff_i in obj['buff']:
if debuff_i[1] <= 0: if debuff_i[1] <= 0:
obj['buff'].remove(debuff_i) obj['buff'].remove(debuff_i)
@ -292,13 +304,16 @@ def scn_minion_affect(cont):
else: else:
obj.actuators['Steering'].velocity = obj['speed_base']*scene.objects['Terrain']['speed'] obj.actuators['Steering'].velocity = obj['speed_base']*scene.objects['Terrain']['speed']
############################################################################### ###############################################################################
# Towers # Towers
############################################################################### ###############################################################################
# Tower caracteristics : category (class), damage, speed, range ##
# Création d'une tour # Création d'une tour
#
# Tower caracteristics : category (class), damage, speed, range
##
def ct_build(x,y, cat='Archer tower', tower_name="Tower", color=tower_purple, building="square-A"): def ct_build(x,y, cat='Archer tower', tower_name="Tower", color=tower_purple, building="square-A"):
tower_minion_3d= scene.objects['Terrain']['tower_minion_3d'] tower_minion_3d= scene.objects['Terrain']['tower_minion_3d']
if cat=='Archer tower': # Archer if cat=='Archer tower': # Archer
@ -308,13 +323,16 @@ def ct_build(x,y, cat='Archer tower', tower_name="Tower", color=tower_purple, bu
body = random.choice(tower_minion_3d[category][0])+"_"+random.choice(tower_minion_3d[category][1])+"_"+random.choice(tower_minion_3d[category][2]) body = random.choice(tower_minion_3d[category][0])+"_"+random.choice(tower_minion_3d[category][1])+"_"+random.choice(tower_minion_3d[category][2])
return (ct_build_details(x,y, cat, tower_name, color, building, body)) return (ct_build_details(x,y, cat, tower_name, color, building, body))
##
# Création d'une tour détaillée # Création d'une tour détaillée
##
def ct_build_details(x,y, cat='Archer tower', tower_name="Tower", color=tower_purple, building="square-A", body="Archer_m_A_common"): def ct_build_details(x,y, cat='Archer tower', tower_name="Tower", color=tower_purple, building="square-A", body="Archer_m_A_common"):
# Vérification de la place # Vérification de la place
if [x,y] in scene.objects['Terrain']['scene_tile_noncontruct'] or [x,y] in scene.objects['Terrain']['scene_tile_tower']: if [x,y] in scene.objects['Terrain']['scene_tile_noncontruct'] or [x,y] in scene.objects['Terrain']['scene_tile_tower']:
return False return False
# Vérification du niveau # Vérification du niveau
scene.objects['Points']['level']= scene.objects['Points']['level'] + 1 scene.objects['Points']['level']= scene.objects['Points']['level'] + 1
if scene.objects['Points']['level'] > scene.objects['Points']['level_max'] : if scene.objects['Points']['level'] > scene.objects['Points']['level_max'] :
@ -324,7 +342,7 @@ def ct_build_details(x,y, cat='Archer tower', tower_name="Tower", color=tower_pu
scene.objects['Terrain']['scene_tile_tower'].append([x,y]) scene.objects['Terrain']['scene_tile_tower'].append([x,y])
return False return False
# Blocage des autres threads pendant la construction # Blocage des autres threads pendant la construction
scene.objects['Terrain']['thread_cmd_lock'] = True scene.objects['Terrain']['thread_cmd_lock'] = True
# Objets 3D # Objets 3D
@ -345,12 +363,12 @@ def ct_build_details(x,y, cat='Archer tower', tower_name="Tower", color=tower_pu
# Draw3d # Draw3d
if cat=='Archer tower': if cat=='Archer tower':
for i in range (10): for i in range (3):
ct_add_bullet(x,y,i) ct_add_bullet(x,y,i)
# Sounds # Sounds
sound_play(sndbuff_build) sound_play(sndbuff_build)
# Caracteristics # Caracteristics
tower_carac= scene.objects['Terrain']['tower_carac'] tower_carac= scene.objects['Terrain']['tower_carac']
tour['cat']=tower_carac[cat][0] tour['cat']=tower_carac[cat][0]
@ -372,12 +390,15 @@ def ct_build_details(x,y, cat='Archer tower', tower_name="Tower", color=tower_pu
tour.sensors['Near'].distance=tour['range'] tour.sensors['Near'].distance=tour['range']
tour.sensors['Near'].skippedTicks =round(1/(tour['speed']*scene.objects['Terrain']['speed'])) tour.sensors['Near'].skippedTicks =round(1/(tour['speed']*scene.objects['Terrain']['speed']))
# Déblocage des autres threads après la construction # Déblocage des autres threads après la construction
scene.objects['Terrain']['thread_cmd_lock'] = False scene.objects['Terrain']['thread_cmd_lock'] = False
# print (scene.objects) # print (scene.objects)
return True return True
##
# Suppression d'une tour # Suppression d'une tour
##
def ct_remove(x,y): def ct_remove(x,y):
for obj_i in scene.objects: for obj_i in scene.objects:
if "type_tower" in obj_i.getPropertyNames(): if "type_tower" in obj_i.getPropertyNames():
@ -386,23 +407,24 @@ def ct_remove(x,y):
obj_i.endObject() obj_i.endObject()
scene.objects['Points']['level']= scene.objects['Points']['level'] - 1 scene.objects['Points']['level']= scene.objects['Points']['level'] - 1
##
# Création d'un projectile # Création d'un projectile
def ct_add_bullet(x,y,num): ##
bullet1= scene.addObject("Bullet", scene.objects['Terrain'])
bullet1.name="tower("+str(x)+','+str(y)+")-bullet"+str(num)
bullet1.mass=0.001
bullet1.worldPosition=[x,y,1.5]
bullet1.worldScale=[0.75,0.75,0.75]
bullet1.suspendPhysics (True)
bullet1.setVisible(False)
bullet1['init_lx']=x
bullet1['init_ly']=y
bullet1['init_lz']=1.5
bullet1['activated']=False
bullet1['velocity']=10
# print ("Création : "+bullet1.name)
def ct_add_bullet(x,y,num):
bullet= scene.addObject("Bullet", scene.objects['Terrain'])
bullet.name="tower("+str(x)+','+str(y)+")-bullet"+str(num)
bullet.worldPosition=[x,y,1.5]
bullet.worldScale=[0.75,0.75,0.75]
bullet.suspendPhysics (True)
bullet.setVisible(False)
bullet['activated']=False
# print ("Création : "+bullet.name)
##
# Réaction d'une tour # Réaction d'une tour
##
def scn_tower_near(cont): def scn_tower_near(cont):
obj = cont.owner obj = cont.owner
sensor = obj.sensors['Near'] sensor = obj.sensors['Near']
@ -458,7 +480,7 @@ def scn_tower_near(cont):
# obj['target_past']=[] # obj['target_past']=[]
# for obj_i in sensor.hitObjectList: # for obj_i in sensor.hitObjectList:
# obj['target_past'].append([obj_i.name, obj.getDistanceTo(obj_i)]) # obj['target_past'].append([obj_i.name, obj.getDistanceTo(obj_i)])
# Orientation du tower minion # Orientation du tower minion
towerminion="tm("+str(round(obj.worldPosition.x))+','+str(round(obj.worldPosition.y))+")" towerminion="tm("+str(round(obj.worldPosition.x))+','+str(round(obj.worldPosition.y))+")"
angle =math.atan((target.worldPosition.y-obj.worldPosition.y)/(target.worldPosition.x-obj.worldPosition.x)) angle =math.atan((target.worldPosition.y-obj.worldPosition.y)/(target.worldPosition.x-obj.worldPosition.x))
@ -470,61 +492,6 @@ def scn_tower_near(cont):
angle3=math.pi+angle angle3=math.pi+angle
scene.objects[towerminion].applyRotation((0, 0, angle2), False) scene.objects[towerminion].applyRotation((0, 0, angle2), False)
# Bullet (3d object) (vitesse lente) # -> tendance au plantage
# if scene.objects['Terrain']['speed']<1:
# bullet= scene.addObject("Bullet", scene.objects['Terrain'])
# bullet.mass=0.001 # bullet.applyForce=((0,0,9.81),True)
# bullet.worldPosition=[obj.worldPosition.x,obj.worldPosition.y,1.5]
# bullet.worldScale=[0.75,0.75,0.75]
# # bullet.worldScale=[0.5,0.5,0.5]
# bullet.worldLinearVelocity.x = (target.worldPosition.x-bullet.worldPosition.x)*bullet['velocity']
# bullet.worldLinearVelocity.y= (target.worldPosition.y-bullet.worldPosition.y)*bullet['velocity']
# bullet.worldLinearVelocity.z = (target.worldPosition.z+0.1-bullet.worldPosition.z)*bullet['velocity']
# print (obj.name)
# bullet1_name=obj.name+"-bullet1" # Tower bullet 1 (tb)
for i in range (10):
bullet = scene.objects[obj.name+"-bullet"+str(i)]
if bullet['activated']==False:
print ("Activate bullet : ", bullet.name, "-> minion : ", target.name)
bullet['activated']=True
bullet.setVisible(True)
bullet.mass=0.001
bullet['velocity']=20
bullet.restorePhysics()
# bullet.worldPosition=[target.worldPosition.x,target.worldPosition.y,target.worldPosition.z+0.5]
bullet.worldPosition=[bullet['init_lx'],bullet['init_ly'],1.5]
# bullet.worldPosition=[round(obj.worldPosition.x),round(obj.worldPosition.y),1.5]
# bullet.worldLinearVelocity.x = (target.worldPosition.x-bullet.worldPosition.x)*bullet['velocity']
# bullet.worldLinearVelocity.y= (target.worldPosition.y-bullet.worldPosition.y)*bullet['velocity']
# bullet.worldLinearVelocity.z = 0
# bullet.worldLinearVelocity.z = (target.worldPosition.z+0.5-bullet.worldPosition.z)*bullet['velocity']
# bullet.worldLinearVelocity.z = (target.worldPosition.z-0.1-bullet.worldPosition.z)*bullet['velocity']
bullet.worldLinearVelocity=[(target.worldPosition.x-bullet.worldPosition.x)*bullet['velocity'],
(target.worldPosition.y-bullet.worldPosition.y)*bullet['velocity'],
(target.worldPosition.z+0.5-1.5)*bullet['velocity']]
print ("bullet.worldPosition.x : "+str(bullet.worldPosition.x)+" -> target.worldPosition.x : "+str(target.worldPosition.x)+" - bullet.worldLinearVelocity.x :"+str(bullet.worldLinearVelocity.x))
print ("bullet.worldPosition.y : "+str(bullet.worldPosition.y)+" -> target.worldPosition.y : "+str(target.worldPosition.y)+" - bullet.worldLinearVelocity.y :"+str(bullet.worldLinearVelocity.y))
print ("bullet.worldPosition.z : "+str(bullet.worldPosition.z)+" -> target.worldPosition.z : "+str(target.worldPosition.z)+" - bullet.worldLinearVelocity.z :"+str(bullet.worldLinearVelocity.z))
# print ("bullet.worldLinearVelocity.x : "+str(bullet.worldLinearVelocity.x))
# print ("bullet.worldPosition.y : "+str(bullet.worldPosition.y)+" -> target.worldPosition.y : ", str(target.worldPosition.y))
# print ("bullet.worldPosition.z : "+str(bullet.worldPosition.z)+" -> target.worldPosition.z : ", str(target.worldPosition.z))
# bullet.worldLinearVelocity.z = (target.worldPosition.z+0.1-bullet.worldPosition.z)*bullet['velocity']
# bullet.worldLinearVelocity.z = 0
break
if i ==9 :
print ("Plus de bullet de disponible !!")
# Sounds # Sounds
if obj['cat']=="Archer tower": if obj['cat']=="Archer tower":
sound_play(sndbuff_archer) sound_play(sndbuff_archer)
@ -538,17 +505,28 @@ def scn_tower_near(cont):
# Archer (tir de flêche) # Archer (tir de flêche)
if obj['cat']=="Archer tower": if obj['cat']=="Archer tower":
if target.name in scene.objects: if target.name in scene.objects:
pass
# scene.objects['Terrain']['draw2d_process']=True # scene.objects['Terrain']['draw2d_process']=True
# scene.objects['Terrain']['draw2d_list'].append([5, "arrow", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8],target.name, angle3, ray_black, 5]) # scene.objects['Terrain']['draw2d_list'].append([5, "arrow", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8], target.name, angle3, ray_black, 5])
# scene.objects['Terrain']['draw3d_process']=True for i in range (3):
# scene.objects['Terrain']['draw3d_list'].append([5, "arrow", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8], obj.name, target.name, angle3, ray_black, 5]) bullet = scene.objects[obj.name+"-bullet"+str(i)]
if bullet['activated']==False:
bullet.worldPosition=[obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8]
bullet['activated']=True
bullet.setVisible(True)
scene.objects['Terrain']['draw3d_process']=True
scene.objects['Terrain']['draw3d_list'].append([20, "arrow", obj.name, bullet.name, target.name, angle3, ray_black, 20])
break
if i ==3 :
print ("Plus de bullet de disponible pour la tour : "+obj.name)
# Cast zone # Cast zone
if obj['cat']=="Mage tower": # Mage (cast) if obj['cat']=="Mage tower": # Mage (cast)
scene.objects['Terrain']['draw2d_process']=True scene.objects['Terrain']['draw2d_process']=True
scene.objects['Terrain']['draw2d_list'].append([30, "cast", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8],ray_blue,30]) scene.objects['Terrain']['draw2d_list'].append([30, "cast", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8],ray_blue,30])
# 'Archer tower' : ["Archer tower", 1.0 , 0.02, 2.5],
# 'Mage tower' : ["Mage tower", 0.0 , 0.005, 2.5],
# Rayon # Rayon
if obj['cat']=="Test": if obj['cat']=="Test":
if target.name in scene.objects: if target.name in scene.objects:
@ -565,21 +543,24 @@ def scn_tower_near(cont):
for target_i in sensor.hitObjectList: for target_i in sensor.hitObjectList:
target_i['buff'].append([obj['cast'], obj['cast_duration']]) target_i['buff'].append([obj['cast'], obj['cast_duration']])
# Cible touchée par un projectile # # Cible touchée par un projectile
def scn_bullet_collision(cont): # def scn_bullet_collision(cont):
obj = cont.owner # obj = cont.owner
# obj['activated']=False # # obj['activated']=False
# # obj.suspendPhysics (True) # # # obj.suspendPhysics (True)
# obj.setVisible(False) # # obj.setVisible(False)
# # obj.worldPosition=[obj['init_lx'],obj['init_ly'],obj['init_lz']] # # # obj.worldPosition=[obj['init_lx'],obj['init_ly'],obj['init_lz']]
# print ("dead bullet : ", obj.name) # # print ("dead bullet : ", obj.name)
############################################################################### ###############################################################################
# Carte # Carte
############################################################################### ###############################################################################
##
# Texte de carte # Texte de carte
##
def ct_map_text_wave(wave): def ct_map_text_wave(wave):
scene.objects['Points-Map-text']['Text']=("Wave " + str(wave)) scene.objects['Points-Map-text']['Text']=("Wave " + str(wave))
scene.objects['Points-Map-text'].setVisible(True,False) scene.objects['Points-Map-text'].setVisible(True,False)
@ -587,17 +568,26 @@ def ct_map_text_wave(wave):
scene.objects['Points-Map-text']['timer']=0 scene.objects['Points-Map-text']['timer']=0
scene.objects['Points-Map-text']['anim']=True scene.objects['Points-Map-text']['anim']=True
##
# Texte de carte # Texte de carte
##
def ct_map_text(text): def ct_map_text(text):
scene.objects['Points-Map-text']['Text']=text scene.objects['Points-Map-text']['Text']=text
scene.objects['Points-Map-text'].setVisible(True,False) scene.objects['Points-Map-text'].setVisible(True,False)
##
# Fin # Fin
##
def ct_map_end(x,y): def ct_map_end(x,y):
scene.objects['Map_end'].worldPosition=[x,y,0.2] scene.objects['Map_end'].worldPosition=[x,y,0.2]
scene.objects['Map_end'].worldScale=[0.25,0.25,0.25] scene.objects['Map_end'].worldScale=[0.25,0.25,0.25]
##
# Minion arrivé à la fin # Minion arrivé à la fin
##
def scn_map_end_near(cont): def scn_map_end_near(cont):
obj = cont.owner obj = cont.owner
sensor = obj.sensors['Near'] sensor = obj.sensors['Near']
@ -610,26 +600,10 @@ def scn_map_end_near(cont):
for obj_i in sensor.hitObjectList : for obj_i in sensor.hitObjectList :
obj_i.endObject() obj_i.endObject()
# def scn_map_end_near(cont): ##
# obj = cont.owner # Drapeau de fin
# print(obj) ##
# sensor = obj.sensors['Near']
# if sensor.positive and len(sensor.hitObjectList)>0 :
# # print ("end, len(sensor.hitObjectList) : ", len(sensor.hitObjectList))
# for obj_i in sensor.hitObjectList :
# # print ("obj['idm_last'], obj_i ['id'] : ", obj['idm_last'], obj_i ['id'])
# if obj['idm_last'] != obj_i ['id']:
# obj['idm_last'] = obj_i ['id']
# sound_play(sndbuff_life)
# if scene.objects['Points']['lifes']>0:
# scene.objects['Points']['lifes']= scene.objects['Points']['lifes']-obj_i['lifes_damage']
# scene.objects['Points']['minions_run'] -=1
# obj['idm_last'] = obj_i ['id']
# for obj_i in sensor.hitObjectList :
# obj_i.endObject()
# Drapeau de fin
def ct_map_endflag(x,y): def ct_map_endflag(x,y):
endflag= scene.addObject("Map_endflag", scene.objects['Terrain']) endflag= scene.addObject("Map_endflag", scene.objects['Terrain'])
endflag.worldPosition=[x,y,0.3] endflag.worldPosition=[x,y,0.3]
@ -650,7 +624,7 @@ def ct_map_endflag(x,y):
scene.objects['Terrain']['scene_tile_noncontruct'].append([math.ceil(x),math.floor(y)]) scene.objects['Terrain']['scene_tile_noncontruct'].append([math.ceil(x),math.floor(y)])
scene.objects['Terrain']['scene_tile_noncontruct'].append([math.ceil(x),math.ceil(y)]) scene.objects['Terrain']['scene_tile_noncontruct'].append([math.ceil(x),math.ceil(y)])
############################################################################### ###############################################################################
# Temporisation # Temporisation
############################################################################### ###############################################################################
@ -674,11 +648,14 @@ def ct_sleep (duration):
# def ct_tempo_wave_trigger (duree): # def ct_tempo_wave_trigger (duree):
# print ("delay wave ", scene.objects['Terrain']['delay_wave']) # print ("delay wave ", scene.objects['Terrain']['delay_wave'])
############################################################################### ###############################################################################
# Affichage # Affichage
############################################################################### ###############################################################################
##
# Texte du panel d'information # Texte du panel d'information
##
def ct_print (text): def ct_print (text):
# text_info (texte) # text_info (texte)
if text=="": if text=="":
@ -687,17 +664,17 @@ def ct_print (text):
else: else:
lines_txt=text.split("\n", 6) lines_txt=text.split("\n", 6)
for i in range (len(lines_txt),6): for i in range (len(lines_txt),6):
lines_txt.append("") lines_txt.append("")
scene.objects['Info-1-text'].setVisible(True,False) scene.objects['Info-1-text'].setVisible(True,False)
scene.objects['Info-2-text'].setVisible(True,False) scene.objects['Info-2-text'].setVisible(True,False)
scene.objects['Info-1-text']['Text']=lines_txt[0]+"\n"+lines_txt[1]+"\n"+lines_txt[2] scene.objects['Info-1-text']['Text']=lines_txt[0]+"\n"+lines_txt[1]+"\n"+lines_txt[2]
scene.objects['Info-2-text']['Text']=lines_txt[3]+"\n"+lines_txt[4]+"\n"+lines_txt[5] scene.objects['Info-2-text']['Text']=lines_txt[3]+"\n"+lines_txt[4]+"\n"+lines_txt[5]
############################################################################### ###############################################################################
# Dessin 3d # Dessin 3d
############################################################################### ###############################################################################
# scene.objects['Terrain']['draw3d_list'].append([5, "arrow", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8], obj.name, target.name, angle3, ray_black, 5]) # scene.objects['Terrain']['draw3d_list'].append([5, "arrow", obj.name, bullet.name, target.name, angle3, ray_black, 5])
def scn_draw3d(cont): def scn_draw3d(cont):
obj = cont.owner obj = cont.owner
@ -706,68 +683,50 @@ def scn_draw3d(cont):
if len(scene.objects['Terrain']['draw3d_list'])==0: if len(scene.objects['Terrain']['draw3d_list'])==0:
scene.objects['Terrain']['draw3d_process']=False scene.objects['Terrain']['draw3d_process']=False
return return
# Dépilage des draws à executer # Dépilage des draws à executer
for draw_cmd in scene.objects['Terrain']['draw3d_list']: for draw_cmd in scene.objects['Terrain']['draw3d_list']:
# Archer (tir de flêche) # Archer (tir de flêche)
if draw_cmd[1]=="arrow": if draw_cmd[1]=="arrow":
if draw_cmd[3] in scene.objects: if draw_cmd[4] in scene.objects:
bullet1.name=draw_cmd[3]+"-bullet1" tower= scene.objects[draw_cmd[2]]
if scene.objects['Terrain']['speed']<1: bullet = scene.objects[draw_cmd[3]]
draw_cmd[0] = draw_cmd[0]-scene.objects['Terrain']['speed'] target = scene.objects[draw_cmd[4]]
else: x0 = tower.worldPosition.x
draw_cmd[0] = draw_cmd[0]-1 y0 = tower.worldPosition.y
z0 = tower.worldPosition.z+0.8 # ajustement +0.8
x1 = target.worldPosition.x
y1 = target.worldPosition.y
z1 = target.worldPosition.z+0.5 # ajustement +0.5
# z1 = target.worldPosition.z-0.1 # ajustement -0.1
step_x=(x1-x0)/draw_cmd[7]
step_y=(y1-y0)/draw_cmd[7]
step_z=(z1-z0)/draw_cmd[7]
step = draw_cmd[7]-draw_cmd[0]
bullet.worldPosition=[x0+step_x*step, y0+step_y*step, z0+step_z*step]
draw_cmd[0] = draw_cmd[0]-scene.objects['Terrain']['speed']
# Dégats
if draw_cmd[0]<=0:
bullet['activated']=False
bullet.setVisible(False)
# bullet.worldPosition=[x0,y0,z0]
target['hp'] = target['hp'] - tower['damage']
if target['hp']<=0: # Mort
target['dead']=True
bullet1.name="tower("+str(x)+','+str(y)+")-bullet1" # Tower bullet 1 (tb) # Suppression des draws finis
i=0
for draw_cmd in scene.objects['Terrain']['draw3d_list']:
if draw_cmd[0]<=0:
scene.objects['Terrain']['draw3d_list'].pop(i)
else:
i=i+1
if len(scene.objects['Terrain']['draw3d_list'])==0:
scene.objects['Terrain']['draw3d_process']=False
# bullet= scene.addObject("Bullet", scene.objects['Terrain']) ###############################################################################
# bullet.mass=0.001 # bullet.applyForce=((0,0,9.81),True)
# bullet.worldPosition=[obj.worldPosition.x,obj.worldPosition.y,1.5]
# bullet.worldScale=[0.75,0.75,0.75]
# # bullet.worldScale=[0.5,0.5,0.5]
# bullet.worldLinearVelocity.x = (target.worldPosition.x-bullet.worldPosition.x)*bullet['velocity']
# bullet.worldLinearVelocity.y= (target.worldPosition.y-bullet.worldPosition.y)*bullet['velocity']
# bullet.worldLinearVelocity.z = (target.worldPosition.z+0.1-bullet.worldPosition.z)*bullet['velocity']
# # x0 = draw_cmd[2][0]+0.25*(math.cos(draw_cmd[4]))
# # y0 = draw_cmd[2][1]+0.25*(math.sin(draw_cmd[4]))
# x0 = draw_cmd[2][0]
# y0 = draw_cmd[2][1]
# z0 = draw_cmd[2][2]
# x1 = scene.objects[draw_cmd[3]].worldPosition.x
# y1 = scene.objects[draw_cmd[3]].worldPosition.y
# z1 = scene.objects[draw_cmd[3]].worldPosition.z-0.1 # ajustement -0.1
# distance = math.sqrt((x1-x0)**2+(y1-y0)**2+(z1-z0)**2)
# distance_xy = math.sqrt((x1-x0)**2+(y1-y0)**2)
# distance_z = z1-z0
# angle_z =math.atan((z1-z0)/(distance_xy))
# angle_xy =math.atan((y1-y0)/(x1-x0))
# step=distance_xy/(2+draw_cmd[6])
# step_z=distance_z/(2+draw_cmd[6])
# if x1>x0:
# angle2=angle_xy
# else:
# angle2=math.pi+angle_xy
# x2=x0+(((6-draw_cmd[0])*step)*(math.cos(angle2)))
# y2=y0+(((6-draw_cmd[0])*step)*(math.sin(angle2)))
# z2=z0-(((6-draw_cmd[0])*step_z)*(math.sin(angle_z)))
# x3=x0+(((6-draw_cmd[0])*step+step)*(math.cos(angle2)))
# y3=y0+(((6-draw_cmd[0])*step+step)*(math.sin(angle2)))
# z3=z0-(((6-draw_cmd[0])*step_z+step_z)*(math.sin(angle_z)))
# bge.render.drawLine([x2,y2, z2], [x3,y3,z3], draw_cmd[5])
# draw_cmd[0] = draw_cmd[0]-scene.objects['Terrain']['speed']
# # if scene.objects['Terrain']['speed']<1:
# # draw_cmd[0] = draw_cmd[0]-scene.objects['Terrain']['speed']
# # else:
# # draw_cmd[0] = draw_cmd[0]-1
# # bge.render.drawLine([draw_cmd[2][0]+((6-draw_cmd[0])*0.25)*(math.cos(draw_cmd[4])), draw_cmd[2][1]+((6-draw_cmd[0])*0.25)*(math.sin(draw_cmd[4])),draw_cmd[2][2]],
# # [draw_cmd[2][0]+((6-draw_cmd[0])*0.25+0.25)*(math.cos(draw_cmd[4])), draw_cmd[2][1]+((6-draw_cmd[0])*0.25+0.25)*(math.sin(draw_cmd[4])),draw_cmd[2][2]],
# # draw_cmd[5])
###############################################################################
# Dessin 2d (bge.render.drawLine) # Dessin 2d (bge.render.drawLine)
############################################################################### ###############################################################################
@ -783,13 +742,15 @@ def circle (center, radius, color):
bge.render.drawLine([x0,y0,center[2]],[x1,y1,center[2]],color) bge.render.drawLine([x0,y0,center[2]],[x1,y1,center[2]],color)
ang += ang_step ang += ang_step
##
# Affiche les draws 2d en cours # Affiche les draws 2d en cours
# #
# Type de draw 2d: # Type de draw 2d:
# arrow : [5, "arrow", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8],target.name, angle3, ray_yellow,5] # arrow : [5, "arrow", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8],target.name, angle3, ray_yellow,5]
# cast : [30, "cast", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8], ray_blue,30] # cast : [30, "cast", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8], ray_blue,30]
# ray : [5, "ray", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8],[target.worldPosition.x, target.worldPosition.y, target.worldPosition.z], angle3, ray_yellow,5] # ray : [5, "ray", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8],[target.worldPosition.x, target.worldPosition.y, target.worldPosition.z], angle3, ray_yellow,5]
# ##
def scn_draw2d(cont): def scn_draw2d(cont):
obj = cont.owner obj = cont.owner
if obj.sensors['Draw2d'].positive==False: if obj.sensors['Draw2d'].positive==False:
@ -797,12 +758,12 @@ def scn_draw2d(cont):
if len(scene.objects['Terrain']['draw2d_list'])==0: if len(scene.objects['Terrain']['draw2d_list'])==0:
scene.objects['Terrain']['draw2d_process']=False scene.objects['Terrain']['draw2d_process']=False
return return
# Dépilage des draws à executer # Dépilage des draws à executer
for draw_cmd in scene.objects['Terrain']['draw2d_list']: for draw_cmd in scene.objects['Terrain']['draw2d_list']:
# Archer (tir de flêche) # Archer (tir de flêche)
if draw_cmd[1]=="arrow": if draw_cmd[1]=="arrow":
if draw_cmd[3] in scene.objects: if draw_cmd[3] in scene.objects:
# x0 = draw_cmd[2][0]+0.25*(math.cos(draw_cmd[4])) # x0 = draw_cmd[2][0]+0.25*(math.cos(draw_cmd[4]))
# y0 = draw_cmd[2][1]+0.25*(math.sin(draw_cmd[4])) # y0 = draw_cmd[2][1]+0.25*(math.sin(draw_cmd[4]))

View File

@ -14,16 +14,16 @@ import os
# #
# This game is a tower defense coding game. The towers are driven by Python code. # This game is a tower defense coding game. The towers are driven by Python code.
# The file is the the map and waves definition. # The file is the the map and waves definition.
# #
############################################################################### ###############################################################################
scene = bge.logic.getCurrentScene() scene = bge.logic.getCurrentScene()
############################################################################### ###############################################################################
# En: Threads management << DONT CHANGE THIS SECTION >> # En: Threads management << DONT CHANGE THIS SECTION >>
# Fr: Gestion des tâches (threads) << NE PAS MODIFIER CETTE SECTION >> # Fr: Gestion des tâches (threads) << NE PAS MODIFIER CETTE SECTION >>
############################################################################### ###############################################################################
# waves_f={ # waves_f={
# 1 : wave1(), # 1 : wave1(),
# 2 :wave2(), # 2 :wave2(),
@ -181,7 +181,7 @@ def tower_definition():
# Tower caracteristics : category (class), damage, speed, range # Tower caracteristics : category (class), damage, speed, range
tower_carac={ tower_carac={
'Archer tower' : ["Archer tower", 1.0 , 0.02, 2.5], 'Archer tower' : ["Archer tower", 1.0 , 0.01, 2.5],
'Mage tower' : ["Mage tower", 0.0 , 0.005, 2.5], 'Mage tower' : ["Mage tower", 0.0 , 0.005, 2.5],
'Barrack' : ["Barrack", 1.0 , 0.0001, 2.5]} 'Barrack' : ["Barrack", 1.0 , 0.0001, 2.5]}
scene.objects['Terrain']['tower_carac'] = tower_carac scene.objects['Terrain']['tower_carac'] = tower_carac
@ -224,7 +224,7 @@ def map_init():
ct_map_end(1,-10) ct_map_end(1,-10)
ct_map_endflag(0.5,-10) ct_map_endflag(0.5,-10)
ct_map_endflag(1.5,-10) ct_map_endflag(1.5,-10)
# Reset counters # Reset counters
def map_reset(): def map_reset():
scene.objects['Points']['lifes']=10 scene.objects['Points']['lifes']=10
@ -235,4 +235,3 @@ def map_reset():
scene.objects['Points']['minions']=0 scene.objects['Points']['minions']=0
scene.objects['Points']['minions_run']=0 scene.objects['Points']['minions_run']=0
scene.objects['Points']['wave']=1 scene.objects['Points']['wave']=1