codetower/ct_map1.py

231 lines
7.3 KiB
Python
Raw Normal View History

2022-03-30 03:10:33 +02:00
import bge # Bibliothèque Blender Game Engine (UPBGE)
import bpy # Blender
2022-03-30 03:10:33 +02:00
from ct_lib import * # Bibliothèque CodeTower
import os
2022-03-30 03:10:33 +02:00
###############################################################################
# ct_map1.py
# @title: Map #1 definition
# @project: CodeTower
# @lang: fr,en
# @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
# This game is a tower defense coding game. The towers are driven by Python code.
# The file is the the map and waves definition.
2022-03-30 03:10:33 +02:00
#
###############################################################################
scene = bge.logic.getCurrentScene()
###############################################################################
# En: Threads management << DONT CHANGE THIS SECTION >>
# Fr: Gestion des tâches (threads) << NE PAS MODIFIER CETTE SECTION >>
###############################################################################
# waves_f={
# 1 : wave1(),
# 2 :wave2(),
# 3 :wave3(),
# 4 :wave4()}
2022-03-30 03:10:33 +02:00
def start(wave):
scene.objects['Terrain']['thread_wave']=True
if wave==1:
thread_waves_start(wave1)
2022-03-30 03:10:33 +02:00
if wave==2:
thread_waves_start(wave2)
2022-03-30 03:10:33 +02:00
if wave==3:
thread_waves_start(wave3)
if wave==4:
thread_waves_start(wave4)
2022-03-30 03:10:33 +02:00
def stop():
thread_waves_stop()
2022-03-30 03:10:33 +02:00
def end():
ct_sleep (2)
print ("Waves thread is arrived.")
2022-03-30 03:10:33 +02:00
scene.objects['Terrain']['thread_wave']=False
###############################################################################
# En: Minions definition
# Fr: Définition des minions
#
# Minion caracteristics :
# - category, minion class (string) :
# - Knight
# - Barbarian
# - Warrior
# - Mage
# - Rogue
# - Orc
# - Squelette
# - level : 1, 2 or 3 (integer)
# - hp (float)
# - speed (float)
# - armor (float)
# - bounty (integer)
# - lifes_damage (integer)
#
# Minion 3D object :
# - body : male,female,old, ... (string)
# - variante : A,B,C,D, ... (string)
# - level : common, uncommon, rare, ... (string)
#
###############################################################################
def minion_definition():
# Minion caracteristics : category (class), level, hp, speed, armor, bounty, lifes_damage
minion_carac={
'Knight-lv1' : ["Knight", 1 , 2.0, 1.0, 0.0, 5,1],
'Knight-lv2' : ["Knight", 2, 4.0, 1.0, 1.0, 20,1],
'Knight-lv3' : ["Knight", 3, 8.0, 1.0, 2.0, 80,1],
'Orc-lv1' : ["Orc", 1 , 2.0, 1.0, 0.0, 5,1],
'Orc-lv2' : ["Orc", 2, 4.0, 1.0, 1.0, 20,1],
'Orc-lv3' : ["Orc", 3, 8.0, 1.0, 2.0, 80,1]}
scene.objects['Terrain']['minion_carac'] = minion_carac
# Minion 3D object : body (male,female,old, ...), variante (A,B,C,D, ...), level
minion_3d={
'Knight-lv1' : [['Knight_m', 'Knight_f', 'OldKnight_m'],['A','B','C','D'],['common']],
'Knight-lv2' : [['Knight_m', 'Knight_f', 'OldKnight_m'],['A','B','C','D'],['uncommon']],
'Knight-lv3' : [['Knight_m', 'Knight_f', 'OldKnight_m'],['A','B','C','D'],['rare']],
'Orc-lv1' : [['Orc'],['A','B','C','D','E','F'],['common']],
'Orc-lv2' : [['Orc'],['A','B','C','D','E','F'],['uncommon']],
'Orc-lv3' : [['Orc'],['A','B','C','D','E','F'],['rare']]}
scene.objects['Terrain']['minion_3d'] = minion_3d
###############################################################################
# En: Waves commands
# Fr: Commandes des vagues
#
# Spawn a minion : ct_minion (x, y, cat, level)
# - x spwan position (integer)
# - y spwan position (integer)
# - category, minion class (string) :
# - Knight
# - Barbarian
# - Warrior
# - Mage
# - Rogue
# - Orc
# - Squelette
# - level (1, 2 or 3)
#
# Time management (temporization) : ct_sleep(delay)
# - delay : delay in seconds (integer)
#
# UI management : ct_map_text(text)
# - text for the wave label
#
###############################################################################
# Wave 1
def wave1():
ct_map_text_wave(1)
2022-03-30 03:10:33 +02:00
for i in range (15):
ct_minion(14,3,"Orc",1)
# ct_minion_details(14,3,"Orc",1, "Orc_A_common")
2022-03-30 03:10:33 +02:00
ct_sleep (2)
end()
# Wave 2
def wave2():
ct_map_text_wave(2)
2022-03-30 03:10:33 +02:00
for i in range (20):
ct_minion(14,3,"Orc",1)
# ct_minion_details(14,3,"Orc",1, "Orc_A_common")
2022-03-30 03:10:33 +02:00
ct_sleep (1)
end()
# Wave 3
def wave3():
ct_map_text_wave(3)
2022-03-31 18:26:55 +02:00
for i in range (30):
ct_minion(14,3,"Orc",1)
# ct_minion_details(14,3,"Orc",1, "Orc_A_common")
2022-03-31 18:26:55 +02:00
# ct_minion(14,3,"Knight",1)
2022-03-30 03:10:33 +02:00
ct_sleep (1)
end()
# Wave 4
def wave4():
ct_map_text_wave(4)
for i in range (20):
ct_minion(14,3,"Orc",1)
ct_minion(14,2.5,"Orc",1)
# ct_minion_details(14,3,"Orc",1, "Orc_A_common")
# ct_minion(14,3,"Knight",1)
ct_sleep (0.5)
end()
2022-03-30 03:10:33 +02:00
###############################################################################
# Tower definition
###############################################################################
def tower_definition():
# Tower caracteristics : category (class), damage, speed, range
tower_carac={
'Archer tower' : ["Archer tower", 1.0 , 0.02, 2.5],
'Mage tower' : ["Mage tower", 0.0 , 0.005, 2.5],
'Barrack' : ["Barrack", 1.0 , 0.0001, 2.5]}
scene.objects['Terrain']['tower_carac'] = tower_carac
# Minion 3D object : body (male,female,old, ...), variante (A,B,C,D, ...), level
tower_minion_3d={
'Archer-lv1' : [['Archer_m', 'Archer_f', "OldArcher_m"],['A','B','C','D'],['common']],
'Archer-lv2' : [['Archer_m', 'Archer_f', "OldArcher_m"],['A','B','C','D'],['uncommon']],
'Archer-lv3' : [['Archer_m', 'Archer_f', "OldArcher_m"],['A','B','C','D'],['rare']],
'Mage-lv1' : [['Mage'],['A','B','C','D'],['common']],
'Mage-lv2' : [['Mage'],['A','B','C','D'],['uncommon']],
'Mage-lv3' : [['Mage'],['A','B','C','D'],['rare']]}
scene.objects['Terrain']['tower_minion_3d'] = tower_minion_3d
###############################################################################
# Map
###############################################################################
# Initialization
def map_init():
# Base
2022-03-30 03:10:33 +02:00
scene.objects['Terrain']['size'] = [-15,15,-10,10] # Map size
scene.objects['Terrain']['navmesh'] = "Navmesh.004" # Navmesh
minion_definition()
tower_definition()
scene.objects['Terrain']['nb_waves'] = 4 # Number of waves
2022-03-30 03:10:33 +02:00
# Landscape
file_path = 'asset/map/map1-landscape.blend'
inner_path = 'Object'
object_name = 'Landscape'
bpy.ops.wm.append(
filepath=os.path.join(file_path, inner_path, object_name),
directory=os.path.join(file_path, inner_path),
filename=object_name)
2022-03-30 03:10:33 +02:00
# Ajout des sorties
scene.objects['Terrain']['endtile'] = "tile_straight.036"
ct_map_end(1,-10)
ct_map_endflag(0.5,-10)
ct_map_endflag(1.5,-10)
# Reset counters
def map_reset():
scene.objects['Points']['lifes']=10
scene.objects['Points']['lifes_max']=10
scene.objects['Points']['coins']=0
scene.objects['Points']['level']=0
scene.objects['Points']['level_max']=1
scene.objects['Points']['minions']=0
scene.objects['Points']['minions_run']=0
scene.objects['Points']['wave']=1