370 lines
14 KiB
Python
370 lines
14 KiB
Python
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
||
import aud # Sounds
|
||
|
||
###############################################################################
|
||
# ct_doc.py
|
||
# @title: Documentation
|
||
# @project: CodeTower
|
||
# @lang: fr,en
|
||
# @authors: Philippe Roy <phroy@phroy.org>
|
||
# @copyright: Copyright (C) 2022 Philippe Roy
|
||
# @license: GNU GPL
|
||
#
|
||
# This game is a tower defense coding game. The towers are driven by Python code.
|
||
# The file is the the map and waves definition.
|
||
#
|
||
###############################################################################
|
||
|
||
scene = bge.logic.getCurrentScene()
|
||
|
||
# Colors
|
||
color_doc_chap = (0.153, 0.116, 0.105, 1) # WoodDark
|
||
color_doc_fct = (0.326, 0.101, 0.0592, 1) # BrownDark
|
||
# color_doc_fct = (0.577, 0.233, 0.115, 1) # Brown
|
||
# color_doc_hl = (0.799, 0.617, 0.021, 1) # Yellow
|
||
color_doc_hl = (0.13, 0.254, 0.407, 1) # BlueDark
|
||
color_doc_activate = (1.0, 0.025, 0.116, 1) # Red
|
||
|
||
# Sounds
|
||
audiodev = aud.Device()
|
||
snd_book_open = aud.Sound('asset/sounds/book_open.ogg')
|
||
sndbuff_book_open = aud.Sound.cache(snd_book_open)
|
||
snd_book_close = aud.Sound('asset/sounds/book_close.ogg')
|
||
sndbuff_book_close = aud.Sound.cache(snd_book_close)
|
||
snd_book_flip = aud.Sound('asset/sounds/book_flip.ogg')
|
||
sndbuff_book_flip = aud.Sound.cache(snd_book_flip)
|
||
|
||
# UPBGE constants
|
||
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
|
||
JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED
|
||
ACTIVATE = bge.logic.KX_INPUT_ACTIVE
|
||
# JUST_DEACTIVATED = bge.logic.KX_SENSOR_JUST_DEACTIVATED
|
||
|
||
# Functions description
|
||
fct_description ={}
|
||
|
||
###############################################################################
|
||
# Map
|
||
###############################################################################
|
||
|
||
map_card=["Level-card", "Sleep-card"]
|
||
|
||
# ct_level ()
|
||
ct_level_title="Get your level"
|
||
ct_level_text=" ct_level ()\n \v - Return your level (integer)"
|
||
fct_description.update({"Level-card" : [ct_level_title, ct_level_text]})
|
||
|
||
# ct_sleep (delay)
|
||
ct_sleep_title="Time management"
|
||
ct_sleep_text=" ct_sleep (delay)\n \v - delay : duration in seconds (float)"
|
||
fct_description.update({"Sleep-card" : [ct_sleep_title, ct_sleep_text]})
|
||
|
||
###############################################################################
|
||
# Tower
|
||
###############################################################################
|
||
|
||
tower_card=["Build-card", "Remove-card", "Upgrade-card", "Activate-card", "Tune-card", "Targets-card"]
|
||
|
||
# ct_build (x, y, category, name, color, style)
|
||
ct_build_title="Build a tower"
|
||
ct_build_text="ct_build (x,y, category, name, color, style)\n \v- x position (integer)\n \v- y position (integer)\n"
|
||
ct_build_text = ct_build_text +" \v- category (string) : \n \v \v- \"Archer tower\" (default value)\n \v \v- \"Mage tower\"\n"
|
||
ct_build_text = ct_build_text +" \v- name (string)\n \v- color (RGB tuple, default=purple)\n"
|
||
ct_build_text = ct_build_text +" \v- style (string) : \n \v \v- \"square\" (default value) or \"round\"\n \v \v- version : A (default value), B or C\n \v \v- exemple : 'round-B' \n"
|
||
ct_build_text = ct_build_text +" \v- Return boolean flag (builded -> True)\n\n"
|
||
ct_build_text = ct_build_text +"Predefined colors : blue, green, magenta,\n orange, purple, red, turquoise, yellow.\n\n"
|
||
ct_build_text = ct_build_text +"Exemple : ct_build (1, 1, \"Archer tower\", \n \"Tower #1\", yellow, \"round-A\")\n"
|
||
fct_description.update({"Build-card" : [ct_build_title, ct_build_text]})
|
||
|
||
# ct_remove (x, y)
|
||
ct_remove_title="Remove a tower"
|
||
ct_remove_text=" ct_remove (x, y) \n \v - x position (integer)\n \v - y position (integer)\n"
|
||
fct_description.update({"Remove-card" : [ct_remove_title, ct_remove_text]})
|
||
|
||
# ct_upgrade (x, y)
|
||
ct_upgrade_title="Upgrade a tower"
|
||
ct_upgrade_text=" ct_upgrade (x, y) \n \v - x position (integer)\n \v - y position (integer)\n"
|
||
ct_upgrade_text = ct_upgrade_text +"FIXME\n"
|
||
fct_description.update({"Upgrade-card" : [ct_upgrade_title, ct_upgrade_text]})
|
||
|
||
# ct_activate (x, y)
|
||
ct_activate_title="activate/desactivate a tower"
|
||
ct_activate_text=" ct_activate (x, y, activate) \n \v - x position (integer)\n \v - y position (integer)\n \v - activate (bool)\n"
|
||
fct_description.update({"Activate-card" : [ct_activate_title, ct_activate_text]})
|
||
|
||
# ct_tune (x, y)
|
||
ct_tune_title="Tune a tower"
|
||
ct_tune_text=" ct_tune (x, y) \n \v - x position (integer)\n \v - y position (integer)\n"
|
||
ct_tune_text = ct_tune_text +"FIXME\n"
|
||
fct_description.update({"Tune-card" : [ct_tune_title, ct_tune_text]})
|
||
|
||
# ct_targets (x, y)
|
||
ct_targets_title="FIXME"
|
||
ct_targets_text=" ct_targets (x, y) \n \v - x position (integer)\n \v - y position (integer)\n"
|
||
ct_targets_text = ct_targets_text +"FIXME\n"
|
||
fct_description.update({"Targets-card" : [ct_targets_title, ct_targets_text]})
|
||
|
||
###############################################################################
|
||
# Tech
|
||
###############################################################################
|
||
|
||
tech_card=["Accurate-card", "Volley-card", "Slow_tech-card", "Fire-card", "Bolt-card", "Ice-card", "Acid-card"]
|
||
|
||
# ct_accurate
|
||
ct_accurate_title="FIXME"
|
||
ct_accurate_text="FIXME\n"
|
||
fct_description.update({"Accurate-card" : [ct_accurate_title, ct_accurate_text]})
|
||
|
||
# ct_volley
|
||
ct_volley_title="FIXME"
|
||
ct_volley_text="FIXME\n"
|
||
fct_description.update({"Volley-card" : [ct_volley_title, ct_volley_text]})
|
||
|
||
# ct_slow_tech
|
||
ct_slow_tech_title="FIXME"
|
||
ct_slow_tech_text="FIXME\n"
|
||
fct_description.update({"Slow_tech-card" : [ct_slow_tech_title, ct_slow_tech_text]})
|
||
|
||
# ct_fire
|
||
ct_fire_title="FIXME"
|
||
ct_fire_text="FIXME\n"
|
||
fct_description.update({"Fire-card" : [ct_fire_title, ct_fire_text]})
|
||
|
||
# ct_bolt
|
||
ct_bolt_title="FIXME"
|
||
ct_bolt_text="FIXME\n"
|
||
fct_description.update({"Bolt-card" : [ct_bolt_title, ct_bolt_text]})
|
||
|
||
# ct_ice
|
||
ct_ice_title="FIXME"
|
||
ct_ice_text="FIXME\n"
|
||
fct_description.update({"Ice-card" : [ct_ice_title, ct_ice_text]})
|
||
|
||
# ct_acid
|
||
ct_acid_title="FIXME"
|
||
ct_acid_text="FIXME\n"
|
||
fct_description.update({"Acid-card" : [ct_acid_title, ct_acid_text]})
|
||
|
||
###############################################################################
|
||
# Spell
|
||
###############################################################################
|
||
|
||
spell_card=["Slow_spell-card", "Detect-card", "Fear-card", "Aura-card"]
|
||
|
||
# ct_slow_spell
|
||
ct_slow_spell_title="FIXME"
|
||
ct_slow_spell_text="FIXME\n"
|
||
fct_description.update({"Slow_spell-card" : [ct_slow_spell_title, ct_slow_spell_text]})
|
||
|
||
# ct_detect
|
||
ct_detect_title="FIXME"
|
||
ct_detect_text="FIXME\n"
|
||
fct_description.update({"Detect-card" : [ct_detect_title, ct_detect_text]})
|
||
|
||
# ct_fear
|
||
ct_fear_title="FIXME"
|
||
ct_fear_text="FIXME\n"
|
||
fct_description.update({"Fear-card" : [ct_fear_title, ct_fear_text]})
|
||
|
||
# ct_aura
|
||
ct_aura_title="FIXME"
|
||
ct_aura_text="FIXME\n"
|
||
fct_description.update({"Aura-card" : [ct_aura_title, ct_aura_text]})
|
||
|
||
|
||
###############################################################################
|
||
# Interface
|
||
###############################################################################
|
||
|
||
##
|
||
# Initialisation du livre
|
||
##
|
||
|
||
def init():
|
||
|
||
# Mettre les pages avec la couleurs par defaut
|
||
scene.objects['Book'].worldPosition = [0, -22, 16.5]
|
||
scene.objects['Book_close'].color = color_doc_chap
|
||
scene.objects['Book_chap-screen'].color = color_doc_chap
|
||
scene.objects['Book_chap-map'].color = color_doc_chap
|
||
scene.objects['Book_chap-tower'].color = color_doc_chap
|
||
scene.objects['Book_chap-tech'].color = color_doc_chap
|
||
scene.objects['Book_chap-spell'].color = color_doc_chap
|
||
scene.objects['Book_close'].color = color_doc_chap
|
||
scene.objects['Book'].setVisible(True,True)
|
||
scene.objects['Book_text_title'].setVisible(False,True)
|
||
scene.objects['Book_text'].setVisible(False,True)
|
||
sound_play (sndbuff_book_open)
|
||
|
||
# Activer la page screen (page par defaut)
|
||
scene.objects['Book']['page_chap'] = "Book_chap-screen"
|
||
scene.objects['Book']['page_fct'] = ""
|
||
scene.objects['Book_chap-screen'].color = color_doc_activate
|
||
scene.objects['Book_page_screen'].worldPosition = scene.objects['Book'].worldPosition
|
||
scene.objects['Book_page_screen'].setVisible(True,True)
|
||
|
||
# Mettre les cartes avec la couleurs par defaut
|
||
for i in range(len(map_card)):
|
||
scene.objects[map_card[i]].color = color_doc_fct
|
||
scene.objects[map_card[i]+"-colbox"].suspendPhysics()
|
||
for i in range(len(tower_card)):
|
||
scene.objects[tower_card[i]].color = color_doc_fct
|
||
scene.objects[tower_card[i]+"-colbox"].suspendPhysics()
|
||
for i in range(len(tech_card)):
|
||
scene.objects[tech_card[i]].color = color_doc_fct
|
||
scene.objects[tech_card[i]+"-colbox"].suspendPhysics()
|
||
for i in range(len(spell_card)):
|
||
scene.objects[spell_card[i]].color = color_doc_fct
|
||
scene.objects[spell_card[i]+"-colbox"].suspendPhysics()
|
||
|
||
##
|
||
# Fermeture du livre
|
||
##
|
||
|
||
def close():
|
||
sound_play (sndbuff_book_close)
|
||
|
||
# Effacer les fonctions cartes
|
||
scene.objects['Book_page_screen'].setVisible(False,True)
|
||
scene.objects['Book_page_map'].setVisible(False,True)
|
||
scene.objects['Book_page_tower'].setVisible(False,True)
|
||
scene.objects['Book_page_tech'].setVisible(False,True)
|
||
scene.objects['Book_page_spell'].setVisible(False,True)
|
||
|
||
scene.objects['Book_page_screen'].setVisible(False,True)
|
||
scene.objects['Book'].setVisible(False,True)
|
||
# scene.objects['Book'].worldPosition = [28, 0.84549, 1.53626] # Position dans Blender [28, 0.84549, 1.53626]
|
||
scene.objects['Book'].worldPosition = [28, 15, 14] # Position dans Blender [28, 0.84549, 1.53626]
|
||
scene.objects['Book_page_screen'].worldPosition = scene.objects['Book'].worldPosition
|
||
|
||
##
|
||
# Highlight du livre
|
||
##
|
||
|
||
def hl (cont):
|
||
if cont.sensors['MO'].status == JUST_ACTIVATED :
|
||
obj = cont.owner
|
||
name=obj.name[:-7]
|
||
scene.objects[name].color = color_doc_hl
|
||
if name == scene.objects['Book']['page_chap'] or name == scene.objects['Book']['page_fct'] :
|
||
scene.objects[name].color = color_doc_activate
|
||
else:
|
||
scene.objects[name].color = color_doc_hl
|
||
if cont.sensors['MO'].status == JUST_RELEASED :
|
||
obj = cont.owner
|
||
name=obj.name[:-7]
|
||
if name == scene.objects['Book']['page_chap'] or name == scene.objects['Book']['page_fct'] :
|
||
scene.objects[name].color = color_doc_activate
|
||
else:
|
||
if name[5]=="c":
|
||
scene.objects[name].color = color_doc_chap
|
||
else:
|
||
scene.objects[name].color = color_doc_fct
|
||
|
||
##
|
||
# Afficher le chapitre
|
||
##
|
||
|
||
def chapter(cont):
|
||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and cont.sensors['Click'].positive:
|
||
sound_play (sndbuff_book_flip)
|
||
obj = cont.owner
|
||
last_name_chap= scene.objects['Book']['page_chap']
|
||
name_chap= obj.name[:-7]
|
||
scene.objects[last_name_chap].color = color_doc_chap
|
||
scene.objects[name_chap].color = color_doc_activate
|
||
scene.objects['Book']['page_chap'] = name_chap
|
||
last_name_fct= scene.objects['Book']['page_fct']
|
||
if last_name_fct != "":
|
||
scene.objects[last_name_fct].color = color_doc_fct
|
||
scene.objects['Book']['page_fct'] = ""
|
||
scene.objects['Book_text_title'].setVisible(False,True)
|
||
scene.objects['Book_text'].setVisible(False,True)
|
||
|
||
# Effacer les fonctions cartes
|
||
scene.objects['Book_page_screen'].setVisible(False,True)
|
||
scene.objects['Book_page_map'].setVisible(False,True)
|
||
scene.objects['Book_page_tower'].setVisible(False,True)
|
||
scene.objects['Book_page_tech'].setVisible(False,True)
|
||
scene.objects['Book_page_spell'].setVisible(False,True)
|
||
|
||
# Désactiver les cartes
|
||
for i in range(len(map_card)):
|
||
scene.objects[map_card[i]+"-colbox"].suspendPhysics()
|
||
for i in range(len(tower_card)):
|
||
scene.objects[tower_card[i]+"-colbox"].suspendPhysics()
|
||
for i in range(len(tech_card)):
|
||
scene.objects[tech_card[i]+"-colbox"].suspendPhysics()
|
||
for i in range(len(spell_card)):
|
||
scene.objects[spell_card[i]+"-colbox"].suspendPhysics()
|
||
|
||
# Afficher la page Screen
|
||
if name_chap == "Book_chap-screen":
|
||
scene.objects['Book_page_screen'].worldPosition = scene.objects['Book'].worldPosition
|
||
scene.objects['Book_page_screen'].setVisible(True,True)
|
||
|
||
# Afficher la page Map
|
||
if name_chap == "Book_chap-map":
|
||
scene.objects['Book_page_map'].worldPosition = scene.objects['Book'].worldPosition
|
||
scene.objects['Book_page_map'].setVisible(True,True)
|
||
for i in range(len(map_card)):
|
||
scene.objects[map_card[i]+"-colbox"].restorePhysics()
|
||
|
||
|
||
# Afficher la page Tower
|
||
if name_chap == "Book_chap-tower":
|
||
scene.objects['Book_page_tower'].worldPosition = scene.objects['Book'].worldPosition
|
||
scene.objects['Book_page_tower'].setVisible(True,True)
|
||
for i in range(len(tower_card)):
|
||
scene.objects[tower_card[i]+"-colbox"].restorePhysics()
|
||
|
||
|
||
# Afficher la page Tech
|
||
if name_chap == "Book_chap-tech":
|
||
scene.objects['Book_page_tech'].worldPosition = scene.objects['Book'].worldPosition
|
||
scene.objects['Book_page_tech'].setVisible(True,True)
|
||
for i in range(len(tech_card)):
|
||
scene.objects[tech_card[i]+"-colbox"].restorePhysics()
|
||
|
||
|
||
# Afficher la page Speel
|
||
if name_chap == "Book_chap-spell":
|
||
scene.objects['Book_page_spell'].worldPosition = scene.objects['Book'].worldPosition
|
||
scene.objects['Book_page_spell'].setVisible(True,True)
|
||
for i in range(len(spell_card)):
|
||
scene.objects[spell_card[i]+"-colbox"].restorePhysics()
|
||
|
||
|
||
##
|
||
# Afficher les details de la fonction à partir d'une carte
|
||
##
|
||
|
||
def card (cont):
|
||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
||
sound_play (sndbuff_book_flip)
|
||
obj = cont.owner
|
||
|
||
# Highlight des cartes
|
||
last_name_fct= scene.objects['Book']['page_fct']
|
||
name_fct= obj.name[:-7]
|
||
if last_name_fct != "":
|
||
scene.objects[last_name_fct].color = color_doc_fct
|
||
scene.objects['Book']['page_fct'] = name_fct
|
||
scene.objects[name_fct].color = color_doc_activate
|
||
|
||
# Afficher le texte de la fonction
|
||
print ("name_fct : ", name_fct)
|
||
print ("fct_description : ", fct_description)
|
||
scene.objects['Book_text_title']['Text'] = fct_description[name_fct][0]
|
||
scene.objects['Book_text']['Text'] = fct_description[name_fct][1]
|
||
scene.objects['Book_text_title'].setVisible(True, False)
|
||
scene.objects['Book_text'].setVisible(True, False)
|
||
|
||
##
|
||
# Sounds
|
||
##
|
||
|
||
def sound_play (sound):
|
||
if scene.objects['Commands']['sound']:
|
||
audiodev.play(sound)
|