Exemplo n.º 1
0
    def __init__(self, state):
        GameScreen.__init__(self, state)
        print("- Create Group info Screen")
        self.titleFont = pygame.font.Font(
            PATH_ASSETS + "font/BD_Cartoon_Shout.ttf", 72)
        self.itemFont = pygame.font.Font(
            PATH_ASSETS + "font/BD_Cartoon_Shout.ttf", 48)
        self.menuWidth = 0

        self.menuItems = [
            {
                'title': 'Press ESC to return MENU'
            },
            {
                'title': 'Tran Minh Duc 18127027',
            },
            {
                'title': 'Nguyen Vu Thu Hien 18127004',
            },
            {
                'title': 'Ngo Thanh Phuong Thai 18127208 ',
            },
            {
                'title': 'Tran Quoc Tuan 18127246',
            },
        ]
        for item in self.menuItems:
            surface = self.itemFont.render(item['title'], True, (200, 0, 0))
            self.menuWidth = max(self.menuWidth, surface.get_width())
            item['surface'] = surface

        self.currentMenuItem = 0
        self.menuCursor = pygame.image.load(PATH_IMAGE + "icon.png")
        self.backgroundImage = pygame.image.load(PATH_IMAGE + "bg.jpg")
Exemplo n.º 2
0
    def __init__(self, state):
        GameScreen.__init__(self, state=state)
        self.titleFont = pygame.font.Font(
            PATH_ASSETS + "font/BD_Cartoon_Shout.ttf", 72)
        self.itemFont = pygame.font.Font(
            PATH_ASSETS + "font/BD_Cartoon_Shout.ttf", 48)

        print("Created [level 3 game screen]")
        self.run()
Exemplo n.º 3
0
    def __init__(self, state):
        GameScreen.__init__(self, state=state)
        self.titleFont = pygame.font.Font(
            PATH_ASSETS + "font/BD_Cartoon_Shout.ttf", 72)
        self.itemFont = pygame.font.Font(
            PATH_ASSETS + "font/BD_Cartoon_Shout.ttf", 48)

        print("Created [second level screen]")
        self.tile_manager = SecondLevelManager()
Exemplo n.º 4
0
    def __init__(self, state):
        GameScreen.__init__(self, state)
        print("- Create Play Game Screen")

        self.titleFont = pygame.font.Font(
            PATH_ASSETS + "font/BD_Cartoon_Shout.ttf", 72)
        self.itemFont = pygame.font.Font(
            PATH_ASSETS + "font/BD_Cartoon_Shout.ttf", 48)
        self.player = None
        self.load_data()
        self.new()
Exemplo n.º 5
0
    def __init__(self):
        # initialize the game parameters
        screen_width = 320
        screen_height = 480
        screen_size = (screen_width, screen_height)
        pg_screen = pygame.display.set_mode((screen_width, screen_height))

        # initialize the screens
        self.screens = {
            "game_screen": GameScreen(pg_screen, screen_size),
            "help_screen": HelpScreen(pg_screen, screen_size),
            "highscores_screen": HighscoresScreen(pg_screen, screen_size),
            "main_menu": MainMenu(pg_screen, screen_size),
            "login_screen": LoginScreen(pg_screen, screen_size),
            "register_screen": RegisterScreen(pg_screen, screen_size),
        }
        self.screen = "main_menu"
        self.audio = Audio(has_audio)
        self.audio.set_music(self.screens["main_menu"].music_on)
        self.audio.set_sound(self.screens["main_menu"].sound_on)

        self.game_time = time.time()

        # run the game loop forever
        while True:
            self.game_loop()
Exemplo n.º 6
0
    def __init__(self, state):
        GameScreen.__init__(self, state)
        print("- Create Menu Screen")
        self.titleFont = pygame.font.Font(
            PATH_ASSETS + "font/BD_Cartoon_Shout.ttf", 72)
        self.itemFont = pygame.font.Font(
            PATH_ASSETS + "font/BD_Cartoon_Shout.ttf", 48)
        self.menuWidth = 0

        self.menuItems = [
            {
                'title': 'Level 1',
                'action': EScreenState.LEVEL_1,
            },
            {
                'title': 'Level 2',
                'action': EScreenState.LEVEL_2
            },
            {
                'title': 'Level 3',
                'action': EScreenState.LEVEL_3,

            },
            {
                'title': 'Level 4',
                'action': EScreenState.LEVEL_4
            },
            {
                'title': 'Group Information',
                'action': EScreenState.GROUP

            },
            {
                'title': 'Exit'
            }
        ]
        for item in self.menuItems:
            surface = self.itemFont.render(item['title'], True, (200, 0, 0))
            self.menuWidth = max(self.menuWidth, surface.get_width())
            item['surface'] = surface

        self.currentMenuItem = 0
        self.menuCursor = pygame.image.load(PATH_IMAGE + "icon.png")
        self.backgroundImage = pygame.image.load(PATH_IMAGE + "bg.jpg")
