Beispiel #1
0
    def __init__(self,
                 surface,
                 players,
                 font,
                 font_size,
                 font_color,
                 bgcolor,
                 line_spacing=5):

        for player in players:
            player.hud = self

        self.surface = surface
        self.font = pygame.font.SysFont(font, font_size)
        self.font_color = font_color
        self.bg_color = bgcolor
        self.line_spacing = line_spacing

        line_height = MinimumSize(font, font_size, 1, line_spacing)[1]
        text_size = MinimumSize(font, font_size, len(players), line_spacing)
        hud_size = (text_size[0] + 10, text_size[0] + 10)

        hud_top = pgview.centerRectangles((0, 0), surface.get_size(), hud_size)
        if hud_top == None:
            print 'HUD larger than area'
            sys.exit()
        hud_top = (hud_top[0], 10)

        text_top = pgview.centerRectangles(hud_top, hud_size, text_size)
        if text_top == None:
            print 'Text larger than HUD'
            sys.exit()

        # x and y so that text is centered
        pos = [text_top]
        y = text_top[1]
        for player in players:
            y += line_height
            pos.append((text_top[0], y))
        self.pos = pos

        self.players = players
        self.surface = surface
        self.changed = False

        self.surface.fill(self.bg_color, pygame.Rect(hud_top, hud_size))
        self.update()
Beispiel #2
0
    def __init__(self,surface,players,font,font_size,font_color,bgcolor,line_spacing=5):

        for player in players:
            player.hud=self

        self.surface=surface
        self.font=pygame.font.SysFont(font,font_size)
        self.font_color=font_color
        self.bg_color=bgcolor
        self.line_spacing=line_spacing

        line_height=MinimumSize(font,font_size,1,line_spacing)[1]
        text_size=MinimumSize(font,font_size,len(players),line_spacing)
        hud_size=(text_size[0]+10,text_size[0]+10)

        hud_top=pgview.centerRectangles((0,0),surface.get_size(),hud_size)
        if hud_top==None:
            print 'HUD larger than area'
            sys.exit()
        hud_top=(hud_top[0],10)

        text_top=pgview.centerRectangles(hud_top,hud_size,text_size)
        if text_top==None:
            print 'Text larger than HUD'
            sys.exit()


        # x and y so that text is centered
        pos=[text_top]
        y=text_top[1]
        for player in players:
            y+=line_height
            pos.append((text_top[0],y))
        self.pos=pos

        self.players=players
        self.surface=surface
        self.changed=False

        self.surface.fill(self.bg_color,pygame.Rect(hud_top,hud_size))
        self.update()
Beispiel #3
0
    def __init__(self,surface):

        # Drawing surface
        self.surface=surface
        self.surface.fill(pgview.BG_COLOR)

        # Find largest square on surface
        self.area_top=area_top=(0,0)
        area_size=self.surface.get_size()
        self.area_size=area_size
        if area_size[0]>=area_size[1]:
            arena_size=(area_size[1],area_size[1])
        else:
            arena_size=(area_size[0],area_size[0])
        self.arena_size=arena_size

        arena_top=pgview.centerRectangles(area_top,area_size,arena_size)
        self.arena_top=arena_top
        #print area_top
        #print arena_top

        # Variables for coordinate transformations
        self.scale=(float(arena_size[0])/self.world_size[0],
                    float(arena_size[1])/self.world_size[1])
        self.mirror=(1,-1)
        self.trans=(arena_top[0]+float(arena_size[0])/2,
                arena_top[1]+float(arena_size[1])/2)
        #print 'scale: '+str(self.scale)
        #print 'trans: '+str(self.trans)

        # Ball group
        self.balls=Balls()

        # Physics Engine options
        gravity=(0,-10)
        doSleep=True
        self.timeStep=1.0/60.0
        self.velIterations=10
        self.posIterations=8

        # World bouding box
        aabb=Box2D.b2AABB()
        aabb.upperBound=Box2D.b2Vec2(self.world_size[0]/2,self.world_size[1]/2)
        aabb.lowerBound=Box2D.b2Vec2(-self.world_size[0]/2,-self.world_size[1]/2)
        #print arena_top
        #print arena_size
        #print aabb.upperBound
        #print aabb.lowerBound
        #print self.s2wPos(arena_top)
        #print self.s2wScale(arena_size)
        #print self.s2wPos((arena_top[0]+arena_size[0],arena_top[1]+arena_size[1]))

        # World
        self.world=Box2D.b2World(aabb,gravity,doSleep)
        # World listeners
        self.boundaryListener=BoundListener()
        self.world.SetBoundaryListener(self.boundaryListener)
        self.contactListener=ContactListener(self.balls)
        self.world.SetContactListener(self.contactListener)

        # Walls
        self.staticObjs=[]
        self.makeBounds(arena_top,arena_size)
        # Draw Walls
        for obj in self.staticObjs:
            obj.draw(self.surface)
        self.background=self.surface.copy()