I thought about making something with ApeOut graphics long before it came out and its release motivated me to try - I'm having tons of fun but I stumbled upon a pickle.
I can imagine storing polygons is a very common task in game development. I'm prototyping with pygame and currently store each polygon as a list of Vector2 coordinates/vertices on a 10x10 field and keep these lists in a Python dict. This can't be a good practice.
- Is there an established format to store list of vertices (preferably supported by some free editor)? I was thinking about SVG but it works with curves and I only need straight edges. Or is SVG still the better option?
- What's a sensible way to store frames of an animation for such polygon (e.g. "deer" lowering its head when eating or moving its shoulders while walking, etc.; legs will be driven by invert kinematics)? Right now I'm thinking about each animation being a list of frames where each frame is list of vertices but it'll become unmanageable if I don't separate animations to different files.
What I have so far:
shapes = {
# I edit this in my head, was fun, slowly becomes a nightmare
'deer': [(5,0), (4,1), (2,0), (3,1), (2,1), (1,0), (1,1), (4,2), (3,3), (4,5), (3,7), (3,8), (5,10), (7,8), (7,7), (6,5), (7,3), (6,2), (9,1), (9,0), (8,1), (7,1), (8,0), (6,1)],
}
def loadShape(name, size):
resolution = 10 # 10x10
verts = shapes.get(name)
scaled = [tuple((point[0]/resolution*size, point[1]/resolution*size)) for point in verts]
surface = pygame.Surface((size, size), pygame.SRCALPHA)
pygame.draw.polygon(surface, colors.get(name), scaled)
return surface
