Having trouble with something is very straight forward.
I’m making a simple game (using pygame) where enemies (sprites) enter the game screen at a certain game tick. I figured writing a text file would be easier to manage all of the enemies which could then be read into a list.
If my file “heli.txt” contains:
10 660 130 1
10 660 350 2
I want the program to add two enemies on the 10th tick at a certain x, y and follow a certain pattern around the screen.
This is what I’m going with:
fh = open( "heli.txt" );
heliList = []
for line in fh.readlines():
y = [value for value in line.split()]
heliList.append( y )
fh.close()
Which seems to populate the list appropriately:
>>> print (heliList)
[['10', '660', '130', '1'], ['10', '660', '350', '2']]
The current method I’m using for the second enemy is:
if timer.returnTick() == 10:
heli = Heli(660, 350, 2)
And this gets very hard to maintain as more enemies are added. Moreso when I begin to add various enemy types.
Basically, I want the game to loop through the list each tick, see if the current tick matches any line’s first parameter and if so, add that enemy. However, I’m a little stuck on the correct syntax here (I feel like there may also be an issue with the values as they seem to be strings and not integers).
Any help is appreciated, thanks.
to make the values into ints:
once you have all your list of enemies, to check their tick do something like this: