import bge # Bibliothèque Blender Game Engine (UPBGE) from ct_lib import * # Bibliothèque CodeTower ############################################################################### # ct_cmd.py # @title: Commands for the CodeTower game # @project: CodeTower # @lang: fr,en # @authors: Philippe Roy # @copyright: Copyright (C) 2022 Philippe Roy # @license: GNU GPL # # En: This game is a tower defense coding game. The towers are driven by Python code. # Fr: Ce simulateur est un jeu du type tower defense où les tours sont à piloter par la programmation Python. # ############################################################################### purple = (0.202, 0.114, 0.521,1) turquoise = (0.051, 0.270, 0.279,1) magenta = (0.799, 0.005, 0.314,1) orange = (0.799, 0.130, 0.063,1) yellow = (0.799, 0.617, 0.021, 1) green = (0.246, 0.687, 0.078, 1) red = (0.799, 0.031, 0.038, 1) blue = (0.127, 0.456, 1.000, 1) ############################################################################### # En: Threads management << DONT CHANGE THIS SECTION >> # Fr: Gestion des tâches (threads) << NE PAS MODIFIER CETTE SECTION >> ############################################################################### scene = bge.logic.getCurrentScene() def start(): scene.objects['Terrain']['thread_cmd']=True thread_cmd_start(commands) def stop(): thread_cmd_stop() def end(): ct_sleep (2) print ("Thread commands is arrived.") scene.objects['Terrain']['thread_cmd']=False ############################################################################### # En: Tower commands # Fr: Commandes des tours # # Build a tower : ct_build (x, y, category, name, color, style) # - x position (integer) # - y position (integer) # - category (string) : "Archer tower", "Mage tower" or "Barrack" (not implemented) # - name (string) # - color (RGB model) : purple, turquoise, magenta, orange, yellow, green, red or [R, G, B, 1] # - style : square or round and version (A,B or C), exemple : 'square-A' # - Return boolean flag # - True : builded # - False : not builded # - Exemple : ct_build(1,1, "Archer tower", "Tower #1",yellow,"round-A") # # Remove a tower : ct_remove (x, y) # - x position (integer) # - y position (integer) # # Get your level : ct_level () # - Return your level (integer) # # Time management (temporization) : ct_sleep (delay) # - delay : delay in seconds (float) # ############################################################################### def commands(): while True: if ct_level ()==1: ct_build(4,5, "Archer tower", "Tower #1",yellow,"round-A") if ct_level ()==2: ct_build(3,-1, "Archer tower", "Tower #2",red,"round-A") if ct_level ()==3: ct_build(5,4, "Mage tower", "Tower #3",blue,"square-A") ############################################################################### # En: Externals calls << DONT CHANGE THIS SECTION >> # Fr: Appels externes << NE PAS MODIFIER CETTE SECTION >> ############################################################################### if __name__=='start': start() if __name__=='stop': stop()