コード例 #1
0
    def __init__(self, x_pos, y_pos):
        """ Initializes an EmptyCone object

            x_pos: the starting x-position of the cone
            y_pos: the starting y-position of the cone
        """
        Graphic.__init__(self)
        self.image, self.rect = load_image(os.path.join('assets', 'img', 'cone.png'), -1)
        self.rect.x = x_pos
        self.rect.y = y_pos
コード例 #2
0
ファイル: touhou_ui.py プロジェクト: anubiann00b/Touhou-SRPG
    def __init__(self, level):
        self.ui = UI()
        self.level = level
        self.map = level.map

        self.menus = {}
        self.data = UIData()

        self.left, self.middle, self.right = (0,0,0)

        hover_graphic = Graphic(GFX_TILE_HOVER, 0.5)

        self.hover_tile = MapGraphic(hover_graphic, (0,0), "hover")
        self.highlight = Highlight(hover_graphic)

        self.status_window = StatusWindow(self.level.creatures)
        self.status_window = GraphicAbsPositioned(self.status_window, (0,0))
        self.status_window.make_visible()

        # Status window drawn after sprites.
        self.ui.add(self.status_window)

        # Highlights drawn before sprites.
        self.ui.add_under(self.hover_tile)
        self.ui.add_under(self.highlight)

        #One menu showing at any time
        self.current_menu = None
        
        self.keybuffer = self.new_keybuffer()
        self.mouse_coords = (0,0)
        self.mouse_state = pygame.mouse.get_pressed()

        display = pygame.display.get_surface()
        self.h = display.get_height()
コード例 #3
0
 def load_graphics(self):
     self.ground_tile = Graphic(texture="./content/gfx/sprites/grass.png")
     self.setup_ground()
     for obj in self.obj_list:
         pos = self.obj_list[obj]
         animation = Animated("./content/gfx/sprites/" + obj + ".png",
                              "./content/metadata/" + obj + ".spr")
         self.place_object(animation, pos, obj)
コード例 #4
0
    def __init__(self, x_pos, y_pos):
        """ Initializes an IceCreamCone object

            scale: an int used to scale the width and height to control the size
            x_pos: the starting x-position of the cone
            y_pos: the starting y-position of the cone
        """
        Graphic.__init__(self)
        # Initialize our velocities to zero
        self.x_velocity = 0
        self.y_velocity = 0
        # Create a new sprite group to handle drawing all our sprites
        self.sprite_group = pygame.sprite.OrderedUpdates()
        # Create a new empty cone and add it to our sprite group
        self.cone = EmptyCone(x_pos, y_pos)
        self.sprite_group.add(self.cone)
        # Create a new list to keep track of the scoops on the cone
        self.scoops = list()
コード例 #5
0
    def __init__(self, x_pos, y_pos, kind=None):
        """ Initializes a new Scoop object at the given position and scale.

            rect.x: int - the x-coordinate of the top-left corner
            rect.y: int - the y-coordinate of the top-left corner
        """
        Graphic.__init__(self)

        types_of_cream = [
            'mint.png', 'scoop-white.png', 'pink.png', 'choc.png'
        ]

        if kind is None:
            self.kind = random.choice(types_of_cream)
        else:
            self.kind = kind
        self.image, self.rect = load_image(
            os.path.join('assets', 'img', 'scoops', self.kind), -1)

        self.rect.x = x_pos
        self.rect.y = y_pos
コード例 #6
0
ファイル: touhou_ui.py プロジェクト: anubiann00b/Touhou-SRPG
class HorizontalBar:
    """Bar that has a length that depends on the value, eg. a health bar"""
    def __init__(self, image, length=100.0):
        self.image = Graphic(image)
        self.base_length = float(length)
        self.image.w = self.base_length
        self.image.setup_draw()
        self.max_value = None

    def set_value(self, value, max_value):
        value = float(value)
        max_value = float(max_value)
        self.image.w = value/max_value * self.base_length
        self.image.setup_draw()

    def set_max(self, max_value):
        self.max_value = float(max_value)

    def draw(self):
        self.image.draw()
