So I am picturing what a battle formation might look like. For my example I'll have a row of 3 enemies in the back (top of the screen). I like to use pixels rather than relative positions. I assume the default resolution of 1028 by 800px. Enemies will be 240 by 360px.
I start with a class Battle_Formation and put that in an init -1 python block, where user classes should be.
Code: Select all
init -1 python:
class Battle_Formation_Factory:
#the top left corners of the plots
positions=[]
#which positions are empty
empty=[]
__init__(positions=[(0,0)], empty=[True]):
self.positions=positions
self.empty=empty
#make a function like this for each formation
def default_formation():
return self([(34,80), (394,80), (754,80)], [True, True, True])
Then I need an enemy buffer and the current formation in a global in the init python phase.
Code: Select all
init:
python:
current_formation = None
current_plot=(0,0)
enemy_buffer = []
Next I make a transform to put baddies in position.
Code: Select all
transform battleground:
xpos current_plot[0]
ypos current_plot[1]
Lastly, a scene which I'll call battle_screen. But the contents are unimportant to the script.
And a label where it all comes together in the script.
Code: Select all
label draw_enemies:
#Use the default formation if it hasn't been set already
if not current_formation:
current_formation = Battle_Formation_Factory.default_formation()
#keeps count of the plots in a formation
$plot_index=0
#look at each plot in the formation to check if it is empty
for flag in current_formation.empty:
#if this plot has no enemy in it
if flag:
#somewhere else we are appending and removing enemies to the list
#if there are enemies that haven't been fought
$if len(enemy_buffer):
#store the top left corner of the plot (x,y)
current_plot = (current_formation.positions[plot_index][0], current_formation.positions[plot_index][1])
#see renpy documents function index for renpy.show
$renpy.show('enemy healthy', [battleground], 'master', 0, None, 'plot_'+str(plot_index)+'_enemy')
#prepare the next plot
$plot_index=plot_index+1