コード例 #1
0
ファイル: tooltip.py プロジェクト: bojkott/GymnasieArbete
 def __init__(self, world):
     self.world = world
     self.rect = pygame.Rect((0, 0), (2, 2)).copy()
     self.color = (255, 0, 0)
     self.in_map = True
     self.image = pygame.Surface((32, 32), pygame.SRCALPHA, 32)
     self.image.convert_alpha()
     self.offset = pygame.Rect(0, 0, 0, 0)
     register_handler([pygame.MOUSEMOTION, TIME_PASSED], self.handle_event)
コード例 #2
0
ファイル: char_stat.py プロジェクト: bojkott/GymnasieArbete
 def __init__(self, current, max, info, color, pos):
     self.info = info
     self.current = current
     self.max = max
     self.color = color
     self.info = info
     self.hovering = ALWAYS_SHOW_STATS
     self.image = pygame.Surface((176, 16))
     self.rect = self.image.get_rect()
     self.rect.x = pos[0]
     self.rect.y = pos[1]
     self.image.fill((84, 84, 84))
     width = int((self.current / self.max) * self.image.get_width())
     self.image.fill(color,
                     rect=pygame.Rect((0, 0),
                                      (width, self.image.get_height())))
     self.image.blit(
         render_textrect(str(info), 50, self.rect, (255, 255, 255)), (3, 0))
     self.text = '{0}/{1}'.format(self.current, self.max)
     if self.hovering:
         self.image.blit(
             render_textrect(
                 self.text,
                 50,
                 self.rect,
                 (255, 255, 255),
                 None,
                 1,
             ), (0, 0))
コード例 #3
0
ファイル: char_stat.py プロジェクト: bojkott/GymnasieArbete
 def __init__(self, world):
     self.width = 180
     self.height = 95
     Gui.__init__(
         self, 'character', (0, 200),
         pygame.Surface((self.width, self.height), pygame.SRCALPHA, 32),
         True)
     self.image.convert_alpha()
     self.player_image = world.player.image.copy()
     self.time_passed = 0.0
     self.player_image = pygame.transform.scale(
         self.player_image, (self.player_image.get_width() / 2,
                             self.player_image.get_height() / 2))
     self.name = render_textrect(world.player.name, 30,
                                 self.image.get_rect(), (255, 255, 255))
     self.time_passed_text = render_textrect(self.time_passed, 30,
                                             pygame.Rect(0, 0, 30, 30),
                                             (255, 255, 255), (54, 54, 54))
     self.exp = Bar(world.player.exp, world.player.stats['EXP'],
                    'Lvl {0}'.format(world.player.lvl), (50, 255, 10),
                    (5, 20))
     self.hp = Bar(world.player.hp, world.player.stats['HP'], 'HP',
                   (224, 52, 52), (5, 45))
     self.mp = Bar(world.player.mp, world.player.stats['MP'], 'MP',
                   (96, 132, 224), (5, 70))
     register_handler(TIME_PASSED, self.handle_event)
コード例 #4
0
    def __init__(self):
        self.width = WIDTH
        self.height = HEIGHT
        #self.logo = render_textrect('Dungeon of Doom (Alpha)', 30, self.logo_rect, (255, 255, 0), None, 1)
        self.main_bg = pygame.image.load('../res/gui/main_menu_bg.png')
        self.main_bg = pygame.transform.scale(self.main_bg, (self.width, self.height))
        Gui.__init__(self, 'menu', (0, 0), pygame.Surface((self.width, self.height)), True)
        self.main = True
        register_handler([MENU_NEW_GAME, MENU_CLASS_SELECT, MENU_ENTER_NAME, MENU_QUIT_GAME, pygame.MOUSEBUTTONDOWN],
                         self.handle_event)

        self.buttons = [
            Button('New game', MENU_NEW_GAME, pygame.Rect((self.width / 2 - 100, self.height / 2 - 40), (200, 50))),
            Button('Load game', MENU_NEW_GAME, pygame.Rect((self.width / 2 - 100, self.height / 2), (200, 50))),
            Button('Quit', MENU_QUIT_GAME, pygame.Rect((self.width / 2 - 100, self.height / 2 + 40), (200, 50)))
        ]
コード例 #5
0
ファイル: map_loader.py プロジェクト: bojkott/GymnasieArbete
 def draw(self, surface, offset, explored_tiles=None):
     for row in self.tiles:
         for tile in row:
             x = tile.x - offset.x
             y = tile.y - offset.y
             tile_img = tile.image
             if not self.minimap:
                 if -1 < x < offset.w and -1 < y < offset.h:
                     if explored_tiles:
                         if explored_tiles[tile.y / tile.h][tile.x /
                                                            tile.w] == 0:
                             surface.blit(tile_img, (x, y))
                             surface.blit(self.shadow_tile, (x, y))
                         elif explored_tiles[tile.y / tile.h][tile.x /
                                                              tile.w] == 1:
                             surface.blit(tile_img, (x, y))
                             if tile.feet:
                                 surface.blit(tile.feet, (x, y))
                         else:
                             pygame.draw.rect(surface, (0, 0, 0),
                                              pygame.Rect(x, y, 32, 32))
                     else:
                         surface.blit(tile_img, (x, y))
                     if tile.feet and tile.id == 15:
                         surface.blit(tile.feet, (x, y))
             else:
                 if explored_tiles:
                     if explored_tiles[tile.y / tile.h][tile.x /
                                                        tile.w] in [1, 0]:
                         surface.blit(tile_img, (x, y))
                 else:
                     surface.blit(tile_img, (x, y))
コード例 #6
0
ファイル: char_stat.py プロジェクト: bojkott/GymnasieArbete
 def handle_event(self, event):
     etype = get_event_type(event)
     if etype == TIME_PASSED:
         self.time_passed += event.amount
         self.time_passed_text = render_textrect(self.time_passed, 30,
                                                 pygame.Rect(0, 0, 100, 30),
                                                 (255, 255, 255),
                                                 (54, 54, 54))
コード例 #7
0
 def get_gui(self, mouse):
     if mouse.colliderect(
             pygame.Rect(self.char_stat.x, self.char_stat.y,
                         self.char_stat.width, self.char_stat.height)):
         return self.char_stat
     elif mouse.colliderect(
             pygame.Rect(self.minimap.x, self.minimap.y, self.minimap.width,
                         self.minimap.height)):
         return self.minimap
     elif mouse.colliderect(
             pygame.Rect(self.explorer.x, self.explorer.y,
                         self.explorer.width, self.explorer.height)):
         return self.explorer
     elif mouse.colliderect(
             pygame.Rect(self.inventory.x, self.inventory.y,
                         self.inventory.width, self.inventory.height)):
         return self.inventory
コード例 #8
0
ファイル: console.py プロジェクト: bojkott/GymnasieArbete
 def handle_event(self, event):
     etype = event.type if event.type != pygame.USEREVENT else event.event_type
     if etype == POST_TO_CONSOLE:
         rect = pygame.Rect((5, 5), (self.width, 15))
         color = event.color if hasattr(event, 'color') else (255, 255, 255)
         self.log_processed.append(Text(rect, event.msg, color))
         if len(self.log_processed) > 7:
             self.log_processed = self.log_processed[-7:]
コード例 #9
0
 def __init__(self, x, y, object=None):
     self.object = object
     self.type = 'inventory'
     if object:
         self.image = object
     else:
         self.image = pygame.Surface((32, 32))
     self.x = x
     self.y = y
     self.rect = pygame.Rect(x, y, 32, 32)
コード例 #10
0
ファイル: tooltip.py プロジェクト: bojkott/GymnasieArbete
 def update_data(self):
     self.show_window = False
     self.image = pygame.Surface((200, 100), pygame.SRCALPHA, 32)
     i = 0
     for key, event in self.options.items():
         string = "{0}: {1}".format(key, event[0])
         rect = pygame.Rect((0, 15 * i), (len(string) * 7, 15))
         i += 1
         self.image.blit(
             render_textrect(string, 15, rect, (128, 128, 128), (0, 0, 0)),
             (rect.x, rect.y))
コード例 #11
0
 def __init__(self, world):
     self.rect = pygame.Rect((WIDTH - MENU_WIDTH, 0), (MENU_WIDTH, HEIGHT))
     self.bg = pygame.Surface((self.rect.w, self.rect.h))
     self.char_stat = CharStats(world)
     self.minimap = MiniMap(world)
     self.explorer = Explorer()
     self.inventory = InventoryGui()
     register_handler(
         [pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP, pygame.MOUSEMOTION],
         self.handle_event)
     self.held_item = None
