def update(self):
        """update a farmtiles"""

        modified = False

        #Toggle rain using perlin noise
        seed = self.gamemanager.getgameseed()
        rainnoise = pnoise(time.time() * (1.0 / 64), 23482.8 * (1.0 / 64), seed + 0.5)
        if rainnoise > 0.0:
            self.raining = True
        else:
            self.raining = False

        #update each farmtile
        for farmtile in self.farmtiles.values():

            #Update objects
            if farmtile['object']:
                ret = farmtile['object'].update(farmtile)
                if ret:modified = True
                ret = self.check_wilted(farmtile)
                if ret:modified = True

                farmtile.update()
            else:
                #Create anthills
                chance = random.randint(0, 10000)
                maxanthills = farmlib.rules["MAX_ANTHILLS"]
                if chance == 1 and int(time.time()) % 600 == 0\
                    and self.count_objects(7) < maxanthills:
                    self.create_random_anthill(farmtile)
                    return True
        return modified
Example #2
0
    def getShake(self, t, freq, amp, seed=0, octaves=3):
        """
		getShake (float t, float freq, float amp, int seed = 0, int octaves = 3) -> float noise

			A wrapper around the pnoise() function that produces a fractal sum
			by using the octaves value to generate values multiple times
			with increasing frequency and decreasing amplitude.

			float t  	- the time value, or other changing value
			float freq 	- fequency of the curve values (speed)
			float amp 	- amplitude of the curve values (intensity)
			int seed 	- Any random number. The seed number lets you change the randomization
			int octaves - Creates finer detail (jitter) in the curve values
		"""

        val = 0

        if amp == 0 or freq == 0:
            return val

        # underscore is a special symbol to throw away the
        # value since we dont care about it.
        for _ in range(octaves):

            val += pnoise((t + seed) * freq) * amp

            # modify the freq and amp for the next octave
            freq *= 2
            amp /= 2

        return val
Example #3
0
    def update(self):
        """update a farmtiles"""

        modified = False

        # Toggle rain using perlin noise
        seed = self.gamemanager.getgameseed()
        nx = time.time() * (1.0 / 128.0)
        ny = 23482.8 * (1.0 / 128)
        rainnoise = pnoise(nx, ny, seed + 0.5)
        if rainnoise > 0.2:
            self.raining = True
        else:
            self.raining = False

        # update each farmtile
        for farmtile in self.farmtiles.values():

            # Update objects
            if farmtile['object']:
                ret = farmtile['object'].update(farmtile)
                if ret:
                    modified = True
                ret = self.check_wilted(farmtile)
                if ret:
                    modified = True
                # Water nearest plants for ponds
                if farmtile.farmobject and farmtile.farmobject.id == 11:
                    px = farmtile.posx
                    py = farmtile.posy
                    self.water(px + 1, py, True)
                    self.water(px - 1, py, True)
                    self.water(px, py + 1, True)
                    self.water(px, py - 1, True)
                # update farmtile
                farmtile.update()
            else:
                # Create anthills
                chance = random.randint(0, 10000)
                maxanthills = farmlib.rules["MAX_ANTHILLS"]
                if chance == 1 and int(time.time()) % 600 == 0\
                        and self.count_objects(7) < maxanthills:
                    self.create_random_anthill(farmtile)
                    return True
        return modified
Example #4
0
    def update(self):
        """update a farmtiles"""

        modified = False

        # Toggle rain using perlin noise
        seed = self.gamemanager.getgameseed()
        nx = time.time() * (1.0 / 128.0)
        ny = 23482.8 * (1.0 / 128)
        rainnoise = pnoise(nx, ny, seed + 0.5)
        if rainnoise > 0.2:
            self.raining = True
        else:
            self.raining = False

        # update each farmtile
        for farmtile in self.farmtiles.values():

            # Update objects
            if farmtile['object']:
                ret = farmtile['object'].update(farmtile)
                if ret:
                    modified = True
                ret = self.check_wilted(farmtile)
                if ret:
                    modified = True
                # Water nearest plants for ponds
                if farmtile.farmobject and farmtile.farmobject.id == 11:
                    px = farmtile.posx
                    py = farmtile.posy
                    self.water(px + 1, py, True)
                    self.water(px - 1, py, True)
                    self.water(px, py + 1, True)
                    self.water(px, py - 1, True)
                # update farmtile
                farmtile.update()
            else:
                # Create anthills
                chance = random.randint(0, 10000)
                maxanthills = farmlib.rules["MAX_ANTHILLS"]
                if chance == 1 and int(time.time()) % 600 == 0\
                        and self.count_objects(7) < maxanthills:
                    self.create_random_anthill(farmtile)
                    return True
        return modified
Example #5
0
	f.close()

for z0 in range(-1,3):
	for x0 in range(-1,3):
		for y0 in range(-1,3):
			print("generating block "+str(x0)+","+str(y0)+","+str(z0))
			#v3 blockp = v3(x0,y0,z0)
			
			# Create a MapBlock
			block = MapBlock()
			
			# Generate stuff in it
			for z in range(0,16):
				for x in range(0,16):
					h = 20.0*pnoise((x0*16+x)/100.,(z0*16+z)/100.,SEED+0)
					h += 5.0*pnoise((x0*16+x)/25.,(z0*16+z)/25.,SEED+0)
					if pnoise((x0*16+x)/25.,(z0*16+z)/25.,SEED+92412) > 0.05:
						h += 10
					#print("r="+str(r))
					# This enables comparison by ==
					h = int(h)
					for y in range(0,16):
						p = v3(x,y,z)
						b = 254
						y1 = y0*16+y
						if y1 <= h-3:
							b = 0 #stone
						elif y1 <= h and y1 <= 0:
							b = 8 #mud
						elif y1 == h:

for z0 in range(-1, 3):
    for x0 in range(-1, 3):
        for y0 in range(-1, 3):
            print("generating block " + str(x0) + "," + str(y0) + "," +
                  str(z0))
            #v3 blockp = v3(x0,y0,z0)

            # Create a MapBlock
            block = MapBlock()

            # Generate stuff in it
            for z in range(0, 16):
                for x in range(0, 16):
                    h = 20.0 * pnoise((x0 * 16 + x) / 100.,
                                      (z0 * 16 + z) / 100., SEED + 0)
                    h += 5.0 * pnoise((x0 * 16 + x) / 25.,
                                      (z0 * 16 + z) / 25., SEED + 0)
                    if pnoise((x0 * 16 + x) / 25.,
                              (z0 * 16 + z) / 25., SEED + 92412) > 0.05:
                        h += 10
                    #print("r="+str(r))
                    # This enables comparison by ==
                    h = int(h)
                    for y in range(0, 16):
                        p = v3(x, y, z)
                        b = 254
                        y1 = y0 * 16 + y
                        if y1 <= h - 3:
                            b = 0  #stone
                        elif y1 <= h and y1 <= 0: