Beispiel #1
0
    def __init__(self, pos=[0, 0], seed=0):
        Planets.pl = []
        self.seed = seed
        self.rnd = random.Random(self.seed)
        self.pos = Vex(self.rnd.randint(-2000, 2000),
                       self.rnd.randint(-2000, 2000))
        self.rot = [0, 0, 0]
        self.points = []
        self.surfProjPoints = []
        self.edges = []
        self.corePoints = []
        self.coreProjPoints = []
        self.coreEdges = []
        self.corHealth = 10000

        self.rad = self.rnd.randint(Sun.minRad, Sun.maxRad)
        self.xoffset = self.rnd.randint(1, 99999999999)
        self.yoffset = self.rnd.randint(1, 99999999999)
        self.pickRndSurfacePoints = self.rnd.randint(Sun.minSize, Sun.maxSize)
        self.numPlanets = self.rnd.randint(Sun.minPlanets, Sun.maxPlanets)
        self.planets = []
        self.doCore()
        for i in range(self.numPlanets):
            ang_rad = math.radians(self.rnd.randint(0, 360))
            dist_sun = self.rnd.randint(self.maxRad * 2 + 25, Sun.maxRange)
            px = math.sin(ang_rad) * dist_sun
            py = math.cos(ang_rad) * dist_sun
            p = Planets(self.rnd.randint(1, 123456789012345678901234567890),
                        (px + self.pos.x(), py + self.pos.y()))
            for pl in Planets.pl:
                while pl.pos.dist2D(p.pos) <= pl.atmos + p.atmos and p != pl:
                    ang_rad = math.radians(self.rnd.randint(0, 360))
                    dist_sun = self.rnd.randint(self.maxRad * 2 + 25,
                                                Sun.maxRange)
                    px = math.sin(ang_rad) * dist_sun
                    py = math.cos(ang_rad) * dist_sun
                    p.pos.set2D(px + self.pos.x(), py + self.pos.y())
            self.planets += [p]

        step = math.radians(360.0 / self.pickRndSurfacePoints)
        for surfacePoint in range(self.pickRndSurfacePoints):
            sx = math.sin(step * surfacePoint)
            sy = math.cos(step * surfacePoint)
            x = sx * (self.rad)
            y = sy * (self.rad)
            h = rand2D(x, y)
            self.points += [Vex(sx * (self.rad + h), sy * (self.rad + h))]
            self.surfProjPoints += [0, 0]

        for i in range(len(self.points)):
            if i + 1 < len(self.points):
                self.edges.append([i, i + 1])
            else:
                self.edges.append([i, 0])
Beispiel #2
0
    def init(self, cam):
        x = (cam.pos.x())
        y = (cam.pos.y())
        rnd = random.seed(self.seed)
        self.localPos = [int(x), int(y)]
        self.objectGrid = [[[None] for x in range(0, self.width)] for y in range(0, self.height)]
        self.objects = []
        px = -(x - int(x))
        py = -(y - int(y))
        hh = int(self.height / 2)
        hw = int(self.width / 2)
        for row in range(0, self.height):
            for col in range(0, self.width):
                o = None
                val = (((rand2D((x) + col - hw, (y) + row - hh, self.seed) + 1) / 2) * 100)
                if val < self.percent:
                    val = rand2D(int(x), int(y) , self.seed)
                    o = Objects.Objects(self.parent, val, Vex((x + px + col - hh), (y + py + row - hw)))
                    self.objects += [o]
                self.objectGrid[row][col] = o

        Objects.Objects.update_image_rotation(cam)
        for o in self.objects:
            o.selfUpdate(cam)
Beispiel #3
0
    def doSurface(self):
        pickRndSurfacePoints = self.rnd.randint(self.minSize, self.maxSize)
        step = (360.0 / pickRndSurfacePoints)
        mi = 0
        stp = 1
        maxH = 0

        for surfacePoint in range(pickRndSurfacePoints):
            sx = math.sin(math.radians(step * surfacePoint))
            sy = math.cos(math.radians(step * surfacePoint))
            x = sx * (self.rad / Planets.con) * stp
            y = sy * (self.rad / Planets.con) * stp
            # h = (Noise.Perlin3D(x, y, 0, 16, 1, 0, 4))*2
            h = rand2D(x, y) * 2

            x = sx * (self.rad + h)
            y = sy * (self.rad + h)
            sax = sx * (self.rad - 6)
            say = sy * (self.rad - 6)
            if maxH < h: maxH = h
            self.surfPoints += [Vex(x, y)]
            self.sancPoints += [Vex(sax, say)]
            self.surfProjPoints += [(0, 0)]
            self.sancProjPoints += [(0, 0)]

        self.atmos = maxH + self.rad / 5 + self.rad

        entryPs = []
        ents = self.rnd.randint(1, 4)
        leng = len(self.surfProjPoints)
        for i in range(mi, leng):
            r2 = 0
            r1 = i % int((leng) / (ents + 1))
            if r1 == 0: r2 = 1
            if i + 1 < len(self.surfProjPoints):
                seg = (i, i + 1)
            else:
                seg = (i, mi)
                mi = i + 1
            if r2 == 1:
                entryPs += [seg]
            self.edges.append((seg, r2))

        return entryPs