Exemplo n.º 7
0
    def __init__(self):
        self.root = Tk()
        self.width = 1024
        self.height = 675
        self.root.title("Minesweeper")
        self.root.geometry("{}x{}".format(self.width, self.height))
        self.root.resizable(width=False, height=False)
        self.root["bg"] = "#c9daf8"

        self.is_setup = False
        self.is_game = False

        ####setup screen
        self.setup_screen = SetUpScreen(self)
        self.setup_screen.but_play["command"] = self.showGameScreen

        ####game screen
        self.game_screen = GameScreen(self)
        self.game_screen.but_cancel["command"] = self.showSetUpScreen
Exemplo n.º 8
0
    def __init__(self, window):
        super(WindowManager, self).__init__()
        self.window = window
        self.InputHandler = InputHandler(self.window)
        self.window.push_handlers(self.InputHandler.keys)
        self.stack = []
        #self.cross = CrossHair()
        self.saved_mouse = (1280 / 2, 720 / 2)

        # set up main menu as starting screen
        self.current_screen = MainMenu(self.window)
        self.register_screen()

        """@self.window.event
Exemplo n.º 9
0
    def setState(self, state):
        if state == GAME_STATES["INTRO"]:
            self.__actualScreen = IntroScreen(self)
        elif state == GAME_STATES["HOME"]:
            self.__actualScreen = HomeScreen(self)
        elif state == GAME_STATES["GAME"]:
            self.__actualScreen = GameScreen(self)
        elif state == GAME_STATES["GAME_OVER"]:
            self.__actualScreen = GameOverScreen(self)
        elif state == GAME_STATES["FINISH"]:
            self.__actualScreen = FinishScreen(self)

        else:
            print('[setStateError]: the state "', state, '" does not exist !')
            self.stop()
Exemplo n.º 10
0
class MainWindow:
    """
    Class representing the game's main window.
    Contains the tkinter's root (Tk).
    Manages the communication between the Setup and Game screens.
    """
    def __init__(self):
        self.root = Tk()
        self.width = 1024
        self.height = 675
        self.root.title("Minesweeper")
        self.root.geometry("{}x{}".format(self.width, self.height))
        self.root.resizable(width=False, height=False)
        self.root["bg"] = "#c9daf8"

        self.is_setup = False
        self.is_game = False

        ####setup screen
        self.setup_screen = SetUpScreen(self)
        self.setup_screen.but_play["command"] = self.showGameScreen

        ####game screen
        self.game_screen = GameScreen(self)
        self.game_screen.but_cancel["command"] = self.showSetUpScreen

    def showSetUpScreen(self):
        self.is_setup = True
        if self.is_game:
            self.game_screen.destroy()
        self.is_game = False

        self.setup_screen.show()

    def showGameScreen(self):
        h = self.setup_screen.height_option
        w = self.setup_screen.width_option
        n_m = self.setup_screen.mines_option
        if (h.ent.get().isdigit() \
           and h.mini <= int(h.ent.get()) <= h.maxi \
           and w.ent.get().isdigit() \
           and w.mini <= int(w.ent.get()) <= w.maxi \
           and n_m.ent.get().isdigit() \
           and n_m.mini <= int(n_m.ent.get()) <= n_m.maxi):

            self.game_screen.setNewGame(int(h.ent.get()), int(w.ent.get()),
                                        int(n_m.ent.get()))

            self.is_game = True
            if self.is_setup:
                self.setup_screen.destroy()
            self.is_setup = False

            self.game_screen.show()
Exemplo n.º 11
0
    def __init__(self):
        # set the display name
        pygame.display.set_caption("Kanaraimasu - Learn to draw kana")

        # initialize the game parameters
        self.fps = Settings.get("fps")

        # initialize the screen and render surfaces
        width = Settings.get("width")
        height = Settings.get("height")
        fullscreen = pygame.FULLSCREEN if Settings.get("fullscreen") else 0
        self.screen_size = (width, height)
        self.pg_screen = pygame.display.set_mode(self.screen_size,
                                                 RESIZABLE | fullscreen)

        self.render_size = (1920, 1080)
        self.render_surface = pygame.Surface(self.render_size)

        self.show_splash_screen()

        # initialize the screens
        self.screens = {
            "gamescreen":
            GameScreen(self.render_surface, self.render_size),
            "optionsforhiragana":
            KanaSelectScreen(self.render_surface, self.render_size,
                             "hiragana"),
            "optionsforkatakana":
            KanaSelectScreen(self.render_surface, self.render_size,
                             "katakana"),
            "optionsforkanji":
            KanjiOptionsScreen(self.render_surface, self.render_size),
            "menuscreen":
            MenuScreen(self.render_surface, self.render_size),
            "settingsscreen":
            SettingsScreen(self.render_surface, self.render_size),
        }
        self.set_screen_id("menuscreen")
        # sets the screen size in all screens
        self.set_screen_size(self.screen_size)

        self.game_time = time.time()

        # run the game loop forever
        while True:
            self.game_loop()
Exemplo n.º 12
0
    def build(self):
        self.manager = ScreenManager(transition=FallOutTransition())
        self.manager.add_widget(MainMenu(name='MainMenu'))
        self.manager.add_widget(GameScreen(name='GameScreen'))

        return self.manager
Exemplo n.º 13
0
class WindowManager(Events):
    """docstring for WindowManager"""
    def __init__(self, window):
        super(WindowManager, self).__init__()
        self.window = window
        self.InputHandler = InputHandler(self.window)
        self.window.push_handlers(self.InputHandler.keys)
        self.stack = []
        #self.cross = CrossHair()
        self.saved_mouse = (1280 / 2, 720 / 2)

        # set up main menu as starting screen
        self.current_screen = MainMenu(self.window)
        self.register_screen()

        """@self.window.event
        def on_resize(width, height):
            if isinstance(self.current_screen, GameScreen):
                self.current_screen.camera.on_resize(width, height)
            self.InputHandler.on_resize(width, height)"""

    def update(self, dt):
        self.InputHandler.process_keys(dt)
        if (self.stack[0] != self.current_screen and
                isinstance(self.stack[0], GameScreen)):
            self.stack[0].idle_update(dt)
        self.current_screen.update(dt)

    def draw(self):
        # stack[0] is gamescreen
        if self.stack[0] != self.current_screen:
            self.stack[0].draw()
        self.current_screen.draw()
        #self.cross.draw(*self.InputHandler.mousepos)

    # receive events, a lot of transitions will happen here
    def receive_events(self, event, msg):
        if event == 'kill_self':
            from twisted.internet import reactor
            reactor.stop()

        elif event == 'start_game':
            self.stack = []
            self.start_game()

        elif event == 'to_main':
            self.stack = []
            self.current_screen = MainMenu(self.window)
            self.register_screen()
            self.disconnect()
            self.saved_mouse = (1280 / 2, 720 / 2)

        elif event == 'menu_transition_+':
            msg, arg = msg
            if isinstance(self.current_screen, GameScreen):
                self.saved_mouse = tuple(self.InputHandler.m_cam)
                self.current_screen.player.input = proto.Input()
                self.InputHandler.unregister(self.current_screen.camera.
                                             receive_m_pos, 'mouse_cam')
            self.current_screen = msg(arg)
            self.register_screen()

        elif event == 'menu_transition_-':
            self.stack.pop()
            self.current_screen = self.stack[-1]
            self.register_screen()

        # input to client
        elif event == 'input':
            self.send_message('input', msg)

        elif event == 'other':
            self.send_message('other', msg)

        # server plaerdata
        elif event == 'serverdata':
            if isinstance(self.stack[0], GameScreen):
                self.stack[0].from_server(msg)

        elif event == 'on_connect':
            self.stack[0].on_connect(msg)
            self.current_screen.on_connect()

        elif event == 'try_join':
            self.stack[0].try_join()

        elif event == 'chat':
            self.stack[0].send_chat(msg)

        elif event == 'options':
            self.InputHandler.load_options()

        elif event == 'switch_to':
            msg, arg = msg
            self.stack.pop()
            self.current_screen = msg(arg)
            self.register_screen()

    def start_game(self):
        self.current_screen = GameScreen(self.window)
        self.register_screen()
        #get to load screen
        self.receive_events('menu_transition_+', (LoadScreen, False))
        self.connect()

    def register_screen(self):
        # menu screen
        if not isinstance(self.current_screen, GameScreen):
            self.InputHandler.register(self.current_screen.receive_event,
                                       events=('changed_mouse', 'all_input'))
            self.window.set_mouse_visible(True)
            self.window.set_exclusive_mouse(False)
        # game screen
        else:
            for i, j in enumerate(self.saved_mouse):
                self.InputHandler.m_cam[i] = j

            self.InputHandler.register(self.current_screen.camera.
                                       receive_m_pos, 'mouse_cam')

            # set mouse on same position as it was before opening menu
            self.InputHandler.send_message('mouse_cam',
                                           self.InputHandler.m_cam)
            #needed so player doesnt shoot when coming from a menu
            self.InputHandler.keys[1 + self.InputHandler.mouse_offset] = False
            # pass by ref bullshit
            self.current_screen.player.input = self.InputHandler.directns
            self.current_screen.controls = self.InputHandler.controls
            self.current_screen.update_keys()
            # sends player input to lient class
            self.current_screen.register(self.receive_events, 'input')
            self.current_screen.camera.register(self.InputHandler.receive_aim,
                                                'mousepos')
            self.window.set_mouse_visible(False)
            self.window.set_exclusive_mouse(True)

        self.current_screen.register(self.receive_events)
        self.stack.append(self.current_screen)

    def input_to_client(self):
        pass
Exemplo n.º 14
0
    def receive_events(self, event, msg):
        if event == 'kill_self':
            from twisted.internet import reactor
            reactor.stop()

        elif event == 'start_game':
            self.stack = []
            self.start_game()

        elif event == 'to_main':
            self.stack = []
            self.current_screen = MainMenu(self.window)
            self.register_screen()
            self.disconnect()
            self.saved_mouse = (1280 / 2, 720 / 2)

        elif event == 'menu_transition_+':
            msg, arg = msg
            if isinstance(self.current_screen, GameScreen):
                self.saved_mouse = tuple(self.InputHandler.m_cam)
                self.current_screen.player.input = proto.Input()
                self.InputHandler.unregister(self.current_screen.camera.
                                             receive_m_pos, 'mouse_cam')
            self.current_screen = msg(arg)
            self.register_screen()

        elif event == 'menu_transition_-':
            self.stack.pop()
            self.current_screen = self.stack[-1]
            self.register_screen()

        # input to client
        elif event == 'input':
            self.send_message('input', msg)

        elif event == 'other':
            self.send_message('other', msg)

        # server plaerdata
        elif event == 'serverdata':
            if isinstance(self.stack[0], GameScreen):
                self.stack[0].from_server(msg)

        elif event == 'on_connect':
            self.stack[0].on_connect(msg)
            self.current_screen.on_connect()

        elif event == 'try_join':
            self.stack[0].try_join()

        elif event == 'chat':
            self.stack[0].send_chat(msg)

        elif event == 'options':
            self.InputHandler.load_options()

        elif event == 'switch_to':
            msg, arg = msg
            self.stack.pop()
            self.current_screen = msg(arg)
            self.register_screen()
Exemplo n.º 15
0
 def start_game(self):
     self.current_screen = GameScreen(self.window)
     self.register_screen()
     #get to load screen
     self.receive_events('menu_transition_+', (LoadScreen, False))
     self.connect()
Exemplo n.º 16
0
    def enter_level(level):
        sm.get_screen(level.mode).set_level(level)
        sm.switch_to(level.mode)

    def send_summary(game_summary):
        sm.get_screen('transition').get_summary(game_summary)

    def unlock_next():
        sm.get_screen('gmode').unlock_next_levels()

    # Add all screens to the manager. The first screen added is the current screen.
    sm.add_screen(IntroScreen(name='intro'))
    sm.add_screen(
        MainScreen(mode='lmode',
                   name='lmode_main',
                   enter_level=enter_level,
                   channel=godmode))
    sm.add_screen(
        MainScreen(mode='gmode',
                   name='gmode_main',
                   enter_level=enter_level,
                   channel=godmode))
    sm.add_screen(LearningScreen(webcam, name='lmode'))
    sm.add_screen(GameScreen(webcam, send_summary=send_summary, name='gmode'))
    sm.add_screen(TransitionScreen(unlock_next=unlock_next, name='transition'))

    # Window.fullscreen = 'auto'

    run(sm)