コード例 #1
0
ファイル: player.py プロジェクト: giginet/FormationPuzzle
 def update(self):
     u'''
     なにかキーが押されたらkey_mode=True。このとき、マウス操作は利かない
     マウス座標が前と変わったら、key_mode=False
     '''
     if not self.pre_mouse_point == self.get_mouse_point(): self.key_mode = False
     if 'mouse' in self.interfaces and not self.key_mode: 
         self.point = self.get_mouse_point()
         if self.in_map():
             Mouse.hide_cursor()
         else: 
             Mouse.show_cursor()
     if 'key' in self.interfaces:
         if Key.is_press(K_UP):
             self.press_counter[0] += 1
             self.key_mode = True
         elif Key.is_press(K_DOWN):
             self.press_counter[1] += 1
             self.key_mode = True
         if Key.is_press(K_LEFT):
             self.press_counter[2] += 1
             self.key_mode = True
         elif Key.is_press(K_RIGHT):
             self.press_counter[3] += 1
             self.key_mode = True
     if 'pad' in self.interfaces:
         if self.joy.get_count() == 1: id = 0
         else: id = self.number
         axes = self.joy.sticks[id].get_numaxes() >= 2
         pad = self.joy.sticks[id]
         if pad.get_button(0) or (axes and pad.get_axis(1) < -0.5):
             self.press_counter[0] += 1
             self.key_mode = True
         if pad.get_button(1) or (axes and pad.get_axis(1) > 0.5):
             self.press_counter[1] += 1
             self.key_mode = True
         if pad.get_button(2) or (axes and pad.get_axis(0) < -0.5):
             self.press_counter[2] += 1
             self.key_mode = True
         if pad.get_button(3) or (axes and pad.get_axis(0) > 0.5):
             self.press_counter[3] += 1
             self.key_mode = True
     if self.press_counter[0] > 2:
         self.press_counter[0] = 0
         self.point.y -= 1
     if self.press_counter[1] > 2:
         self.press_counter[1] = 0
         self.point.y += 1
     if self.press_counter[2] > 2:
         self.press_counter[2] = 0
         self.point.x -= 1
     if self.press_counter[3] > 2:
         self.press_counter[3] = 0
         self.point.x += 1
     if self.point.x < 0: self.point.x = 0
     elif self.point.x > settings.STAGE_WIDTH-2: self.point.x = settings.STAGE_WIDTH-2
     if self.point.y < 0: self.point.y =0
     elif self.point.y > settings.STAGE_HEIGHT-2: self.point.y = settings.STAGE_HEIGHT-2
     self.move_pointer()
     self.pre_mouse_point = self.get_mouse_point()
コード例 #2
0
ファイル: keysetting.py プロジェクト: maraigue/MachiMatch
 def update(self):
     # Joypadによるカーソル操作
     # 各Joypadについて動きをチェックする
     for joypad_id in range(len(self.joypads)):
         # 直近のキー操作から
         xaxis = self.joypads[joypad_id].get_axis(0)
         yaxis = self.joypads[joypad_id].get_axis(1)
         time_now = time.time()
         if xaxis > 0.9:
             if (K_RIGHT in self.last_press_key[joypad_id]) and (time_now - self.last_press_key[joypad_id][K_RIGHT] < self.KEY_REPEAT_TIME): continue
             self.last_press_key[joypad_id][K_RIGHT] = time_now
         elif xaxis < -0.9:
             if (K_LEFT in self.last_press_key[joypad_id]) and (time_now - self.last_press_key[joypad_id][K_LEFT] < self.KEY_REPEAT_TIME): continue
             self.last_press_key[joypad_id][K_LEFT] = time_now
         elif yaxis > 0.9:
             if (K_DOWN in self.last_press_key[joypad_id]) and (time_now - self.last_press_key[joypad_id][K_DOWN] < self.KEY_REPEAT_TIME): continue
             self.last_press_key[joypad_id][K_DOWN] = time_now
         elif yaxis < -0.9:
             if (K_UP in self.last_press_key[joypad_id]) and (time_now - self.last_press_key[joypad_id][K_UP] < self.KEY_REPEAT_TIME): continue
             self.last_press_key[joypad_id][K_UP] = time_now
         else:
             pass
     
     # キーボードによるカーソル操作
     if Key.is_press(K_RETURN):
         # 設定を反映して戻る
         Game.get_scene_manager().change_scene('mainmenu')
     elif Key.is_press(K_BACKSPACE):
         # 設定を破棄して戻る
         Game.get_scene_manager().change_scene('mainmenu')
