コード例 #1
0
ファイル: GameManager.py プロジェクト: csauers/monster_sim
class GameManager(metaclass = Singleton):
    def __init__(self):
        self.title = Title()
        self.create_monster = CreateMonster()
        self.game_screen = GameScreen()
        self.currentscreen = Screen()
        self.fps_container = SimpleBox(pygame.Rect(10,10,0,0))
        self.fps_container.add_sprite(MText(1,Point(0,0),50,Resources().font12,""))
        
        self.change_screen(self.title,False);
        return

    def update(self):
        self.fps_container.update()
        self.fps_container.get_sprite(1).set_text("%.3f" % TimeManager().fps)

        InputManager().update_start()
        if self.currentscreen is not None:
            self.currentscreen.update()
        InputManager().update_end()
        return

    def draw(self,screen):
        if self.currentscreen is not None:
            self.currentscreen.draw(screen)

        self.fps_container.draw(screen)
        return

    def change_screen(self, new_screen, perform_transition = False):
        if self.currentscreen is not None:
            self.currentscreen.close()

        if perform_transition:
            self.currentscreen = new_screen
        else:
            self.currentscreen = new_screen
        self.currentscreen.open()
        return
コード例 #2
0
ファイル: Screen.py プロジェクト: csauers/monster_sim
class CreateMonster(Screen):
    def __init__(self):       
        self.background = SimpleBox(pygame.Rect(0,0,480,320))
        self.background.add_sprite(MSprite(1,Point(0,0),Resources().title_bg))
        self.title = SimpleBox(pygame.Rect(Static.center(0,256,Static.width),-50,256,32),Static.beige,False,True)
        self.title.add_sprite(MText(0,Point(20,3),256,Resources().font24,"Choose a name!",Static.gray))
        self.monster = SimpleBox(pygame.Rect(200,-100,0,0))
        self.monster.add_sprite(MSprite(1,Point(0,0),Resources().monster_placeholder))
        self.virtual_keyboard = VirtualKeyboard(Point(50,600))

        self.name = ""
        self.name_container = SimpleBox(pygame.Rect(Static.center(0,256,Static.width),-50,256,32),Static.gray,False,True)
        self.name_container.add_sprite(MText(0,Point(20,3),256,Resources().font24,"",Static.white))
        return
    
    def draw(self,screen):
        self.background.draw(screen)
        self.title.draw(screen)
        self.monster.draw(screen)
        self.name_container.draw(screen)
        self.virtual_keyboard.draw(screen)
        return

    def update(self):
        self.background.update()
        self.title.update()
        self.monster.update()
        self.name_container.update()
        self.virtual_keyboard.update()

        if self.virtual_keyboard.pressed_key != "":
            if self.virtual_keyboard.pressed_key == "<-":
                self.name = self.name[:-1]
                self.name_container.get_sprite(0).set_text(self.name)
            elif self.virtual_keyboard.pressed_key == "GO":
                if self.name != "":
                    GameManager().change_screen(GameManager().game_screen,False)
            else:
                self.name = self.name + self.virtual_keyboard.pressed_key
                self.name_container.get_sprite(0).set_text(self.name)

        if InputManager().key_pressed(MKey.BUTTON_2,True):
            GameManager().change_screen(GameManager().game_screen,False)
        return

    def open(self):
        self.name = ""
        self.name_container.get_sprite(0).set_text(self.name)

        self.title.set_tween((Static.center(0,256,Static.width),15))
        self.monster.set_tween((200,60))
        self.name_container.set_tween((Static.center(0,256,Static.width),135))
        self.virtual_keyboard.open(Point(50,175))
        return

    def close(self):
        self.title.set_position((Static.center(0,256,Static.width),-100))
        self.monster.set_position((200,-100))
        self.name_container.set_position((Static.center(0,256,Static.width),-100))
        self.virtual_keyboard.close(Point(50,600))
        return