示例#1
0
 def events(self):
     for event in pygame.event.get():
         joystick.Update(event)
         click = False
         if event.type == pygame.QUIT:
             confirmExit(self.Display, self.profile, self.profile_number)
         if event.type == pygame.MOUSEBUTTONDOWN and not self.focused in ("theSun", None):
             planet = self.planets[self.focused]
             rect = pygame.Rect((0, 0), (205, 50))
             rect.midtop = planet.center[1][0], planet.center[1][1] + 35
             if rect.collidepoint(pygame.mouse.get_pos()):
                 click = True
         if event.type == pygame.MOUSEBUTTONDOWN:
             self.start_click = pygame.math.Vector2(pygame.mouse.get_pos())
             self.last_sample = copy.copy(self.start_click)
             if pygame.Rect(0, 0, 32, 32).collidepoint(pygame.mouse.get_pos()):
                 self.done = True
             rect = pygame.Rect(0, 0, 32, 32)
             rect.midright = self.Display.get_rect().midright
             if rect.collidepoint(pygame.mouse.get_pos()):
                 for e, p in enumerate(self.planets):
                     if p.name == "Earth":
                         self.focused = e
         if event.type == pygame.MOUSEBUTTONUP:
             self.start_click = None
         if event.type == pygame.KEYDOWN or joystick.WasEvent():
             if not hasattr(event, 'key'):
                 event.key = None
             if event.key == pygame.K_ESCAPE or joystick.BackEvent():
                 self.done = True
             if event.key == pygame.K_RETURN or event.key == pygame.K_SPACE or joystick.GoEvent():
                 click = True
             if event.key == pygame.K_LEFT or joystick.JustWentLeft():
                 self.speed -= .1
                 if self.speed <= 0.2:
                     self.speed = 0.2
             if event.key == pygame.K_RIGHT or joystick.JustWentRight():
                 self.speed += .1
                 if self.speed > 2:
                     self.speed = 2
             if event.key == pygame.K_F2 or joystick.JustPressedLB():
                 screenshot.capture(self.profile_number, self.Display)
             if event.key == pygame.K_COMMA or joystick.JustPressedLT():
                 if self.focused == None:
                     self.focused = 0
                 self.focused = (self.focused + 1) % len(self.planets)
                 self.target_zoom = 1.5
             if event.key == pygame.K_PERIOD or joystick.JustPressedRT():
                 if self.focused == None:
                     self.focused = 0
                 self.focused = (self.focused - 1) % len(self.planets)
                 self.target_zoom = 1.5
         if event.type == pygame.MOUSEMOTION:
             self.mouse_on = True
         if event.type == pygame.MOUSEBUTTONUP:
             pos = pygame.mouse.get_pos()
             nto = self.target_offset[:]
             if event.button == 5:
                 self.target_zoom -= self.zoom_amount
                 nto[0] -= (pos[0] - self.Display.get_width() / 2) / 10
                 nto[1] -= (pos[1] - self.Display.get_height() / 2) / 10
             if event.button == 4:
                 self.target_zoom += self.zoom_amount
                 nto[0] += (pos[0] - self.Display.get_width() / 2) / 10
                 nto[1] += (pos[1] - self.Display.get_height() / 2) / 10
             if self.target_zoom < .5:
                self.target_zoom = .5
             elif self.target_zoom > 2:
                 self.target_zoom = 2
             else:
                 self.target_offset = nto
         if not self.focused in ("theSun", None) and self.zoom >= 1.25 and click and self.planets[self.focused] in self.unlocked_planets:
             self.profile["planet"] = self.planets[self.focused]
             self.done = True
示例#2
0
    def events(self):
        for event in pygame.event.get():
            joystick.Update(event)
            click = False
            if event.type == pygame.QUIT:
                confirmExit(self.display, self.profile, self.profile_number)
                self.pause_time = True
            if event.type == pygame.MOUSEBUTTONDOWN:
                sel = self.selected_point
                rect = pygame.Rect((0, 0), (220, 50))
                rect.midtop = self.map[sel].pos[0], self.map[sel].pos[1] + 35
                backrect = pygame.Rect(0, 0, 32, 32)
                if rect.collidepoint(pygame.mouse.get_pos()):
                    click = True
                elif backrect.collidepoint(pygame.mouse.get_pos()):
                    self.toMenu = True
                    self.done = True
                self.click = True
            if not hasattr(event, "key"):
                event.key = None
            if event.type == pygame.KEYDOWN or joystick.WasEvent():
                if event.key == pygame.K_F2 or joystick.JustPressedLB():
                    screenshot.capture(self.profile_number, self.display)
                    self.pause_time = True
                if event.key == pygame.K_RETURN or event.key == pygame.K_SPACE or joystick.GoEvent():
                    click = True
                if event.key == pygame.K_ESCAPE or joystick.BackEvent():
                    tmm = pause_menu(self.display, self.images, self.profile, self.profile_number)
                    self.pause_time = True
                    if tmm:
                        self.toMenu = True
                        self.done = True
            if event.type == pygame.KEYUP or joystick.WasEvent():
                tabbed = False
                sel = self.selected_point
                if (event.key == pygame.K_TAB) and not self.map[self.selected_point].alien_flag:
                    sel += 1
                    tabbed = True
                FB = self.GoForwardOrBack(event)
                if (FB):
                    sel += 1
                if (FB == False):
                    sel -= 1