コード例 #12
0
 def redraw(self):
     self.image.fill((0, 0, 0))
     x = self.world.player.x * self.tile_size
     y = self.world.player.y * self.tile_size
     self.camera.center = (x, y)
     self.map.load_dungeon(self.world.map.dungeon, True, self.tile_size)
     self.map.draw(self.image, self.camera, self.world.map.explored_tiles)
     self.image.fill((0, 255, 0), pygame.Rect((x - self.camera.x, y - self.camera.y),
                                              (self.tile_size, self.tile_size)))
     self.zoom_in_arrow.create()
     self.zoom_out_arrow.create()
     self.image.blit(self.zoom_in_arrow.arrow, (self.zoom_in_arrow.rect.x, self.zoom_in_arrow.rect.y))
     self.image.blit(self.zoom_out_arrow.arrow, (self.zoom_out_arrow.rect.x, self.zoom_out_arrow.rect.y))
コード例 #13
0
    def __init__(self):
        self.width = MENU_WIDTH
        self.height = 80

        Gui.__init__(self, 'inventory', (30, 300),
                     pygame.Surface((self.width, self.height), pygame.SRCALPHA, 32).convert_alpha(), False)
        self.slots = []
        self.slots_rect = []
        for y in range(0, 2):
            for x in range(0, 4):
                self.slots_rect.append(pygame.Rect(5 + x * 35, 5 + y * 35, 32, 32))
                self.slots.append(Slot(5 + x * 35, 5 + y * 35))
        register_handler(PLAYER_PICKUP_ITEM, self.handle_event)
コード例 #14
0
    def handle_event(self, event):
        etype = get_event_type(event)
        if self.active:
            if etype == pygame.MOUSEBUTTONDOWN and event.button == 1:
                mouse_rect = pygame.Rect(event.pos, (2, 2))
                for button in self.buttons:
                    if mouse_rect.colliderect(button.rect):
                        button.onclick()

            elif etype == MENU_NEW_GAME:
                self.main = False
                self.active = False
            elif etype == MENU_QUIT_GAME:
                pygame.event.post(pygame.event.Event(pygame.QUIT))
コード例 #15
0
    def __init__(self, world):
        self.world = world
        self.tile_size = 6
        self.width = 192
        self.height = 192
        self.camera = pygame.Rect((0, 0), (self.width, self.height)).copy()
        self.map = Map()
        self.map.load_dungeon(world.map.dungeon, True, self.tile_size)
        self.zoom_in_arrow = ZoomArrow(0, (174, 10))
        self.zoom_in_arrow.create()
        self.zoom_out_arrow = ZoomArrow(1, (174, 20))
        self.zoom_out_arrow.create()

        Gui.__init__(self, 'minimap', (4, 4), pygame.Surface((self.width, self.height)), True)
        x = self.world.player.x * self.tile_size
        y = self.world.player.y * self.tile_size
        self.camera.center = (x, y)
        self.map.draw(self.image, self.camera, self.world.map.explored_tiles)
        self.image.fill((0, 255, 0), pygame.Rect((x - self.camera.x, y - self.camera.y),
                                                 (self.tile_size, self.tile_size)))
        self.image.blit(self.zoom_in_arrow.arrow, (self.zoom_in_arrow.rect.x, self.zoom_in_arrow.rect.y))
        self.image.blit(self.zoom_out_arrow.arrow, (self.zoom_out_arrow.rect.x, self.zoom_out_arrow.rect.y))

        register_handler([TIME_PASSED, pygame.MOUSEBUTTONDOWN], self.handle_event)
コード例 #16
0
ファイル: map_loader.py プロジェクト: bojkott/GymnasieArbete
    def __init__(self, x, y, w, h, tile_id):
        self.x = x
        self.y = y
        self.w = w
        self.h = h
        self.dirs = [
            0, 0
        ]  # Each index of dir is able to be in 8 directions. 0 being up and 7 being left-up
        self.rect = pygame.Rect(self.x, self.y, self.w, self.h)

        self.image = pygame.surface.Surface((self.w, self.h), pygame.SRCALPHA,
                                            32)

        self.anim = None
        self.id = tile_id
        self.load_image()
コード例 #17
0
ファイル: get_sprite.py プロジェクト: bojkott/GymnasieArbete
def get_item_sprite(sheet, id='rand'):
    items = pygame.image.load(
        "../res/spritesheets/items/{0}.png".format(sheet))
    spritesheet_width = items.get_width()
    spritesheet_height = items.get_height()
    if id == 'rand':
        max = (spritesheet_width * spritesheet_height) / 32
        id = random.randint(max)
    x = id * 32 % spritesheet_width
    y = int(id * 32 / spritesheet_width)
    y *= 32
    if y > spritesheet_height:
        print("Cant find given item image")
        return None
    rect = pygame.Rect((x, y), (32, 32))
    image = pygame.Surface((32, 32))
    image.blit(items, (0, 0), rect)
    return image
