class Navigation(Singleton): X = 675 Y = 20 def __init__(self, stage): self.image = pygame.surface.Surface((98,558)) self.image.set_colorkey((0,0,0)) self.background = Image(u'../resources/image/main/navigation/background.png') self.background.draw(self.image) self.contents = OrderedUpdates() self.timer = NavigationTimer(settings.TIME, x=46, y=82) self.stage = stage self.gauge = Gauge(x=10, y=5) self.update() self.draw() def update(self): self.timer.update() self.gauge.update(self.stage.count) def draw(self): if not self.timer.is_update and not self.gauge.is_update: return [] self.timer.draw(self.image) self.gauge.draw(self.image) rects = [Game.get_screen().blit(self.image, self.image.get_rect().move(self.X, self.Y))] return rects
class Timer(pygame.sprite.Sprite): COLON_HEIGHT = 4 HEIGHT = 40 WIDTH = 20 OFFSET = 10 u"""9分59秒〜0分00秒の間のみ""" def __init__(self, max, x=0, y=0): super(Timer, self).__init__() self.x = x self.y = y self.timer = _Timer(max*settings.FRAMERATE) self.gauge = Image(u'../resources/image/main/navigation/gauge_timer.png') self.gauge.center = Vector(0, self.gauge.rect.h) self.pre_second = 0 self.image = pygame.surface.Surface((70,396)).convert() self.image.set_colorkey((0,0,0)) self.is_update = True self._parse(self.convert_time()) def draw(self, surface=Game.get_screen()): return surface.blit(self.image, self.image.get_rect().move(self.x, self.y)) def _parse(self, time): minute = time[0] second = time[1] minute_surface = Number(minute, u'../resources/image/main/navigation/time.png').get_surface() timer_surface = pygame.surface.Surface((self.WIDTH,self.HEIGHT*3+self.COLON_HEIGHT+self.OFFSET*3)) timer_surface.blit(minute_surface, minute_surface.get_rect()) self.pre_second = second if second < 10: second10 = Number(0,u'../resources/image/main/navigation/time.png').get_surface() second1 = Number(second,u'../resources/image/main/navigation/time.png').get_surface() else: second10 = Number(int(second/10),u'../resources/image/main/navigation/time.png').get_surface() second1 = Number(second%10,u'../resources/image/main/navigation/time.png').get_surface() timer_surface.blit(second10, second10.get_rect().move(0, self.HEIGHT+self.COLON_HEIGHT+self.OFFSET*2)) timer_surface.blit(second1, second1.get_rect().move(0, self.HEIGHT*2+self.COLON_HEIGHT+self.OFFSET*3)) self.image.blit(Image(u'../resources/image/main/background.png').image, self.gauge.image.get_rect(), self.gauge.image.get_rect().move(self.x, self.y)) self.image.blit(timer_surface, timer_surface.get_rect().move(28,96)) max = int(self.timer.max/settings.FRAMERATE)-1 now = int(self.timer.now/settings.FRAMERATE) self.gauge.yscale = float(max-now)/float(max) self.gauge.draw(self.image) def update(self): self.is_update = False self.timer.tick() second = self.convert_time()[1] if not second == self.pre_second: self.is_update = True self._parse(self.convert_time()) def play(self): self.timer.play() def convert_time(self): n = (self.timer.max - self.timer.now)/settings.FRAMERATE return int(n/60), n%60 def is_over(self): return self.timer.is_over()
def ready(self, *args, **kwargs): super(LogoScene, self).ready() self.background = Image("../resources/image/menu/whiteback.png", alpha=False) self.logo = Image("../resources/image/menu/kawaz.png", alpha=False) self.logo.x = 340 self.logo.y = 230 self.sprites.add(self.background) self.sprites.add(self.logo) self.timer = Timer(210) self.mouse = Mouse(0) self.joypads = [] for i in xrange(0, JoyPad.get_num_joypads()): self.joypads.append(JoyPad(i))
def load_player_selection(self, joypad_number): fail = ("" if joypad_number >= 2 else "x") self.player2 = Image(os.path.join(self.IMAGE_PATH, "player2%s.png" % fail), alpha=False) fail = ("" if joypad_number >= 3 else "x") self.player3 = Image(os.path.join(self.IMAGE_PATH, "player3%s.png" % fail), alpha=False) fail = ("" if joypad_number >= 4 else "x") self.player4 = Image(os.path.join(self.IMAGE_PATH, "player4%s.png" % fail), alpha=False)
class Result(Singleton): def __init__(self, stage, navigation): self.navigation = navigation self.stage = stage def ready(self): self.background = Image(u'../resources/image/main/result/background.png') self.gauge1 = Image(u'../resources/image/main/result/gauge1_full.png', x=60, y=160) self.gauge2 = Image(u'../resources/image/main/result/gauge2_full.png', x=60, y=160) self.retry = Button(u'../resources/image/main/result/retry.png', w=180, h=80, x=140, y=460) self.menu = Button(u'../resources/image/main/result/menu.png', w=180, h=80, x=480, y=460) self.minute = Number(0, u'../resources/image/main/result/time.png', x=420, y=306, w=60, h=75) self.second10 = Number(0, u'../resources/image/main/result/time.png', x=540, y=306, w=60, h=75) self.second1 = Number(0, u'../resources/image/main/result/time.png', x=600, y=306, w=60, h=75) self.sprites = OrderedUpdates(self.gauge2, self.gauge1, self.minute, self.second10, self.second1, self.retry, self.menu) self.retry.on_release = lambda : Game.get_scene_manager().change_scene('game',self.stage.bomb, self.stage.cpu) self.menu.on_release = lambda : Game.get_scene_manager().change_scene('title') for button in [self.retry, self.menu]: button.hover_sound = '../resources/sound/on_cursor.wav' button.press_sound = '../resources/sound/selected.wav' self.gauge1.xscale = float(self.navigation.gauge.proportion[0])/100 m, s = self.navigation.timer.convert_time() self.minute.n = m if s < 10: self.second10.n = 0 self.second1.n = s else: self.second10.n = int(str(s)[0]) self.second1.n = int(str(s)[1]) if self.stage.count[0] > self.stage.count[1]: self.sprites.add(Image(u'../resources/image/main/result/win.png', x=80, y=160)) self.sprites.add(Image(u'../resources/image/main/result/lose.png', x=480, y=160)) elif self.stage.count[0] < self.stage.count[1]: self.sprites.add(Image(u'../resources/image/main/result/win.png', x=480, y=160)) self.sprites.add(Image(u'../resources/image/main/result/lose.png', x=80, y=160)) else: self.sprites.add(Image(u'../resources/image/main/result/draw.png', x=280, y=170)) def draw(self, surface=Game.get_screen()): self.background.draw() self.navigation.background.draw(self.navigation.image) self.sprites.draw(Game.get_screen()) def update(self): self.sprites.update()
def ready(self, *args, **kwargs): self.background = Image(u'../resources/image/main/background.png') self.frame = Image(u'../resources/image/main/frame.png', x=settings.STAGE_OFFSET[0]-15, y=settings.STAGE_OFFSET[1]-15) self.stage = Stage(args[0], args[1]) self.bgm = BGM(u'../resources/bgm/game_intro.wav', -1, u'../resources/bgm/game_loop.wav') self.background.draw() self.frame.draw() self.navigation = Navigation(self.stage) self.sequence_mng = SceneManager({'ready':ReadySequence(self.frame, self.background), 'main': MainSequence(self.stage, self.navigation), 'result':ResultSequence(self.stage, self.navigation, self.frame, self.bgm), 'pause':PauseSequence(self.navigation)}) def init(): if settings.DEBUG: return 'main' else: return 'ready' self.sequence_mng.change_scene(init()) self.redraw = False Effect.reset() self.draw()
def __init__(self, stage): self.image = pygame.surface.Surface((98,558)) self.image.set_colorkey((0,0,0)) self.background = Image(u'../resources/image/main/navigation/background.png') self.background.draw(self.image) self.contents = OrderedUpdates() self.timer = NavigationTimer(settings.TIME, x=46, y=82) self.stage = stage self.gauge = Gauge(x=10, y=5) self.update() self.draw()
def __init__(self, max, x=0, y=0): super(Timer, self).__init__() self.x = x self.y = y self.timer = _Timer(max*settings.FRAMERATE) self.gauge = Image(u'../resources/image/main/navigation/gauge_timer.png') self.gauge.center = Vector(0, self.gauge.rect.h) self.pre_second = 0 self.image = pygame.surface.Surface((70,396)).convert() self.image.set_colorkey((0,0,0)) self.is_update = True self._parse(self.convert_time())
class GameScene(Scene): def ready(self, *args, **kwargs): self.background = Image(u'../resources/image/main/background.png') self.frame = Image(u'../resources/image/main/frame.png', x=settings.STAGE_OFFSET[0]-15, y=settings.STAGE_OFFSET[1]-15) self.stage = Stage(args[0], args[1]) self.bgm = BGM(u'../resources/bgm/game_intro.wav', -1, u'../resources/bgm/game_loop.wav') self.background.draw() self.frame.draw() self.navigation = Navigation(self.stage) self.sequence_mng = SceneManager({'ready':ReadySequence(self.frame, self.background), 'main': MainSequence(self.stage, self.navigation), 'result':ResultSequence(self.stage, self.navigation, self.frame, self.bgm), 'pause':PauseSequence(self.navigation)}) def init(): if settings.DEBUG: return 'main' else: return 'ready' self.sequence_mng.change_scene(init()) self.redraw = False Effect.reset() self.draw() def update(self): super(GameScene, self).update() self.bgm.play() next = self.sequence_mng.current_scene.update() if next: self.redraw = True self.sequence_mng.change_scene(next) def draw(self): super(GameScene, self).draw() if self.redraw: self.redraw = False self.background.draw() self.frame.draw() if self.stage.redraw_frame(): self.frame.draw() #マップのはじで回転させたとき、回転の軌跡が残ってしまうため、フレームを再描画 rect_draw = self.stage.draw() rect_draw += self.navigation.draw() rect_draw += self.sequence_mng.current_scene.draw() return rect_draw
def _parse(self): if self.n < 0: self.n = 0 place = len(str(self.n)) # 桁 self.image = pygame.surface.Surface((self.width*place+self.margin*place, self.height)) self.image.set_colorkey((0,0,0)) dest = self.image.get_rect().move(self.x, self.y) area = dest for i,s in enumerate(str(self.n)): n = int(s) image = Image(self.filepath) dest = pygame.rect.Rect((self.width+self.margin)*i,0, self.width, self.height) area = Rect(n*self.width, 0, self.width, self.height) self.image.blit(image.image, dest, area)
def ready(self, *args, **kwargs): super(MainMenuScene, self).ready() self.bgm = BGM(u'../resources/music/title.wav', -1) self.cursor_sound = Sound("../resources/sound/cursor.wav") self.decide_sound = Sound('../resources/sound/decide.wav') self.decide_timer = Timer(settings.FPS * 2.5) self.num_joypads = JoyPad.get_num_joypads() self.joypads = [] for i in xrange(0, self.num_joypads): self.joypads.append(JoyPad(i)) self.background = Image(os.path.join(self.IMAGE_PATH, "background3.png"), alpha=False) self.logo = Image(os.path.join(self.IMAGE_PATH, "logo.png")) self.config = Image(os.path.join(self.IMAGE_PATH, "config.png"), alpha=False) self.exit = Image(os.path.join(self.IMAGE_PATH, "exit.png"), alpha=False) self.cursor = Image(os.path.join(self.IMAGE_PATH, "cursor.png"), alpha=True) self.cursor_threshold = [ [0, 0], ] * self.num_joypads # ジョイスティックを倒したときに、axisがどれくらい倒れたかの総量 self.cursor_move = [False] * self.num_joypads self.load_player_selection(self.num_joypads) self.logo.x = 280 self.logo.y = 20 self.player2.x = 160 self.player2.y = 400 self.player3.x = 380 self.player3.y = 400 self.player4.x = 600 self.player4.y = 400 self.config.x = 380 self.config.y = 460 self.exit.x = 600 self.exit.y = 460 # カーソル位置を初期化 self.options = ((self.player2, self.player3, self.player4), (None, self.config, self.exit)) self.actions = ( ( lambda: self.start_game(2), # self.player2 lambda: self.start_game(3), # self.player3 lambda: self.start_game(4), ) # self.player4 , ( lambda: 0, # None lambda: Game.get_scene_manager().change_scene('keysetting' ), #self.config lambda: sys.exit()) # self.exit ) self.cursor_logical_x = 0 self.cursor_logical_y = 0 self.set_cursor_pos(0, 0) self.sprites.add(self.background) self.sprites.add(self.logo) self.sprites.add(self.player2) self.sprites.add(self.player3) self.sprites.add(self.player4) self.sprites.add(self.config) self.sprites.add(self.exit) self.sprites.add(self.cursor) self.last_press_key = [{}] for dummy in self.joypads: self.last_press_key.append({})