def makeImg(images):
    obstacles = []
    background = Image.open("back.png")
    # radius for checking if objects are inside circle and positioning center
    radius = 180
    # x from 0 to 310; y from 155 - sqrt(-(x-310)x) to 155 + sqrt(-(x-310)x)
    x = np.random.normal(radius, (radius/goalVariance)/3)
    yRadius = math.sqrt(-1 * x * (x - radius * 2))
    y = np.random.normal(radius, (yRadius)/3)
    for i in range(1, 5):
        # selects objects in random order
        j = random.randrange(0, len(images))
        name = "obj" + str(images[j]) + ".png"
        images.pop(j)
        obj = Image.open(name)
        objX = x
        objY = y
        # splits objects into four quadrants around point
        if (i % 2 == 0):
            objX -= w(obj)
        if (i > 2):
            objY -= h(obj)
        z = Rectangle(objX, w(obj), objY, h(obj))
        foundLoc = (not z.hasCollision(obstacles)) and z.insideCircle(radius, radius, radius)
        if not foundLoc:
            return None
        else:
            pasteOn(background, obj, objX, objY)
        obstacles.append(z)
    return background
def makeImg(images):
    gripper = Rectangle(295, 125, 120, 125)
    obstacles = [gripper]
    # grip = Image.new('RGB', (125,125), color=400)
    # white background
    clusterBack = Image.open("scripts/objects/back.png")
    # background of result
    background = Image.open("scripts/objects/" + backName + ".png")
    # radius for checking if objects are inside circle and positioning center
    radius = 180 # 180
    xCenter = 160
    yRadius = 210
    yCenter = 210
    # x from 0 to 310; y from 155 - sqrt(-(x-310)x) to 155 + sqrt(-(x-310)x)
    x = np.random.normal(xCenter, (radius*1.2))
    # print (radius/2), yRadius/2
    # field = Image.new('RGB', (int(radius*1.2),int(yRadius*1.2)), color=400)
    # yRadius = math.sqrt(-1 * x * (x - radius * 2))
    y = np.random.normal(yCenter, (yRadius*1.2))
    center = (x,y)
    order = []
    for i in range(1, 5):
        # selects objects in random order
        j = random.randrange(0, len(images))
        name = "scripts/objects/" + "obj" + str(images[j]) + ".png"
        order.append(images[j])
        images.pop(j)
        obj = Image.open(name)
        objX = x
        objY = y
        # splits objects into four quadrants around point
        if (i % 2 == 0):
            objX -= w(obj)
        if (i > 2):
            objY -= h(obj)
        z = Rectangle(objX, w(obj), objY, h(obj))
        # foundLoc = (not z.hasCollision(obstacles)) and z.insideCircle(radius, radius, radius)
        foundLoc = (not z.hasCollision(obstacles) and z.insideRectangle((0, 2*yRadius), (2*radius,0)))
        if not foundLoc:
            # print "Failed: ", (x,y)
            return None, None, order
        else:
            pasteOn(clusterBack, obj, objX, objY)
        obstacles.append(z)
    # Random angle from -30 to 30; noise
    theta = (random.random() * 60) - 30
    clusterBack = clusterBack.rotate(theta)
    clusterBack = makeTransparent(clusterBack)
    # pasteOn(background, field, xCenter - int(radius/2*1.2), yCenter- int(yRadius/2*1.2))
    # pasteOn(background, field, 0, 0)
    pasteOn(background, clusterBack, 0, 0)
    return background, center, order
Exemple #3
0
 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))
Exemple #4
0
    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))
Exemple #5
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()
Exemple #6
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()
Exemple #7
0
 while (not foundLoc):
     # increases rotation of object if it did not fit
     if (reRotate):
         rotLimit += 20
         rObj = obj.rotate(getRot(rotLimit), Image.NEAREST, True)
         reRotate = False
     # avoid infinite loops
     if (rotLimit > 700):
         foundLoc = True
     hasSpace = True
     radialD = w(goal)/2
     # iterates distance from goal to find valid placement at current angle
     while (not foundLoc and hasSpace):
         objx = gObj.cenX + radialD * cosine(theta)
         objy = gObj.cenY + radialD * sine(theta)
         z = Rectangle(objx, w(rObj), objy, h(rObj))
         foundLoc = not z.hasCollision(obstacles)
         hasSpace = z.insideCircle(trueRadius, trueRadius, trueRadius)
         foundLoc = foundLoc and hasSpace
         radialD += 5
         if (foundLoc):
             pasteOn(background, rObj, objx, objy)
             obstacles.append(z)
         # change angle if no valid placement is available at current angle
         elif (not hasSpace):
             currentTheta += thetaShift
             theta += thetaShift
         # changes object rotation if no valid placement is available at any angle
         if (currentTheta > 720):
             currentTheta = 0
             reRotate = True