mirror of
https://forge.apps.education.fr/phroy/codetower.git
synced 2024-01-27 11:35:17 +01:00
bullet et cast en 3D
This commit is contained in:
parent
e7b75b267d
commit
b0c8dc5629
Binary file not shown.
6
ct.py
6
ct.py
@ -295,8 +295,6 @@ def terrain_init ():
|
|||||||
scene.addOverlayCollection(scene.cameras['Camera-Hud'], bpy.data.collections['Hud'])
|
scene.addOverlayCollection(scene.cameras['Camera-Hud'], bpy.data.collections['Hud'])
|
||||||
|
|
||||||
# Pile des draws
|
# Pile des draws
|
||||||
scene.objects['Terrain']['draw2d_process']=False
|
|
||||||
scene.objects['Terrain']['draw2d_list']=[]
|
|
||||||
scene.objects['Terrain']['draw3d_process']=False
|
scene.objects['Terrain']['draw3d_process']=False
|
||||||
scene.objects['Terrain']['draw3d_list']=[]
|
scene.objects['Terrain']['draw3d_list']=[]
|
||||||
|
|
||||||
@ -376,6 +374,10 @@ def terrain_run ():
|
|||||||
obj_i.endObject()
|
obj_i.endObject()
|
||||||
if "type_towerminion" in obj_i.getPropertyNames() :
|
if "type_towerminion" in obj_i.getPropertyNames() :
|
||||||
obj_i.endObject()
|
obj_i.endObject()
|
||||||
|
if "type_bullet" in obj_i.getPropertyNames() :
|
||||||
|
obj_i.endObject()
|
||||||
|
if "type_cast" in obj_i.getPropertyNames() :
|
||||||
|
obj_i.endObject()
|
||||||
scene.objects['Terrain']['scene_tile_tower']= []
|
scene.objects['Terrain']['scene_tile_tower']= []
|
||||||
|
|
||||||
# Scripts utilisateur et vagues
|
# Scripts utilisateur et vagues
|
||||||
|
88
ct_lib.py
88
ct_lib.py
@ -364,9 +364,11 @@ def ct_build_details(x,y, cat='Archer tower', tower_name="Tower", color=tower_pu
|
|||||||
tower_minion.worldScale=[0.25,0.25,0.25]
|
tower_minion.worldScale=[0.25,0.25,0.25]
|
||||||
|
|
||||||
# Draw3d
|
# Draw3d
|
||||||
if cat=='Archer tower':
|
if cat=="Archer tower":
|
||||||
for i in range (3):
|
for i in range (3):
|
||||||
ct_add_bullet(x,y,i)
|
ct_add_tower_bullet(x,y,i, "Arrow")
|
||||||
|
if cat=="Mage tower":
|
||||||
|
ct_add_tower_cast(x,y)
|
||||||
|
|
||||||
# Sounds
|
# Sounds
|
||||||
sound_play(sndbuff_build)
|
sound_play(sndbuff_build)
|
||||||
@ -413,15 +415,31 @@ def ct_remove(x,y):
|
|||||||
# Création d'un projectile
|
# Création d'un projectile
|
||||||
##
|
##
|
||||||
|
|
||||||
def ct_add_bullet(x,y,num):
|
def ct_add_tower_bullet(x, y, num, cat="Ball"):
|
||||||
|
if cat=="Ball":
|
||||||
bullet= scene.addObject("Bullet", scene.objects['Terrain'])
|
bullet= scene.addObject("Bullet", scene.objects['Terrain'])
|
||||||
|
if cat=="Arrow":
|
||||||
|
bullet= scene.addObject("Arrow", scene.objects['Terrain'])
|
||||||
bullet.name="tower("+str(x)+','+str(y)+")-bullet"+str(num)
|
bullet.name="tower("+str(x)+','+str(y)+")-bullet"+str(num)
|
||||||
bullet.worldPosition=[x,y,1.5]
|
bullet.worldPosition=[x,y,1.5]
|
||||||
bullet.worldScale=[0.75,0.75,0.75]
|
bullet.worldScale=[0.75,0.75,0.75]
|
||||||
bullet.suspendPhysics (True)
|
bullet.suspendPhysics (True)
|
||||||
bullet.setVisible(False)
|
bullet.setVisible(False)
|
||||||
bullet['activated']=False
|
bullet['activated']=False
|
||||||
# print ("Création : "+bullet.name)
|
|
||||||
|
##
|
||||||
|
# Création des sort
|
||||||
|
##
|
||||||
|
|
||||||
|
def ct_add_tower_cast(x, y):
|
||||||
|
cast= scene.addObject("Cast-slow", scene.objects['Terrain'])
|
||||||
|
cast.name="tower("+str(x)+','+str(y)+")-cast"
|
||||||
|
cast.worldPosition=[x,y,1.5]
|
||||||
|
cast.worldScale=[0.75,0.75,0.75]
|
||||||
|
cast.suspendPhysics (True)
|
||||||
|
cast.setVisible(False)
|
||||||
|
cast['activated']=False
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Réaction d'une tour
|
# Réaction d'une tour
|
||||||
@ -501,13 +519,11 @@ def scn_tower_near(cont):
|
|||||||
sound_play(sndbuff_mage)
|
sound_play(sndbuff_mage)
|
||||||
|
|
||||||
# Ligne (drawLine) (vitesse rapide)
|
# Ligne (drawLine) (vitesse rapide)
|
||||||
if scene.objects['Terrain']['speed']<10: # Pas d'animation à 10 -> plantage
|
if scene.objects['Terrain']['speed']<10: # Pas d'animation à 10 -> plantage
|
||||||
|
|
||||||
# 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:
|
||||||
# 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])
|
|
||||||
for i in range (3):
|
for i in range (3):
|
||||||
bullet = scene.objects[obj.name+"-bullet"+str(i)]
|
bullet = scene.objects[obj.name+"-bullet"+str(i)]
|
||||||
if bullet['activated']==False:
|
if bullet['activated']==False:
|
||||||
@ -515,23 +531,32 @@ def scn_tower_near(cont):
|
|||||||
bullet['activated']=True
|
bullet['activated']=True
|
||||||
bullet.setVisible(True)
|
bullet.setVisible(True)
|
||||||
scene.objects['Terrain']['draw3d_process']=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])
|
scene.objects['Terrain']['draw3d_list'].append([20, "arrow", obj.name, bullet.name, target.name, "normal", 20])
|
||||||
break
|
break
|
||||||
if i ==3 :
|
if i ==3 :
|
||||||
print ("Plus de bullet de disponible pour la tour : "+obj.name)
|
print ("Plus de bullet de disponible pour la tour : "+obj.name)
|
||||||
|
|
||||||
# Cast zone
|
# Cast zone
|
||||||
# FIXME : ne marche plus (zoom et pan)
|
|
||||||
if obj['cat']=="Mage tower": # Mage (cast)
|
if obj['cat']=="Mage tower": # Mage (cast)
|
||||||
scene.objects['Terrain']['draw2d_process']=True
|
cast = scene.objects[obj.name+"-cast"]
|
||||||
scene.objects['Terrain']['draw2d_list'].append([30, "cast", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8],ray_blue,30])
|
cast.worldPosition=[obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8]
|
||||||
|
cast.worldScale=[0.01,0.01,0.01]
|
||||||
|
cast.setVisible(True)
|
||||||
|
scene.objects['Terrain']['draw3d_process']=True
|
||||||
|
scene.objects['Terrain']['draw3d_list'].append([60, "cast", obj.name, cast.name, "slow", 60])
|
||||||
|
|
||||||
# Rayon
|
# Rayon
|
||||||
# FIXME : ne marche plus (zoom et pan)
|
# FIXME : ne marche plus (zoom et pan)
|
||||||
if obj['cat']=="Test":
|
# if obj['cat']=="Test":
|
||||||
if target.name in scene.objects:
|
# if target.name in scene.objects:
|
||||||
scene.objects['Terrain']['draw2d_process']=True
|
# scene.objects['Terrain']['draw2d_process']=True
|
||||||
scene.objects['Terrain']['draw2d_list'].append([5, "ray", [obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z+0.8], target.name, angle3, ray_yellow,5]) # Suivi du minion
|
# scene.objects['Terrain']['draw2d_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 : pas d'animation à 10
|
||||||
|
if scene.objects['Terrain']['speed']==10:
|
||||||
|
target['hp'] = target['hp'] - obj['damage']
|
||||||
|
if target['hp']<=0:
|
||||||
|
target['dead']=True
|
||||||
|
|
||||||
# Cast (buff and debuff)
|
# Cast (buff and debuff)
|
||||||
if obj['cat']=="Mage tower":
|
if obj['cat']=="Mage tower":
|
||||||
@ -661,8 +686,6 @@ def ct_print (text):
|
|||||||
# Dessin 3d
|
# Dessin 3d
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
# 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
|
||||||
if obj.sensors['Draw3d'].positive==False:
|
if obj.sensors['Draw3d'].positive==False:
|
||||||
@ -675,6 +698,7 @@ def scn_draw3d(cont):
|
|||||||
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)
|
||||||
|
# scene.objects['Terrain']['draw3d_list'].append([20, "arrow", obj.name, bullet.name, target.name, "normal", 20])
|
||||||
if draw_cmd[1]=="arrow":
|
if draw_cmd[1]=="arrow":
|
||||||
if draw_cmd[4] in scene.objects:
|
if draw_cmd[4] in scene.objects:
|
||||||
tower= scene.objects[draw_cmd[2]]
|
tower= scene.objects[draw_cmd[2]]
|
||||||
@ -682,15 +706,22 @@ def scn_draw3d(cont):
|
|||||||
target = scene.objects[draw_cmd[4]]
|
target = scene.objects[draw_cmd[4]]
|
||||||
x0 = tower.worldPosition.x
|
x0 = tower.worldPosition.x
|
||||||
y0 = tower.worldPosition.y
|
y0 = tower.worldPosition.y
|
||||||
z0 = tower.worldPosition.z+0.8 # ajustement +0.8
|
# z0 = tower.worldPosition.z+0.8 # ajustement +0.8
|
||||||
|
z0 = tower.worldPosition.z+1 # ajustement +1
|
||||||
x1 = target.worldPosition.x
|
x1 = target.worldPosition.x
|
||||||
y1 = target.worldPosition.y
|
y1 = target.worldPosition.y
|
||||||
z1 = target.worldPosition.z+0.5 # ajustement +0.5
|
z1 = target.worldPosition.z+0.5 # ajustement +0.5
|
||||||
step_x=(x1-x0)/draw_cmd[7]
|
if x1>x0:
|
||||||
step_y=(y1-y0)/draw_cmd[7]
|
angle_z =math.atan((y1-y0)/(x1-x0))+math.pi/2
|
||||||
step_z=(z1-z0)/draw_cmd[7]
|
else:
|
||||||
step = draw_cmd[7]-draw_cmd[0]
|
angle_z =math.pi+math.atan((y1-y0)/(x1-x0))+math.pi/2
|
||||||
|
angle_y =math.atan((z1-z0)/(math.sqrt((x1-x0)**2+(y1-y0)**2)))
|
||||||
|
step_x=(x1-x0)/draw_cmd[6]
|
||||||
|
step_y=(y1-y0)/draw_cmd[6]
|
||||||
|
step_z=(z1-z0)/draw_cmd[6]
|
||||||
|
step = draw_cmd[6]-draw_cmd[0]
|
||||||
bullet.worldPosition=[x0+step_x*step, y0+step_y*step, z0+step_z*step]
|
bullet.worldPosition=[x0+step_x*step, y0+step_y*step, z0+step_z*step]
|
||||||
|
bullet.worldOrientation=[0, angle_y, angle_z]
|
||||||
draw_cmd[0] = draw_cmd[0]-scene.objects['Terrain']['speed']
|
draw_cmd[0] = draw_cmd[0]-scene.objects['Terrain']['speed']
|
||||||
|
|
||||||
# Dégats
|
# Dégats
|
||||||
@ -701,6 +732,19 @@ def scn_draw3d(cont):
|
|||||||
if target['hp']<=0: # Mort
|
if target['hp']<=0: # Mort
|
||||||
target['dead']=True
|
target['dead']=True
|
||||||
|
|
||||||
|
# Mage (cast)
|
||||||
|
# scene.objects['Terrain']['draw3d_list'].append([60, "cast", obj.name, cast.name, "slow", 60])
|
||||||
|
if draw_cmd[1]=="cast":
|
||||||
|
cast = scene.objects[draw_cmd[3]]
|
||||||
|
step = draw_cmd[5]-draw_cmd[0]
|
||||||
|
cast.worldScale=[0.05*step,0.05*step,0.05*step]
|
||||||
|
# cast.worldScale=[0.75*step,0.75*step,0.75*step]
|
||||||
|
draw_cmd[0] = draw_cmd[0]-scene.objects['Terrain']['speed']
|
||||||
|
|
||||||
|
# Fin
|
||||||
|
if draw_cmd[0]<=0:
|
||||||
|
cast.setVisible(False)
|
||||||
|
|
||||||
# Suppression des draws finis
|
# Suppression des draws finis
|
||||||
i=0
|
i=0
|
||||||
for draw_cmd in scene.objects['Terrain']['draw3d_list']:
|
for draw_cmd in scene.objects['Terrain']['draw3d_list']:
|
||||||
|
Loading…
Reference in New Issue
Block a user