Beispiel #1
0
    def draw(self):
        """
        Method called each frame to (re)draw UI
        :return:
        """
        self.screen.blit(Assets.background, (0, 0))
        self.screen.blit(self.title, (LEVEL_WIDTH / 2 - self.title.get_rect().width / 2, 30))

        o_max_width = max([option.get_rect().width for option in self.menu_options])
        width = o_max_width + MENU_PADDING[0] * 2
        height = self.menu_options[0].get_rect().height + MENU_PADDING[1] * 2
        x = LEVEL_WIDTH / 2 - width / 2
        y = LEVEL_HEIGHT / 2 - (height * len(self.menu_options)) / 2
        counter = 0
        for option in self.menu_options:
            if counter == self.menu_option:
                used_color = MENU_COLORS[1]
            else:
                used_color = MENU_COLORS[0]
            draw.rect(self.screen, used_color, (x, y + counter * height, width, height), 0)
            option_x = x + MENU_PADDING[0] + (o_max_width - option.get_rect().width) / 2
            self.screen.blit(option, (option_x, y + height * counter + MENU_PADDING[1]))
            counter += 1

        authors_rect = self.authors.get_rect()
        self.screen.blit(self.authors, (LEVEL_WIDTH - authors_rect.width,
                                        LEVEL_HEIGHT - authors_rect.height))
Beispiel #2
0
    def activate(self):
        xsize = 300
        ysize = 70
        bkg = Surface((xsize, ysize))
        bkg.lock()
        bkg.fill((128,128,128))
        for i in range(1, 4):
            draw.rect(bkg,(i*32,i*32,i*32),(4-i,4-i,xsize+(i-4)*2,ysize+(i-4)*2),3)

        corner = (64,64,64)
        bkg.set_at((0,0), corner)
        bkg.set_at((xsize,0), corner)
        bkg.set_at((xsize,ysize), corner)
        bkg.set_at((0,ysize), corner)

        bkg.unlock()

        bkg.set_alpha(64)

        self.bkg = bkg

        if self.title != None:
            banner = OutlineTextBanner(self.title, (200,200,200), 20)
            self.title_image = banner.render()
            self.title_image.set_alpha(96)

        self.arrow = res.loadImage("wait_arrow.png", colorkey=1)
