def unpause(self): State.unpause(self) self.level += 1 self.done = False if self.level >= len(self.map_list): self.next = YouWin() self.quit()
def __init__(self, mapname="level01.map", folder="lvl", test=False, camp=False, pacmode=False): State.__init__(self) self.mapname = mapname self.fps = 60 self.folder = folder self.test = test self.lives = 3 self.camp = camp self.start_paused = False if self.camp: self.lives = SAVE["cur"]["lives"] #lives self.restart() #add keyboard events self.add_kbevent(KEYDOWN, K_ESCAPE, self.to_pause) if not pacmode: #movement self.add_kbevent(KEYDOWN, K_UP, self.cat_go, vel=(0, -1)) self.add_kbevent(KEYDOWN, K_DOWN, self.cat_go, vel=(0, 1)) self.add_kbevent(KEYDOWN, K_LEFT, self.cat_go, vel=(-1, 0)) self.add_kbevent(KEYDOWN, K_RIGHT, self.cat_go, vel=(1, 0)) #ghost selection self.add_kbevent(KEYDOWN, K_1, self.set_active, nr=0) self.add_kbevent(KEYDOWN, K_2, self.set_active, nr=1) self.add_kbevent(KEYDOWN, K_3, self.set_active, nr=2) self.add_kbevent(KEYDOWN, K_4, self.set_active, nr=3) self.add_kbevent(KEYDOWN, K_5, self.set_active, nr=4)
def unpause(self): if self.success: if self.cur_clan: self.show_signet([self.cur_clan]) player_data["unlocked"].append(self.cur_clan) #track progress self.cur_clan = None self.autosave() #save progress State.unpause(self)
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): State.__init__(self) self.bg_image = GLOBALS["backgrounds"]["the_end.png"] self.overlay = StaticWidget((638, 169)) self.overlay.set_pos((2, 160)) self.overlay.set_alpha(255) self.overlay.fill((0, 0, 0)) self.wait = Timer(50)
def __init__(self): State.__init__(self) self.kill_prev = True pygame.mouse.set_visible(0) self.background.blit(GLOBALS["backgrounds"]["game_over.png"], (0,0)) #keyboard events self.add_kbevent(KEYUP, K_ESCAPE, self.quit)
def __init__(self, level=0): State.__init__(self) self.map_list = get_mapnames() #set current level if level > len(self.map_list): level = len(self.map_list) - 1 self.level = level self.done = False
def __init__(self, old_screen, new_screen, next_state): State.__init__(self) self.fps = 30 self.background.blit(old_screen, (0, 0)) self.new_screen = pygame.Surface(new_screen.get_size()) self.new_screen.blit(new_screen, (0, 0)) self.new_screen.set_alpha(0) self.alpha_add = 1 self.alpha_max = 100 self.blend_timer = Timer(2) self.next = next_state
def __init__(self): State.__init__(self) self.background.blit(GLOBALS["backgrounds"]["main_menu.png"], (0, 0)) buttons = { " Start ": pygame.Rect([53, 228, 132, 119]), " Resume ": pygame.Rect([246, 184, 151, 117]), " Exit ": pygame.Rect([458, 232, 126, 114]), " Credits ": pygame.Rect([285, 398, 69, 64]) } for b in buttons.keys(): ca = ClickArea(buttons[b], self.button_pressed, name=b) self.widgets.append(ca)
def update_screen(self): self.background.fill((0, 0, 0)) self.background.blit(self.bg_image, (0, 0)) if not self.wait.active: alpha = self.overlay.get_alpha() if alpha > 0: self.overlay.set_alpha(alpha - 10) if alpha < 20: self.add_kbevent(KEYDOWN, K_ESCAPE, self.quit) elif self.wait.update(): self.wait.deactivate() self.overlay.draw(self.background) State.update_screen(self)
def update_screen(self): #draw map self.lvl_layer.set_colorkey(None) self.lvl_layer.fill((255, 0, 255)) self.lvl_layer.blit(self.lvl_img, (0, 0)) self.lvl_layer.set_colorkey((255, 0, 255)) self.map_area.fill((0, 0, 0)) self.map_area.blit(self.lvl_layer, (0, 0), area=[self.camera.pos, GLOBALS["screen_size"]]) self.map_area.draw_border((255, 255, 255)) #draw map area self.map_area.draw(self.background) self.grid.draw(self.background) State.update_screen(self)
def update_screen(self): self.background.blit(self.bg_image, (0, 0)) #update and draw vortex self.vortex.update() self.background.blit(self.vortex.image, self.vortex.pos) #update and draw doors self.update_doors() #draw grass, building self.background.blit(self.top_layer, (0, 0)) #draw nanji self.update_nanji() State.update_screen(self)
def __init__(self): State.__init__(self) self.maps = [ "level01.map", "level02.map", "level03.map", "level04.map", "level05.map", "level06.map", "level07.map", "level08.map", "level09.map", "level10.map", "level11.map", "level12.map", "level13.map", "level14.map", "level15.map", ] self.cur = SAVE["cur"]["level"] self.first_run = True
def unpause(self): if self.next and SAVE["cur"]: w, l, s = self.next.win, self.next.lost, self.next.score b = self.next.screen SAVE["cur"]["score"] += s State.unpause(self) if w: if self.cur > SAVE["unlock"]: SAVE["unlock"] = self.cur save_data() self.cur += 1 if self.cur < len(self.maps): self.start_map() else: SAVE["unlock"] = len(get_maps("lvl")) - 1 self.to_overall_score(img=b, lost=False) elif l: self.to_overall_score(img=b, lost=True) else: self.quit() else: State.unpause(self) self.quit()
def __init__(self): State.__init__(self) self.background.blit(GLOBALS["backgrounds"]["credits.png"], (0, 0)) ca = ClickArea(pygame.Rect((0, 0), GLOBALS["screen_size"]), self.quit) self.widgets.append(ca) self.add_kbevent(KEYDOWN, K_ESCAPE, self.quit)
def main_start(self): pygame.mouse.set_visible(0) State.main_start(self)
def __init__(self, lvl_map="tutorial.map", testing=False, prev=None): State.__init__(self) self.fps = 60 self.prev = prev tsize = GLOBALS["tile_size"] self.trigger = None self.exit_timer = Timer(50) self.exit_timer.deactivate() pygame.mixer.music.set_volume(1) GLOBALS["jb"].play("bgm.xm", -1) player_data["health"] = 9 #always full health on map start #player_data["lives"] = #for gameover testing #scrolling background - maybe later XD #bg_back = GLOBALS["backgrounds"]["fuji.png"] #bg_front = GLOBALS["backgrounds"]["trees.png"] #self.scroll_bg = Background(bg_back, bg_front) #non-scrolling background self.bg = GLOBALS["backgrounds"]["fuji.png"] #map self.map_filename = lvl_map self.map = Map(lvl_map) self.lvl_map = self.map["tilemap"] x, y = self.map["max"] self.lvl_img, self.blocks = self.map.draw(editing=False) self.lvl_layer = pygame.Surface(self.lvl_img.get_size()) #other spritegroups self.bullets = pygame.sprite.Group() #player self.player = Nanji(None) self.player.set_pos((self.map["start"][0]*tsize, self.map["start"][1]*tsize)) self.sprites.add(self.player) #camera self.camera = Camera(self.player) screen_x, screen_y = GLOBALS["screen_size"] mx = self.map["max"][0] * tsize - screen_x my = self.map["max"][1] * tsize - screen_y + 4*tsize self.camera.set_max(mx,my) self.player.camera = self.camera self.camera.update() #add enemies self.enemies = pygame.sprite.Group() clan = self.map["options"]["clan"] for e in self.map.enemies: ninjat = Ninjat(self.camera, clan) ninjat.set_pos((e[0]*tsize, e[1]*tsize-32))#FIXME:enemies are spawned too low..? self.enemies.add(ninjat) self.sprites.add(ninjat) #ui layer self.ui_layer = StaticWidget((GLOBALS["screen_size"][0], 30)) self.ui_layer.fill((255,0,255)) self.ui_layer.set_colorkey((255,0,255)) self.ui_layer.set_pos((0,0)) self.heart_img = GLOBALS["ui_stuff"]["heart"] self.heart_empty_img = GLOBALS["ui_stuff"]["heart_empty"] self.life_img = GLOBALS["ui_stuff"]["life"] self.fontholder = TextLine("", fontsize=16) self.update_ui() #keyboard events self.key_pressed = { "up": 0, "down": 0, "left": 0, "right": 0, "jump":0, "sprint":0, "throw": 0, "shuriken": 0, } self.add_kbevent(KEYDOWN, K_LEFT, self.set_keypress, k="left", v=1) #move self.add_kbevent(KEYDOWN, K_RIGHT, self.set_keypress, k="right", v=1) self.add_kbevent(KEYDOWN, K_UP, self.set_keypress, k="up", v=1) self.add_kbevent(KEYDOWN, K_DOWN, self.set_keypress, k="down", v=1) self.add_kbevent(KEYDOWN, K_SPACE, self.set_keypress, k="jump", v=1) #jump self.add_kbevent(KEYDOWN, K_LSHIFT, self.set_keypress, k="sprint", v=1) #sprint self.add_kbevent(KEYDOWN, K_RSHIFT, self.set_keypress, k="sprint", v=1) self.add_kbevent(KEYDOWN, K_RCTRL, self.set_keypress, k="throw", v=1) #throw self.add_kbevent(KEYDOWN, K_LCTRL, self.set_keypress, k="throw", v=1) self.add_kbevent(KEYUP, K_LEFT, self.set_keypress, k="left", v=0) self.add_kbevent(KEYUP, K_RIGHT, self.set_keypress, k="right", v=0) self.add_kbevent(KEYUP, K_UP, self.set_keypress, k="up", v=0) self.add_kbevent(KEYUP, K_DOWN, self.set_keypress, k="down", v=0) self.add_kbevent(KEYUP, K_SPACE, self.set_keypress, k="jump", v=0) self.add_kbevent(KEYUP, K_LSHIFT, self.set_keypress, k="sprint", v=0) self.add_kbevent(KEYUP, K_RSHIFT, self.set_keypress, k="sprint", v=0) self.add_kbevent(KEYUP, K_RCTRL, self.set_keypress, k="throw", v=0) self.add_kbevent(KEYUP, K_LCTRL, self.set_keypress, k="throw", v=0) if testing: self.add_kbevent(KEYUP, K_ESCAPE, self.quit)
def unpause(self): self.reset_keys() State.unpause(self)
def __init__(self): State.__init__(self) self.screen = pygame.display.get_surface() self.background = pygame.Surface(self.screen.get_size()) self.background.fill((0,0,0))
def __init__(self, screen): State.__init__(self) self.background.blit(screen, (0, 0))
def __init__(self): State.__init__(self) self.screen = pygame.display.get_surface() self.background = pygame.Surface(self.screen.get_size()) self.buttons = {}
def __init__(self): State.__init__(self) self.screen = pygame.display.get_surface() self.bg = pygame.Surface((800, 600)) self.button = {}
def main_start(self): pygame.mouse.set_visible(0) State.main_start(self) GLOBALS["jb"].stop()
def __init__(self, new=True): State.__init__(self) self.success = False self.new = new #start tutorial before showing level selection! self.signet_pos = { "wood": (83, 181), "day": (158, 75), "fire": (284, 34), "life": (410, 75), "earth": (485, 181), "night": (456, 307), "metal": (348, 368), "water": (220, 368), "death": (112, 307) } self.light_pos = { "wood": (239, 225), "day": (261, 173), "fire": (315, 155), "life": (369, 173), "earth": (391, 225), "night": (383, 271), "metal": (345, 307), "water": (285, 307), "death": (247, 271) } self.cur_blinking = None self.cur_blending = None self.cur_clan = None self.blink_timer = Timer(50) self.blink_count = 0 self.blink_max = 10 self.light = GLOBALS["ui_stuff"]["green_light"] r = pygame.Rect([281, 203, 78, 77]) r.inflate(-10, -10) bigredbutton = ClickArea(r, self.bigred_pressed) self.widgets.append(bigredbutton) self.donotpress = pygame.Rect([267, 188, 106, 95]) self.signets = GLOBALS["signets"] self.bg_image = GLOBALS["backgrounds"]["gameboard.png"].copy() self.ui_layer = pygame.Surface(GLOBALS["screen_size"]) self.ui_layer.fill((255, 0, 255)) self.ui_layer.set_colorkey((255, 0, 255)) self.tooltip_layer = pygame.Surface(GLOBALS["screen_size"]) self.tooltip_layer.fill((255, 0, 255)) self.tooltip_layer.set_colorkey((255, 0, 255)) self.tooltip = StaticWidget((80, 20)) self.dnp_tooltip = GLOBALS["ui_stuff"]["donotpress"] #level selection buttons self.signet_buttons = [] levels = GLOBALS["clan_levels"] for k in self.signet_pos.keys(): if self.signets.has_key(k) and levels.has_key(k): btn = ImgButton(self.signets[k][0], self.start_level, \ clan=k, level=levels[k]) btn.set_pos(self.signet_pos[k]) btn.rect = pygame.Rect([self.signet_pos[k], btn.get_size()]) btn.rect.inflate(-20, -20) btn.clan = k self.widgets.append(btn) self.signet_buttons.append(btn) #show savegame progress self.show_signet(player_data["unlocked"]) #keyboard events self.add_kbevent(KEYDOWN, K_ESCAPE, self.quit) self.background.blit(self.bg_image, (0, 0)) self.background.blit(self.tooltip_layer, (0, 0)) self.background.blit(self.ui_layer, (0, 0)) self.tooltip_layer.fill((255, 0, 255))
def update_screen(self): self.background.blit(self.bg_image, (0, 0)) self.background.blit(self.tooltip_layer, (0, 0)) self.background.blit(self.ui_layer, (0, 0)) self.tooltip_layer.fill((255, 0, 255)) State.update_screen(self)
def __init__(self): State.__init__(self) self.fps = 40 #animation checkpoints and flags self.opening = 0 self.closing = 0 self.door_timer = Timer(15) #open slowly, then faster self.maelstrom_timer = Timer(30) #open doors a bit.. then pull self.nanji_command = None #generate pseudo-map screen_size = GLOBALS["screen_size"] self.bg_image = pygame.Surface(screen_size) self.top_layer = pygame.Surface(screen_size) self.top_layer.set_colorkey((255, 0, 255)) self.top_layer.fill((255, 0, 255)) #draw map background bg = GLOBALS["backgrounds"]["fuji.png"] self.bg_image.blit(bg, (0, 0)) #draw grass tsize = GLOBALS["tile_size"] grass_tile = GLOBALS["ts_tileset"][1, 0] x = -tsize y = screen_size[1] - tsize for i in xrange(22): self.top_layer.blit(grass_tile, (x, y)) x += tsize #draw mysterious myst = GLOBALS["ui_stuff"]["mysterious.png"] #draw full signet board on mysterious board = GLOBALS["ui_stuff"]["board_filled.png"] x, y = 66, 197 myst.blit(board, (x, y)) x = 5 * tsize y = screen_size[1] - myst.get_size()[1] - tsize self.myst = StaticWidget(myst.get_size()) self.myst.set_colorkey((255, 0, 255)) self.myst.fill((255, 0, 255)) self.myst.blit(myst, (0, 0)) self.myst.set_pos((x, y)) self.myst.pos = (x, y) self.myst.draw(self.top_layer) myst_centerx = x + myst.get_size()[0] / 2 myst_top = y + 30 #init doors self.door_speed = 1 door_left_image = GLOBALS["ui_stuff"]["door_left.png"] door_right_image = GLOBALS["ui_stuff"]["door_right.png"] self.door_left = StaticWidget(door_left_image.get_size()) self.door_left.blit(door_left_image, (0, 0)) self.door_left.set_pos((self.myst.pos[0] + 99, self.myst.pos[1] + 63)) self.door_right = StaticWidget(door_right_image.get_size()) self.door_right.blit(door_right_image, (0, 0)) self.door_right.set_pos( (self.myst.pos[0] + 177, self.myst.pos[1] + 63)) #init whirling vortex self.vortex = Vortex(centerpos=(myst_centerx, myst_top)) #init Nanji self.nanji = Nanji(cam=None) self.nanji.status = 0 self.nanji.set_pos((205, 401)) self.nanji_angle = 0 self.nanji_fly_img = self.nanji.all_images["landing"][0] self.nanji_shrink = 1 self.sprites.add(self.nanji) self.nanji_do("throw")
def __init__(self): State.__init__(self) self.buttons = {} #tileset area self.tileset_area = StaticWidget((1020, 280)) self.tileset_area.set_pos((2, 485)) self.tileset_area.pos = (2, 485) ca = ClickArea(pygame.Rect([2, 485, 1024, 280]), self.choose_tiletype) self.widgets.append(ca) self.tileset_id = "ts_tileset" self.marked_type = None self.load_tileset() #set clan buttons = [ "wood", "day", "fire", "life", "earth", "night", "metal", "water", "death" ] x, y = 900, 50 for clan in buttons: btn = ImgButton(GLOBALS["signets"][clan][1], \ self.set_clan, clan=clan) btn.set_pos((x, y)) self.widgets.append(btn) self.buttons[clan] = btn btn.draw(self.background) y = y + btn.get_size()[1] + 5 self.clan = "fire" #Camera self.camera = Camera(None) #load empty map self.filename = "" self.load_map(new=True) #map area self.map_area = StaticWidget((640, 480)) self.map_area.set_pos((0, 0)) self.map_area_rect = pygame.Rect([0, 0, 640, 480]) self.widgets.append(ca) #grid overlay for map area w, h = self.map_area.get_size() self.grid = StaticWidget((w, h)) self.grid.fill((255, 0, 255)) self.grid.set_colorkey((255, 0, 255)) self.grid.set_alpha(100) for row in xrange(h / tsize): for col in xrange(w / tsize): pygame.draw.line(self.grid, (255, 255, 255), (col * 32, 0), (col * 32, h)) pygame.draw.line(self.grid, (255, 255, 255), (0, row * 32), (w, row * 32)) self.grid.set_pos(self.map_area.get_pos()) #buttons buttons = [(" NEW ", self.new_map), (" LOAD ", self.open_file), (" SAVE AS ", self.save_file), (" SAVE ", self.save_map)] x, y = 650, 1 for b in buttons: name, callback = b btn = ImgButton(TextLine(name), callback) btn.set_pos((x, y)) btn.draw_border((255, 255, 255)) self.widgets.append(btn) btn.draw(self.background) x = x + btn.get_size()[0] + 4 #add objects buttons = [ (" delete obj", "delete"), (" add start ", "start"), (" add exit ", "exit"), (" add enemy ", "enemy"), (" add dialog-trigger ", "dtrigger"), ] x, y = 650, 50 for b in buttons: name, cmd = b btn = ImgButton(TextLine(name, fontsize=15), \ self.select_add_object, cmd=cmd) btn.set_pos((x, y)) self.widgets.append(btn) btn.draw(self.background) y = y + btn.get_size()[1] + 5 self.buttons[cmd] = btn #TEST button :) btn = ImgButton(TextLine(" TEST ", fontsize=25), self.test) btn.set_pos((900, 420)) btn.draw_border((255, 255, 255)) self.widgets.append(btn) btn.draw(self.background) #keyboard events pygame.key.set_repeat(10, 20) #scroll map self.add_kbevent(KEYDOWN, K_UP, self.scroll_map, vy=-1) self.add_kbevent(KEYDOWN, K_DOWN, self.scroll_map, vy=1) self.add_kbevent(KEYDOWN, K_LEFT, self.scroll_map, vx=-1) self.add_kbevent(KEYDOWN, K_RIGHT, self.scroll_map, vx=1)