Exemplo n.º 1
0
 def update(self):
     for tank in tanks.values():
         if tank.alive:
             rect = Rectangle(10 + (tank.sprite.position[0] * self.factorx),
                              10 + (tank.sprite.position[1] * self.factory),
                              5, 5, (255, 0, 0, 255))
             rect.draw()
     for projectile in projectiles.values():
         rect = Rectangle(
             10 + (projectile.sprite.position[0] * self.factorx),
             10 + (projectile.sprite.position[1] * self.factory), 4, 4,
             (40, 40, 40, 255))
         rect.draw()
     tank = tanks[self.cl_id]
     area_w = Game.WIDTH * self.factorx
     area_h = Game.HEIGHT * self.factory
     area_x = 10 + (tank.sprite.position[0] * self.factorx) - (area_w / 2)
     area_y = 10 + (tank.sprite.position[1] * self.factory) - (area_h / 2)
     if area_x < 10:
         area_x = 10
     elif area_x + area_w > 260:
         area_x = 260 - area_w
     if area_y < 10:
         area_y = 10
     elif area_y + area_h > 260:
         area_y = 260 - area_h
     area = Rectangle(area_x, area_y, area_w, area_h, (255, 255, 255, 255),
                      True)
     area.draw()
Exemplo n.º 2
0
    class HP_Bar:
        def __init__(self, pos):
            self.border = Rectangle(pos[0] - (54 / 2) - 3, pos[1] + 51, 60, 16,
                                    (40, 40, 40, 255))
            self.full_bar = Rectangle(pos[0] - (54 / 2), pos[1] + 50, 54, 10,
                                      (255, 0, 0, 255))
            self.hp_bar = Rectangle(pos[0] - (54 / 2), pos[1] + 50, 54, 10,
                                    (0, 255, 0, 255))

        def update(self, position, hp):
            self.full_bar.lx = position[0] - (54 / 2)
            self.full_bar.ly = position[1] + 50
            self.hp_bar.lx = position[0] - (54 / 2)
            self.hp_bar.ly = position[1] + 50
            self.border.lx = self.hp_bar.lx - 3
            self.border.ly = self.hp_bar.ly - 3
            self.hp_bar.width = max(54 - (.54 * (100 - hp)), 0)

        def draw(self):
            self.border.draw()
            self.full_bar.draw()
            self.hp_bar.draw()
Exemplo n.º 3
0
class Hud:
    def __init__(self):
        self.bullet1_x = Game.WIDTH - 100
        self.bullet1_y = 200

        self.bullet2_x = Game.WIDTH - 100
        self.bullet2_y = 165

        self.bullet1_overlay = Rectangle(self.bullet1_x, self.bullet1_y, 100, 35, (40,40,40,200))
        self.bullet1_img = pyglet.image.load("res/PNG/bullets/bulletBeige_outline.png")
        self.bullet1_img.anchor_x = self.bullet1_img.width // 2 
        self.bullet1_img.anchor_y = self.bullet1_img.height // 2 
        self.bullet1_sprite = pyglet.sprite.Sprite(self.bullet1_img, x = self.bullet1_x + 20, y = self.bullet1_y + self.bullet1_overlay.height // 2, batch = hud_batch, group=hud_group)
        self.bullet1_sprite.scale = 0.75
        self.bullet1_ammo = pyglet.text.HTMLLabel(
        '<font face="Arial" size="13" color="white"><b>x40</b></font>',
        x=self.bullet1_x+45, y=self.bullet1_y + self.bullet1_overlay.height // 2,
        anchor_x='center', anchor_y='center')
        self.bullet1_text = pyglet.text.HTMLLabel(
        '<font face="Arial" size="13" color="white"><b>1</b></font>',
        x=self.bullet1_x+80, y=self.bullet1_y + self.bullet1_overlay.height // 2,
        anchor_x='center', anchor_y='center')

        self.bullet2_overlay = Rectangle(self.bullet2_x, self.bullet2_y, 100, 35, (40,40,40,100))
        self.bullet2_img = pyglet.image.load("res/PNG/bullets/bulletBeigeSilver_outline.png")
        self.bullet2_img.anchor_x = self.bullet1_img.width // 2 
        self.bullet2_img.anchor_y = self.bullet1_img.height // 2 
        self.bullet2_sprite = pyglet.sprite.Sprite(self.bullet2_img, x = self.bullet2_x + 20, y = self.bullet2_y + self.bullet2_overlay.height // 2, batch = hud_batch, group=hud_group)
        self.bullet2_sprite.scale = 0.75
        self.bullet2_sprite.opacity = 100
        self.bullet2_ammo = pyglet.text.HTMLLabel(
        '<font face="Arial" size="13" color="white"><b>x5</b></font>',
        x=self.bullet2_x+45, y=self.bullet2_y + self.bullet2_overlay.height // 2,
        anchor_x='center', anchor_y='center')
        self.bullet2_text = pyglet.text.HTMLLabel(
        '<font face="Arial" size="13" color="white"><b>2</b></font>',
        x=self.bullet2_x+80, y=self.bullet2_y + self.bullet2_overlay.height // 2,
        anchor_x='center', anchor_y='center')

        self.bullet2_text.color = (255,255,255,100)
        self.bullet2_ammo.color = (255,255,255,100)

        self.minimap_border = Rectangle(0, 0, 260, 260, (40,40,40,255))
    def update(self, ammo1, ammo2):
        self.bullet1_ammo = pyglet.text.HTMLLabel(
        '<font face="Arial" size="13" color="white"><b>x%d</b></font>' % (ammo1),
        x=self.bullet1_x+45, y=self.bullet1_y + self.bullet1_overlay.height // 2,
        anchor_x='center', anchor_y='center')
        self.bullet2_ammo = pyglet.text.HTMLLabel(
        '<font face="Arial" size="13" color="white"><b>x%d</b></font>' % (ammo2),
        x=self.bullet2_x+45, y=self.bullet2_y + self.bullet2_overlay.height // 2,
        anchor_x='center', anchor_y='center')
    def draw(self):
        self.bullet1_overlay.draw()
        self.bullet1_text.draw()
        self.bullet1_ammo.draw()

        self.bullet2_overlay.draw()
        self.bullet2_text.draw()
        self.bullet2_ammo.draw()
        
        self.minimap_border.draw()