def loadImageV2(self): for animation in self.whole: for part in self.whole[animation]: self.whole[animation][part] = utils.simple_load_image(animation+"/"+self.imageInfo[part]["name"], (255,0,255)) try: self.image[part] = self.whole[animation][part].subsurface((self.animX*64,self.animY*64,64,64)) except: pass self.rect = pygame.rect.Rect(128,100,64,64)
def loadImageV2(self): for animation in self.whole: for part in self.whole[animation]: self.whole[animation][part] = utils.simple_load_image( animation + "/" + self.imageInfo[part]["name"], (255, 0, 255)) try: self.image[part] = self.whole[animation][part].subsurface( (self.animX * 64, self.animY * 64, 64, 64)) except: pass self.rect = pygame.rect.Rect(128, 100, 64, 64)
def main(self): self.screen = pygame.display.set_mode(self.RESO) pygame.key.set_repeat(1, 30) self.running = True self.clock = utils.GameClock(*(self.TICKS_PER_SECOND, 0)) self.clock.use_wait = False self.char = hero.Hero(self.screen) self.char.loadImageV2() self.test = pygame.sprite.Sprite() self.test.whole = utils.simple_load_image("walkcycle/"+self.equip["Body"][0],self.INVIS) self.test.image = self.test.whole.subsurface((0,128,64,64)) self.test.rect = pygame.rect.Rect(100,100,64,64) self.auswahl = 0 self.auswahl_text = self.font.render(self.auswahl_liste[self.auswahl] + ": 0", 1, self.WHITE) self.anim_text = self.font.render("Animation: "+str(self.char.anim_run),1,self.WHITE) while self.running: self.screen.fill((0,0,0)) self.clock.tick() if self.clock.update_ready: self.update_gameclock() if self.clock.frame_ready: self.display_gameclock(self.clock.interpolate) for e in pygame.event.get(): if e.type == pygame.QUIT: self.running = False if e.type == pygame.KEYUP: # Links/Rechts für Spriteauswahl if e.key == pygame.K_RIGHT: self.char.imageInfo[self.auswahl_liste[self.auswahl]]["id"] += 1 if self.char.imageInfo[self.auswahl_liste[self.auswahl]]["id"] >= len(self.equip[self.auswahl_liste[self.auswahl]]): self.char.imageInfo[self.auswahl_liste[self.auswahl]]["id"] = 0 self.char.imageInfo[self.auswahl_liste[self.auswahl]]["name"] = self.equip[self.auswahl_liste[self.auswahl]][self.char.imageInfo[self.auswahl_liste[self.auswahl]]["id"]] self.auswahl_text = self.font.render(self.auswahl_liste[self.auswahl]+": "+str(self.char.imageInfo[self.auswahl_liste[self.auswahl]]["id"]), 1, self.WHITE) self.char.loadImageV2() elif e.key == pygame.K_LEFT: self.char.imageInfo[self.auswahl_liste[self.auswahl]]["id"] -= 1 if self.char.imageInfo[self.auswahl_liste[self.auswahl]]["id"] < 0: self.char.imageInfo[self.auswahl_liste[self.auswahl]]["id"] = len(self.equip[self.auswahl_liste[self.auswahl]])-1 self.char.imageInfo[self.auswahl_liste[self.auswahl]]["name"] = self.equip[self.auswahl_liste[self.auswahl]][self.char.imageInfo[self.auswahl_liste[self.auswahl]]["id"]] self.auswahl_text = self.font.render(self.auswahl_liste[self.auswahl]+": "+str(self.char.imageInfo[self.auswahl_liste[self.auswahl]]["id"]), 1, self.WHITE) self.char.loadImageV2() # Hoch/Runter für Körperteilasuswahl if e.key == pygame.K_UP: self.auswahl -= 1 if self.auswahl < 0: self.auswahl = len(self.auswahl_liste)-1 self.auswahl_text = self.font.render(self.auswahl_liste[self.auswahl]+": "+str(self.char.imageInfo[self.auswahl_liste[self.auswahl]]["id"]), 1, self.WHITE) elif e.key == pygame.K_DOWN: self.auswahl += 1 if self.auswahl >= len(self.auswahl_liste): self.auswahl = 0 self.auswahl_text = self.font.render(self.auswahl_liste[self.auswahl]+": "+str(self.char.imageInfo[self.auswahl_liste[self.auswahl]]["id"]), 1, self.WHITE) # Animation starten if e.key == pygame.K_RETURN: self.char.anim_run = not self.char.anim_run self.anim_text = self.font.render("Animation: "+str(self.char.anim_run),1,self.WHITE) if e.key == pygame.K_SPACE: print self.char.anim print self.char.anim_list[self.char.anim] print self.char.whole[self.char.anim_list[self.char.anim]["name"]]