def __init__(self, img1, img2, callback, **kwargs): img = pygame.Surface(img1.get_size()) ImgButton.__init__(self, img, callback, **kwargs) self.anim_timer = utils.Timer(20) self.images = [img1, img2] self.blit(img1, (0, 0)) self.cur_img = 0 self.anim_timer.counter = self.anim_timer.interval + 1
def __init__(self): State.__init__(self) img = GLOBALS["ui_stuff"]["logo.png"] self.background.blit( img, utils.center(img.get_size(), GLOBALS["screen_size"])) self.quit_timer = utils.Timer(50) self.quit_timer.deactivate() GLOBALS["sfx"]["pululummm.wav"].play()
def __init__(self, imglists): Chara.__init__(self, imglists) self.jumping = 0 self.jumpheight = 0 self.old_y = 0 self.new_y = 0 self.timer = utils.Timer(10) self.state = None
def __init__(self, size=(160, 22), fontsize=20, text="", blinky="|"): self.text = text self.fsize = fontsize self.text_img = TextLine(self.text, fontsize=fontsize) self.blinky = TextLine(blinky, fontsize=fontsize) self.do_blink = False StaticWidget.__init__(self, size) self.timer = utils.Timer(20) self.changed = 1 self.update()
def __init__(self, mapdata): BaseState.__init__(self) if not mapdata: self.quit() return self.fps = 60 self.sprites = pygame.sprite.Group() #timer for pipe movement self.timer = utils.Timer(5) #map layer self.mapdata = mapdata self.mapcopy = mapdata.copy() self.map_layer = pygame.Surface((800, 544)) self.map_layer.set_colorkey((255, 0, 255)) self.pipe_layer = pygame.Surface((800, 544)) self.pipe_layer.set_colorkey((255, 0, 255)) self.pipe_layer.fill((255, 0, 255)) draw_map(self.mapdata, self.map_layer) draw_pipes(self.mapdata, self.pipe_layer) #get gfxmap self.gfxmap = GfxMap(mapdata) #player self.player = MrWobbly(GFX_wobbly) self.gfxmap.place_player(self.player) self.sprites.add(self.player) self.old_y = self.player.pos[1] #black message box self.no_msg = pygame.Surface((800, 24)) self.no_msg.fill((0, 0, 0)) self.no_msg_pos = utils.center(self.no_msg.get_size(), (800, 600)) self.no_msg_pos[1] = 600 - self.no_msg.get_size()[1] #keyboard bindings self.add_kbevent(KEYDOWN, K_r, callback=self.reload) self.add_kbevent(KEYDOWN, K_F12, callback=self.reload) #player movement self.add_kbevent(KEYDOWN, K_RIGHT, callback=self.player.move, dir=1) self.add_kbevent(KEYUP, K_RIGHT, callback=self.player.move, dir=0) self.add_kbevent(KEYDOWN, K_LEFT, callback=self.player.move, dir=-1) self.add_kbevent(KEYUP, K_LEFT, callback=self.player.move, dir=0) self.add_kbevent(KEYDOWN, K_UP, callback=self.use) #use btn self.add_kbevent(KEYDOWN, K_DOWN, callback=self.pipe) #use pipe
def __init__(self, img, map, mapname="", folder="custom"): BgState.__init__(self, img) self.map = map self.folder = folder pygame.mouse.set_visible(1) #background image + "save as" self.menu = StaticWidget((250, 100)) self.menu.fill((0, 0, 0)) txt = TextLine("Save as:", fontsize=15) self.menu.blit(txt, (10, 10)) w, h = self.menu.get_size() pygame.draw.lines(self.menu, (0, 0, 255), True, ((0, 0), (w - 4, 0), (w - 4, h - 4), (0, h - 4)), 4) x, y = utils.center((w, h), (800, 600)) self.menu.set_pos((x, y)) #text entry + ".map" self.entry = TextEntry(text=mapname[:-4]) self.entry.set_pos((x + 10, y + 30)) txt = TextLine(".map", fontsize=20) self.menu.blit(txt, (self.entry.get_size()[0] + 15, 30)) #save/cancel buttons msg_pos = self.menu.get_pos() size = self.menu.get_size() btn = FixedTextButton((100, 24), "Cancel", callback=self.quit) btn.set_pos((msg_pos[0], msg_pos[1] + size[1] + 4)) btn.draw_border() self.add_button("cancel", btn) btn.draw(self.background) btn = FixedTextButton((100, 24), "Save", callback=self.submit) btn.set_pos((msg_pos[0] + size[0] - 100, msg_pos[1] + size[1] + 4)) btn.draw_border() self.add_button("save", btn) btn.draw(self.background) self.redraw() self.quit_timer = utils.Timer(20) self.quit_timer.deactivate() self.add_kbevent(KEYDOWN, K_ESCAPE, callback=self.quit) self.add_textentry_events(self.entry)
def __init__(self, dialog): self.done = 0 size = (590, 140) pos = (utils.center(size, GLOBALS["screen_size"])[0], 30) StaticWidget.__init__(self, size) self.set_pos(pos) self.dialog = dialog self.cur_page = 0 #txt and portrait placement self.txt_length = 45 self.txt_pos = (130, 15) self.port_pos = (20, 15) #blinky <press space> textline self.blink_timer = utils.Timer(20) self.draw_textline = 0 self.textline = TextLine("PRESS X", fontsize=12) x = size[0] - self.textline.get_size()[0] - 5 y = size[1] - self.textline.get_size()[1] - 2 self.textline.set_pos((x, y)) self.bg = pygame.Surface(size) #may add some border/decoration
def restart(self): mapname = self.mapname folder = self.folder test = self.test self.upd = 1 self.fps = 50 self.win = False self.lost = False self.win_shown = False self.started = False self.custom = not folder == "lvl" self.screen = pygame.display.get_surface() self.background = pygame.Surface(self.screen.get_size()) pygame.mouse.set_visible(False) self.cataway_timer = utils.Timer(100) self.cataway_timer.deactivate() #load map self.map = Map(mapname, edit=False, folder=folder) self.map_pos = utils.center(self.map.get_size(), self.screen.get_size()) self.background.blit(self.map, self.map_pos) pygame.display.flip() #setup blocking spritegroup self.walls = pygame.sprite.Group() block = self.map.get_blocking() size = (32, 32) for b in block: pos = (b[0] * 32 + self.map_pos[0], b[1] * 32 + self.map_pos[1]) s = pygame.sprite.Sprite() s.rect = pygame.Rect(pos, size) self.walls.add(s) #catnip pellets catnip = [] self.catnip_rects = [] for p in self.map.pellets: c = CatNip(p) c.set_pos( (p[0] * 32 + self.map_pos[0], p[1] * 32 + self.map_pos[1])) catnip.append(c) self.catnip_rects.append(c.rect) self.catnip = pygame.sprite.Group(catnip) #cataway cataway = [] for c in self.map.cataway: x = CatAway(c) x.set_pos( (c[0] * 32 + self.map_pos[0], c[1] * 32 + self.map_pos[1])) cataway.append(x) self.cataway = pygame.sprite.Group(cataway) #catghosts cats = [] for g in self.map.ghost_start: c = Cat(len(cats)) c.set_pos( (g[0] * 32 + self.map_pos[0], g[1] * 32 + self.map_pos[1])) cats.append(c) self.catlist = cats self.cats = pygame.sprite.Group(cats) self.active_cat = 0 self.set_active(0) #pacdogs dogs = [] self.doglist = [] for p in self.map.pac_start: d = PacDog() d.set_pos( (p[0] * 32 + self.map_pos[0], p[1] * 32 + self.map_pos[1])) d.ai.setup(self.map, self.catlist) self.doglist.append(d) dogs.append(d) self.dogs = pygame.sprite.Group(dogs) #player stats self.score = self.map.get_score() #score self.score_img = Score(self.score) self.lives_img = StaticWidget((60, 32)) self.lives_img.blit(GFX["ghost"], (0, 0)) self.lives_img.blit(TextLine("x" + str(self.lives)), (32, 10)) self.lives_img.set_pos((800 - self.lives_img.get_size()[0], 0)) self.level_img = TextLine(self.mapname[:-4].upper()) x = utils.center(self.level_img.get_size(), (800, 600))[0] self.level_img.set_pos((x, 2)) #setup spritegroups self.sprites = pygame.sprite.RenderUpdates() self.sprites.add(self.cats) self.sprites.add(self.dogs) self.static_sprites = pygame.sprite.Group() self.static_sprites.add(self.catnip) self.static_sprites.add(self.cataway) self.start_paused = False
def __init__(self, images, interval=40): StaticWidget.__init__(self, images[0].get_size()) self.images = images self.cur = 0 self.timer = utils.Timer(interval) self.blit(self.images[self.cur], (0, 0))