예제 #1
0
파일: root.py 프로젝트: junhg0211/Kreylin
def handle():
    global running

    keyboard_manager.initialize()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.VIDEORESIZE:
            display.resize(event.dict['size'], root_object_manager,
                           state_manager, ResizeAlert)
        elif event.type == pygame.KEYDOWN:
            keyboard_manager.start_key(event.key)
            keyboard_manager.pressed(event.unicode)
        elif event.type == pygame.KEYUP:
            keyboard_manager.end_key(event.key)
예제 #2
0
파일: menu.py 프로젝트: chozabu/Neinjarz
 def runMenu(self):
     inmenu = 1
     self.currentMenu = self.mainMenu
     while inmenu:
         self.drawMenu()
         #time.sleep(1.0/60.0)
         timer.tick()
         for event in pygame.event.get():
             if event.type == pygame.QUIT: sys.exit()
             if event.type == 2:#keypress
                 if event.key == pgl.K_ESCAPE:
                     sys.exit()
             elif event.type == pgl.VIDEORESIZE:
                 print(event.dict['size'])
                 display.resize(event.dict['size'][0], event.dict['size'][1])
                 pygame.display.flip()
             if self.currentMenu.handleEvent(event):
                 inmenu = 0
예제 #3
0
    def tick(self):
        loop_time = time()
        if self.keyboard_manager.is_start(pygame.K_BACKSPACE):
            self.backspace_pressed_time = time()
        if self.keyboard_manager.is_pressed(pygame.K_BACKSPACE) and \
                self.backspace_sleep_duration + self.backspace_pressed_time <= time():
            self.backspace_cycle_elapsed += loop_time - self.last_loop_time
            if self.backspace_cycle_elapsed >= self.backspace_repress_cycle:
                self.line += '\b'
                self.backspace_cycle_elapsed -= self.backspace_repress_cycle

        self.line += self.keyboard_manager.pop_buffer()
        while '\x7f' in self.line:
            i = self.line.index('\x7f')
            self.line = self.line[:i - 1] + self.line[i + 1:]
        while '\b' in self.line:
            i = self.line.index('\b')
            self.line = self.line[:i - 1] + self.line[i + 1:]

        self.surface = self.font.render(self.line)
        self.surface_background_width += \
            (self.surface.get_width() - self.surface_background_width) / constants.FRICTION

        start_time = center(display.size[0], self.surface.get_width())
        self.x += (start_time - self.x) / (constants.FRICTION / 3)

        if self.keyboard_manager.is_start(pygame.K_ESCAPE):
            self.line = ''
        elif self.line == 'c\n':
            self.state_manager.state = Clock()
        elif len(self.line) > 1 and (
                self.keyboard_manager.is_start(pygame.K_RETURN)
                or self.keyboard_manager.is_start(pygame.K_KP_ENTER)):
            self.line = self.line.lower()

            # noinspection SpellCheckingInspection
            if self.line[-2] == '.':
                self.alarm(self.line)
            elif self.line[-2] == '`':
                self.timer(self.line)
            elif self.line[-2] == '/':
                now = datetime.now()
                year, day = 0, 0
                hour, minute, second = 0, 0, 0
                change = True
                try:
                    minute += float(self.line[:-2])
                except ValueError:
                    try:
                        tmp = float(self.line[:-3])
                    except ValueError:
                        change = False
                    else:
                        if self.line[-3].lower() == 's':
                            second += tmp
                        elif self.line[-3].lower() == 'h':
                            hour += tmp
                        elif self.line[-3].lower() == 'd':
                            day += tmp
                        elif self.line[-3].lower() == 'y':
                            year += tmp
                    while second > 60:
                        second -= 60
                        minute += 1
                    while minute > 60:
                        minute -= 60
                        hour += 1
                    while hour > 24:
                        hour -= 24
                        day += 1
                if change:
                    try:
                        start_time = now - timedelta(days=(year * 365 + day),
                                                     hours=hour,
                                                     minutes=minute,
                                                     seconds=second)
                    except ValueError:
                        pass
                    except OverflowError:
                        pass
                    else:
                        self.state_manager.state = Stopwatch(start_time)
                else:
                    self.state_manager.state = Stopwatch()
            elif self.line[-2] == '-':
                self.state_manager.state = Clock()
            elif self.line[-2] == 'x':
                self.shutdown()
            elif self.line[-2] == 'f':
                display.toggle_full_screen(self.root_object_manager,
                                           self.state_manager)
            elif self.line[-2] == 'h':
                self.root_object_manager.hud = None if self.root_object_manager.hud else \
                    HUD(self.state_manager, self.root_object_manager, self.keyboard_manager, self.handler_manager)
            elif self.line[-2] == 'c':
                constants.responsible_color = False
                if len(self.line) >= 19:
                    constants.change_color(
                        (int(self.line[:2], 16), int(
                            self.line[2:4], 16), int(self.line[4:6], 16)),
                        (int(self.line[6:8], 16), int(
                            self.line[8:10], 16), int(self.line[10:12], 16)),
                        (int(self.line[12:14], 16), int(
                            self.line[14:16], 16), int(self.line[16:18], 16)))
                    self.state_manager.state = Clock()
                elif len(self.line) >= 3:
                    if ord(self.line[-3].upper()) - ord('G') < len(
                            Color.SAMPLE_PALETTES):
                        constants.change_color(
                            *Color.SAMPLE_PALETTES[ord(self.line[-3].upper()) -
                                                   ord('G')])
                    self.state_manager.state = Clock()
                else:
                    if isinstance(self.state_manager.state, Color):
                        constants.responsible_color = True
                        self.state_manager.state = Clock()
                    else:
                        self.state_manager.state = Color()
                if self.root_object_manager.hud is not None:
                    self.root_object_manager.hud.recolor_background()
            elif self.line[-2] == 's':
                if 'x' in (resolution := self.line[:-2]):
                    width, height = resolution.split('x')
                    width, height = int(width), int(height)
                    display.resize((width, height), self.root_object_manager,
                                   self.state_manager, ResizeAlert)
                else:
                    display.resize((480, 720), self.root_object_manager,
                                   self.state_manager, ResizeAlert)
            elif self.line[-2] == 'o':
                Timer.PLAY_SOUND = not Timer.PLAY_SOUND
                if Timer.PLAY_SOUND:
                    play_wav(Timer.END_SOUND)
            elif self.line.lower().startswith('uuddlrlrab'):
                self.state_manager.state = EasterEgg()

            self.line = ''