Beispiel #3
0
 def show(self, screen):
     W, H = self.wc, self.hc
     sx , sy = self.sx, self.sy
     #Print background cells
     for cell in self.cases:
         screen.blit(cell.background.surf, cell.background.pos)
     #Generates lines of walls
     for y in range(self.h - 1):
         for x in range(self.w - 1):
             c = self.get_cell(x, y)
             
             if c.gate[const.right]:
                 draw.line(screen, const.gray, (sx + ((x + 1) * W), (sy + (y * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 3)
             if c.gate[const.down]:
                 draw.line(screen, const.gray, ((sx + (x * W)), (sy + ((y+1) * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 3)
                                  
     x = self.w - 1
     #Creates walls from buttom to top
     for y in range(self.h - 1):
         c = self.get_cell(x, y)
         
         if c.gate[const.down]:
             draw.line(screen, const.gray, ((sx + (x * W)), (sy + ((y+1) * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 3)
             
     y = self.h - 1
     #Creates walls from left to right
     for x in range(self.w - 1):
         c = self.get_cell(x, y)
         
         if c.gate[const.right]:
             draw.line(screen, const.gray, (sx + ((x + 1) * W), (sy + (y * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 3)
             
     #Draws outline
     draw.rect(screen, const.gray, (sx, sy, W * self.w, H * self.h), 3)
Beispiel #4
0
    def draw(self, surf):
        if self.visible:
            if not self.enabled:
                suffix = '-disabled'
            elif self.mousedown:
                suffix = "-down"
            elif self.mouseover:
                suffix = "-over"
            else:
                suffix = "-normal"

            if self.value:
                prefix = "checked"
            else:
                prefix = "unchecked"

            centerPoint = ((self.style)['spacing'] * 1 + (self.position)[0] +
                           (self.style)['checked-normal'].get_width(),
                           center(self.position, self.size, self.textsurf.get_size())[1])

            image = (self.style)[prefix + suffix]
            imagePoint = ((self.position)[0], center(self.position, self.size,
                          image.get_size())[1])

            surf.blit(image, imagePoint)
            surf.blit(self.textsurf, centerPoint, Rect((0, 0), self.size))

            if (self.style)['border-width']:
                draw.rect(surf, (self.style)['border-color'], self.rect,
                          (self.style)['border-width'])
Beispiel #5
0
def draw_my_hp(pkmn):
    """
    function
    """
    maxhp = pkmn.maxhp
    hp = pkmn.hp
    bar_len = floor(hp / float(maxhp) * 399)
    if bar_len < 100:
        color = RED
    elif bar_len < 200:
        color = YELLOW
    else:
        color = GREEN
    if 10 <= maxhp < 100:
        maxhp = ' ' + str(maxhp)
    elif maxhp < 10:
        maxhp = '  ' + str(maxhp)
    else:
        maxhp = str(maxhp)
    if 10 <= hp < 100:
        hp = ' ' + str(hp)
    elif hp < 10:
        hp = '  ' + str(hp)
    else:
        hp = str(hp)
    draw.rect(SCREEN, WHITE, MYHP_RECT)
    if hp > 0:
        draw.rect(
            SCREEN, color, [MYHP_RECT[0], MYHP_RECT[1], bar_len, MYHP_RECT[3]])
    retval = []
    retval.append(MYHP_RECT)
    retval.append(
        word_builder('{0}/{1}'.format(hp, maxhp), SIZE[0] - 570, SIZE[1] - 445))
    return retval
Beispiel #6
0
    def draw(self, surface):
        frame = self.get_margin_rect()
        fg = self.fg_color
        font = self.font
        focused = self.has_focus()
        text, i = self.get_text_and_insertion_point()
        if focused and i is None:
            if self.selection_start is None or self.selection_end is None:
                surface.fill(self.sel_color, frame)
            else:
                startStep = self.selection_start
                endStep = self.selection_end

                if startStep > endStep:
                    x1, h = font.size(text[0:endStep])[0], font.get_linesize()
                    x2, h = font.size(text[0:startStep])[0], font.get_linesize()
                    x1 += frame.left
                    x2 += frame.left
                    y = frame.top
                    selRect = pygame.Rect(x1, y, (x2 - x1), h)
                else:
                    x1, h = font.size(text[0:startStep])[0], font.get_linesize()
                    x2, h = font.size(text[0:endStep])[0], font.get_linesize()
                    x1 += frame.left
                    x2 += frame.left
                    y = frame.top
                    selRect = pygame.Rect(x1, y, (x2 - x1), h)
                draw.rect(surface, self.sel_color, selRect)
        image = font.render(text, True, fg)
        surface.blit(image, frame)
        if focused and i is not None:
            x, h = font.size(text[:i]) #[0], font.get_linesize()
            x += frame.left
            y = frame.top
            draw.line(surface, fg, (x, y), (x, y + h - 1))
Beispiel #7
0
 def refresh(self):
     self.offset = self.style['offset']
     if self.size[1] < self.style['font'].get_ascent() + self.offset[1] * 2:
         self.size = (self.size[0], self.style['font'].get_ascent() + self.offset[1] * 2)
     self.textsurf = self.style['font'].render(self.pwdtext, self.style['antialias'], self.style['font-color'])
     if not self.surf or self.surf.get_size() != self.size:
         self.surf = pygame.Surface(self.size, pygame.SRCALPHA)
     if self.hasFocus:
         suffix = '-focus'
     else:
         suffix = '-normal'
     self.surf.fill(self.style['bg-color' + suffix])
     textpos = (self.offset[0], self.size[1] / 2.0 - self.textsurf.get_height() / 2)
     cursorWidth = self.style['font'].size(self.pwdtext[:self.currpos])[0]
     cursorx = cursorWidth + self.offset[0]
     self.textWidth = self.textsurf.get_width()
     if cursorWidth - self._textStartX < self.size[0] - self.offset[0] * 2:
         if cursorx - self._textStartX < 0:
             self._textStartX = max(0, cursorx - (self.size[0] - self.offset[0] * 2))
     else:
         self._textStartX = cursorWidth - (self.size[0] - self.offset[0] * 2)
     self.surf.blit(self.textsurf, textpos, Rect(self._textStartX, 0, self.size[0] - self.offset[0] * 2, self.textsurf.get_height()))
     if self.hasFocus:
         cursorx -= self._textStartX
         draw.line(self.surf, (255, 255, 255), (cursorx, self.offset[1]), (cursorx, self.size[1] - self.offset[1]))
     if self.style['appearence'] == APP_FLAT:
         draw.rect(self.surf, self.style['border-color' + suffix], Rect((0, 0), self.size), self.style['border-width'])
     else:
         bgcolor = self.style['bg-color' + suffix]
         color_dark = colorLuminosity(bgcolor, -50)
         color_light = colorLuminosity(bgcolor, +30)
         draw.line(self.surf, color_dark, (0, 0), (self.size[0] - 2, 0))
         draw.line(self.surf, color_dark, (0, 0), (0, self.size[1] - 2))
         draw.line(self.surf, color_light, (1, self.size[1] - 1), (self.size[0], self.size[1] - 1))
         draw.line(self.surf, color_light, (self.size[0] - 1, 1), (self.size[0] - 1, self.size[1] - 1))
Beispiel #8
0
    def update(self, plitki=[]):
        if len(plitki) > 1:
            for pl in plitki:
                if self != pl:
                    if collide_rect(self, pl):
                        if self.rect.x < pl.rect.x:
                            self.rect.x -= 1
                            pl.rect.x += 1
                        elif self.rect.x > pl.rect.x:
                            self.rect.x += 1
                            pl.rect.x -= 1
                        if self.rect.y < pl.rect.y:
                            self.rect.y -= 1
                            pl.rect.y += 1
                        elif self.rect.y > pl.rect.y:
                            self.rect.y += 1
                            pl.rect.y -= 1
        surf = get_surface()
        if self.rect.x <= 0:
            self.rect.x += 1
        if self.rect.y <= 0:
            self.rect.y += 1
        if self.rect.x+self.rect.w >= surf.get_width():
            self.rect.x -= 1
        if self.rect.y+self.rect.h >= surf.get_height():
            self.rect.y -= 1

        if self.mouse_on_button():
            self.image.fill((255-self.color[0], 255-self.color[1], 255-self.color[2]))
            rect(self.image, (125, 125, 125), (0, 0, self.rect.width, self.rect.height), 1)
            self.image.blit(self.font.render(self.text, 1, self.color), (3, 3))
        else:
            self.image.fill(self.color)
            rect(self.image, (255, 255, 255), (0, 0, self.rect.width, self.rect.height), 1)
            self.image.blit(self.font.render(self.text, 1, (255-self.color[0], 255-self.color[1], 255-self.color[2])), (3, 3))
Beispiel #9
0
    def bar(self, surface, text, pos, w=300):
        rect = Rect(pos, (w, 60))
        draw.rect(surface, (0, 200, 200), rect)

        sf = font.SysFont('blah', 60, bold=False, italic=False)
        txt = sf.render(text, True, (0, 0, 0))
        surface.blit(txt, rect.inflate(-10, -10))
Beispiel #10
0
def runGUI():
    pygame.display.set_mode((800,600))
    pygame.display.set_caption("Neuro Junk 2012/13")
    screen = pygame.display.get_surface()
    
    while True:
        input(pygame.event.get())
        
        screen.fill((0,0,0))
        circle(screen, (255,255,255), (0,0), radius, 1)
        line(screen, (255,255,255), point1, point2, 1)
        
        polygon(screen, (255,255,255), outer_line, 2)
        polygon(screen, (255,255,255), inner_line,2)
        
        if intersectCircle(point1, point2, radius):
            rect(screen, (0,255,0), Rect(600, 200, 100, 100), 0)
        
        inn = changeField(inner_line, car)
        out = changeField(outer_line, car)
        csect = curSection(inn, out)
        
        polygon(screen, (0,0,255), out, 2)
        polygon(screen, (0,0,255), inn, 2)
        
        rect(screen, (255,255,255), Rect(car.x-2, car.y-2, 4, 4), 0)
        
        if csect is not None:
            line(screen, (0,255,0), csect.inner_start, csect.inner_end, 1)
            line(screen, (0,255,0), csect.outer_start, csect.outer_end, 1)
        
        pygame.display.update()
Beispiel #11
0
    def draw(self,screen):
        #draw listcontrol as white? box
        #draw listitems as text, icons available
        #current item as marked?
        if self._background != None:
            screen.blit(self._background,self._pos)
        else:
            draw.rect(screen, (205,202,255), Rect(self._pos,self._size))
            
        if self._curindex != None and self._displayselection:
            draw.rect(screen, (88,100,241), Rect( (self._pos[0] + 10), (self._pos[1]+6 + self._yOffset + (self._curindex * 18)),self._size[0]-20,20))

        for y,item in enumerate(self._listitems[self._topDisplayItem: (self._topDisplayItem + self._itemsPerPage)]):
            if type(item) is str:
                item = [item]
                
            for i,x in enumerate(self._columnstarts):
                if i + 1 > len(self._columnstarts) - 1:
                    stop = self._size[0] - 10
                else:
                    stop = self._columnstarts[i+1] - x - 10

                tmp = item[i]
                while self._fonten.size(tmp)[0] > stop:
                    tmp= tmp[0:-1]
                    
                tmpfont = self._fonten.render(tmp,True,(0,0,0))
                screen.blit(tmpfont, (self._pos[0]+x, self._pos[1]+10 + self._yOffset + (y * 18)))
Beispiel #12
0
    def render(self, component, entity, event):
        rect = self.rect
        position = entity.handle("get_position")
        rect.center = position

        surf = entity.mode.game.screen
        draw.rect(surf, self.color, self.rect)
Beispiel #13
0
 def draw(self, surface):
     from pygame.draw import rect
     
     #surface dimensions
     w = surface.get_width()
     h = surface.get_height()
     
     padding = 0.05 #decimal percent
     
     #calculate the exact board height
     (self.bw, self.bh) = fit((self.height, self.width), (h, w))
     
     
     #calculate the offsets to centre everything
     self.offset = ((w/2)-(self.bw/2), (h/2)-(self.bh/2))
     
     #draw board outline
     rect(surface, (128, 200, 255), (self.offset[0], self.offset[1], self.bw, self.bh), 5)
     
     #loop round holes drawing each of them
     #print self.holes
     for hole in self.holes:
         hole.draw(surface)
     
     return self
Beispiel #14
0
 def refresh(self):
     #Reposition of the closebutton if visible
     if self.closeable:
         self.closebutton.visible = True
         self.closebutton.position = (self.size[0] - self.style['offset'][0] - self.closebutton.size[0],
                                  self.style['offset'][1])
     else:
         self.closebutton.visible = False
         
     if self.shadeable:
         self.shadebutton.visible = True
         self.shadebutton.position = (self.size[0] - 2*(self.style['offset'][0] + self.shadebutton.size[0]),
                                  self.style['offset'][1])
     else:
         self.shadebutton.visible = False
     
     #If I don't have a surface or surface size is different from my size, i create a new one
     temp='shaded-' if self.shaded else ''
     if not self.surf or self.size != self.surf.get_size():
         del self.surf
         self.surf = pygame.Surface(self.size, pygame.SRCALPHA)
     
     if self.style[temp+'bg-color']:
         self.surf.fill(self.style[temp+'bg-color'])
     
     if self.style['border-width']:
         draw.rect(self.surf, self.style['border-color'], Rect((0,0), self.size), self.style['border-width'])
         
     self.surf.blit(self.style['font'].render(self.text, True, self.style[temp+'font-color']), self.style['offset'])
Beispiel #15
0
    def show(self, screen):
        W, H = self.wc, self.hc
        sx , sy = self.sx, self.sy
        
        for y in range(self.h - 1):
            for x in range(self.w - 1):
                c = self.get_cell(x, y)
                
                if c.gate[const.right]:
                    draw.line(screen, const.black, (sx + ((x + 1) * W), (sy + (y * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 2)
                if c.gate[const.down]:
                    draw.line(screen, const.black, ((sx + (x * W)), (sy + ((y+1) * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 2)
                                     
        x = self.w - 1
        
        for y in range(self.h - 1):
            c = self.get_cell(x, y)
            
            if c.gate[const.down]:
                draw.line(screen, const.black, ((sx + (x * W)), (sy + ((y+1) * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 2)
                
        y = self.h - 1
        
        for x in range(self.w - 1):
            c = self.get_cell(x, y)
            
            if c.gate[const.right]:
                draw.line(screen, const.black, (sx + ((x + 1) * W), (sy + (y * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 2)
                
                

        draw.rect(screen, const.black, (sx, sy, W * self.w, H * self.h), 2)
Beispiel #16
0
 def get_image(self):
     """Draw the rectange on a transparent surface."""
     img = Surface(self.rect.size).convert_alpha()
     img.fill((0, 0, 0, 0), special_flags=pg.BLEND_RGBA_MULT)
     draw.rect(img, self.model.color, img.get_rect(), 1)
     img.fill((255, 255, 255, 128), special_flags=pg.BLEND_RGBA_MULT)
     return img
Beispiel #17
0
 def draw_graph_box_and_legend(self):
     x_end = self.left_bottom_corner_of_graph[0] + self.graph_box_length
     # y_end = self.left_bottom_corner_of_graph[1] - self.graph_box_length
     color = (30,30,30)
     draw.line(self.screen, color, 
                 self.left_bottom_corner_of_graph,
                 (self.left_bottom_corner_of_graph[0] + self.graph_box_length,
                     self.left_bottom_corner_of_graph[1]))
     draw.line(self.screen, color, 
                 self.left_bottom_corner_of_graph,
                 (self.left_bottom_corner_of_graph[0],
                     self.left_bottom_corner_of_graph[1] - self.graph_box_length))
     # legend
     x = self.field_length+padding_graph
     y = 10
     if not compare_wv_counts:
         rectsize = 15
         for legend_item_name, (legend_item_color,_) in self.legend_items.items():
             draw.rect(self.screen, Color(legend_item_color), [x,y, rectsize,rectsize])
             x += rectsize + 10
             x_size_text = self.draw_text(legend_item_name, x, y)
             x += x_size_text + 20
     elif compare_avg_qual_per_wv==1:
         self.draw_text("Average quality per WV",x,y)
     else:
         self.draw_text("WV distribution",x,y)
    def draw(self):
        """
        Method called each frame to (re)draw the objects and UI
        :return:
        """
        if not self.overlay_drawn:
            overlay = Surface((self.scaled_width, LEVEL_HEIGHT))
            overlay.set_alpha(128)
            overlay.fill((0, 0, 0))
            self.overlay_drawn = True
            self.screen.blit(overlay, (0, 0))

        o_max_width = max([option.get_rect().width for option in self.menu_options])
        width = o_max_width + MENU_PADDING[0] * 2
        height = self.menu_options[0].get_rect().height + MENU_PADDING[1] * 2
        x = self.scaled_width / 2 - width / 2
        y = LEVEL_HEIGHT / 2 - (height * len(self.menu_options)) / 2
        counter = 0
        for option in self.menu_options:
            if counter == self.menu_option:
                used_color = MENU_COLORS[1]
            else:
                used_color = MENU_COLORS[0]
            draw.rect(self.screen, used_color, (x, y + counter * height, width, height), 0)
            option_x = x + MENU_PADDING[0] + (o_max_width - option.get_rect().width) / 2
            self.screen.blit(option, (option_x, y + height * counter + MENU_PADDING[1]))
            counter += 1
Beispiel #19
0
    def refresh(self):
        self._padding = self.style['padding']
        itemheight = self.style['item-height']
        maxItemWidth = self.size[0]
        for item in self.items:
            itemWidth = self.style['font'].size(str(item))[0]
            if itemWidth > maxItemWidth:
                maxItemWidth = itemWidth

        if self.style['autosize']:
            self.size = (maxItemWidth, len(self.items) * itemheight)
        listsize = (self.size[0], len(self.items) * itemheight)
        if not self.surf or self.surf.get_size() != listsize:
            self.surf = pygame.Surface(listsize, pygame.SRCALPHA)
        self.surf.fill(self.style['bg-color'])
        for i in xrange(len(self.items)):
            drawRect = True
            if i == self.overedIndex == self.selectedIndex and self.mouseover:
                fontcolor = self.style['font-color']
                bgcolor = mixColors(self.style['bg-color-over'], self.style['bg-color-selected'])
            if i == self.overedIndex and self.mouseover:
                fontcolor = self.style['font-color']
                bgcolor = self.style['bg-color-over']
            elif i == self.selectedIndex:
                fontcolor = self.style['font-color-selected']
                bgcolor = self.style['bg-color-selected']
            else:
                fontcolor = self.style['font-color']
                bgcolor = self.style['bg-color']
                drawRect = False
            if drawRect:
                draw.rect(self.surf, bgcolor, Rect(0, i * itemheight, self.surf.get_width(), itemheight))
            render = self.style['font'].render(str(self.items[i]), True, fontcolor, bgcolor)
            self.surf.blit(render, (2, i * itemheight + itemheight / 2 - render.get_height() / 2))
Beispiel #20
0
    def draw(self, screen):
        draw.rect(screen, (0, 0, 0), (0, 0, self.width, self.size))
        screen.blit(self.current_block, (self.width-self.size*2, self.y, self.size, self.size))
        screen.blit(COIN, (0, 0))
        screen.blit(self.draw_msg(self.gold), (self.size, self.size//4))
        screen.blit(self.draw_msg(self.current_i), (self.size*4, self.size//4))
        screen.blit(self.draw_msg('HP ' + str(int(self.level.heart_hp))), (self.width-self.size*6, self.size//4))
        if self.paused:
            screen.blit(self.draw_msg('GAME PAUSED'), (self.size*8, self.size//4))

        if self.splash > 0:
            screen.blit(self.draw_msg(self.splash_msg), (self.size*7, self.size*2))

        if self.gold_cooldown > 0:
            screen.blit(self.draw_msg(self.gold_msg), (self.size*1.5, self.size))

        if self.level.heart_hp <= 0:
            lost_msg = 'Your kingdom has fallen on:'
            day_msg = 'DAY:' + str(self.level.game_clock.days)
            restart_msg1 = 'Press R to restart'
            restart_msg2 = 'Press Q to return to menu'
            screen.blit(self.draw_msg(lost_msg), (self.size*2, self.size*3))
            screen.blit(self.draw_msg(day_msg), (self.size*7, self.size*4))
            screen.blit(self.draw_msg(restart_msg1), (self.size*4, self.size*5))
            screen.blit(self.draw_msg(restart_msg2), (self.size*3, self.size*6))
Beispiel #21
0
 def draw(self, surf):
     if self.visible:
         if self.enabled:
             if self.value:
                 prefix = "checked"
             else:
                 prefix = "unchecked"
             
             if self.mousedown:
                 suffix = "-down"
             elif self.mouseover:
                 suffix = "-over"
             else:
                 suffix = "-normal"
                 
             image = self.style[prefix + suffix]
         else:
             image = self.style["disabled"]
             
         centerPoint = self.style['spacing'] * 1 + self.position[0] + self.style['checked-normal'].get_width(), center(self.position, self.size, self.textsurf.get_size())[1]
         
         imagePoint = self.position[0], center(self.position,self.size, image.get_size())[1]
         
         #Draws the image
         surf.blit(image, imagePoint)
         surf.blit(self.textsurf, centerPoint, Rect((0,0), self.size))
         
         if self.style['border-width']:
             draw.rect(surf, self.style['border-color'], self.rect, self.style['border-width'])
Beispiel #22
0
 def drawRects(self, surface):
     """
     Draws the contours of the collision rect and the image rect.
     Usefuf for debuging.
     """
     _draw.rect(surface, (0, 0, 0), self.rect, 2)
     _draw.rect(surface, (200, 50, 200), self.crect, 2)
Beispiel #23
0
 def updateScore(self, display, score_rect):
     font = getScaledFont("Times New Roman", (score_rect.w, score_rect.h),
                          str(self.score))
     text = font.render(str(self.score), 1, (255, 255, 255))
     text_rect = text.get_rect(center=(score_rect.centerx,
                                       score_rect.centery))
     rect(display, (0, 0, 0), text_rect)
     display.blit(text, text_rect)
Beispiel #24
0
    def draw(self, surface):
        rect(surface, self.colour, self.bounds())
        d = [self.bounds()]

        for t in self.things:
            d += t.draw(surface)

        return d
Beispiel #25
0
def draw_background(screen):
    width, height = screen.get_width(), screen.get_height()

    screen.fill(COLORS["sky"])
    dr.rect(screen, COLORS["grey"], [0, height // 2, width, height // 2])
    dr.line(screen, COLORS["black"], (0, height // 2), (width, height // 2))

    draw_sun(screen)
Beispiel #26
0
 def draw(self, screen, x, y, active):
     width = 140
     draw.rect(screen, (80, 0, 0), (x, y, width, 20))
     if active:
         draw.rect(screen, (255, 0, 0), (x, y, width, 20))
     my_font = pygame.font.Font(None, 20)
     name = my_font.render(self.name, 1, (50, 255, 50))
     pygame.Surface.blit(screen, name, (x + 7, y + 5))
Beispiel #27
0
def dra():
    # Отрисовка
    draw.rect(window, [255, 246, 18], dvi.ne_krug)
    draw.circle(window, [33, 55, 77], dvi.krug.center, set.RADIUS)

    display.flip()

    window.fill([138, 21, 255])
Beispiel #28
0
def _fill_surface(surface):
    """Fill the surface with lines in various colours"""
    y = 0
    for colour in [(255, 0, 0, 255), (0, 255, 0, 255), (0, 0, 255, 0),
                   (255, 255, 255, 255), (0, 0, 0, 255), (255, 255, 0, 255),
                   (0, 255, 255, 255), (255, 0, 255, 255)]:
        draw.rect(surface, colour, (0, y, 800, y + 75))
        y += 75
Beispiel #29
0
 def message(self, qw, text):
     "Display entered text."
     frect = ((self.irect[0][0] + qw, self.irect[0][1]),
              (self.irect[1][0] - qw, self.irect[1][1]))
     draw.rect(self.screen, self.boxc, frect)
     if text:
         self.blitfont(text, (self.fontupleft[0] + qw, self.fontupleft[1]))
     display.update(self.irect)
def top_windows(x, y, width, height):
    for i in range(11):
        if i % 2 == 0:
            clr = brown
        else:
            clr = window_color
        d.rect(screen, clr,
               (x + i * width // 11, y - height, width // 11, height))
Beispiel #31
0
 def draw(self, screen):
     from pygame.draw import rect
     if self.imageOverLay is not None:
         screen.blit(self.imageOverLay, self.pos.getTuple(),
                     (0, 0, self.size.x, self.size.y))
     else:
         rect(screen, (255, 0, 0), self.getRect())
     rect(screen, (0, 0, 0), self.getRect(), 2)
def tubes(x, y, width, height):
    """function draws a random number of house chimneys on the its root"""
    for i in range(int(6 * rnd.random())):
        d.rect(screen, (40, 42, 40),
               (x + int(width * rnd.random()),
                y - height + int(0.12 * height * rnd.random()),
                int(width / 10 * rnd.random()) + 3,
                -int(height / 3 * rnd.random()) - 20))
Beispiel #33
0
    def _draw_base(self):
        # Active state background
        self._images["image"].fill(self._settings["col_focus"])
        draw.rect(self._images["image"], (0,0,1), ((0,0), self.rect.size), 4)

        # Inactive state background
        self._images["inactive"].fill(self._settings["col_focus_not"])
        draw.rect(self._images["inactive"], (0,0,1), ((0,0), self.rect.size), 4)
Beispiel #34
0
    def resetPixel(self, x, y):
        # Set a pixel in the buffer to be off at a specific x, y location. Need to call update()
        # to actually make it show on screen
        x_pos = x * self.scale
        y_pos = y * self.scale

        draw.rect(self.surface, pixelOff,
                  (x_pos, y_pos, self.scale, self.scale))
Beispiel #35
0
def draw_enpassant_moves(screen, pieces):
    """Draw the enpassant moves for the currently selected player"""
    colour = COLOURS[ENPASSANT_MOVES]
    for piece in pieces:
        if str(piece) == 'pawn' and piece.selected:
            for enpassant_move in piece.enpassant_move:
                rect = get_rect(enpassant_move)
                draw.rect(screen, colour, rect, 5)
Beispiel #36
0
 def render(self, surf, pos, scale):
     draw.rect(surf, self.backcol, Rect(pos, (scale * 16 + 16, ) * 2))
     draw.rect(surf, Colour.darker(self.backcol, 0.9),
               Rect(pos, (scale * 16 + 15, ) * 2), 2)
     surf.blit(self.item.img[scale], pos)
     Img.draw_num(surf, self.q, pos, scale + 1)
     if not self.q:
         surf.blit(self.trans[scale], pos)
Beispiel #37
0
 def _draw_background(self):
     rect(
         self._screen,
         MAIN_BACKGROUND_COLOR,
         Rect(
             0, 0, self._width, self._height
         )
     )
Beispiel #38
0
    def drawRect(self, rect):

        h = rect.height
        w = rect.width
        x = rect.x + self.camx
        y = rect.y + self.camy

        d.rect(self.screen, Color(0, 0, 0, 255), Rect(x, y, w, h), 0)
Beispiel #39
0
    def draw(self, surface):
        draw.rect(surface, self.color, self.rect)
        myfont = font.SysFont('Times New Roman', 24)
        textsurface = myfont.render(self.text, False, (0, 0, 0))
        TextLeftRightCor = (self.rect.center[0] - textsurface.get_width() / 2,
                            self.rect.center[1] - textsurface.get_height() / 2)

        surface.blit(textsurface, TextLeftRightCor)
Beispiel #40
0
    def draw(self):
        draw.rect(self.canvas, self.color.get(),
                  ((0, 0), (self.WIDTH, self.BASE_HEIGTH * self.SIZE)))
        self.canvas.blit(self.header, (self.TAB, 0))

        content = self.FONT.render(str(self.content), True,
                                   self.highlight_color)
        self.canvas.blit(content, (self.header.get_width() + 2 * self.TAB, 0))
Beispiel #41
0
    def _draw_base(self):
        # Active state background
        self._images["image"].fill(self._settings["col_focus"])
        draw.rect(self._images["image"], (0,0,1), ((0,0), self.rect.size), 4)

        # Inactive state background
        self._images["inactive"].fill(self._settings["col_focus_not"])
        draw.rect(self._images["inactive"], (0,0,1), ((0,0), self.rect.size), 4)
Beispiel #42
0
def _fill_surface(surface):
    """Fill the surface with lines in various colours"""
    y = 0
    for colour in [(255, 0, 0, 255), (0, 255, 0, 255), (0, 0, 255, 0),
                   (255, 255, 255, 255), (0, 0, 0, 255), (255, 255, 0, 255),
                   (0, 255, 255, 255), (255, 0, 255, 255)]:
        draw.rect(surface, colour, (0, y, 800, y + 75))
        y += 75
Beispiel #43
0
 def draw(self):
     draw.rect(self.canvas,  self.color.get(), ((0, 0), (self.WIDTH, self.BASE_HEIGTH*self.SIZE)) )
     
     self.canvas.blit(self.header, (self.TAB,0))
     if len( self.scrollist)!= 0:
         #content= self.FONT.render(str(self.scrollist[self.tick]), True, self.scrollist[self.tick].color.get())
         content= self.FONT.render(str(self.scrollist[self.tick]), True, self.highlight_color)
         self.canvas.blit( content, (self.header.get_width()+ 2*self.TAB, 0))
Beispiel #44
0
 def __init__(self, scene):
     color = (43,73,85)
     grid_color = (170,170,170)
     self.size = (16,16)
     Sprite.__init__(self, scene, self.size, color)
     if config.DEBUG:
         offset = self.rect.move([1,1])
         draw.rect(self.image, grid_color, offset, 1)
Beispiel #45
0
 def __init__(self, text, color):
     self.HEIGTH
     self.canvas= pygame.Surface( ( self.WIDTH, self.HEIGTH) )
     self.color= color
     self.text_color= Gcolor.darken( self.color.mix(self.color.WHITE, 0.5), 0.1)
     
     draw.rect(self.canvas, self.color.get(), ( (0, 0), (self.WIDTH, self.HEIGTH) ))
     self.canvas.blit( self.FONT.render(text, True, self.text_color), (self.TAB, 0) )
Beispiel #46
0
 def draw(self, surface):
     rect(surface, self.colour, self.bounds())
     d = [self.bounds()]
         
     for t in self.things:
         d += t.draw(surface)
     
     return d
Beispiel #47
0
 def message(self, qw, text):
     "Display entered text."
     frect = ((self.irect[0][0] + qw, self.irect[0][1]),
              (self.irect[1][0] - qw, self.irect[1][1]))
     draw.rect(self.screen, self.boxc, frect)
     if text:
         self.blitfont(text, (self.fontupleft[0] + qw, self.fontupleft[1])) 
     display.update(self.irect)
Beispiel #48
0
def test_rect(test_surf):
    """Draw several rectangles."""
    for y in range(10, 200, 45):
        x = 10
        for width in range(10, 30, 3):
            for height in range(10, 40, 7):
                r = rect.Rect(x, y, width, height)
                x += width + 2
                draw.rect(test_surf, (255, 255, 255, 255), r)
Beispiel #49
0
 def draw(self, width, height, scr):
     if not self.wall and not self.visited:
         rect(scr, (255, 255, 255),
              (self.i * width + 25, self.j * height + 25, width - 2,
               height - 2), 2)
     elif self.visited:
         rect(scr, (255, 0, 0), (self.i * width + 25, self.j * height + 25,
                                 width - 2, height - 2))
     return
Beispiel #50
0
    def draw(self, surface):
        """
        Draws the border onto the given surface.

        :param surface:  The surface to draw the border onto
        """
        for pos in self.__square_positions:
            draw.rect(surface, self.__color,
                      (pos[0], pos[1], self.__cell_size, self.__cell_size))
Beispiel #51
0
    def maze_prim(self, x: int, y: int, screen: Surface) -> None:
        """draw maze in the screen based on prim's algorithm

                Parameters:
                        x (int): x screen coordinates
                        y (int): y screen coordinates
                        screen (Surface): game screen

                Returns:
                        None
        """
        check = [[False for i in range(self.vertical)]
                 for j in range(self.horizontal)]
        vetX = []
        vetY = []
        # neighbors
        vetNX = []
        vetNY = []

        vetX.append(x)
        vetY.append(y)
        vetNX.append(0)
        vetNY.append(0)

        while vetX:

            n = randint(0, len(vetX) - 1)

            if self.out_of_range(vetX[n],
                                 vetY[n]) or check[vetX[n]][vetY[n]] == True:
                vetX.pop(n)
                vetY.pop(n)
                vetNX.pop(n)
                vetNY.pop(n)
                continue

            posX = (self.margin + self.width) * (vetY[n]) + self.margin
            posY = (self.margin + self.height) * (vetX[n]) + self.margin
            draw.rect(screen, WALL, (posX, posY, 13, 13))

            posX = (self.margin + self.width) * (vetY[n] +
                                                 vetNY[n] / 2) + self.margin
            posY = (self.margin + self.height) * (vetX[n] +
                                                  vetNX[n] / 2) + self.margin
            draw.rect(screen, WALL, (posX, posY, 13, 13))

            check[vetX[n]][vetY[n]] = True

            for i in range(0, 4):
                newX = vetX[n] + self.dx[i]
                newY = vetY[n] + self.dy[i]
                if not (self.out_of_range(newX, newY)
                        or check[newX][newY] == True):
                    vetX.append(newX)
                    vetY.append(newY)
                    vetNX.append(self.dx[i])
                    vetNY.append(self.dy[i])
Beispiel #52
0
    def display(self, screen):

        upper_rect = Rect((self.x, 0), (self.width, self.height))
        lower_rect = Rect(
                (self.x, self.height+self.gapsize),
                (self.width, self.resolution[1] - self.height+self.gapsize))

        draw.rect(screen, (25,255,25), upper_rect)
        draw.rect(screen, (25,255,25), lower_rect)
Beispiel #53
0
 def drawLiveCells(self, screen):
     for i in range(self.width):
         for j in range(self.height):
             if self.state[j][i]:
                 cell_width = screen.get_width() / self.width
                 cell_height = screen.get_height() / self.height
                 draw.rect(screen, (0, 0, 0),
                           (i * cell_width, j * cell_height, cell_width,
                            cell_height))
Beispiel #54
0
    def drawText(self, window):
        rect = (0, 118, 160, 144 - 118)
        draw.rect(window, Palette.NORM, rect)

        text = self.getText()
        label = self.font.render(text[0], False, Palette.LIGHT)
        window.blit(label, (3, 120))
        label = self.font.render(text[1], False, Palette.LIGHT)
        window.blit(label, (3, 130))
Beispiel #55
0
    def resetPixel(self, x, y):
        """Set a pixel in the buffer to be off at a specific x, y location. Need
        to call update() to laod the buffer onto the screen.
        """
        x_pos = x * self.scale
        y_pos = y * self.scale

        draw.rect(self.surface, PIXEL_OFF,
                  (x_pos, y_pos, self.scale, self.scale))
Beispiel #56
0
 def draw_error(self, e, block='<unknown>'):
     draw.rect(self.surface_d, Color('#131313'), self.surface_d.get_rect())
     lines = []
     lines.append(f'{e!r} occurred in {block}')
     lines += format_exc().split('\n')
     for i, line in enumerate(lines):
         print(line)
         surf = self.font_d.render(line, True, RED, Color('#131313'))
         self.surface_d.blit(surf, (0, i * 16))
Beispiel #57
0
def new_map(screen, image, game):
    cities = game.take_cities_list()
    graph = game.take_cities_graph()
    screen.blit(image, (0, 0))
    exceptions = [(16, 38), (16, 45), (24, 47)]
    # Отрисовка ребер между городами
    for city in cities:
        for neighbor in city.take_neighbors():
            # Если ребро должно выходить за пределы карты и входить с другой стороны
            if (city.take_num(), neighbor.take_num()) in exceptions:
                x1, y1 = city.take_cords()
                x2, y2 = neighbor.take_cords()
                if x1 > x2:
                    x1, y1 = x2, y2
                draw.line(screen,
                          EDGE_COLOR, (x1, y1), (0, (y1 + y2) // 2),
                          width=3)
                draw.line(screen,
                          EDGE_COLOR, (x2, y2), (IMAGE_W, (y1 + y2) // 2),
                          width=3)
                font = pygame.font.Font(None, 20)
                text = font.render(neighbor.take_name(), True, TEXT_COLOR)
                screen.blit(text, (0, (y1 + y2) // 2))
                font = pygame.font.Font(None, 20)
                text = font.render(city.take_name(), True, TEXT_COLOR)
                screen.blit(text, (IMAGE_W - 105, (y1 + y2) // 2))
            elif (int(neighbor.take_num()),
                  int(city.take_num())) not in exceptions:
                draw.line(screen,
                          EDGE_COLOR,
                          city.take_cords(),
                          neighbor.take_cords(),
                          width=3)
    for city in cities:
        x, y = city.take_cords()
        draw.circle(screen, VIRUS_COLORS[city.take_virus()], (x, y),
                    CITY_RADIUS)
        if city.is_station():
            draw.polygon(screen, STATION_COLOR,
                         ((x + 5, y), (x + 5, y - 7), (x + 7 + 5, y - 14),
                          (x + 19, y - 7), (x + 19, y)))
        draw.circle(screen, CONTAMINATION_COLOR, (x - 10 - 5, y + 8), 7)
        font = pygame.font.Font(None, 20)
        text = font.render(str(city.take_contamination()), True,
                           (100, 255, 100))
        screen.blit(text, (x - 10 - 9, y + 2))
        font = pygame.font.Font(None, 18)
        text = font.render(city.take_name(), True, TEXT_COLOR)
        if city.take_name() == 'Нью-Дели' or city.take_name(
        ) == 'Лос-Анджелес' or city.take_name() == 'Монреаль':
            draw.rect(screen, 'white', ((x - 15, y - 25),
                                        (text.get_width(), text.get_height())))
            screen.blit(text, (x - 15, y - 25))
        else:
            draw.rect(screen, 'white',
                      ((x - 5, y + 7), (text.get_width(), text.get_height())))
            screen.blit(text, (x - 5, y + 7))
Beispiel #58
0
    def update(self):
        # Il existe une fonction par type de joueur, manuel ou IA
        if (self.is_player):
            self.manual_control()
        else:
            self.automatic_control()

        # Maintenant que les coordonées ont changés, on dessine la raquette
        draw.rect(self.screen, (255, 255, 255), self.as_rect())
Beispiel #59
0
 def move(self):
     '''
     this function moves button
     :return:
     '''
     self.x += self.speed_x
     self.y += self.speed_y
     d.rect(screen, self.color, (self.x - int(self.length / 2), self.y - int(self.height / 2), self.length,
                                 self.height))
Beispiel #60
-1
 def render(self):
     # ~ draw magnetradius
     if self.magnetradius:
         # ~ gfxdraw.aacircle(scr,self.centerx,self.centery,int(self.magnetradius),(150,130,110,int(self.magnetradius)))
         m = image.load("img/magnetichalo.png")
         m = transform.smoothscale(m, [int(self.magnetradius * 2)] * 2)
         scr.blit(m, m.get_rect(center=self.center))
     # ~ draw shieldbar
     r = draw.rect(scr, (50, 50, 50), (10, 500, 380, 18), 1)
     osdlayer.fill((100, 100, 200, self.shieldfxttl * 4 + 150), (10, 0, self.shield_ / self.shieldmax * 380, 18))
     # scr.blit(self.SHIELDTEXT,self.SHIELDRECT)
     # ~ draw lazerstate
     r = draw.rect(scr, (50, 50, 50), (10, 520, 380, 18), 1)
     osdlayer.blit(self.lazertempfx, (10, 20), (0, 0, DoubleLazer.temper / DoubleLazer.tempmax * 380, 18))
     # scr.blit(self.LAZERTEXT,self.LAZERRECT)
     # ~ draw bonusbar
     self.settingbonus_.render()
     self.loader1_.render()
     # ~ draw shieldcircle
     if self.shieldfxttl:
         self.shieldcolor.a = int(4 * self.shieldfxttl)
         gfxdraw.filled_circle(scr, self.centerx, self.centery, self.w, self.shieldcolor)
         self.shieldfxttl -= 1
     if self.foo:
         self.foo -= 1
         scr.blit(self.img2, ship)
         return
     # ~ draw ship
     scr.blit(self.img, ship)