#                if (event.key == pygame.K_LEFT or joystick.JustWentLeft()):
#                    sel -= 1
#                if (event.key == pygame.K_RIGHT or joystick.JustWentRight()) and not self.map[self.selected_point].alien_flag:
#                    sel += 1
                if (event.key == pygame.K_END or joystick.JustPressedRT()):
                    self.waypoints = []
                    x = 0
                    for x in range(self.selected_point, len(self.map)):
                        self.waypoints.append(x)
                        if self.map[x].alien_flag:
                            break
                    sel = x
                    if self.waypoints:
                        self.target_pos = self.get_point(self.waypoints[0])
                        self.changed = True
                if (event.key == pygame.K_HOME or joystick.JustPressedLT()):
                    self.waypoints = []
                    x = 0
                    for x in reversed(range(self.selected_point)):
                        self.waypoints.append(x)
                        if self.map[x].alien_flag:
                            break
                    sel = x
                    if self.waypoints:
                        self.target_pos = self.get_point(self.waypoints[0])
                        self.changed = True
                self.selected_point = sel
                if self.target_pos != self.avatar_pos:
                    self.waypoints.append(sel)
                if self.selected_point < 0:
                    self.selected_point = 0
                yes = False
                if self.waypoints:
                    if self.waypoints[-1] >= len(self.map):
                        yes = True
                if self.selected_point >= len(self.map) or yes:
                    if yes:
                        self.waypoints[-1] = len(self.map) - 1
                    if tabbed and not yes:
                        self.selected_point = 0
                        self.waypoints += list(reversed(range(len(self.map))))
                        for x in reversed(range(len(self.map))):
                            if x > 0:
                                if self.map[x - 1].alien_flag:
                                    break
                            self.waypoints.append(x)
                    else:
                        self.selected_point = len(self.map) - 1
            if self.target_pos == self.avatar_pos and click:
                t = self.map[self.selected_point].type
                if t == "spaceport":
                    spacemap = SpaceMap(self.images, self.display, self.profile, self.profile_number, focus = self.planet.name)
                    transition(self.display, 5)
                    self.profile = spacemap.main()
                    self.__init__(self.images, self.display, self.profile, self.profile_number)
                if t == "mission":
                    self.done = True
                if t == "store":
                    sel1 = self.selected_point
                    store = StoreUI(self.display, self.images, self.profile, self.profile_number, self.map[self.selected_point])
                    if store.main():
                        self.waypoints = []
                        self.target_pos = self.get_point(0)
                        self.changed = True
                        self.avatar_pos = self.get_point(0)
                        self.set_velocity()
                        self.selected_point = 0
示例#3
0
 def events(self):
     for event in pygame.event.get():
         joystick.Update(event)
         cat = self.catagories[self.rect_sel]
         click = False
         if not hasattr(event, 'key'):
             event.key = None
         if event.type == pygame.QUIT:
             #                self.confirmExit()
             self.done = True
         if event.type == pygame.KEYUP or joystick.WasEvent():
             if (event.key == pygame.K_y
                     or joystick.JustPressedY()) and cat:
                 selected = list(cat.keys())[self.sel_num[self.rect_sel]]
                 display_info(self.display, self.images, selected)
         if event.type == pygame.KEYDOWN or joystick.WasEvent():
             jwu = joystick.JustWentUp() or event.key in (pygame.K_w,
                                                          pygame.K_UP)
             jwd = joystick.JustWentDown() or event.key in (pygame.K_s,
                                                            pygame.K_DOWN)
             mod_sel = False
             if jwu or jwd:
                 sel = self.sel_num[self.rect_sel]
                 new_sel = copy(sel)
                 if jwd and sel + MAX_STORE_ITEM_LENGTH < len(cat):
                     mod_sel = True
                     new_sel += MAX_STORE_ITEM_LENGTH
                 if jwu and sel - MAX_STORE_ITEM_LENGTH >= 0:
                     mod_sel = True
                     new_sel -= MAX_STORE_ITEM_LENGTH
                 if mod_sel:
                     self.sel_num[self.rect_sel] = new_sel
             if event.key == pygame.K_ESCAPE or joystick.BackEvent():
                 self.done = True
             if (jwu and not mod_sel) or joystick.JustPressedLT(
             ) or event.key == pygame.K_PAGEUP:
                 self.rect_sel -= 1
             if (jwd and not mod_sel) or joystick.JustPressedRT(
             ) or event.key == pygame.K_PAGEDOWN:
                 self.rect_sel += 1
             if self.rect_sel < 0:
                 self.rect_sel = 0
             if self.rect_sel >= len(self.rects):
                 self.rect_sel = len(self.rects) - 1
             cat = self.catagories[
                 self.rect_sel]  # REMEMBER: this line must be here!!!
             if event.key in (pygame.K_a,
                              pygame.K_LEFT) or joystick.JustWentLeft():
                 self.sel_num[self.rect_sel] -= 1
             if event.key in (pygame.K_d,
                              pygame.K_RIGHT) or joystick.JustWentRight():
                 self.sel_num[self.rect_sel] += 1
             if self.sel_num[self.rect_sel] < 0:
                 self.sel_num[self.rect_sel] = 0
             if self.sel_num[self.rect_sel] >= len(cat):
                 self.sel_num[self.rect_sel] = len(cat) - 1
             if event.key == pygame.K_RETURN or joystick.JustPressedA():
                 click = True
         if event.type == pygame.MOUSEBUTTONDOWN:
             if self.purchase_rect.collidepoint(pygame.mouse.get_pos()):
                 click = True
             if self.exit_rect.collidepoint(pygame.mouse.get_pos()):
                 self.done = True
         if click:
             self.purchase()