mirror of
https://forge.apps.education.fr/phroy/codetower.git
synced 2024-01-27 11:35:17 +01:00
200 lines
7.6 KiB
Python
200 lines
7.6 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_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
|
||
|
||
###############################################################################
|
||
# Map
|
||
###############################################################################
|
||
|
||
map_fct=["ct_level", "ct_sleep"]
|
||
|
||
# ct_level ()
|
||
ct_level_title="Get your level"
|
||
ct_level_text=" ct_level ()\n \v - Return your level (integer)"
|
||
|
||
# ct_sleep (delay)
|
||
ct_sleep_title="Time management"
|
||
ct_sleep_text=" ct_sleep (delay)\n \v - delay : duration in seconds (float)"
|
||
|
||
map_fct_title=[ct_level_title, ct_sleep_title]
|
||
map_fct_text=[ct_level_text, ct_sleep_text]
|
||
|
||
###############################################################################
|
||
# Tower
|
||
###############################################################################
|
||
|
||
tower_fct=["ct_build", "ct_remove"]
|
||
|
||
# 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"
|
||
|
||
# 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"
|
||
|
||
tower_fct_title=[ct_build_title, ct_remove_title]
|
||
tower_fct_text=[ct_build_text, ct_remove_text]
|
||
|
||
###############################################################################
|
||
# Tech
|
||
###############################################################################
|
||
|
||
tech_fct=[]
|
||
tech_fct_title=[]
|
||
tech_fct_text=[]
|
||
|
||
###############################################################################
|
||
# Spell
|
||
###############################################################################
|
||
|
||
spell_fct=[]
|
||
spell_fct_title=[]
|
||
spell_fct_text=[]
|
||
|
||
###############################################################################
|
||
# General
|
||
###############################################################################
|
||
|
||
fct = {
|
||
'Book_chap-screen': "",
|
||
'Book_chap-map' : map_fct,
|
||
'Book_chap-tower' : tower_fct,
|
||
'Book_chap-tech' : tech_fct,
|
||
'Book_chap-spell' : spell_fct}
|
||
|
||
fct_title = {
|
||
'Book_chap-screen': "",
|
||
'Book_chap-map' : map_fct_title,
|
||
'Book_chap-tower' : tower_fct_title,
|
||
'Book_chap-tech' : tech_fct_title,
|
||
'Book_chap-spell' : spell_fct_title}
|
||
|
||
fct_text = {
|
||
'Book_chap-screen': "",
|
||
'Book_chap-map' : map_fct_text,
|
||
'Book_chap-tower' : tower_fct_text,
|
||
'Book_chap-tech' : tech_fct_text,
|
||
'Book_chap-spell' : spell_fct_text}
|
||
|
||
###############################################################################
|
||
# Interface
|
||
###############################################################################
|
||
|
||
# Sounds
|
||
def sound_play (sound):
|
||
if scene.objects['Commands']['sound']:
|
||
audiodev.play(sound)
|
||
|
||
# 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
|
||
name_chap=obj.name[:-7]
|
||
|
||
# Highlight des onglets
|
||
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[name_chap].color = color_doc_activate
|
||
scene.objects["Book"]['page_chap'] = name_chap
|
||
|
||
# Tout effacer (fonctions + texte)
|
||
for i in range (1,13):
|
||
if i<10:
|
||
name_fct = "Book_fct-0"+str(i)
|
||
else:
|
||
name_fct = "Book_fct-"+str(i)
|
||
scene.objects[name_fct].setVisible(False,False)
|
||
scene.objects[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)
|
||
|
||
# Afficher la page Ecran
|
||
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 les fonctions
|
||
if name_chap != "Book_chap-screen":
|
||
scene.objects['Book_page_screen'].setVisible(False,True)
|
||
if len(fct[name_chap])==0:
|
||
scene.objects['Book_text']['Text'] = " No functions yet. \n Work in progress..."
|
||
scene.objects['Book_text'].setVisible(True,True)
|
||
for i in range(len(fct[name_chap])):
|
||
j=i+1
|
||
if j<10:
|
||
name_fct = "Book_fct-0"+str(j)
|
||
else:
|
||
name_fct = "Book_fct-"+str(j)
|
||
scene.objects[name_fct]['Text']=fct[name_chap][i]
|
||
scene.objects[name_fct].setVisible(True,False)
|
||
|
||
# Afficher les details de la fonction
|
||
def function(cont):
|
||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
||
sound_play (sndbuff_book_flip)
|
||
obj = cont.owner
|
||
|
||
# Highlight des fonctions
|
||
for i in range (1,13):
|
||
if i<10:
|
||
name_fct = "Book_fct-0"+str(i)
|
||
else:
|
||
name_fct = "Book_fct-"+str(i)
|
||
scene.objects[name_fct].color = color_doc_fct
|
||
scene.objects[obj.name[:-7]].color = color_doc_activate
|
||
scene.objects["Book"]['page_fct'] = obj.name[:-7]
|
||
|
||
# Afficher le texte de la fonction
|
||
name_chap = scene.objects["Book"]['page_chap']
|
||
nb = int(obj.name[9:11])-1
|
||
scene.objects['Book_text_title']['Text'] = fct_title[name_chap][nb]
|
||
scene.objects['Book_text']['Text'] = fct_text[name_chap][nb]
|
||
scene.objects['Book_text_title'].setVisible(True,True)
|
||
scene.objects['Book_text'].setVisible(True,False)
|