コード例 #7
0
 def __init__(self, y_velocity, max_wind_speed):
     Graphic.__init__(self)
     self.x_velocity = 0
     self.y_velocity = y_velocity
     self.max_wind_speed = max_wind_speed
コード例 #8
0
 def load_portraits(self):
     for c in self.creatures:
         self.creatures[c].portrait = Graphic("./content/gfx/sprites/" + c +
                                              ".png")
コード例 #9
0
ファイル: touhou_menu.py プロジェクト: JDShu/Touhou-SRPG
 def set_entry_hover_graphic(self, graphic):
     self.entry_hover_graphic = Graphic(graphic)
コード例 #10
0
ファイル: touhou_menu.py プロジェクト: JDShu/Touhou-SRPG
 def set_body_graphic(self, graphic):
     self.body_graphic = Graphic(graphic)
コード例 #11
0
ファイル: touhou_menu.py プロジェクト: JDShu/Touhou-SRPG
class Menu:
    def __init__(self, title, data=None):
        self.title = title
        self.data = data

        self.entries = []
        self.body_graphic = None
        self.entry_graphic = None
        self.entry_hover_graphic = None
        self.set_font("./content/font/free_sans.ttf", 12)
        self.header_height = 0
        self.entry_height = 0
        self.hovering = None
        self.pending = None

    def set_body_graphic(self, graphic):
        self.body_graphic = Graphic(graphic)

    def set_w(self, w):
        self.w = w
        if self.body_graphic:
            self.body_graphic.set_w(self.w)
        if self.entry_graphic:
            self.entry_graphic.set_w(self.w)
        if self.entry_hover_graphic:
            self.entry_hover_graphic.set_w(self.w)

    def set_header_height(self, h):
        self.header_height = h
        self.h = self.header_height + len(self.entries) * self.entry_height
        self.body_graphic.set_h(self.h)

    def set_entry_height(self, h):
        self.entry_height = h
        self.h = self.header_height + len(self.entries) * self.entry_height
        if self.entry_graphic:
            self.entry_graphic.set_h(self.entry_height)
        if self.entry_hover_graphic:
            self.entry_hover_graphic.set_h(self.entry_height)

    def add_entry(self, name, function):
        self.entries += [(name,function)]
        self.h = self.header_height + len(self.entries) * self.entry_height
        self.body_graphic.set_h(self.h)

    def set_entry_graphic(self, graphic):
        self.entry_graphic = Graphic(graphic)

    def set_entry_hover_graphic(self, graphic):
        self.entry_hover_graphic = Graphic(graphic)

    def set_font(self,font,size):
        self.font = glFreeType.font_data(font,size)

    def draw(self):
        glPushMatrix()
        glTranslate(0, -self.h,0) #check later
        if self.body_graphic:
            self.body_graphic.draw()
        for index, entry in enumerate(self.entries):
            if self.hovering == index:
                if self.entry_hover_graphic:
                    self.entry_hover_graphic.draw()
            else:
                if self.entry_graphic:
                    self.entry_graphic.draw()
            glPushMatrix()
            glTranslate(0,self.font.m_font_height/2.0,0)
            self.print_text(entry[0])
            glPopMatrix()
            glTranslate(0, self.entry_height,0)

        self.print_text(self.title)

        glPopMatrix()

    def print_text(self, text):
        self.font.glPrint(0,0,text)

    def update(self, mouse_coords):
        x,y = mouse_coords
        if x < 0 or x > self.w or y >= -self.header_height or y <= -self.h:
            self.hovering = None
        else:
            self.hovering = len(self.entries) - (-y/self.entry_height)

    # figure out which entry will be executed upon mouse release
    def log_pending(self):
        self.pending = self.hovering

    def clear_pending(self):
        self.pending = None

    def execute_entry(self):
        if self.pending != None and self.hovering != None:
            f = self.entries[self.hovering][1]
            f()