コード例 #3
0
ファイル: keysetting.py プロジェクト: giginet/MachiMatch
 def update(self):
     # Joypadによるカーソル操作
     # 各Joypadについて動きをチェックする
     for joypad_id in range(len(self.joypads)):
         # 直近のキー操作から
         xaxis = self.joypads[joypad_id].get_axis(0)
         yaxis = self.joypads[joypad_id].get_axis(1)
         time_now = time.time()
         if xaxis > 0.9:
             if (K_RIGHT in self.last_press_key[joypad_id]) and (time_now - self.last_press_key[joypad_id][K_RIGHT] < self.KEY_REPEAT_TIME): continue
             self.last_press_key[joypad_id][K_RIGHT] = time_now
         elif xaxis < -0.9:
             if (K_LEFT in self.last_press_key[joypad_id]) and (time_now - self.last_press_key[joypad_id][K_LEFT] < self.KEY_REPEAT_TIME): continue
             self.last_press_key[joypad_id][K_LEFT] = time_now
         elif yaxis > 0.9:
             if (K_DOWN in self.last_press_key[joypad_id]) and (time_now - self.last_press_key[joypad_id][K_DOWN] < self.KEY_REPEAT_TIME): continue
             self.last_press_key[joypad_id][K_DOWN] = time_now
         elif yaxis < -0.9:
             if (K_UP in self.last_press_key[joypad_id]) and (time_now - self.last_press_key[joypad_id][K_UP] < self.KEY_REPEAT_TIME): continue
             self.last_press_key[joypad_id][K_UP] = time_now
         else:
             pass
     
     # キーボードによるカーソル操作
     if Key.is_press(K_RIGHT):
         pass
     elif Key.is_press(K_LEFT):
         pass
     elif Key.is_press(K_DOWN):
         pass
     elif Key.is_press(K_UP):
         pass
コード例 #4
0
ファイル: main.py プロジェクト: maraigue/MachiMatch
def main():
    
    pygame.init() # pygameの初期化
    
    game = Game()
    game.get_scene_manager().set_scenes({
        'logo':LogoScene(),
        'game':GameScene(),
        'mainmenu':MainMenuScene(),
        'keysetting':KeySettingScene(),
    })
    if settings.DEBUG:        
        game.get_scene_manager().change_scene('game')
    else:
        game.get_scene_manager().change_scene('logo')
    while 1:
        game._clock.tick(settings.FPS)
        Key.poll()
        scene = game.current_scene()
        if not scene: return
        game.update()
        rects = game.draw()
        pygame.display.update(rects) # 画面を反映
        for event in pygame.event.get(): # イベントチェック
            if event.type == QUIT: return
            if (event.type == KEYDOWN and event.key  == K_ESCAPE): return
コード例 #5
0
ファイル: sequences.py プロジェクト: giginet/FormationPuzzle
 def update(self):
     self.navigation.gauge.is_update = True
     if not Key.is_press(K_SPACE):
         self.press = False
     if not self.press and Key.is_press(K_SPACE):
         Sound(u'../resources/sound/pause.wav').play()
         BGM.set_volume(1)
         return 'main'