예제 #4
0
파일: main.py 프로젝트: chozabu/Neinjarz
 def handleEvent(self, event, cplayer):
     if event.type == pygame.QUIT:
         sys.exit()
     elif event.type == pgl.VIDEORESIZE:
         print(event.dict['size'])
         display.resize(event.dict['size'][0], event.dict['size'][1])
         pygame.display.flip()
     elif simplenet.isClient:
         ne = netevent()
         ne.type = event.type
         if event.type == 2 or event.type == 3:
             if event.key == pgl.K_ESCAPE:
                 sys.exit()
             ne.key = event.key
             simplenet.sendserv("event", ne)
         elif event.type == pgl.MOUSEMOTION:
             ne.pos = [event.pos[0], event.pos[1]]
             simplenet.sendserv("event", ne)
         elif event.type == pgl.MOUSEBUTTONDOWN:
             ne.button = event.button
             ne.pos = [event.pos[0], event.pos[1]]
             simplenet.sendserv("event", ne)
         elif event.type == pgl.MOUSEBUTTONUP:
             ne.button = event.button
             ne.pos = [event.pos[0], event.pos[1]]
             simplenet.sendserv("event", ne)
         return
     if event.type == 2:#keypress
         if event.key == pgl.K_DELETE:
             if len(self.walkers) > 0:self.walkers.remove(self.walkers[0])
         if event.key == pgl.K_w:
             #for i in range(0, len(self.walkers)):self.walkers[i].upkey = 1
             cplayer.upkey = 1
         if event.key == pgl.K_ESCAPE:
             sys.exit()
         if event.key == pgl.K_m:
             self.menu.runMenu()
         if event.key == pgl.K_s:
             cplayer.dnkey = 1
         if event.key == pgl.K_a:
             cplayer.ltkey = 1
         if event.key == pgl.K_d:
             cplayer.rtkey = 1
         if event.key == pgl.K_SPACE:
             cplayer.jumpkey = 1
         if event.key == pgl.K_LCTRL:
             cplayer.crouchkey = 1
         if event.key == pgl.K_v:
             cplayer.digkey = 1
         if event.key == pgl.K_q:
             cplayer.changegun(1)
         if event.key == pgl.K_e:
             cplayer.changegun(-1)
     if event.type == 3:#keyrelease
         if event.key == pgl.K_n:
             newplayer = player.playerclass(self.gamestate, "A Bot " + str(len(self.gamestate.clients)), None)
             newplayer.isbot = 1#int(random()*2)
             newplayer.jumpkey = int(random()*2)
             newplayer.x = cplayer.gmx
             newplayer.y = cplayer.gmy
             self.walkers.append(newplayer)
         if event.key == pgl.K_w:
             cplayer.upkey = 0
         if event.key == pgl.K_s:
             cplayer.dnkey = 0
         if event.key == pgl.K_a:
             cplayer.ltkey = 0
         if event.key == pgl.K_d:
             cplayer.rtkey = 0
         if event.key == pgl.K_SPACE:
             cplayer.jumpkey = 0
         if event.key == pgl.K_LCTRL:
             cplayer.crouchkey = 0
         if event.key == pgl.K_v:
             cplayer.digkey = 0
     if event.type == pgl.MOUSEMOTION or event.type == pgl.MOUSEBUTTONUP or event.type == pgl.MOUSEBUTTONDOWN:
         cplayer.msinx = event.pos[0]
         cplayer.msiny = event.pos[1]
     #print event.type
     if event.type == pgl.MOUSEBUTTONUP:
         if event.button == 1:
             cplayer.unshoot()#jumpkey = 1
         if event.button == 3:
             cplayer.altunshoot()#jumpkey = 1
     if event.type == pgl.MOUSEBUTTONDOWN:
         #print event.button
         if event.button == 4:
             cplayer.changegun(1)
         if event.button == 5:
             cplayer.changegun(-1)
         if event.button == 3:
             cplayer.altshoot()
             #terrain.explode(cplayer.gmx, cplayer.gmy, 90, 255)
         if event.button == 1:
             cplayer.shoot()#jumpkey = 1