mirror of
https://forge.apps.education.fr/phroy/codetower.git
synced 2024-01-27 11:35:17 +01:00
animation des tours avec draw (sans objet 3d)
This commit is contained in:
parent
a19fa62b94
commit
92917af45f
BIN
codetower-13.blend
Normal file
BIN
codetower-13.blend
Normal file
Binary file not shown.
25
ct.py
25
ct.py
@ -25,7 +25,7 @@ import ct_map
|
||||
###############################################################################
|
||||
|
||||
# Import dynamique des fichiers Python élève et vagues
|
||||
# sys.setrecursionlimit(10**5) # Limite sur la récursivité (valeur par défaut : 1000) -> segfault de Blender
|
||||
sys.setrecursionlimit(10**5) # Limite sur la récursivité (valeur par défaut : 1000) -> segfault de Blender
|
||||
importlib.invalidate_caches()
|
||||
ct_wv = importlib.import_module('ct_waves') # waves script
|
||||
ct_cmd = importlib.import_module('ct_cmd') # user script (commands)
|
||||
@ -146,6 +146,7 @@ def scn_terrain_mo(cont):
|
||||
text_info ("Tower position : "+str(round(hitPosition.x))+","+str(round(hitPosition.y)))
|
||||
|
||||
# Affiche les informations sur la tour
|
||||
# FIXME : High-light sur la tower sélectionnée
|
||||
else:
|
||||
hitPosition = cont.sensors['MO'].hitPosition
|
||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Terrain']['manip_mode']==0:
|
||||
@ -162,6 +163,10 @@ def scn_terrain_mo(cont):
|
||||
# Initialisation lors du chargement du terrain
|
||||
def terrain_init (cont):
|
||||
|
||||
# Pile des draws
|
||||
scene.objects['Terrain']['draw_process']=False
|
||||
scene.objects['Terrain']['draw_list']=[]
|
||||
|
||||
# Mise à zéro des compteurs
|
||||
scene.objects['Points']['lifes']=10
|
||||
scene.objects['Points']['lifes_max']=10
|
||||
@ -197,7 +202,7 @@ def terrain_run (cont):
|
||||
scene.objects['Pause-Hl'].setVisible(False,False)
|
||||
scene.objects['Run-Hl'].setVisible(True,False)
|
||||
for obj_i in scene.objects: # Pause des Steerings
|
||||
if "type_minion" in obj_i.getPropertyNames():
|
||||
if "type_minion" in obj_i.getPropertyNames() and "type_towerminion" not in obj_i.getPropertyNames():
|
||||
obj_i.actuators['Steering'].velocity=0
|
||||
else:
|
||||
|
||||
@ -210,9 +215,11 @@ def terrain_run (cont):
|
||||
# Démarrage de la map
|
||||
if scene.objects['Terrain']['thread_run']==False:
|
||||
for obj_i in scene.objects: # Supprimer les tours
|
||||
if "type_tower" in obj_i.getPropertyNames():
|
||||
if "type_tower" in obj_i.getPropertyNames() :
|
||||
obj_i.endObject()
|
||||
scene.objects['Points']['level']= scene.objects['Points']['level'] - 1
|
||||
if "type_towerminion" in obj_i.getPropertyNames() :
|
||||
obj_i.endObject()
|
||||
scene.objects['Terrain']['scene_tile_tower']= []
|
||||
scene.objects['Stop'].setVisible(True,False)
|
||||
scene.objects['Terrain']['thread_run']=True
|
||||
@ -248,7 +255,7 @@ def terrain_runspeed (cont):
|
||||
if "type_tower" in obj_i.getPropertyNames() and "Near" in obj_i.sensors :
|
||||
obj_i.sensors['Near'].skippedTicks =round(1/(obj_i.components['Tower'].args['speed']*scene.objects['Terrain']['speed']))
|
||||
print (obj_i.sensors['Near'].skippedTicks)
|
||||
if "type_minion" in obj_i.getPropertyNames():
|
||||
if "type_minion" in obj_i.getPropertyNames() and "type_towerminion" not in obj_i.getPropertyNames():
|
||||
obj_i.actuators['Steering'].velocity=obj_i.components['Minion'].args['speed']*scene.objects['Terrain']['speed']
|
||||
|
||||
# Maj du fichier de config (vitesse du jeu : data/config/speed)
|
||||
@ -269,7 +276,7 @@ def terrain_stop (cont):
|
||||
|
||||
# Supprimer les enemis
|
||||
for obj_i in scene.objects:
|
||||
if "type_minion" in obj_i.getPropertyNames():
|
||||
if "type_minion" in obj_i.getPropertyNames() and "type_towerminion" not in obj_i.getPropertyNames():
|
||||
obj_i.endObject()
|
||||
scene.objects['Points']['minions']=0
|
||||
|
||||
@ -414,7 +421,7 @@ def mode(cont):
|
||||
scene.objects['Pause'].setVisible(False,False)
|
||||
scene.objects['Run'].setVisible(True,False)
|
||||
for obj_i in scene.objects: # Pause des Steerings
|
||||
if "type_minion" in obj_i.getPropertyNames():
|
||||
if "type_minion" in obj_i.getPropertyNames() and "type_towerminion" not in obj_i.getPropertyNames() :
|
||||
obj_i.actuators['Steering'].velocity=0
|
||||
|
||||
# Run
|
||||
@ -426,9 +433,11 @@ def mode(cont):
|
||||
# Démarrage de la map
|
||||
if scene.objects['Terrain']['thread_run']==False:
|
||||
for obj_i in scene.objects: # Supprimer les tours
|
||||
if "type_tower" in obj_i.getPropertyNames():
|
||||
if "type_tower" in obj_i.getPropertyNames() :
|
||||
obj_i.endObject()
|
||||
scene.objects['Points']['level']= scene.objects['Points']['level'] - 1
|
||||
if "type_towerminion" in obj_i.getPropertyNames() :
|
||||
obj_i.endObject()
|
||||
scene.objects['Terrain']['scene_tile_tower']= []
|
||||
scene.objects['Stop'].setVisible(True,False)
|
||||
scene.objects['Terrain']['thread_run']=True
|
||||
@ -467,7 +476,7 @@ def mode(cont):
|
||||
scene.objects['Stop-Hl'].setVisible(False,False)
|
||||
|
||||
###############################################################################
|
||||
# Manipulation 3D du système
|
||||
# Manipulation 3D de la scène
|
||||
###############################################################################
|
||||
|
||||
# Mémorisation de la position et orientation initiales du modèle 3D et de la caméra
|
||||
|
14
ct_cmd.py
14
ct_cmd.py
@ -22,6 +22,7 @@ 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 >>
|
||||
@ -42,9 +43,10 @@ def stop():
|
||||
# En: Tower commands
|
||||
# Fr: Commandes des tours
|
||||
#
|
||||
# Build a tower : ct_build(x, y, name, color,style)
|
||||
# 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'
|
||||
@ -52,6 +54,8 @@ def stop():
|
||||
# - True : builded
|
||||
# - False : not builded
|
||||
#
|
||||
# - exemple : ct_build("archer tower", 4,5, "Tower #1",yellow,"round-A")
|
||||
#
|
||||
# Remove a tower : ct_remove(x, y)
|
||||
# - x position (integer)
|
||||
# - y position (integer)
|
||||
@ -65,8 +69,10 @@ def commands():
|
||||
|
||||
# Code your commands here ...
|
||||
|
||||
ct_build(4,5, "Tower #1")
|
||||
ct_build(5,5, "Tower #2", green)
|
||||
ct_build(4,5, "Archer tower", "Tower #1", blue, "square-A")
|
||||
# ct_build_details(4,5, "Mage tower", "Tower #1", blue, "square-A", "Mage_A_common")
|
||||
# ct_build(4,5, "Mage tower", "Tower #1", yellow, "square-A")
|
||||
# ct_build(5,5)
|
||||
# ct_build(5,4, "Tower #3")
|
||||
# ct_build(4,4, "Tower #4", [0.3, 0.5, 0.5, 1])
|
||||
# ct_build(4,5, "Tower #5")
|
||||
@ -76,6 +82,6 @@ def commands():
|
||||
# ct_remove(4,4)
|
||||
# ct_print("ok")
|
||||
|
||||
ct_tempo(2)
|
||||
ct_sleep(2)
|
||||
print ("Threads commands #", len(threads)-1, "are arrived -> close them.") # Thread closed << DONT CHANGE THIS LINE >>
|
||||
scene.objects['Terrain']['thread_cmd']=False # End of cycle << DONT CHANGE THIS LINE >>
|
||||
|
282
ct_lib.py
282
ct_lib.py
@ -7,8 +7,6 @@ import math
|
||||
import mathutils
|
||||
import random
|
||||
|
||||
# from ct import * # Bibliothèque CodeTower
|
||||
|
||||
###############################################################################
|
||||
# ct_lib.py
|
||||
# @title: User library
|
||||
@ -37,6 +35,10 @@ tower_orange = [0.799, 0.130, 0.063,1]
|
||||
tower_yellow = [0.799, 0.617, 0.021, 1]
|
||||
tower_green = [0.246, 0.687, 0.078, 1]
|
||||
tower_red = [0.799, 0.031, 0.038, 1]
|
||||
tower_blue = [0.127, 0.456, 1.000, 1]
|
||||
|
||||
ray_yellow = [0.799, 0.617, 0.021, 1] # [0.8, 0.619, 0.021])
|
||||
ray_blue = [0.127, 0.456, 1.000, 1]
|
||||
|
||||
###############################################################################
|
||||
# Méthode kill pour les tâches (threads)
|
||||
@ -130,16 +132,23 @@ minion_3d={
|
||||
# Création d'un minion
|
||||
def ct_minion(x,y,cat,level):
|
||||
category=cat+"-lv"+str(level)
|
||||
body = random.choice(minion_3d[category][0])+"_"+random.choice(minion_3d[category][1])+"_"+random.choice(minion_3d[category][2])
|
||||
ct_minion_details(x,y,cat,level,body)
|
||||
|
||||
def ct_minion_details(x,y,cat,level,body="Knight_m_A_common"):
|
||||
category=cat+"-lv"+str(level)
|
||||
|
||||
# Pause
|
||||
# FIXME : buggé
|
||||
while scene.objects['Terrain']['run'] == False:
|
||||
time.sleep(0)
|
||||
time.sleep(0.01)
|
||||
|
||||
# Object 3D
|
||||
body = random.choice(minion_3d[category][0])+"_"+random.choice(minion_3d[category][1])+"_"+random.choice(minion_3d[category][2])
|
||||
minion= scene.addObject(body, scene.objects['Terrain'])
|
||||
minion.worldScale=mathutils.Vector((0.25,0.25,0.25))
|
||||
minion.worldPosition=mathutils.Vector((x,y,0.1))
|
||||
minion.worldScale=[0.25,0.25,0.25]
|
||||
minion.worldPosition=[x,y,0.1]
|
||||
scene.objects['Terrain']['idm']=scene.objects['Terrain']['idm']+1
|
||||
minion.name="wm("+str(scene.objects['Terrain']['idm'])+")" # Wave minion (wm), identifier minion (idm)
|
||||
# minion.worldPosition=mathutils.Vector((x,y,0.3))
|
||||
# minion.worldPosition=mathutils.Vector((x,y,0.37)) # old 2
|
||||
scene.objects['Points']['minions']= scene.objects['Points']['minions']+1
|
||||
@ -159,6 +168,7 @@ def ct_minion(x,y,cat,level):
|
||||
minion.actuators['Steering'].target=scene.objects[scene.objects['Terrain']['endtile']]
|
||||
minion.actuators['Steering'].distance=0.5
|
||||
minion.actuators['Steering'].velocity=minion.components['Minion'].args['speed']*scene.objects['Terrain']['speed']
|
||||
# print (minion.getPropertyNames())
|
||||
|
||||
# Destruction d'un minion
|
||||
def scn_minion_dead(cont):
|
||||
@ -174,13 +184,28 @@ def scn_minion_dead(cont):
|
||||
# Tower caracteristics : category (class), damage, speed, range
|
||||
|
||||
tower_carac={
|
||||
'Base' : ["Base", 1.0 , 0.02, 3.0]}
|
||||
'Archer tower' : ["Archer tower", 1.0 , 0.02, 2.5],
|
||||
'Mage tower' : ["Mage tower", 1.0 , 0.005, 2.5],
|
||||
'Barrack' : ["Barrack", 1.0 , 0.0001, 2.5]}
|
||||
|
||||
# carac_tower={
|
||||
# 'Base' : ["Base", 1.0 , 0.02, 3.0]}
|
||||
tower_minion_3d={
|
||||
'Archer-lv1' : [['Archer_m', 'Archer_f', "OldArcher_m"],['A','B','C','D'],['common']],
|
||||
'Archer-lv2' : [['Archer_m', 'Archer_f', "OldArcher_m"],['A','B','C','D'],['uncommon']],
|
||||
'Archer-lv3' : [['Archer_m', 'Archer_f', "OldArcher_m"],['A','B','C','D'],['rare']],
|
||||
'Mage-lv1' : [['Mage'],['A','B','C','D'],['common']],
|
||||
'Mage-lv2' : [['Mage'],['A','B','C','D'],['uncommon']],
|
||||
'Mage-lv3' : [['Mage'],['A','B','C','D'],['rare']]}
|
||||
|
||||
# Création d'une tour
|
||||
def ct_build(x,y,tower_name="Tower",color=tower_purple, tower_3d="square-A",cat='Base'):
|
||||
def ct_build(x,y, cat='Archer tower', tower_name="Tower", color=tower_purple, tower_3d="square-A"):
|
||||
if cat=='Archer tower': # Archer
|
||||
category="Archer-lv1"
|
||||
if cat=='Mage tower': # Mage
|
||||
category="Mage-lv1"
|
||||
body = random.choice(tower_minion_3d[category][0])+"_"+random.choice(tower_minion_3d[category][1])+"_"+random.choice(tower_minion_3d[category][2])
|
||||
ct_build_details(x,y, cat, tower_name, color, tower_3d, body)
|
||||
|
||||
def ct_build_details(x,y, cat='Archer tower', tower_name="Tower", color=tower_purple, tower_3d="square-A", body="Archer_m_A_common"):
|
||||
|
||||
# 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']:
|
||||
@ -190,18 +215,23 @@ def ct_build(x,y,tower_name="Tower",color=tower_purple, tower_3d="square-A",cat=
|
||||
scene.objects['Points']['level']= scene.objects['Points']['level'] + 1
|
||||
if scene.objects['Points']['level'] > scene.objects['Points']['level_max'] :
|
||||
tour= scene.addObject("Tower_error", scene.objects['Terrain'])
|
||||
tour.worldPosition=mathutils.Vector((x,y,0.2))
|
||||
tour.worldScale=mathutils.Vector((1,1,1))
|
||||
tour.worldPosition=[x,y,0.2]
|
||||
tour.worldScale=[1,1,1]
|
||||
scene.objects['Terrain']['scene_tile_tower'].append([x,y])
|
||||
return False
|
||||
|
||||
# Objet 3D
|
||||
# Objets 3D
|
||||
tour= scene.addObject('Tower-'+tower_3d, scene.objects['Terrain'])
|
||||
tour.color = color
|
||||
tour.worldPosition=mathutils.Vector((x,y,0.2))
|
||||
tour.worldScale=mathutils.Vector((1,1,1))
|
||||
tour.worldPosition=[x,y,0.2]
|
||||
tour.worldScale=[1,1,1]
|
||||
scene.objects['Terrain']['scene_tile_tower'].append([x,y])
|
||||
|
||||
tower_minion= scene.addObject(body, scene.objects['Terrain'])
|
||||
tower_minion["type_towerminion"]=False
|
||||
tower_minion.name="tm("+str(x)+','+str(y)+")" # Tower minion (tm)
|
||||
tower_minion.worldPosition=[x,y,1]
|
||||
tower_minion.worldScale=[0.25,0.25,0.25]
|
||||
|
||||
# Caractéristiques (composant python et propriétés de l'objet 3D)
|
||||
tour.components['Tower'].args['cat']=tower_carac[cat][0]
|
||||
tour.components['Tower'].args['lvl']=1
|
||||
@ -216,21 +246,26 @@ def ct_build(x,y,tower_name="Tower",color=tower_purple, tower_3d="square-A",cat=
|
||||
tour['speed']=tower_carac[cat][2]
|
||||
tour['range']=tower_carac[cat][3]
|
||||
|
||||
# Gestion du draw
|
||||
tour['fire_frame']=0
|
||||
tour['fire_target']=[]
|
||||
|
||||
# Capteur Near
|
||||
tour.sensors['Near'].distance=tour.components['Tower'].args['range']
|
||||
tour.sensors['Near'].skippedTicks =round(1/(tour.components['Tower'].args['speed']*scene.objects['Terrain']['speed']))
|
||||
print (tour.sensors['Near'].skippedTicks)
|
||||
|
||||
# for obj_i in scene.objects:
|
||||
# if "type_tower" in obj_i.getPropertyNames():
|
||||
# print (obj_i['tower_name'])
|
||||
# print (tour.getPropertyNames())
|
||||
return True
|
||||
|
||||
# Supression d'une tour
|
||||
# Suppression d'une tour
|
||||
def ct_remove(x,y):
|
||||
for obj_i in scene.objects: # Supprimer les tours
|
||||
for obj_i in scene.objects:
|
||||
if "type_tower" in obj_i.getPropertyNames():
|
||||
if x == obj_i.worldPosition.x and y == obj_i.worldPosition.y:
|
||||
scene.objects["tm("+str(round(obj_i.worldPosition.x))+','+str(round(obj_i.worldPosition.y))+")"].endObject()
|
||||
obj_i.endObject()
|
||||
scene.objects['Points']['level']= scene.objects['Points']['level'] - 1
|
||||
|
||||
@ -240,31 +275,56 @@ def scn_tower_near(cont):
|
||||
sensor = obj.sensors['Near']
|
||||
|
||||
# Tir
|
||||
# FIXME: deux tirs à la fois ?
|
||||
# FIXME: tir sur le plus avancé
|
||||
if len(sensor.hitObjectList)>0 and scene.objects['Terrain']['run']==True :
|
||||
|
||||
if sensor.positive and len(sensor.hitObjectList)>0 and scene.objects['Terrain']['run']==True :
|
||||
target=sensor.hitObjectList[0]
|
||||
# target.actuators['Steering'].velocity=(target.components['Minion'].args['speed']*scene.objects['Terrain']['speed'])/2 # Reduction de la vitesse du minion
|
||||
|
||||
# Bullet (3d object) (vitesse <=1)
|
||||
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=mathutils.Vector((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']
|
||||
# Orientation du tower minion
|
||||
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))
|
||||
if target.worldPosition.x>obj.worldPosition.x:
|
||||
angle2=math.pi/2+angle-scene.objects[towerminion].worldOrientation.to_euler().z
|
||||
angle3=angle
|
||||
else:
|
||||
angle2=math.pi+math.pi/2+angle-scene.objects[towerminion].worldOrientation.to_euler().z
|
||||
angle3=math.pi+angle
|
||||
scene.objects[towerminion].applyRotation((0, 0, angle2), False)
|
||||
|
||||
# Line (vitesse >=2)
|
||||
if scene.objects['Terrain']['speed']>=2:
|
||||
bge.render.drawLine([obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.1],
|
||||
[target.worldPosition.x, target.worldPosition.y, target.worldPosition.z],
|
||||
[0.8, 0.619, 0.021])
|
||||
# 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']
|
||||
|
||||
# Ligne (drawLine) (vitesse rapide)
|
||||
# if scene.objects['Terrain']['speed']>=1:
|
||||
if scene.objects['Terrain']['speed']<10: # Pas d'animation à 10 -> plantage
|
||||
|
||||
# Archer (tir de flêche)
|
||||
if obj['cat']=="Archer tower":
|
||||
if target.name in scene.objects:
|
||||
scene.objects['Terrain']['draw_process']=True
|
||||
scene.objects['Terrain']['draw_list'].append([5, "arrow", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8],target.name, angle3, ray_yellow, 5])
|
||||
|
||||
# Cast zone
|
||||
if obj['cat']=="Mage tower": # Mage (cast)
|
||||
scene.objects['Terrain']['draw_process']=True
|
||||
scene.objects['Terrain']['draw_list'].append([30, "cast", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8],ray_blue,30])
|
||||
|
||||
# Rayon
|
||||
if obj['cat']=="Test":
|
||||
if target.name in scene.objects:
|
||||
scene.objects['Terrain']['draw_process']=True
|
||||
scene.objects['Terrain']['draw_list'].append([5, "ray", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8], target.name, angle3, ray_yellow,5]) # Suivi du minion
|
||||
|
||||
# Dégats
|
||||
# FIXME : cast -> buff
|
||||
target['hp'] = target['hp'] - obj.components['Tower'].args['damage']
|
||||
if target['hp']<=0:
|
||||
target['dead']=True
|
||||
@ -283,8 +343,6 @@ def ct_map_end(x,y):
|
||||
def scn_map_end_near(cont):
|
||||
obj = cont.owner
|
||||
sensor = obj.sensors['Near']
|
||||
# if len(sensor.hitObjectList)>0:
|
||||
# print ("Arrive à la fin", sensor.hitObjectList)
|
||||
for i in range (len(sensor.hitObjectList)) :
|
||||
sensor.hitObjectList[i].endObject()
|
||||
scene.objects['Points']['lifes']= scene.objects['Points']['lifes']-sensor.hitObjectList[0].components['Minion'].args['lifes_damage']
|
||||
@ -318,19 +376,19 @@ def ct_map_endflag(x,y):
|
||||
def ct_sleep (duration):
|
||||
time.sleep(duration*(1/scene.objects['Terrain']['speed']))
|
||||
|
||||
def ct_tempo (duration):
|
||||
scene.objects['Terrain']['delay_cmd']=0
|
||||
while scene.objects['Terrain']['delay_cmd']<duration*(1/scene.objects['Terrain']['speed']):
|
||||
# print("Temporization commands :",scene.objects['Terrain']['delay_cmd'])
|
||||
time.sleep(0.001)
|
||||
# pass
|
||||
# def ct_tempo (duration):
|
||||
# scene.objects['Terrain']['delay_cmd']=0
|
||||
# while scene.objects['Terrain']['delay_cmd']<duration*(1/scene.objects['Terrain']['speed']):
|
||||
# # print("Temporization commands :",scene.objects['Terrain']['delay_cmd'])
|
||||
# time.sleep(0.001)
|
||||
# # pass
|
||||
|
||||
def ct_tempo_wave (duration):
|
||||
scene.objects['Terrain']['delay_wave']=0
|
||||
while scene.objects['Terrain']['delay_wave']<duration*(1/scene.objects['Terrain']['speed']):
|
||||
# print("Temporization waves :",scene.objects['Terrain']['delay_wave'])
|
||||
time.sleep(0.001)
|
||||
# pass
|
||||
# def ct_tempo_wave (duration):
|
||||
# scene.objects['Terrain']['delay_wave']=0
|
||||
# while scene.objects['Terrain']['delay_wave']<duration*(1/scene.objects['Terrain']['speed']):
|
||||
# # print("Temporization waves :",scene.objects['Terrain']['delay_wave'])
|
||||
# time.sleep(0.001)
|
||||
# # pass
|
||||
|
||||
# def ct_tempo_wave_trigger (duree):
|
||||
# print ("delay wave ", scene.objects['Terrain']['delay_wave'])
|
||||
@ -358,3 +416,125 @@ def ct_print (text):
|
||||
def ct_map_text(text):
|
||||
scene.objects['Map_text']['Text']=text
|
||||
scene.objects['Map_text'].setVisible(True,False)
|
||||
|
||||
###############################################################################
|
||||
# Dessin bas niveau (bge.render.drawLine)
|
||||
###############################################################################
|
||||
|
||||
def circle (center, radius, color):
|
||||
ang = 0.0
|
||||
ang_step = 0.1
|
||||
while ang< 2 * math.pi:
|
||||
x0 = center[0]+float(radius*math.cos(ang))
|
||||
y0 = center[1]+float(radius*math.sin(ang))
|
||||
x1 = center[0]+float(radius*math.cos(ang+ang_step))
|
||||
y1 = center[1]+float(radius*math.sin(ang+ang_step))
|
||||
bge.render.drawLine([x0,y0,center[2]],[x1,y1,center[2]],color)
|
||||
ang += ang_step
|
||||
|
||||
# Fire : projectile ou cast
|
||||
# def scn_tower_fire(cont):
|
||||
# obj = cont.owner
|
||||
# if obj["fire_frame"]!=0:
|
||||
# if obj['cat']=="Archer tower": # Archer (tir de flêche)
|
||||
# bge.render.drawLine([obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8],obj['fire_target'][0], ray_yellow)
|
||||
# if obj['cat']=="Mage tower": # Mage (cast)
|
||||
# circle([obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8], 3, ray_blue)
|
||||
# obj["fire_frame"] -=1
|
||||
|
||||
# Affiche les draws en cours
|
||||
# FIXME: tir sur le plus avancé
|
||||
# FIXME : remplacer le rayon par un projectile
|
||||
# FIXME : remplacer le cercle par un cercle progressif
|
||||
#
|
||||
# Type de draw :
|
||||
# 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]
|
||||
# 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_draw(cont):
|
||||
obj = cont.owner
|
||||
if obj.sensors['Property'].positive==False:
|
||||
return
|
||||
if len(scene.objects['Terrain']['draw_list'])==0:
|
||||
scene.objects['Terrain']['draw_process']=False
|
||||
return
|
||||
|
||||
# Dépilage des draws à executer
|
||||
for draw_cmd in scene.objects['Terrain']['draw_list']:
|
||||
|
||||
# Archer (tir de flêche)
|
||||
if draw_cmd[1]=="arrow":
|
||||
if draw_cmd[3] in scene.objects:
|
||||
# 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])
|
||||
|
||||
# Mage (cast)
|
||||
if draw_cmd[1]=="cast": # Mage (cast)
|
||||
circle(draw_cmd[2], 3.1-draw_cmd[0]*0.1, draw_cmd[3])
|
||||
circle(draw_cmd[2], 3-draw_cmd[0]*0.1, draw_cmd[3])
|
||||
circle(draw_cmd[2], 2.9-draw_cmd[0]*0.1, draw_cmd[3])
|
||||
draw_cmd[0] = draw_cmd[0]-scene.objects['Terrain']['speed']
|
||||
# if scene.objects['Terrain']['speed']<=2:
|
||||
# draw_cmd[0] = draw_cmd[0]-scene.objects['Terrain']['speed']
|
||||
# if scene.objects['Terrain']['speed']==4:
|
||||
# draw_cmd[0] = draw_cmd[0]-draw_cmd[4]/2
|
||||
# circle(draw_cmd[2], 3, draw_cmd[3]) # simple
|
||||
# radius=[3,3,2.5,2.5,2,2,1.5,1.5,1,1,1] # basé sur un tableau
|
||||
# circle(draw_cmd[2], radius[draw_cmd[0]], draw_cmd[3])
|
||||
|
||||
# Rayon
|
||||
if draw_cmd[1]=="ray":
|
||||
if draw_cmd[3] in scene.objects:
|
||||
x0 = draw_cmd[2][0]+0.25*(math.cos(draw_cmd[4]))
|
||||
y0 = draw_cmd[2][1]+0.25*(math.sin(draw_cmd[4]))
|
||||
x1 = scene.objects[draw_cmd[3]].worldPosition.x
|
||||
y1 = scene.objects[draw_cmd[3]].worldPosition.y
|
||||
z1 = scene.objects[draw_cmd[3]].worldPosition.z
|
||||
bge.render.drawLine([x0,y0, draw_cmd[2][2]], [x1,y1,z1], draw_cmd[5]) # suivi minion
|
||||
# bge.render.drawLine([draw_cmd[2][0]+0.25*(math.cos(draw_cmd[4])), draw_cmd[2][1]+0.25*(math.sin(draw_cmd[4])), draw_cmd[2][2]], draw_cmd[3], draw_cmd[5]) # décalage minion
|
||||
# bge.render.drawLine(draw_cmd[2], draw_cmd[3], draw_cmd[5]) # simple
|
||||
draw_cmd[0] = draw_cmd[0]-scene.objects['Terrain']['speed']
|
||||
|
||||
# Suppression des draws finis
|
||||
i=0
|
||||
for draw_cmd in scene.objects['Terrain']['draw_list']:
|
||||
if draw_cmd[0]<=0:
|
||||
scene.objects['Terrain']['draw_list'].pop(i)
|
||||
else:
|
||||
i=i+1
|
||||
if len(scene.objects['Terrain']['draw_list'])==0:
|
||||
scene.objects['Terrain']['draw_process']=False
|
||||
|
24
ct_waves.py
24
ct_waves.py
@ -59,10 +59,21 @@ def stop():
|
||||
|
||||
# Minion caracteristics : category (class), level, hp, speed, armor, bounty, lifes_damage
|
||||
|
||||
# carac_minion={
|
||||
# minion_carac={
|
||||
# 'Knight-lv1' : ["Knight", 1 , 2.0, 1.0, 0.0, 5,1],
|
||||
# 'Knight-lv2' : ["Knight", 2, 4.0, 1.0, 1.0, 20,1],
|
||||
# 'Knight-lv3' : ["Knight", 3, 8.0, 1.0, 2.0, 80,1]}
|
||||
# 'Knight-lv3' : ["Knight", 3, 8.0, 1.0, 2.0, 80,1],
|
||||
# 'Orc-lv1' : ["Orc", 1 , 2.0, 1.0, 0.0, 5,1],
|
||||
# 'Orc-lv2' : ["Orc", 2, 4.0, 1.0, 1.0, 20,1],
|
||||
# 'Orc-lv3' : ["Orc", 3, 8.0, 1.0, 2.0, 80,1]}
|
||||
|
||||
# minion_3d={
|
||||
# 'Knight-lv1' : [['Knight_m', 'Knight_f', 'OldKnight_m'],['A','B','C','D'],['common']],
|
||||
# 'Knight-lv2' : [['Knight_m', 'Knight_f', 'OldKnight_m'],['A','B','C','D'],['uncommon']],
|
||||
# 'Knight-lv3' : [['Knight_m', 'Knight_f', 'OldKnight_m'],['A','B','C','D'],['rare']],
|
||||
# 'Orc-lv1' : [['Orc'],['A','B','C','D','E','F'],['common']],
|
||||
# 'Orc-lv2' : [['Orc'],['A','B','C','D','E','F'],['uncommon']],
|
||||
# 'Orc-lv3' : [['Orc'],['A','B','C','D','E','F'],['rare']]}
|
||||
|
||||
def waves():
|
||||
|
||||
@ -70,18 +81,17 @@ def waves():
|
||||
ct_map_text("Wave 1")
|
||||
for i in range (15):
|
||||
ct_minion(14,3,"Orc",1)
|
||||
# ct_tempo_wave (1)
|
||||
ct_sleep (1)
|
||||
|
||||
ct_tempo_wave (20)
|
||||
ct_sleep (20)
|
||||
|
||||
# # Wave 2
|
||||
# Wave 2
|
||||
ct_map_text("Wave 2")
|
||||
for i in range (20):
|
||||
ct_minion(14,3,"Knight",1)
|
||||
# ct_minion(14,3,"Knight",1)
|
||||
ct_minion_details(14,3,"Knight",1, "OldKnight_m_A_common")
|
||||
ct_sleep (1)
|
||||
|
||||
ct_sleep (2)
|
||||
# ct_tempo_wave (2)
|
||||
print ("Threads waves #", len(threads)-1, "are arrived -> close them.") # Thread closed << DONT CHANGE THIS LINE >>
|
||||
scene.objects['Terrain']['thread_wave']=False # End of cycle << DONT CHANGE THIS LINE >>
|
||||
|
Loading…
x
Reference in New Issue
Block a user