Beispiel #4
0
    def selfUpdate(self, cam):
        env = Environment.Environment
        # self.weapon.update()
        inscreen = False
        projectedPoints = []
        dis = cam.pos.dist2D(self.pos)
        if dis < 1 and env.interact:
            print("Enter " + self.img_name)
            print(self.parent.seed)
            # enter dungeon with 0,0,0
            cam.dpos.assign(cam.pos)
            cam.pos.set2D(0, 0)
            cam.dmpos.set2D(0, 0)
            nseed = rand2D(self.pos.x(), self.pos.y(), self.parent.seed)
            print(str(cam.pos) + '   ' + str(cam.dmpos))
            DungeonGenerator.invoke(nseed, cam, self.img)
            cam.pos.assign(cam.dpos)
            cam.dpos.set2D(0, 0)

            pass
            """ enter thing """
        if dis < 50 and self.pos.dist2D(self.parent.pos) < self.parent.rad - 8:
            for i, p in enumerate(self.points):
                v = ((p * self.scale).rotate2dXY(math.radians(self.ang)) +
                     self.pos - cam.pos).rotate2dXY(cam.rot[1]).rotate2dYZ(
                         cam.mov[2], cam.rot[0])
                f = env.fov / (v.z() + .000000001)
                if (f < env.lim):
                    f = 1000
                p = (v * f + env.center).p2D()
                projectedPoints += [p]
                if env.inScreen(p):
                    inscreen = True

            if inscreen:
                env.add_visible_object(self)
                env.add_edge(self.color, projectedPoints, 1, 2)
                env.add_image(
                    Objects.rot_images[self.img],
                    ((self.pos.projectedPos(cam))[1] - Vex(16, self.height)))
                # env.screen.blit(self.img,((self.pos.projectedPos(cam))[1]-Vex(16, 64)).p2D())
        return inscreen
Beispiel #5
0
    def update(self, cam):
        # update should only do parts of a grid that have moved on.
        x = (cam.pos.x())
        y = (cam.pos.y())
        intX = int(x)
        intY = int(y)
        px = -(x - intX)
        py = -(y - intY)

        hh = int(self.height / 2)
        hw = int(self.width / 2)

        if intX > self.localPos[0]:

            self.objectGrid = shift(LEFT, 1, self.objectGrid)

            col = self.width
            for row in range(0, self.height):
                if self.objectGrid[row][col - 1] != [None] and self.objectGrid[row][col - 1] != None:
                    self.objects.remove(self.objectGrid[row][col - 1])
                val = (((rand2D((x) + col - hw, (y) + row - hh, self.seed) + 1) / 2) * 100)
                o = None
                if val < self.percent:
                    val = rand2D(int(x)+col, int(y)+row, self.seed)
                    o = Objects.Objects(self.parent, val, Vex((x + px + (col - 1) - hw), (y + py + row - hh)))
                    self.objects += [o]
                self.objectGrid[row][col - 1] = o

        if intX < self.localPos[0]:
            self.objectGrid = shift(RIGHT, 1, self.objectGrid)

            col = 0
            for row in range(0, self.height):
                if self.objectGrid[row][col] != [None] and self.objectGrid[row][col] != None:
                    self.objects.remove(self.objectGrid[row][col])
                val = (((rand2D((x) + col - hw, (y) + row - hh, self.seed) + 1) / 2) * 100)
                o = None
                if val < self.percent:
                    val = rand2D(int(x) + col, int(y) + row, self.seed)
                    o = Objects.Objects(self.parent, val, Vex((x + px + col - hw), (y + py + row - hh)))
                    self.objects += [o]
                self.objectGrid[row][col] = o

        if intY > self.localPos[1]:
            self.objectGrid = shift(UP, 1, self.objectGrid)

            row = self.height
            for col in range(0, self.width):
                if self.objectGrid[row - 1][col] != [None] and self.objectGrid[row - 1][col] != None:
                    self.objects.remove(self.objectGrid[row - 1][col])
                val = (((rand2D((x) + col - hw, (y) + row - hh, self.seed) + 1) / 2) * 100)
                o = None
                if val < self.percent:
                    val = rand2D(int(x) + col, int(y) + row, self.seed)
                    o = Objects.Objects(self.parent, val, Vex((x + px + col - hw), (y + py + (row - 1) - hh)))
                    self.objects += [o]
                self.objectGrid[row - 1][col] = o

        if intY < self.localPos[1]:
            self.objectGrid = shift(DOWN, 1, self.objectGrid)

            row = 0
            for col in range(0, self.width):
                if self.objectGrid[row][col] != [None] and self.objectGrid[row][col] != None:
                    self.objects.remove(self.objectGrid[row][col])
                val = (((rand2D((x) + col - hw, (y) + row - hh, self.seed) + 1) / 2) * 100)
                o = None
                if val < self.percent:
                    val = rand2D(int(x) + col, int(y) + row, self.seed)
                    o = Objects.Objects(self.parent, val, Vex((x + px + col - hw), (y + py + row - hh)))
                    self.objects += [o]
                self.objectGrid[row][col] = o

        self.localPos = [intX, intY]

        #Objects.Objects.update_image_rotation(cam)
        for o in self.objects:
            o.selfUpdate(cam)
