import bge # Bibliothèque Blender Game Engine (UPBGE) import bpy # Blender from ct_lib import * # Bibliothèque CodeTower import os ############################################################################### # ct_map1.py # @title: Map #1 definition # @project: CodeTower # @lang: fr,en # @authors: Philippe Roy # @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() ############################################################################### # 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()} def start(wave): scene.objects['Terrain']['thread_wave']=True if wave==1: thread_waves_start(wave1) if wave==2: thread_waves_start(wave2) if wave==3: thread_waves_start(wave3) if wave==4: thread_waves_start(wave4) def stop(): thread_waves_stop() def end(): ct_sleep (2) print ("Thread waves is arrived.") 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(): # Text ct_map_text_wave(1) # Pooling wave_minion_name=[] for i in range (15): wave_minion_name.append(ct_minion_create_details(14,3,"Orc",1, "Orc_A_common")) # Go ! for i in range (len(wave_minion_name)): ct_minion_go(wave_minion_name[i]) ct_sleep (2) end() # Wave 2 def wave2(): # Text ct_map_text_wave(2) # Pooling wave_minion_name=[] for i in range (20): wave_minion_name.append(ct_minion_create(14,3,"Orc",1)) # Go ! for i in range (len(wave_minion_name)): ct_minion_go(wave_minion_name[i]) ct_sleep (1) end() # Wave 3 def wave3(): # Text ct_map_text_wave(3) # Pooling wave_minion_name=[] for i in range (30): wave_minion_name.append(ct_minion_create(14,3,"Orc",1)) # Go ! for i in range (len(wave_minion_name)): ct_minion_go(wave_minion_name[i]) ct_sleep (1) end() # Wave 4 def wave4(): # Text ct_map_text_wave(4) # Pooling wave_minion_name_group1=[] wave_minion_name_group2=[] for i in range (20): wave_minion_name_group1.append(ct_minion_create(14,2.5,"Orc",1)) wave_minion_name_group2.append(ct_minion_create(14,3,"Knight",1)) # Go ! for i in range (len(wave_minion_name_group1)): ct_minion_go(wave_minion_name_group1[i]) ct_minion_go(wave_minion_name_group2[i]) ct_sleep (0.5) end() ############################################################################### # Tower definition ############################################################################### def tower_definition(): # Tower caracteristics : category (class), damage, speed, range # Damage : 1 point = 1 point # Speed : 1 point = 50 tics # Range : 1 point = 2,5 m 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 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 # 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) # Exit 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