コード例 #18
0
ファイル: char_stat.py プロジェクト: bojkott/GymnasieArbete
 def refresh(self):
     self.image.fill((84, 84, 84))
     width = int((self.current / self.max) * self.image.get_width())
     self.image.fill(self.color,
                     rect=pygame.Rect((0, 0),
                                      (width, self.image.get_height())))
     self.image.blit(
         render_textrect(str(self.info), 50, self.rect, (255, 255, 255)),
         (3, 0))
     self.text = '{0}/{1}'.format(self.current, self.max)
     if self.hovering:
         self.image.blit(
             render_textrect(
                 self.text,
                 50,
                 self.rect,
                 (255, 255, 255),
                 None,
                 1,
             ), (0, 0))
コード例 #19
0
ファイル: map_loader.py プロジェクト: bojkott/GymnasieArbete
    def __init__(self, x, y, w, h, tile_id):

        self.x = x
        self.y = y
        self.w = w
        self.h = h
        self.rect = pygame.Rect(self.x, self.y, self.w, self.h)
        self.image = pygame.surface.Surface((self.w, self.h), pygame.SRCALPHA,
                                            32)
        self.image.convert_alpha()

        self.id = tile_id
        if self.id == 1 or self.id == 11 or self.id == 7:
            self.image.fill((40, 40, 40))
        elif self.id in [2, 3, 4, 5, 6]:
            self.image.fill((20, 20, 20))
        elif self.id == 8:
            self.image.fill((75, 75, 75))
        elif self.id == 9:
            self.image.fill((255, 10, 10))
コード例 #20
0
 def __init__(self, x, y, contains=None):
     self.x = x
     self.y = y
     self.rect = pygame.Rect((self.x, self.y), (32, 32))
     self.containts = contains
コード例 #21
0
 def getRect(self):
     # Returns a pygame.Rect object for this animation object.
     # The top and left will be set to 0, 0, and the width and height
     # will be set to what is returned by getMaxSize().
     maxWidth, maxHeight = self.getMaxSize()
     return pygame.Rect(0, 0, maxWidth, maxHeight)
コード例 #22
0
    def handle_event(self, event):
        mouse_rect = pygame.Rect(event.pos, (2, 2)).copy()
        mouse_rect.x -= self.rect.x + 3
        mouse_rect.y -= self.rect.y + 26
        slot = None
        gui = self.get_gui(mouse_rect)

        if gui == self.char_stat:
            self.char_stat.mouse(mouse_rect, event)
        elif gui == self.minimap:
            self.minimap.mouse(mouse_rect, event)
        elif gui == self.explorer:
            self.explorer.mouse(mouse_rect, event)
            slot = self.explorer.get_slot(mouse_rect)
            if event.type == pygame.MOUSEBUTTONUP and self.held_item:
                if slot and not slot.object:
                    if self.held_item.type == 'inventory':
                        post_event(GUI_EXPLORER_CLEAR)
                        post_event(PLAYER_DROP_ITEM,
                                   target=self.held_item.object)
                    elif self.held_item.type == 'explorer':
                        slot.object = self.held_item.object
        else:
            post_event(GUI_EXAMINE_ITEM_CLEAR)

        if gui == self.inventory:
            self.inventory.mouse(mouse_rect, event)
            slot = self.inventory.get_slot(mouse_rect)
            if event.type == pygame.MOUSEBUTTONUP and self.held_item:
                if slot and not slot.object:
                    if self.held_item.type == 'explorer':
                        post_event(PLAYER_PICKUP_ITEM,
                                   target=self.held_item.object,
                                   slot=slot)
                    elif self.held_item.type == 'inventory':
                        slot.object = self.held_item.object

        if event.type == pygame.MOUSEBUTTONDOWN:
            if slot and slot.object:
                self.held_item = copy.copy(slot)
                slot.object = None
                pygame.mouse.set_visible(False)
                slot.image = pygame.Surface((32, 32))
                post_event(GUI_EXAMINE_ITEM_CLEAR)

        if event.type == pygame.MOUSEBUTTONUP:
            if self.held_item:
                if not slot:
                    if self.held_item.type == 'inventory':
                        if mouse_rect.x < 0:
                            post_event(PLAYER_DROP_ITEM,
                                       target=self.held_item.object)
                        else:
                            self.inventory.slots[
                                self.inventory.slots_rect.index(
                                    self.held_item.rect
                                )].object = self.held_item.object
                    elif self.held_item.type == 'explorer':
                        self.explorer.slots[self.explorer.slots_rect.index(
                            self.held_item.rect
                        )].object = self.held_item.object
                self.held_item = None
            pygame.mouse.set_visible(True)