Hi Brian,
There are a few changes I think you need to make. Here's my interpretation of what you want as well as a few other options:
sprite_1 = (...) # Some 8x8 sprite data
sprite_invader_a = (...) # Some other 8x8 sprite data
inv = [] # A Python list
# sprite number, x, y
inv.append({'s':sprite_invader_a, 'x':40, 'y':28})
inv.append({'s':sprite_1, 'x':50, 'y':28})
inv.append({'s':sprite_1, 'x':60, 'y':28})
inv.append({'s':sprite_1, 'x':70, 'y':28})
inv.append({'s':sprite_1, 'x':80, 'y':28})
while(1):
thumby.display.fill(0)
for invader in inv:
thumby.display.blit(invader['s'],invader['x'], invader['y'], 8, 8, 0)
To remove an element from inv:
# By index:
del inv[0] # removes invader_a
del inv[0] # removes {'s':sprite_1, 'x':50, 'y':28}
# By value:
inv.remove({'s':sprite_invader_a, 'x':40, 'y':28}) # the whole dict needs to be passed in, which might not make sense for you
# This probably won't do what you expect (deleting all elements) because the indices change as you delete elements:
for invader_i in range(len(inv)):
del inv[invader_i]
Other methods:
I'm not sure what the rest of your game code will look like, but for a space invaders style game, I would consider a pre-allocated list or using a dict to store information about game objects.
If you're unsure of the index of any particular object and you want to remove an element a little more efficiently than searching through the list and removing by index, I would recommend using a Python dict like this:
sprite_1 = (...) # Some 8x8 sprite data
sprite_invader_a = (...) # Some other 8x8 sprite data
inv = {} # A Python dict
# sprite number, x, y
inv[0] = {'s':sprite_invader_a, 'x':40, 'y':28} # The key/id (0) can be any immutable object. Usually it's an integer as shown here or a string like 'a', 'b', 'c'
inv[1] = {'s':sprite_1, 'x':50, 'y':28}
inv[2] = {'s':sprite_1, 'x':60, 'y':28}
inv[3] = {'s':sprite_1, 'x':70, 'y':28}
inv[4] = {'s':sprite_1, 'x':80, 'y':28}
while(1):
thumby.display.fill(0)
for inv_id in inv:
invader = inv[inv_id]
thumby.display.blit(invader['s'],invader['x'], invader['y'], 8, 8, 0)
# Removing an object:
del inv[3] # Removes {'s':sprite_1, 'x':70, 'y':28}
del inv[4] # Removes {'s':sprite_1, 'x':80, 'y':28}
del inv[0] # Removes {'s':sprite_invader_a, 'x':40, 'y':28}
Note the difference in what's removed compared to removal by index in the list version above.
If you pre-allocate a list instead, you can use the value None to mark an object as deleted:
inv = [None] * 5 # a List
inv[0] = {'s':sprite_invader_a, 'x':40, 'y':28}
inv[1] = {'s':sprite_1, 'x':50, 'y':28}
inv[2] = {'s':sprite_1, 'x':60, 'y':28}
inv[3] = {'s':sprite_1, 'x':70, 'y':28}
inv[4] = {'s':sprite_1, 'x':80, 'y':28}
# Removal:
inv[3] = None
Same thing:
inv = [ # List
{'s':sprite_invader_a, 'x':40, 'y':28},
{'s':sprite_1, 'x':50, 'y':28},
{'s':sprite_1, 'x':60, 'y':28},
{'s':sprite_1, 'x':70, 'y':28},
{'s':sprite_1, 'x':80, 'y':28}
]
# Removal:
inv[3] = None
Good luck!
Edit: left an incorrect comment in there. Good catch