python - Short animation class in Pygame? -
i litterally have no idea still how use classes. need 18 frame animation , have capability of doing anywhere (25 times) in 5x5 grid. ideas on how accomplished?
anyway, have far:
class showrectangles: def __init__(self): pass def flipcard(self): while showrect: pygame.draw.rect(window,black,[self.position,75*scale,75*scale]) self.blitoptions = self.image,self.position,[[55,self.frame,0],[75*scale,75*scale]] window.blit(pygame.transform.smoothscale(self.blitoptions,75*scale).convert_alpha()) if self.flipping , self.frame != 18: self.frame += 1 else: self.flipping = false class boardcard(showrectangles): def __init__(self,pos): self.position = pos self.rect = rect(self.position[0]*scale,self.position[1]*scale,self.position[0]+75*scale,self.position[1]+75*scale) self.flipping = false self.frame = 0 self.image = themedb["default"]["images"]["flipanimation"] # def getrect(self): # return pygame.rect(int(self.position[0]),int(self.position[1]),int(self.position[0])+75*scale,int(self.position[1])+75*scale)
variables:
showrect shows areas clickable sort of "debug view".
scale resizes window , images on it.
themedb set of themes game. "flipanimation.png" stored here.
did read python tutorials? have great explanation classes.
i'm not sure trying accomplish, seems have grid of rectangles, , after click, want flip card animation.
what want define class myrectangle, have methods __init__
, draw
, update
. here short example:
class card: def __init__(self,pos): self.flipping = false self.images = loadimages() self.frame = 0 self.pos = pos def flip(): self.flipping = true def update(): if self.flipping: self.frame += 1 self.frame %= len(self.images) def draw(screen): screen.blit(self.images[self.frame],self.pos)
your main loop code this:
cards = [] x in range(10): y in range(10): cards.append(card((x*10,y*10))) while not finished: card in cards: card.draw(screen) card.update() #somewhere in event loop: card.flip()
Comments
Post a Comment