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
|
2022-03-24 17:00:09 +01:00
|
|
|
# @lang: fr,en
|
2022-03-11 00:21:00 +01:00
|
|
|
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
|
|
|
# @copyright: Copyright (C) 2022 Philippe Roy
|
|
|
|
# @license: GNU GPL
|
2022-04-01 01:34:54 +02:00
|
|
|
#
|
|
|
|
# En: This game is a tower defense coding game. The towers are driven by Python code.
|
2022-03-23 00:27:11 +01:00
|
|
|
# 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-04-03 06:21:42 +02: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)
|
|
|
|
blue = (0.127, 0.456, 1.000, 1)
|
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: 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
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
scene = bge.logic.getCurrentScene()
|
|
|
|
|
|
|
|
def start():
|
|
|
|
scene.objects['Terrain']['thread_cmd']=True
|
2022-04-06 17:28:16 +02:00
|
|
|
thread_cmd_start(commands)
|
2022-03-11 00:21:00 +01:00
|
|
|
|
|
|
|
def stop():
|
2022-04-06 17:28:16 +02:00
|
|
|
thread_cmd_stop()
|
2022-03-30 03:10:33 +02:00
|
|
|
|
|
|
|
def end():
|
|
|
|
ct_sleep (2)
|
2022-04-06 17:28:16 +02:00
|
|
|
print ("Commands thread is arrived.")
|
2022-03-30 03:10:33 +02:00
|
|
|
scene.objects['Terrain']['thread_cmd']=False
|
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
|
|
|
|
#
|
2022-03-31 18:26:55 +02:00
|
|
|
# Build a tower : ct_build (x, y, category, name, color, style)
|
2022-03-23 00:27:11 +01:00
|
|
|
# - x position (integer)
|
|
|
|
# - y position (integer)
|
2022-03-27 10:28:03 +02:00
|
|
|
# - category (string) : "Archer tower", "Mage tower" or "Barrack" (not implemented)
|
2022-03-23 00:27:11 +01:00
|
|
|
# - name (string)
|
|
|
|
# - color (RGB model) : purple, turquoise, magenta, orange, yellow, green, red or [R, G, B, 1]
|
2022-03-25 01:56:02 +01:00
|
|
|
# - style : square or round and version (A,B or C), exemple : 'square-A'
|
2022-03-23 00:27:11 +01:00
|
|
|
# - Return boolean flag
|
|
|
|
# - True : builded
|
|
|
|
# - False : not builded
|
2022-04-06 17:28:16 +02:00
|
|
|
# - Exemple : ct_build(1,1, "Archer tower", "Tower #1",yellow,"round-A")
|
2022-03-27 10:28:03 +02:00
|
|
|
#
|
2022-03-31 18:26:55 +02:00
|
|
|
# Remove a tower : ct_remove (x, y)
|
2022-03-23 00:27:11 +01:00
|
|
|
# - x position (integer)
|
|
|
|
# - y position (integer)
|
|
|
|
#
|
2022-04-06 17:28:16 +02:00
|
|
|
# Get your level : ct_level ()
|
|
|
|
# - Return your level (integer)
|
|
|
|
#
|
2022-03-31 18:26:55 +02:00
|
|
|
# Time management (temporization) : ct_sleep (delay)
|
2022-03-24 17:00:09 +01:00
|
|
|
# - delay : delay in seconds (float)
|
2022-03-23 00:27:11 +01:00
|
|
|
#
|
2022-03-11 00:21:00 +01:00
|
|
|
###############################################################################
|
|
|
|
|
2022-03-23 00:27:11 +01:00
|
|
|
def commands():
|
|
|
|
|
|
|
|
# Code your commands here ...
|
|
|
|
|
2022-03-30 03:10:33 +02:00
|
|
|
while True:
|
2022-03-23 00:27:11 +01:00
|
|
|
|
2022-04-03 06:21:42 +02:00
|
|
|
if ct_level() == 1:
|
2022-03-30 03:10:33 +02:00
|
|
|
ct_build(4,5, "Archer tower", "Tower #1", blue, "square-A")
|
2022-04-03 06:21:42 +02:00
|
|
|
|
2022-04-06 17:28:16 +02:00
|
|
|
if ct_level()==2:
|
|
|
|
ct_build(4,-2, "Archer tower", "Tower #2", blue, "square-A")
|
2022-03-31 18:26:55 +02:00
|
|
|
|
2022-04-06 17:28:16 +02:00
|
|
|
if ct_level()==3:
|
|
|
|
ct_build(5,4, "Mage tower", "Tower #3", magenta, "square-B")
|
|
|
|
|
2022-03-30 03:10:33 +02:00
|
|
|
|
2022-04-06 17:28:16 +02:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# En: Externals calls << DONT CHANGE THIS SECTION >>
|
|
|
|
# Fr: Appels externes << NE PAS MODIFIER CETTE SECTION >>
|
|
|
|
###############################################################################
|
2022-04-06 06:25:03 +02:00
|
|
|
|
|
|
|
if __name__=='start':
|
|
|
|
start()
|
|
|
|
if __name__=='stop':
|
|
|
|
stop()
|
|
|
|
|