2022-03-11 00:21:00 +01:00
|
|
|
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
|
|
|
from ct_lib import * # Bibliothèque CodeTower
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# ct_cmd.py
|
2022-03-20 05:57:07 +01:00
|
|
|
# @title: Commands for the CodeTower game
|
2022-03-11 00:21:00 +01:00
|
|
|
# @project: CodeTower
|
|
|
|
# @lang: fr
|
|
|
|
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
|
|
|
# @copyright: Copyright (C) 2022 Philippe Roy
|
|
|
|
# @license: GNU GPL
|
|
|
|
#
|
2022-03-23 00:27:11 +01:00
|
|
|
# En: This game is a tower defense coding game. The towers are driven with Python code.
|
|
|
|
# Fr: Ce simulateur est un jeu du type tower defense où les tours sont à piloter par la programmation Python.
|
2022-03-11 00:21:00 +01:00
|
|
|
#
|
|
|
|
###############################################################################
|
|
|
|
|
2022-03-23 00:27:11 +01:00
|
|
|
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]
|
|
|
|
|
2022-03-11 00:21:00 +01:00
|
|
|
###############################################################################
|
2022-03-23 00:27:11 +01:00
|
|
|
# En: Threads management << DONT CHANGE THIS SECTION >>
|
|
|
|
# Fr: Gestion des tâches (threads) << NE PAS MODIFIER CETTE SECTION >>
|
2022-03-11 00:21:00 +01:00
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
threads=[]
|
|
|
|
scene = bge.logic.getCurrentScene()
|
|
|
|
|
|
|
|
def start():
|
|
|
|
scene.objects['Terrain']['thread_cmd']=True
|
2022-03-23 00:27:11 +01:00
|
|
|
thread_start(threads, "commands", commands)
|
2022-03-11 00:21:00 +01:00
|
|
|
|
|
|
|
def stop():
|
2022-03-20 05:57:07 +01:00
|
|
|
thread_stop(threads, "commands")
|
2022-03-23 00:27:11 +01:00
|
|
|
|
2022-03-11 00:21:00 +01:00
|
|
|
###############################################################################
|
2022-03-23 00:27:11 +01:00
|
|
|
# En: Tower commands
|
|
|
|
# Fr: Commandes des tours
|
|
|
|
#
|
|
|
|
# Build a tower : ct_build(x, y, name, color)
|
|
|
|
# - x position (integer)
|
|
|
|
# - y position (integer)
|
|
|
|
# - name (string)
|
|
|
|
# - color (RGB model) : purple, turquoise, magenta, orange, yellow, green, red or [R, G, B, 1]
|
|
|
|
# - Return boolean flag
|
|
|
|
# - True : builded
|
|
|
|
# - False : not builded
|
|
|
|
#
|
|
|
|
# Remove a tower : ct_remove(x, y)
|
|
|
|
# - x position (integer)
|
|
|
|
# - y position (integer)
|
|
|
|
#
|
|
|
|
# Time management (temporization) : ct_tempo(delay)
|
|
|
|
# - delay : delay in seconds (integer)
|
|
|
|
#
|
2022-03-11 00:21:00 +01:00
|
|
|
###############################################################################
|
|
|
|
|
2022-03-23 00:27:11 +01:00
|
|
|
def commands():
|
|
|
|
|
|
|
|
# Code your commands here ...
|
|
|
|
|
|
|
|
ct_build(4,5, "Tower #1")
|
|
|
|
ct_build(5,5, "Tower #2", green)
|
|
|
|
ct_build(5,4, "Tower #3")
|
|
|
|
ct_build(4,4, "Tower #4", [0.3, 0.5, 0.5, 1])
|
|
|
|
ct_build(4,5, "Tower #5")
|
|
|
|
|
|
|
|
ct_tempo(20)
|
2022-03-11 00:21:00 +01:00
|
|
|
|
2022-03-23 00:27:11 +01:00
|
|
|
ct_remove(4,4)
|
|
|
|
ct_print("ok")
|
2022-03-11 00:21:00 +01:00
|
|
|
|
2022-03-23 00:27:11 +01:00
|
|
|
ct_tempo(2)
|
|
|
|
print ("Threads commands #", len(threads)-1, "are arrived -> close them.") # Thread closed << DONT CHANGE THIS LINE >>
|
|
|
|
scene.objects['Terrain']['thread_cmd']=False # End of cycle << DONT CHANGE THIS LINE >>
|