コード例 #6
0
ファイル: player.py プロジェクト: giginet/FormationPuzzle
 def poll(self):
     if 'mouse' in self.interfaces and not self.key_mode:
         if Mouse.is_press('LEFT') and not self.pressed:
             self.pressed = True
             return 1
         elif Mouse.is_press('RIGHT') and not self.pressed:
             self.pressed = True
             return -1
         if Mouse.is_release(self):
             self.pressed = False
     if 'key' in self.interfaces:
         if Key.is_press(K_x): 
             if not self.press_counter[4]:
                 self.press_counter[4] = 1
                 self.key_mode = True
                 return -1
         elif Key.is_press(K_z):
             if not self.press_counter[5]: 
                 self.press_counter[5] = 1
                 self.key_mode = True
                 return 1
         else:
             self.press_counter[4] = 0
             self.press_counter[5] = 0
     if 'pad' in self.interfaces:
         if self.joy.get_count() == 1: id = 0
         else: id = self.number
         if self.joy.sticks[id].get_numbuttons >= 13:
             left = 12
             right = 11
         else:
             left = 5
             right = 6
         pad = self.joy.sticks[id]
         if pad.get_button(left):
             if not self.press_counter[4]:
                 self.press_counter[4] = 1
                 return -1
         elif pad.get_button(right):
             if not self.press_counter[5]: 
                 self.press_counter[5] = 1
                 return 1
         else:
             self.press_counter[4] = 0
             self.press_counter[5] = 0
     return 0
コード例 #7
0
ファイル: player.py プロジェクト: maraigue/MachiMatch
 def _poll_key(self):
     if Key.is_press(K_z):
         if not self.pressed_rotate_l: 
             self.pressed_rotate_l = True 
             return -1
     elif Key.is_press(K_x):
         if not self.pressed_rotate_r: 
             self.pressed_rotate_r = True
             return 1
     elif Key.is_press(K_c):
         if not self.pressed_attach:
             self.pressed_attach = True 
             return 2
     else:
         self.pressed_attach = False
         self.pressed_rotate_l = False
         self.pressed_rotate_r = False
     return 0
コード例 #8
0
ファイル: logo.py プロジェクト: maraigue/MachiMatch
 def update(self):
     self.timer.tick()
     self.timer.play()
     if self.timer.is_over() or Mouse.is_press("LEFT") or Key.is_press(K_RETURN):
         Game.get_scene_manager().change_scene("mainmenu")
     elif self.timer.now < 60:
         self.logo.alpha = 255 * self.timer.now / 60
     elif 120 < self.timer.now:
         self.logo.alpha = 255 * (180 - self.timer.now) / 60
コード例 #9
0
ファイル: player.py プロジェクト: maraigue/MachiMatch
    def update(self):
        self.city.update()
        if not self.number == 0: return
        # ToDo 操作性が悪いのであとで改善する
        if Key.is_press(K_RIGHT):
            self.cursol_counter_h += 1
            if self.cursol_counter_h > 1:
                self.cursol_counter_h = 0
                self.point.x += 1
        elif Key.is_press(K_LEFT):
            self.cursol_counter_h += 1
            if self.cursol_counter_h > 1:
                self.cursol_counter_h = 0
                self.point.x -= 1
        else:
            self.cursol_counter_h = 0
        if Key.is_press(K_UP):
            self.cursol_counter_v += 1
            if self.cursol_counter_v > 1:
                self.cursol_counter_v = 0
                self.point.y -= 1
        elif Key.is_press(K_DOWN):
            self.cursol_counter_v += 1
            if self.cursol_counter_v > 1:
                self.cursol_counter_v = 0
                self.point.y += 1
        else:
            self.cursol_counter_v = 0
        if self.point.x < 0:
            self.point.x = 0
        elif self.point.x > settings.STAGE_WIDTH-1:
            self.point.x = settings.STAGE_WIDTH-1
        if self.point.y < 0:
            self.point.y = 0
        elif self.point.y > settings.STAGE_HEIGHT-1:
            self.point.y = settings.STAGE_HEIGHT-1
#
#        xaxis = self.joy.get_axis(0)
#        yaxis = self.joy.get_axis(1)
#        if abs(xaxis) > 0.5:
#            self.point.x += 1 if xaxis > 0 else -1
#        if abs(yaxis) > 0.5:
#            self.point.y += 1 if yaxis > 0 else -1
        self.current_road.point = self.point.clone()
