mirror of
https://forge.apps.education.fr/phroy/codetower.git
synced 2024-01-27 11:35:17 +01:00
Add graphical mouse
This commit is contained in:
parent
e3adb80bd3
commit
2d96b4759b
@ -6,9 +6,9 @@ CodeTower is a Tower Defense coding game where the towers are driven by Python c
|
||||
|
||||
* [Screencast](http://www.phroy.org/cloud/index.php/s/BbMSaNayJHRbk5N)
|
||||
|
||||
It's a early prototype. CodeTower is a open source software distributed under the terms of the GPLv3 license.
|
||||
It's a early prototype. CodeTower is a open source software distributed under the terms of the [GPLv3 license]('https://www.gnu.org/licenses/gpl-3.0.html').
|
||||
|
||||
The game engine is [Blender](https://blender.org) - [UPGE](https://upbge.org).
|
||||
The game engine is [Blender](https://blender.org) / [UPGE](https://upbge.org).
|
||||
|
||||
![Screenshot](img/screenshot-01.jpg)
|
||||
|
||||
@ -24,7 +24,7 @@ With your Python script, you can build, remove and upgrade your towers.
|
||||
|
||||
For each tower, you will be able to choose dynamically most appropriate techno (archer tower) or spell (mage tower).
|
||||
|
||||
The Python script is **ct_cmd.py** (in the game folder), you have to edit it with editing software (Spyder, Emacs, Atom, ...).
|
||||
The Python script is the file **ct_cmd.py** (in the game folder), you have to edit it with editing software (Spyder, Emacs, Atom, ...).
|
||||
|
||||
* **Build a tower : ct_build (x, y, category, name, color, style)**
|
||||
- x position (integer)
|
||||
|
BIN
codetower-21.blend
Normal file
BIN
codetower-21.blend
Normal file
Binary file not shown.
228
ct.py
228
ct.py
@ -4,6 +4,7 @@ import bge # Blender Game Engine (UPBGE)
|
||||
import bpy # Blender
|
||||
import aud # Sounds
|
||||
import math
|
||||
import mathutils
|
||||
import time
|
||||
import sys
|
||||
import os
|
||||
@ -20,7 +21,7 @@ import ct_map1 as ct_map # waves script
|
||||
# @title: the CodeTower game
|
||||
# @project: CodeTower
|
||||
# @lang: fr,en
|
||||
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
||||
# @authors: Philippe Roy <phroy@phroy.org>
|
||||
# @copyright: Copyright (C) 2022 Philippe Roy
|
||||
# @license: GNU GPL
|
||||
#
|
||||
@ -140,6 +141,11 @@ def points_maj (cont):
|
||||
|
||||
global fps_time
|
||||
|
||||
# Synchronisation des threads
|
||||
while scene.objects['Terrain']['thread_cmd_lock'] == True:
|
||||
# print ("UPBGE : thread_cmd_lock =True")
|
||||
time.sleep(0.01)
|
||||
|
||||
# Texte
|
||||
scene.objects['Lifes_text']['Text']=str(scene.objects['Points']['lifes'])+"/"+str(scene.objects['Points']['lifes_max'])
|
||||
scene.objects['Coins_text']['Text']=str(scene.objects['Points']['coins'])
|
||||
@ -160,7 +166,7 @@ def points_maj (cont):
|
||||
scene.objects['Map_text']['anim']=False
|
||||
|
||||
# Gestion du FPS
|
||||
if scene.objects['Terrain']['debug_fps']:
|
||||
if scene.objects['Commands']['debug_fps']:
|
||||
if scene.objects['Points']['tics']%60 ==0: # Toutes les 60 tics
|
||||
milliseconds = int(time.time() * 1000)
|
||||
print (milliseconds-fps_time)
|
||||
@ -181,22 +187,23 @@ def points_maj (cont):
|
||||
scene.objects['Level_text'].color = color_text
|
||||
|
||||
# Ramasse minions perdues ou zombis
|
||||
if scene.objects['Points']['tics']%240 == 0: # Toutes les 4 secondes
|
||||
scene.objects['Points']['minions_lost']=[]
|
||||
for obj_i in scene.objects:
|
||||
if "type_minion" in obj_i.getPropertyNames() and "type_towerminion" not in obj_i.getPropertyNames():
|
||||
# print ("Minion lost : (dist, dist_old, x, last_x, y, last_y) : ", obj_i.name, obj_i['dist'], obj_i['dist_old'], obj_i.worldPosition.x, obj_i['dist_last_x'], obj_i.worldPosition.y, obj_i['dist_last_y'])
|
||||
if obj_i['dist']==obj_i['dist_old'] and obj_i['dist_new']==False:
|
||||
print ("Minion lost : dist =dist_old (dist, dist_old) : ", obj_i.name, obj_i['dist'], obj_i['dist_old'])
|
||||
obj_i['dead']=True
|
||||
elif obj_i.worldLinearVelocity.x >0 and abs(obj_i.worldLinearVelocity.x) < 0.001 and obj_i.worldLinearVelocity.y >0 and abs(obj_i.worldLinearVelocity.y) < 0.001:
|
||||
print ("Minion lost : x' or y' very slow (x, y, z, x', y') : ", obj_i.name, obj_i.worldPosition.x, obj_i.worldPosition.y, obj_i.worldPosition.z, abs(obj_i.worldLinearVelocity.x), abs(obj_i.worldLinearVelocity.y))
|
||||
obj_i['dead']=True
|
||||
elif obj_i.worldPosition.x<scene.objects['Terrain']['size'][0] or obj_i.worldPosition.x>scene.objects['Terrain']['size'][1] or obj_i.worldPosition.y<scene.objects['Terrain']['size'][2] or obj_i.worldPosition.y>scene.objects['Terrain']['size'][3]:
|
||||
print ("Minion lost : x or y outside the map (x, y, z, x', y') : ", obj_i.name, obj_i.worldPosition.x, obj_i.worldPosition.y, obj_i.worldPosition.z, abs(obj_i.worldLinearVelocity.x), abs(obj_i.worldLinearVelocity.y))
|
||||
obj_i['dead']=True
|
||||
obj_i['dist_old'] = obj_i['dist']
|
||||
obj_i['dist_new']=False
|
||||
if scene.objects['Terrain']['run'] == True: # Pas en pause
|
||||
if scene.objects['Points']['tics']%240 == 0: # Toutes les 4 secondes
|
||||
scene.objects['Points']['minions_lost']=[]
|
||||
for obj_i in scene.objects:
|
||||
if "type_minion" in obj_i.getPropertyNames() and "type_towerminion" not in obj_i.getPropertyNames():
|
||||
# print ("Minion lost : (dist, dist_old, x, last_x, y, last_y) : ", obj_i.name, obj_i['dist'], obj_i['dist_old'], obj_i.worldPosition.x, obj_i['dist_last_x'], obj_i.worldPosition.y, obj_i['dist_last_y'])
|
||||
if obj_i['dist']==obj_i['dist_old'] and obj_i['dist_new']==False:
|
||||
print ("Minion lost : dist =dist_old (dist, dist_old) : ", obj_i.name, obj_i['dist'], obj_i['dist_old'])
|
||||
obj_i['dead']=True
|
||||
elif obj_i.worldLinearVelocity.x >0 and abs(obj_i.worldLinearVelocity.x) < 0.001 and obj_i.worldLinearVelocity.y >0 and abs(obj_i.worldLinearVelocity.y) < 0.001:
|
||||
print ("Minion lost : x' or y' very slow (x, y, z, x', y') : ", obj_i.name, obj_i.worldPosition.x, obj_i.worldPosition.y, obj_i.worldPosition.z, abs(obj_i.worldLinearVelocity.x), abs(obj_i.worldLinearVelocity.y))
|
||||
obj_i['dead']=True
|
||||
elif obj_i.worldPosition.x<scene.objects['Terrain']['size'][0] or obj_i.worldPosition.x>scene.objects['Terrain']['size'][1] or obj_i.worldPosition.y<scene.objects['Terrain']['size'][2] or obj_i.worldPosition.y>scene.objects['Terrain']['size'][3]:
|
||||
print ("Minion lost : x or y outside the map (x, y, z, x', y') : ", obj_i.name, obj_i.worldPosition.x, obj_i.worldPosition.y, obj_i.worldPosition.z, abs(obj_i.worldLinearVelocity.x), abs(obj_i.worldLinearVelocity.y))
|
||||
obj_i['dead']=True
|
||||
obj_i['dist_old'] = obj_i['dist']
|
||||
obj_i['dist_new']=False
|
||||
|
||||
# Fin de la vague
|
||||
if scene.objects['Terrain']['thread_wave']==False and scene.objects['Terrain']['map_run'] == True :
|
||||
@ -384,6 +391,7 @@ def terrain_end ():
|
||||
scene.objects['Camera'].worldPosition.y = scene.objects['Camera']['init_ly']
|
||||
scene.objects['Camera'].worldPosition.z = scene.objects['Camera']['init_lz']
|
||||
|
||||
|
||||
# Wave
|
||||
if scene.objects['Points']['wave']== scene.objects['Terrain']['nb_waves'] and scene.objects['Points']['lifes'] > 0:
|
||||
scene.objects['Endbanner_wave']['Text']="Victory"
|
||||
@ -407,14 +415,16 @@ def terrain_end ():
|
||||
scene.objects['Endbanner_points'].color = color_black
|
||||
scene.objects['Endbanner_ok'].color = color_black
|
||||
scene.objects['End'].setVisible(True,True)
|
||||
scene.objects['End'].worldPosition = [0, 1.53623, -0.892838]
|
||||
# scene.objects['End']['position_init']= scene.objects['End'].localPosition
|
||||
# scene.objects['End']['position_init']= [scene.objects['End'].localPosition.x, scene.objects['End'].localPosition.y, scene.objects['End'].localPosition.z]
|
||||
scene.objects['End'].worldPosition = [0, 1.53623, -1.8]
|
||||
scene.objects['End']['timer'] = 0
|
||||
scene.objects['End']['anim'] = True
|
||||
|
||||
# Animation
|
||||
pas=0.5
|
||||
scene.objects['End'].localPosition.y=scene.objects['End'].localPosition.y-1*pas
|
||||
scene.objects['End'].localPosition.z=scene.objects['End'].localPosition.z+0.85*pas
|
||||
scene.objects['End'].localPosition.y -= pas
|
||||
scene.objects['End'].localPosition.z += (0.85*pas)
|
||||
# scene.objects['End'].localPosition.y=scene.objects['End'].localPosition.y-1*pas
|
||||
# scene.objects['End'].localPosition.z=scene.objects['End'].localPosition.z+0.85*pas
|
||||
scene.objects['End']['timer']+=1
|
||||
if scene.objects['End']['timer']== 40:
|
||||
scene.objects['Terrain']['map_run'] = False
|
||||
@ -438,8 +448,9 @@ def terrain_speed (obj):
|
||||
for obj_i in scene.objects:
|
||||
if "type_tower" in obj_i.getPropertyNames() and "Near" in obj_i.sensors :
|
||||
obj_i.sensors['Near'].skippedTicks =round(1/(obj_i['speed']*scene.objects['Terrain']['speed']))
|
||||
if "type_minion" in obj_i.getPropertyNames() and "type_towerminion" not in obj_i.getPropertyNames():
|
||||
obj_i.actuators['Steering'].velocity=obj_i['speed_base']*scene.objects['Terrain']['speed']
|
||||
if scene.objects['Terrain']['run'] == True: # Pas en pause
|
||||
if "type_minion" in obj_i.getPropertyNames() and "type_towerminion" not in obj_i.getPropertyNames():
|
||||
obj_i.actuators['Steering'].velocity=obj_i['speed_base']*scene.objects['Terrain']['speed']
|
||||
|
||||
# Configuration du moteur de rendu
|
||||
if scene.objects['Terrain']['speed']<10: # smaa avec en vitesse 4 et 10 -> tendance au plantage
|
||||
@ -456,6 +467,7 @@ def terrain_speed (obj):
|
||||
# Page de fin
|
||||
def endbanner_hl(cont):
|
||||
if cont.sensors['MO'].status == JUST_ACTIVATED:
|
||||
mouse_up()
|
||||
scene.objects['Endbanner'].color = color_white
|
||||
scene.objects['Endbanner_wave'].color = color_white
|
||||
scene.objects['Endbanner_points'].color = color_white
|
||||
@ -484,6 +496,8 @@ def endbanner_close(cont):
|
||||
# Init
|
||||
def cmd_init():
|
||||
# scene.objects['Terrain']['run']=False
|
||||
|
||||
# UI : Commandes
|
||||
scene.objects['Run-Hl'].setVisible(False,False)
|
||||
scene.objects['Pause'].setVisible(False,False)
|
||||
scene.objects['Pause-Hl'].setVisible(False,False)
|
||||
@ -493,12 +507,23 @@ def cmd_init():
|
||||
scene.objects['About-cmd-Hl'].setVisible(False,False)
|
||||
scene.objects['About'].setVisible(False,True)
|
||||
|
||||
# UI : Texte, ...
|
||||
scene.objects['Map_text'].setVisible(False,False)
|
||||
scene.objects['Text_info-1'].setVisible(False,False)
|
||||
scene.objects['Text_info-2'].setVisible(False,False)
|
||||
scene.objects['Tower_construc_mode'].setVisible(False,False)
|
||||
scene.objects['Terrain']['map_run'] = False
|
||||
|
||||
# UI : Mouse
|
||||
# Window size : 738.5 415.5
|
||||
bge.render.setMousePosition(int(bge.render.getWindowWidth() / 2), int(bge.render.getWindowHeight() / 2))
|
||||
bge.render.showMouse(scene.objects['Commands']['debug_mouse'])
|
||||
scene.objects['Mouse_main'].worldPosition = [0.07, -8.11, 4.71035] # Vielle version : [0.118161, -8.24305, 4.71035] ; [0, -3.5, 2], [0, -8, 6]
|
||||
scene.objects['Mouse_main'].worldScale=[30, 30, 30]
|
||||
scene.objects['Mouse_main']['past_x']=0
|
||||
scene.objects['Mouse_main']['past_y']=0
|
||||
scene.objects['Mouse_main']['mouse_up']=0
|
||||
|
||||
# scene.objects['Raz-vue-Hl'].setVisible(False,False)
|
||||
# scene.objects['Aide-cmd-Hl'].setVisible(False,False)
|
||||
|
||||
@ -535,7 +560,7 @@ def cmd_hl(cont):
|
||||
scene.objects['Stop-Hl'].setVisible(True,False)
|
||||
|
||||
# Désactivation
|
||||
if cont.sensors['MO'].status == JUST_RELEASED and scene.objects['Terrain']['manip_mode']==0:
|
||||
if cont.sensors['MO'].status == JUST_RELEASED and (scene.objects['Terrain']['manip_mode']==0 or scene.objects['Terrain']['manip_mode']==9):
|
||||
if obj.name!="Run" and obj.name!="Pause" and obj.name!="Run-Hl" and obj.name!="Pause-Hl" and obj.name!="Stop" and obj.name!="Stop-Hl" :
|
||||
scene.objects[obj.name+'-Hl'].setVisible(False,True)
|
||||
obj.setVisible(True,True)
|
||||
@ -581,9 +606,10 @@ def cmd_click (cont):
|
||||
def mode(cont):
|
||||
obj = cont.owner
|
||||
keyboard = bge.logic.keyboard
|
||||
|
||||
|
||||
# Touche ESC
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.ESCKEY].queue:
|
||||
terrain_stop ()
|
||||
bge.logic.endGame()
|
||||
|
||||
# Fenêtre modale
|
||||
@ -618,6 +644,12 @@ def mode(cont):
|
||||
scene.objects['Camera'].worldPosition.y = scene.objects['Camera']['init_ly']
|
||||
scene.objects['Camera'].worldPosition.z = scene.objects['Camera']['init_lz']
|
||||
applyRotationTo(scene.objects['Terrain'], 0, 0, 0)
|
||||
|
||||
bge.render.setMousePosition(int(bge.render.getWindowWidth() / 2), int(bge.render.getWindowHeight() / 2))
|
||||
scene.objects['Mouse_main'].worldPosition = [0.07, -8.11, 4.71035] # Vielle version : [0.118161, -8.24305, 4.71035] ; [0, -3.5, 2], [0, -8, 6]
|
||||
scene.objects['Mouse_main'].worldScale=[30, 30, 30]
|
||||
scene.objects['Mouse_main']['past_x']=0
|
||||
scene.objects['Mouse_main']['past_y']=0
|
||||
|
||||
# Touche F5 -> Run et Pause
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.F5KEY].queue:
|
||||
@ -643,6 +675,9 @@ def manip_init(cont):
|
||||
scene.objects['Camera']['init_lx']=scene.objects['Camera'].worldPosition.x
|
||||
scene.objects['Camera']['init_ly']=scene.objects['Camera'].worldPosition.y
|
||||
scene.objects['Camera']['init_lz']=scene.objects['Camera'].worldPosition.z
|
||||
scene.objects['Camera']['past_lx']=scene.objects['Camera'].worldPosition.x
|
||||
scene.objects['Camera']['past_ly']=scene.objects['Camera'].worldPosition.y
|
||||
scene.objects['Camera']['past_lz']=scene.objects['Camera'].worldPosition.z
|
||||
scene.objects['Terrain']['init_lx']=scene.objects['Terrain'].worldPosition.x
|
||||
scene.objects['Terrain']['init_ly']=scene.objects['Terrain'].worldPosition.y
|
||||
scene.objects['Terrain']['init_lz']=scene.objects['Terrain'].worldPosition.z
|
||||
@ -713,26 +748,125 @@ def manip(cont):
|
||||
# Pan
|
||||
if obj['manip_mode']==1: # Shift
|
||||
scene.objects['Camera'].applyMovement((delta_x*-sensibilite_pan, delta_y*sensibilite_pan, 0), True)
|
||||
scene.objects['Mouse_main'].applyMovement((delta_x*-sensibilite_pan, delta_y*sensibilite_pan, 0), True)
|
||||
|
||||
# Zoom
|
||||
# Zoom FIXME : marche pas au niveau de la souris
|
||||
if obj['manip_mode']==2: # Ctrl
|
||||
position_scale_x = 0.0005
|
||||
position_scale_y = position_scale_x
|
||||
mouse_x=scene.objects['Mouse_main'].sensors["Mouse"].position[0]-int(bge.render.getWindowWidth() / 2)
|
||||
mouse_y=scene.objects['Mouse_main'].sensors["Mouse"].position[1]-int(bge.render.getWindowHeight() / 2)
|
||||
distance_cam_past= math.sqrt(scene.objects['Camera']['past_ly']**2+scene.objects['Camera']['past_lz']**2)
|
||||
distance_cam = math.sqrt((scene.objects['Camera'].worldPosition.y**2+scene.objects['Camera'].worldPosition.z**2))
|
||||
size_scale = (distance_cam/distance_cam_past) * 0.23
|
||||
scene.objects['Camera'].applyMovement((0, 0, (delta_x+delta_y)*sensibilite_zoom), True)
|
||||
scene.objects['Mouse_main'].applyMovement((mouse_x*(delta_x+delta_y)*sensibilite_zoom*position_scale_x, -mouse_y*(delta_x+delta_y)*sensibilite_zoom*position_scale_y, 0), True)
|
||||
scene.objects['Mouse_main'].worldScale *= (delta_x+delta_y)*sensibilite_zoom*size_scale
|
||||
scene.objects['Camera']['past_ly']=scene.objects['Camera'].worldPosition.y
|
||||
scene.objects['Camera']['past_lz']=scene.objects['Camera'].worldPosition.z
|
||||
|
||||
|
||||
# Manipulation du modèle ou de la caméra
|
||||
def manip_wheel(cont):
|
||||
if scene.objects['Terrain']['manip_mode']!=9: # Fenêtre modale
|
||||
obj = cont.owner
|
||||
sensibilite_wheel = 5 # Base : 20
|
||||
position_scale_x = 0.0005
|
||||
position_scale_y = position_scale_x
|
||||
mouse_x=scene.objects['Mouse_main'].sensors["Mouse"].position[0]-int(bge.render.getWindowWidth() / 2)
|
||||
mouse_y=scene.objects['Mouse_main'].sensors["Mouse"].position[1]-int(bge.render.getWindowHeight() / 2)
|
||||
distance_cam_past = math.sqrt((scene.objects['Camera'].worldPosition.y**2+scene.objects['Camera'].worldPosition.z**2))
|
||||
# size_scale = (distance_cam/distance_cam_past) * 0.23
|
||||
size_scale = 0.2
|
||||
# size_scale = 0.23
|
||||
if cont.sensors['WheelUp'].positive:
|
||||
scene.objects['Camera'].applyMovement((0, 0, -sensibilite_wheel), True)
|
||||
if cont.sensors['WheelDown'].positive:
|
||||
distance_cam = math.sqrt((scene.objects['Camera'].worldPosition.y**2+scene.objects['Camera'].worldPosition.z**2))
|
||||
scene.objects['Mouse_main'].applyMovement((-mouse_x*sensibilite_wheel*position_scale_x, mouse_y*sensibilite_wheel*position_scale_y, 0), True)
|
||||
scene.objects['Mouse_main'].worldScale *= sensibilite_wheel* (distance_cam/distance_cam_past) *size_scale
|
||||
elif cont.sensors['WheelDown'].positive:
|
||||
scene.objects['Camera'].applyMovement((0, 0, sensibilite_wheel), True)
|
||||
distance_cam = math.sqrt((scene.objects['Camera'].worldPosition.y**2+scene.objects['Camera'].worldPosition.z**2))
|
||||
scene.objects['Mouse_main'].applyMovement((mouse_x*sensibilite_wheel*position_scale_x, -mouse_y*sensibilite_wheel*position_scale_y, 0), True)
|
||||
scene.objects['Mouse_main'].worldScale /= sensibilite_wheel* (distance_cam_past/distance_cam) *size_scale
|
||||
else:
|
||||
return
|
||||
|
||||
# Icone de la souris
|
||||
def mouse(cont):
|
||||
obj = cont.owner
|
||||
|
||||
# Ancienne version basée sur la position de la caméra
|
||||
# distance_cam_init= math.sqrt(scene.objects['Camera']['init_ly']**2+scene.objects['Camera']['init_lz']**2)
|
||||
# distance_cam = math.sqrt((scene.objects['Camera'].worldPosition.y**2+scene.objects['Camera'].worldPosition.z**2))
|
||||
# ratio = ((distance_cam_init - distance_cam)/distance_cam_init)*1.39 # trop vite -> +, pas assez vite -> -
|
||||
# scale_x=0.0118-0.0118*ratio
|
||||
# scale_y=scale_x
|
||||
# delta_x=cont.sensors["Mouse"].position[0]-obj['past_x']
|
||||
# delta_y=cont.sensors["Mouse"].position[1]-obj['past_y']
|
||||
# if delta_x<500 and delta_y<500:
|
||||
# scene.objects['Mouse_main'].worldPosition.x += delta_x*scale_x
|
||||
# scene.objects['Mouse_main'].worldPosition.y -= delta_y*scale_y*math.cos(50*2*math.pi*(1/360))
|
||||
# scene.objects['Mouse_main'].worldPosition.z -= delta_y*scale_y*math.sin(50*2*math.pi*(1/360))
|
||||
# scene.objects['Mouse_main']['past_x']=cont.sensors["Mouse"].position[0]
|
||||
# scene.objects['Mouse_main']['past_y']=cont.sensors["Mouse"].position[1]
|
||||
|
||||
# Version basée sur obj.getDistanceTo(scene.objects['Camera'])
|
||||
delta_x=cont.sensors["Mouse"].position[0]-obj['past_x']
|
||||
delta_y=cont.sensors["Mouse"].position[1]-obj['past_y']
|
||||
vect=mathutils.Vector((1,1,1))-obj.getVectTo(scene.objects['Camera'])[1]
|
||||
dist= obj.getDistanceTo(scene.objects['Camera'])
|
||||
# print ("delta_x, delta_y, vect, dist : ", delta_x, delta_y, vect, dist)
|
||||
if obj['past_dist']==0:
|
||||
obj['past_dist']=obj.getDistanceTo(scene.objects['Camera'])
|
||||
ratio = dist/obj['past_dist']
|
||||
# print ("delta_x, delta_y, vect, dist : ", delta_x, delta_y, vect, dist)
|
||||
scale_x=ratio*0.016
|
||||
scale_y=ratio*0.0162
|
||||
# scale_xy=ratio*0.0005
|
||||
scale_xy=ratio*0
|
||||
if delta_x<500 and delta_y<500:
|
||||
# scene.objects['Mouse_main'].applyMovement((delta_x*scale_x, -vect[1]*delta_y*scale_y, -vect[1]*delta_y*scale_y), False)
|
||||
scene.objects['Mouse_main'].applyMovement((delta_x*scale_x+delta_x*delta_y*scale_xy,
|
||||
-delta_y*scale_y*math.cos(50*2*math.pi*(1/360)),
|
||||
-delta_y*scale_y*math.sin(50*2*math.pi*(1/360))), False)
|
||||
obj['past_x']=cont.sensors["Mouse"].position[0]
|
||||
obj['past_y']=cont.sensors["Mouse"].position[1]
|
||||
|
||||
# Mise en avant de la souris
|
||||
def mouse_up():
|
||||
scene.objects['Mouse_main']['mouse_up']+=1
|
||||
if scene.objects['Mouse_main']['mouse_up'] == 1:
|
||||
decal = 18
|
||||
size_scale = 0.2
|
||||
# print (scene.objects['Mouse_main'].getVectTo(scene.objects['Camera'])[1])
|
||||
vect=scene.objects['Mouse_main'].getVectTo(scene.objects['Camera'])[1]
|
||||
dist_past= scene.objects['Mouse_main'].getDistanceTo(scene.objects['Camera'])
|
||||
scene.objects['Mouse_main'].applyMovement((vect[0]*decal, vect[1]*decal, vect[2]*decal), False)
|
||||
dist= scene.objects['Mouse_main'].getDistanceTo(scene.objects['Camera'])
|
||||
scene.objects['Mouse_main'].worldScale *= (dist/dist_past) *size_scale
|
||||
scene.objects['Mouse_main'].worldScale=[8, 8, 8]
|
||||
|
||||
# Mise en arrière de la souris
|
||||
def mouse_down():
|
||||
scene.objects['Mouse_main']['mouse_up']-=1
|
||||
if scene.objects['Mouse_main']['mouse_up'] == 0:
|
||||
decal = 18
|
||||
size_scale = 0.2
|
||||
# print (scene.objects['Mouse_main'].getVectTo(scene.objects['Camera'])[1])
|
||||
vect=scene.objects['Mouse_main'].getVectTo(scene.objects['Camera'])[1]
|
||||
dist_past= scene.objects['Mouse_main'].getDistanceTo(scene.objects['Camera'])
|
||||
scene.objects['Mouse_main'].applyMovement((-vect[0]*decal, -vect[1]*decal, -vect[2]*decal), False)
|
||||
dist= scene.objects['Mouse_main'].getDistanceTo(scene.objects['Camera'])
|
||||
scene.objects['Mouse_main'].worldScale /= (dist_past/dist) *size_scale
|
||||
scene.objects['Mouse_main'].worldScale=[30, 30, 30]
|
||||
|
||||
###############################################################################
|
||||
# About
|
||||
###############################################################################
|
||||
|
||||
def about_open():
|
||||
scene.objects['Terrain']['manip_mode']=9 # Fenêtre modale
|
||||
scene.objects['About_title'].color = color_black
|
||||
scene.objects['About_text'].color = color_black
|
||||
scene.objects['About_copyright'].color = color_black
|
||||
@ -744,27 +878,51 @@ def about_open():
|
||||
scene.objects['About_link_kenney'].color= color_link
|
||||
scene.objects['About_ok'].color = color_black
|
||||
scene.objects['About'].setVisible(True,True)
|
||||
scene.objects['About'].worldPosition = [0, 1.53623, -0.892838]
|
||||
scene.objects['About'].worldPosition = [0, 1.53623, -1.8] # old [0, 1.53623, -0.892838]
|
||||
scene.objects['About']['timer'] = 0
|
||||
scene.objects['About']['anim'] = True
|
||||
|
||||
def about_open_anim():
|
||||
pas=0.5
|
||||
scene.objects['About'].localPosition.y=scene.objects['About'].localPosition.y-1*pas
|
||||
scene.objects['About'].localPosition.z=scene.objects['About'].localPosition.z+0.85*pas
|
||||
scene.objects['About'].localPosition.y -= pas
|
||||
scene.objects['About'].localPosition.z += 0.85*pas
|
||||
# scene.objects['About'].localPosition.y=scene.objects['About'].localPosition.y-1*pas
|
||||
# scene.objects['About'].localPosition.z=scene.objects['About'].localPosition.z+0.85*pas
|
||||
scene.objects['About']['timer']+=1
|
||||
if scene.objects['About']['timer']== 40:
|
||||
scene.objects['About']['anim'] = False
|
||||
|
||||
def about_hl(cont):
|
||||
# decal = 18
|
||||
# size_scale = 0.2
|
||||
if cont.sensors['MO'].status == JUST_ACTIVATED:
|
||||
mouse_up()
|
||||
# # print (scene.objects['Mouse_main'].getVectTo(scene.objects['Camera'])[1])
|
||||
# vect=scene.objects['Mouse_main'].getVectTo(scene.objects['Camera'])[1]
|
||||
# dist_past= scene.objects['Mouse_main'].getDistanceTo(scene.objects['Camera'])
|
||||
# scene.objects['Mouse_main'].applyMovement((vect[0]*decal, vect[1]*decal, vect[2]*decal), False)
|
||||
# dist= scene.objects['Mouse_main'].getDistanceTo(scene.objects['Camera'])
|
||||
# scene.objects['Mouse_main'].worldScale *= (dist/dist_past) *size_scale
|
||||
scene.objects['Aboutbanner'].color = color_white
|
||||
scene.objects['About_ok'].color = color_white
|
||||
scene.objects['About_title'].color = color_white
|
||||
# scene.objects['Mouse_main'].worldScale=[8, 8, 8]
|
||||
# print("about_hl A après", scene.objects['Mouse_main'].worldPosition)
|
||||
|
||||
if cont.sensors['MO'].status == JUST_RELEASED:
|
||||
# print("about_hl R avant", scene.objects['Mouse_main'].worldPosition)
|
||||
mouse_down()
|
||||
# print (scene.objects['Mouse_main'].getVectTo(scene.objects['Camera'])[1])
|
||||
# vect=scene.objects['Mouse_main'].getVectTo(scene.objects['Camera'])[1]
|
||||
# dist_past= scene.objects['Mouse_main'].getDistanceTo(scene.objects['Camera'])
|
||||
# scene.objects['Mouse_main'].applyMovement((-vect[0]*decal, -vect[1]*decal, -vect[2]*decal), False)
|
||||
# dist= scene.objects['Mouse_main'].getDistanceTo(scene.objects['Camera'])
|
||||
# scene.objects['Mouse_main'].worldScale /= (dist_past/dist) *size_scale
|
||||
scene.objects['Aboutbanner'].color = color_endbanner_bluelight
|
||||
scene.objects['About_ok'].color = color_black
|
||||
scene.objects['About_title'].color = color_black
|
||||
# scene.objects['Mouse_main'].worldScale=[30, 30, 30]
|
||||
# print("about_hl R après", scene.objects['Mouse_main'].worldPosition)
|
||||
|
||||
def about_close(cont):
|
||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
||||
@ -793,13 +951,17 @@ def about_link(cont):
|
||||
if obj.name == "About_link_blender-colbox" :
|
||||
webbrowser.open('https://www.blender.org')
|
||||
|
||||
# FIXME: souris graphique trop compliqué
|
||||
def about_link_hl(cont):
|
||||
decal = 15
|
||||
if cont.sensors['MO'].status == JUST_ACTIVATED :
|
||||
obj = cont.owner
|
||||
name=obj.name[:-7]
|
||||
scene.objects[name].color = color_link_hl
|
||||
mouse_up()
|
||||
|
||||
if cont.sensors['MO'].status == JUST_RELEASED :
|
||||
obj = cont.owner
|
||||
name=obj.name[:-7]
|
||||
scene.objects[name].color = color_link
|
||||
|
||||
mouse_down()
|
||||
|
@ -6,7 +6,7 @@ from ct_lib import * # Bibliothèque CodeTower
|
||||
# @title: Commands for the CodeTower game
|
||||
# @project: CodeTower
|
||||
# @lang: fr,en
|
||||
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
||||
# @authors: Philippe Roy <phroy@phroy.org>
|
||||
# @copyright: Copyright (C) 2022 Philippe Roy
|
||||
# @license: GNU GPL
|
||||
#
|
||||
@ -40,7 +40,7 @@ def stop():
|
||||
|
||||
def end():
|
||||
ct_sleep (2)
|
||||
print ("Commands thread is arrived.")
|
||||
print ("Thread commands is arrived.")
|
||||
scene.objects['Terrain']['thread_cmd']=False
|
||||
|
||||
###############################################################################
|
||||
|
@ -6,7 +6,7 @@ from ct_lib import * # Bibliothèque CodeTower
|
||||
# @title: Commands for the CodeTower game
|
||||
# @project: CodeTower
|
||||
# @lang: fr,en
|
||||
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
||||
# @authors: Philippe Roy <phroy@phroy.org>
|
||||
# @copyright: Copyright (C) 2022 Philippe Roy
|
||||
# @license: GNU GPL
|
||||
#
|
||||
@ -40,7 +40,7 @@ def stop():
|
||||
|
||||
def end():
|
||||
ct_sleep (2)
|
||||
print ("Commands thread is arrived.")
|
||||
print ("Thread commands is arrived.")
|
||||
scene.objects['Terrain']['thread_cmd']=False
|
||||
|
||||
###############################################################################
|
||||
|
@ -6,7 +6,7 @@ from collections import OrderedDict
|
||||
# @title: Composants python
|
||||
# @project: CodeTower
|
||||
# @lang: fr,en
|
||||
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
||||
# @authors: Philippe Roy <phroy@phroy.org>
|
||||
# @copyright: Copyright (C) 2022 Philippe Roy
|
||||
# @license: GNU GPL
|
||||
#
|
||||
|
21
ct_lib.py
21
ct_lib.py
@ -13,7 +13,7 @@ import random
|
||||
# @title: User library
|
||||
# @project: CodeTower
|
||||
# @lang: fr,en
|
||||
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
||||
# @authors: Philippe Roy <phroy@phroy.org>
|
||||
# @copyright: Copyright (C) 2022 Philippe Roy
|
||||
# @license: GNU GPL
|
||||
#
|
||||
@ -176,6 +176,11 @@ def ct_minion_details(x,y,cat,level,body="Knight_m_A_common"):
|
||||
while scene.objects['Terrain']['run'] == False:
|
||||
time.sleep(0.01)
|
||||
|
||||
# Synchronisation des threads
|
||||
while scene.objects['Terrain']['thread_cmd_lock'] == True:
|
||||
# print ("ct_minion : thread_cmd_lock =True")
|
||||
time.sleep(0.01)
|
||||
|
||||
# Object 3D
|
||||
minion= scene.addObject(body, scene.objects['Terrain'])
|
||||
minion.worldScale=[0.25,0.25,0.25]
|
||||
@ -228,6 +233,8 @@ def scn_minion_dead(cont):
|
||||
|
||||
# Buff/debuff Minion
|
||||
def scn_minion_affect(cont):
|
||||
if scene.objects['Terrain']['run'] == False: # Pause
|
||||
return
|
||||
obj = cont.owner
|
||||
# print (obj.name, obj['buff'])
|
||||
slow_state=False
|
||||
@ -275,7 +282,7 @@ def ct_build_details(x,y, cat='Archer tower', tower_name="Tower", color=tower_pu
|
||||
# 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']:
|
||||
return False
|
||||
|
||||
|
||||
# Vérification du niveau
|
||||
scene.objects['Points']['level']= scene.objects['Points']['level'] + 1
|
||||
if scene.objects['Points']['level'] > scene.objects['Points']['level_max'] :
|
||||
@ -285,8 +292,13 @@ def ct_build_details(x,y, cat='Archer tower', tower_name="Tower", color=tower_pu
|
||||
scene.objects['Terrain']['scene_tile_tower'].append([x,y])
|
||||
return False
|
||||
|
||||
# Blocage des autres threads pendant la construction
|
||||
scene.objects['Terrain']['thread_cmd_lock'] = True
|
||||
|
||||
# Objets 3D
|
||||
time.sleep(0.01)
|
||||
tour= scene.addObject('Tower-'+tower_3d, scene.objects['Terrain'])
|
||||
time.sleep(0.01)
|
||||
tour.color = color
|
||||
tour.worldPosition=[x,y,0.2]
|
||||
tour.worldScale=[1,1,1]
|
||||
@ -320,6 +332,8 @@ def ct_build_details(x,y, cat='Archer tower', tower_name="Tower", color=tower_pu
|
||||
# Capteur Near
|
||||
tour.sensors['Near'].distance=tour['range']
|
||||
tour.sensors['Near'].skippedTicks =round(1/(tour['speed']*scene.objects['Terrain']['speed']))
|
||||
|
||||
scene.objects['Terrain']['thread_cmd_lock'] = False
|
||||
return True
|
||||
|
||||
# Suppression d'une tour
|
||||
@ -458,7 +472,7 @@ def ct_map_text_wave(wave):
|
||||
scene.objects['Map_text'].setVisible(True,False)
|
||||
scene.objects['Map_text'].color = color_text_yellow
|
||||
scene.objects['Map_text']['timer']=120
|
||||
scene.objects['Map_text']['position_init']=[8.22904, -2.86185, 6.07395]
|
||||
scene.objects['Map_text']['position_init']=[8.37716, -2.39401, 5.56759]
|
||||
scene.objects['Map_text']['position_end']=[11.1751, 5.99318, 0.480557]
|
||||
scene.objects['Map_text'].worldPosition= scene.objects['Map_text']['position_init']
|
||||
scene.objects['Map_text']['anim']=True
|
||||
@ -679,3 +693,4 @@ def scn_draw(cont):
|
||||
i=i+1
|
||||
if len(scene.objects['Terrain']['draw_list'])==0:
|
||||
scene.objects['Terrain']['draw_process']=False
|
||||
|
||||
|
@ -8,7 +8,7 @@ import os
|
||||
# @title: Map #1 definition
|
||||
# @project: CodeTower
|
||||
# @lang: fr,en
|
||||
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
||||
# @authors: Philippe Roy <phroy@phroy.org>
|
||||
# @copyright: Copyright (C) 2022 Philippe Roy
|
||||
# @license: GNU GPL
|
||||
#
|
||||
@ -46,7 +46,7 @@ def stop():
|
||||
|
||||
def end():
|
||||
ct_sleep (2)
|
||||
print ("Waves thread is arrived.")
|
||||
print ("Thread waves is arrived.")
|
||||
scene.objects['Terrain']['thread_wave']=False
|
||||
|
||||
###############################################################################
|
||||
|
Loading…
Reference in New Issue
Block a user