コード例 #12
0
 def set_entry_hover_graphic(self, graphic):
     self.entry_hover_graphic = Graphic(graphic)
コード例 #13
0
 def set_body_graphic(self, graphic):
     self.body_graphic = Graphic(graphic)
コード例 #14
0
class Menu:
    def __init__(self, title, data=None):
        self.title = title
        self.data = data

        self.entries = []
        self.body_graphic = None
        self.entry_graphic = None
        self.entry_hover_graphic = None
        self.set_font("./content/font/free_sans.ttf", 12)
        self.header_height = 0
        self.entry_height = 0
        self.hovering = None
        self.pending = None

    def set_body_graphic(self, graphic):
        self.body_graphic = Graphic(graphic)

    def set_w(self, w):
        self.w = w
        if self.body_graphic:
            self.body_graphic.set_w(self.w)
        if self.entry_graphic:
            self.entry_graphic.set_w(self.w)
        if self.entry_hover_graphic:
            self.entry_hover_graphic.set_w(self.w)

    def set_header_height(self, h):
        self.header_height = h
        self.h = self.header_height + len(self.entries) * self.entry_height
        self.body_graphic.set_h(self.h)

    def set_entry_height(self, h):
        self.entry_height = h
        self.h = self.header_height + len(self.entries) * self.entry_height
        if self.entry_graphic:
            self.entry_graphic.set_h(self.entry_height)
        if self.entry_hover_graphic:
            self.entry_hover_graphic.set_h(self.entry_height)

    def add_entry(self, name, function):
        self.entries += [(name, function)]
        self.h = self.header_height + len(self.entries) * self.entry_height
        self.body_graphic.set_h(self.h)

    def set_entry_graphic(self, graphic):
        self.entry_graphic = Graphic(graphic)

    def set_entry_hover_graphic(self, graphic):
        self.entry_hover_graphic = Graphic(graphic)

    def set_font(self, font, size):
        self.font = glFreeType.font_data(font, size)

    def draw(self):
        glPushMatrix()
        glTranslate(0, -self.h, 0)  #check later
        if self.body_graphic:
            self.body_graphic.draw()
        for index, entry in enumerate(self.entries):
            if self.hovering == index:
                if self.entry_hover_graphic:
                    self.entry_hover_graphic.draw()
            else:
                if self.entry_graphic:
                    self.entry_graphic.draw()
            glPushMatrix()
            glTranslate(0, self.font.m_font_height / 2.0, 0)
            self.print_text(entry[0])
            glPopMatrix()
            glTranslate(0, self.entry_height, 0)

        self.print_text(self.title)

        glPopMatrix()

    def print_text(self, text):
        self.font.glPrint(0, 0, text)

    def update(self, mouse_coords):
        x, y = mouse_coords
        if x < 0 or x > self.w or y >= -self.header_height or y <= -self.h:
            self.hovering = None
        else:
            self.hovering = len(self.entries) - (-y / self.entry_height)

    # figure out which entry will be executed upon mouse release
    def log_pending(self):
        self.pending = self.hovering

    def clear_pending(self):
        self.pending = None

    def execute_entry(self):
        if self.pending != None and self.hovering != None:
            f = self.entries[self.hovering][1]
            f()
コード例 #15
0
ファイル: touhou_ui.py プロジェクト: anubiann00b/Touhou-SRPG
 def __init__(self, image, length=100.0):
     self.image = Graphic(image)
     self.base_length = float(length)
     self.image.w = self.base_length
     self.image.setup_draw()
     self.max_value = None
コード例 #16
0
ファイル: touhou_ui.py プロジェクト: anubiann00b/Touhou-SRPG
 def setup_portraits(self):
     for c in self.table:
         self.portrait_list[c] = Graphic("./content/gfx/sprites/"+c+"_portrait.png")