codetower/ct_doc.py

370 lines
14 KiB
Python
Raw Normal View History

2022-04-22 02:04:48 +02:00
import bge # Bibliothèque Blender Game Engine (UPBGE)
2022-04-22 16:54:49 +02:00
import aud # Sounds
2022-04-22 02:04:48 +02:00
###############################################################################
# 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
2022-04-22 16:54:49 +02:00
# Sounds
audiodev = aud.Device()
2022-07-22 17:48:41 +02:00
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)
2022-04-22 16:54:49 +02:00
snd_book_flip = aud.Sound('asset/sounds/book_flip.ogg')
sndbuff_book_flip = aud.Sound.cache(snd_book_flip)
2022-04-22 02:04:48 +02:00
# 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
2022-07-29 03:51:06 +02:00
# Functions description
fct_description ={}
2022-04-22 02:04:48 +02:00
###############################################################################
# Map
###############################################################################
2022-07-29 03:51:06 +02:00
map_card=["Level-card", "Sleep-card"]
2022-04-22 02:04:48 +02:00
2022-04-22 16:54:49 +02:00
# ct_level ()
2022-04-22 02:04:48 +02:00
ct_level_title="Get your level"
ct_level_text=" ct_level ()\n \v - Return your level (integer)"
2022-07-29 03:51:06 +02:00
fct_description.update({"Level-card" : [ct_level_title, ct_level_text]})
2022-04-22 02:04:48 +02:00
2022-04-22 16:54:49 +02:00
# ct_sleep (delay)
2022-04-22 02:04:48 +02:00
ct_sleep_title="Time management"
ct_sleep_text=" ct_sleep (delay)\n \v - delay : duration in seconds (float)"
2022-07-29 03:51:06 +02:00
fct_description.update({"Sleep-card" : [ct_sleep_title, ct_sleep_text]})
2022-04-22 02:04:48 +02:00
###############################################################################
# Tower
###############################################################################
2022-07-29 03:51:06 +02:00
tower_card=["Build-card", "Remove-card", "Upgrade-card", "Activate-card", "Tune-card", "Targets-card"]
2022-04-22 02:04:48 +02:00
2022-04-22 16:54:49 +02:00
# ct_build (x, y, category, name, color, style)
2022-04-22 02:04:48 +02:00
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"
2022-04-22 16:54:49 +02:00
ct_build_text = ct_build_text +"Predefined colors : blue, green, magenta,\n orange, purple, red, turquoise, yellow.\n\n"
2022-04-22 02:04:48 +02:00
ct_build_text = ct_build_text +"Exemple : ct_build (1, 1, \"Archer tower\", \n \"Tower #1\", yellow, \"round-A\")\n"
2022-07-29 03:51:06 +02:00
fct_description.update({"Build-card" : [ct_build_title, ct_build_text]})
2022-04-22 02:04:48 +02:00
2022-04-22 16:54:49 +02:00
# ct_remove (x, y)
2022-04-22 02:04:48 +02:00
ct_remove_title="Remove a tower"
ct_remove_text=" ct_remove (x, y) \n \v - x position (integer)\n \v - y position (integer)\n"
2022-07-29 03:51:06 +02:00
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]})
2022-04-22 02:04:48 +02:00
###############################################################################
# Tech
###############################################################################
2022-07-29 03:51:06 +02:00
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]})
2022-04-22 02:04:48 +02:00
###############################################################################
# Spell
###############################################################################
2022-07-29 03:51:06 +02:00
spell_card=["Slow_spell-card", "Detect-card", "Fear-card", "Aura-card"]
2022-04-22 02:04:48 +02:00
2022-07-29 03:51:06 +02:00
# 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]})
2022-04-22 02:04:48 +02:00
2022-04-22 16:54:49 +02:00
###############################################################################
# Interface
###############################################################################
2022-07-22 17:48:41 +02:00
##
# Initialisation du livre
##
def init():
2022-07-29 03:51:06 +02:00
# Mettre les pages avec la couleurs par defaut
2022-07-22 17:48:41 +02:00
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)
2022-07-29 03:51:06 +02:00
sound_play (sndbuff_book_open)
2022-07-22 17:48:41 +02:00
2022-07-29 03:51:06 +02:00
# Activer la page screen (page par defaut)
2022-07-22 17:48:41 +02:00
scene.objects['Book']['page_chap'] = "Book_chap-screen"
2022-07-29 03:51:06 +02:00
scene.objects['Book']['page_fct'] = ""
2022-07-22 17:48:41 +02:00
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)
2022-07-29 03:51:06 +02:00
# 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()
2022-07-22 17:48:41 +02:00
##
# Fermeture du livre
##
def close():
sound_play (sndbuff_book_close)
2022-07-29 03:51:06 +02:00
# 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)
2022-07-22 17:48:41 +02:00
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
##
2022-04-22 16:54:49 +02:00
2022-04-22 02:04:48 +02:00
def chapter(cont):
2022-04-22 16:54:49 +02:00
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and cont.sensors['Click'].positive:
sound_play (sndbuff_book_flip)
2022-04-22 02:04:48 +02:00
obj = cont.owner
2022-07-29 03:51:06 +02:00
last_name_chap= scene.objects['Book']['page_chap']
name_chap= obj.name[:-7]
scene.objects[last_name_chap].color = color_doc_chap
2022-04-22 02:04:48 +02:00
scene.objects[name_chap].color = color_doc_activate
2022-07-29 03:51:06 +02:00
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'] = ""
2022-04-22 02:04:48 +02:00
scene.objects['Book_text_title'].setVisible(False,True)
scene.objects['Book_text'].setVisible(False,True)
2022-07-29 03:51:06 +02:00
# Effacer les fonctions cartes
2022-07-22 17:48:41 +02:00
scene.objects['Book_page_screen'].setVisible(False,True)
scene.objects['Book_page_map'].setVisible(False,True)
2022-07-29 03:51:06 +02:00
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
2022-04-22 02:04:48 +02:00
if name_chap == "Book_chap-screen":
scene.objects['Book_page_screen'].worldPosition = scene.objects['Book'].worldPosition
scene.objects['Book_page_screen'].setVisible(True,True)
2022-07-29 03:51:06 +02:00
# 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()
2022-07-22 17:48:41 +02:00
2022-07-29 03:51:06 +02:00
# 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()
2022-07-22 17:48:41 +02:00
2022-07-29 03:51:06 +02:00
# 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()
2022-07-22 17:48:41 +02:00
2022-04-22 02:04:48 +02:00
2022-07-29 03:51:06 +02:00
# 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()
2022-07-22 17:48:41 +02:00
##
# 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
2022-07-29 03:51:06 +02:00
# 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
2022-07-22 17:48:41 +02:00
# Afficher le texte de la fonction
2022-07-29 03:51:06 +02:00
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)
2022-07-22 17:48:41 +02:00
##
# Sounds
##
def sound_play (sound):
if scene.objects['Commands']['sound']:
audiodev.play(sound)