Beispiel #6
0
    def update2(self, cam):
        env = Environment.Environment
        for p in self.planets:
            p.update(cam)
        ptpdst = cam.pos.dist2D(self.pos)  #player to sun distance

        if ptpdst < env.renderDist + self.rad:
            cam.player.doDMG(((env.renderDist + self.rad) - ptpdst) / 100)

            for i, c in enumerate(self.corePoints):
                v = (c + self.pos - cam.pos).rotate2dXY(
                    cam.rotSC[0]).rotate2dYZ(cam.mov[2], cam.rotSC[1])  # pitch
                f = env.fov / (v.z() + .000000001)
                if (f < env.lim):
                    f = 1000
                v = v * f
                v = v + env.center
                v.setZ(f)
                self.coreProjPoints[i] = v

            hth = -(self.corHealth / 200)
            for line in self.coreEdges:
                points = []
                fs = [
                    self.coreProjPoints[line[0]].z(),
                    self.coreProjPoints[line[1]].z()
                ]
                points = [
                    self.coreProjPoints[line[0]].p2D(),
                    self.coreProjPoints[line[1]].p2D()
                ]
                if ptpdst < env.renderDist + self.rad:
                    esc = env.screenClip(points)
                    if esc[0]:
                        points = esc[1]
                    if (env.inScreen(points[0]) or env.inScreen(points[1])):
                        env.add_edge((255, 0, 0), points, 1, 1, hth, fs)

            onscreen = False
            for i, p in enumerate(self.points):
                cl = 1.5 - rand2D(p.x(), p.y()) / 10
                scl = Vex(cl, cl)
                v = (p * scl + self.pos - cam.pos).rotate2dXY(
                    cam.rotSC[0]).rotate2dYZ(cam.mov[2], cam.rotSC[1])  # pitch

                f = env.fov / (v.z() + .000000001)
                if (f < env.lim):
                    f = 1000
                v = v * f
                v = v + env.center
                self.surfProjPoints[i] = v.p2D()
                if env.inScreen(self.surfProjPoints[i]):
                    onscreen = True
            if onscreen: env.add_edge((170, 23, 23), self.surfProjPoints, 1, 2)

        if ptpdst >= env.renderDist + self.rad:
            p1 = self.pos.projectedPos(cam)
            if p1[0]:
                points = [(p1[1].x() - self.rad * p1[1].z(), p1[1].y()),
                          (p1[1].x() + self.rad * p1[1].z(), p1[1].y())]
                esc = env.screenClip(points)
                if esc[0]:
                    points = esc[1]
                if (env.inScreen(points[0]) or env.inScreen(points[1])):
                    env.add_edge((170, 23, 23), points, 8)
Beispiel #7
0
 def getSeed():
     return rand2D(Environment.gpos.x(), Environment.gpos.y(),
                   Environment.seed)