Tower bullet with 3d object and physic (not finished, bugged)

This commit is contained in:
Philippe Roy 2022-07-20 00:18:04 +02:00
parent 53de5b73a9
commit c8bc8c9859
2 changed files with 76 additions and 16 deletions

BIN
codetower-34.blend Normal file

Binary file not shown.

View File

@ -345,20 +345,8 @@ def ct_build_details(x,y, cat='Archer tower', tower_name="Tower", color=tower_pu
# Draw3d
if cat=='Archer tower':
bullet1= scene.addObject("Bullet", scene.objects['Terrain'])
bullet1.name="tower("+str(x)+','+str(y)+")-bullet1" # Tower bullet 1 (tb)
bullet1.mass=0.001
bullet1.worldPosition=[x,y,1.5]
bullet1.worldScale=[0.75,0.75,0.75]
bullet1.suspendPhysics (True)
bullet1.setVisible(False)
bullet2= scene.addObject("Bullet", scene.objects['Terrain'])
bullet2.name="tower("+str(x)+','+str(y)+")-bullet2" # Tower bullet 2 (tb)
bullet2.mass=0.001
bullet2.worldPosition=[x,y,1.5]
bullet2.worldScale=[0.75,0.75,0.75]
bullet2.suspendPhysics (True)
bullet2.setVisible(False)
for i in range (10):
ct_add_bullet(x,y,i)
# Sounds
sound_play(sndbuff_build)
@ -386,6 +374,7 @@ def ct_build_details(x,y, cat='Archer tower', tower_name="Tower", color=tower_pu
# Déblocage des autres threads après la construction
scene.objects['Terrain']['thread_cmd_lock'] = False
# print (scene.objects)
return True
# Suppression d'une tour
@ -397,6 +386,22 @@ def ct_remove(x,y):
obj_i.endObject()
scene.objects['Points']['level']= scene.objects['Points']['level'] - 1
# 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)
# Réaction d'une tour
def scn_tower_near(cont):
obj = cont.owner
@ -466,6 +471,7 @@ def scn_tower_near(cont):
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)
@ -476,6 +482,49 @@ def scn_tower_near(cont):
# 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
if obj['cat']=="Archer tower":
sound_play(sndbuff_archer)
@ -489,10 +538,11 @@ def scn_tower_near(cont):
# Archer (tir de flêche)
if obj['cat']=="Archer tower":
if target.name in scene.objects:
pass
# 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']['draw3d_process']=True
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_process']=True
# 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])
# Cast zone
if obj['cat']=="Mage tower": # Mage (cast)
@ -515,6 +565,16 @@ def scn_tower_near(cont):
for target_i in sensor.hitObjectList:
target_i['buff'].append([obj['cast'], obj['cast_duration']])
# Cible touchée par un projectile
def scn_bullet_collision(cont):
obj = cont.owner
# obj['activated']=False
# # obj.suspendPhysics (True)
# obj.setVisible(False)
# # obj.worldPosition=[obj['init_lx'],obj['init_ly'],obj['init_lz']]
# print ("dead bullet : ", obj.name)
###############################################################################
# Carte
###############################################################################