コード例 #10
0
ファイル: sequences.py プロジェクト: giginet/FormationPuzzle
 def update(self):
     super(MainSequence, self).update()
     self.stage.update()
     self.navigation.update()
     u"""ポーズへの移行"""
     if not Key.is_press(K_SPACE):
         self.press_pause = False
     if not self.press_pause and Key.is_press(K_SPACE): 
         Sound(u'../resources/sound/pause.wav').play()
         return 'pause'
     u"""リミットの9割に達したとき、音を鳴らす"""
     crisis = (settings.STAGE_WIDTH*settings.STAGE_HEIGHT)*settings.CALLED*0.9
     if self.stage.count[0] > crisis or self.stage.count[1] > crisis: 
         if not self.crisis:
             self.crisis = True
             Sound(u'../resources/sound/area_crisis.wav').play()
     else: self.crisis = False
     u"""ゲーム終了判定"""
     called = (settings.STAGE_WIDTH*settings.STAGE_HEIGHT)*settings.CALLED
     if self.stage.count[0] > called or self.stage.count[1] > called: return 'result' 
     if self.navigation.timer.is_over(): return 'result'
コード例 #11
0
ファイル: mainmenu.py プロジェクト: maraigue/MachiMatch
 def update(self):
     # Joypadによるカーソル操作
     # 各Joypadについて動きをチェックする
     for joypad_id in range(len(self.joypads)):
         # 直近のキー操作から
         xaxis = self.joypads[joypad_id].get_axis(0)
         yaxis = self.joypads[joypad_id].get_axis(1)
         if xaxis > 0.9:
             if self.keysupp.press("%d %d" % (joypad_id, K_RIGHT)):
                 self.set_cursor_pos(1, 0)
         elif xaxis < -0.9:
             if self.keysupp.press("%d %d" % (joypad_id, K_LEFT)):
                 self.set_cursor_pos(-1, 0)
         elif yaxis > 0.9:
             if self.keysupp.press("%d %d" % (joypad_id, K_DOWN)):
                 self.set_cursor_pos(0, 1)
         elif yaxis < -0.9:
             if self.keysupp.press("%d %d" % (joypad_id, K_UP)):
                 self.set_cursor_pos(0, -1)
         
         # ボタン
         for button_id in range(self.joypads[joypad_id].get_numbuttons()):
             if self.joypads[joypad_id].get_button(button_id):
                 self.menu_actions[self.cursor_logical_y][self.cursor_logical_x]()
     
     # キーボードによるカーソル操作
     if Key.is_press(K_RIGHT):
         if self.keysupp.press(K_RIGHT):
             self.set_cursor_pos(1, 0)
     elif Key.is_press(K_LEFT):
         if self.keysupp.press(K_LEFT):
             self.set_cursor_pos(-1, 0)
     elif Key.is_press(K_DOWN):
         if self.keysupp.press(K_DOWN):
             self.set_cursor_pos(0, 1)
     elif Key.is_press(K_UP):
         if self.keysupp.press(K_UP):
             self.set_cursor_pos(0, -1)
     elif Key.is_press(K_RETURN):
         self.menu_actions[self.cursor_logical_y][self.cursor_logical_x]()
コード例 #12
0
ファイル: main.py プロジェクト: giginet/FormationPuzzle
def main():
    pygame.mixer.pre_init(44100, -16, 2, 1024*3)
    pygame.init() # pygameの初期化
    
    game = Game()
    game.get_scene_manager().set_scenes({'logo':LogoScene(),'game':GameScene(), 'title':TitleScene()})
    if settings.DEBUG:
        game.get_scene_manager().change_scene('game',False,True)
    else:
        game.get_scene_manager().change_scene('logo')
    while 1:
        game._clock.tick(settings.FPS)
        Key.poll()
        scene = game.current_scene()
        if not scene: return
        scene.sprites.clear(game.get_screen(), scene.BACKGROUND_SURFACE)
        game.update()
        rects = game.draw()
        pygame.display.update(rects) # 画面を反映
        for event in pygame.event.get(): # イベントチェック
            if event.type == QUIT: return
            if (event.type == KEYDOWN and event.key  == K_ESCAPE): return