Пример #1
0
 def make(self, cls, **kwargs):
     if cls in self.factories:
         factory = self.factories[cls]
         entity = factory.make(**kwargs)
         self.add(entity)
         if cls is Ship:
             self.ships.append(entity)
         return entity
     else:
         log.logmsg("No factory for class " + str(cls), log.LOG_WARNING)
         return None
Пример #2
0
	def make(self, cls, **kwargs):
		if cls in self.factories:
			factory = self.factories[cls]
			entity = factory.make(**kwargs)
			self.add(entity)
			if cls is Ship:
				self.ships.append(entity)
			return entity
		else:
			log.logmsg("No factory for class " + str(cls), log.LOG_WARNING)	
			return None
Пример #3
0
def image(screen, image, pos, angle=0, color=None):
    """
	Draws an image on a screen.

	Args:
		screen: The screen which is drawn on.
		pos: The center position at which the image is drawn on the screen.
		image: The image which is drawn.
		angle: The rotation of the image in degrees.
	"""
    image_data = image.get_data(rotation=angle, tint=color)
    w = image.width
    h = image.height
    pos = (pos[0] - w / 2.0, pos[1] - h / 2.0)

    try:
        screen.blit(image_data, pos)
    except TypeError:
        log.logmsg("Blit failed (position " + str(pos) + ")", log.LOG_ERROR)
Пример #4
0
def image(screen, image, pos, angle=0, color=None):
	"""
	Draws an image on a screen.

	Args:
		screen: The screen which is drawn on.
		pos: The center position at which the image is drawn on the screen.
		image: The image which is drawn.
		angle: The rotation of the image in degrees.
	"""
	image_data = image.get_data(rotation=angle, tint=color)
	w = image.width
	h = image.height
	pos = (pos[0]-w/2.0, pos[1]-h/2.0)

	try:
		screen.blit(image_data, pos)
	except TypeError:
		log.logmsg("Blit failed (position "+str(pos)+")", log.LOG_ERROR)
Пример #5
0
    def add_part(self, bp, name=None):

        candidates = []
        for i in range(len(bp.parts)):
            for j in range(len(bp.parts[i])):
                if not self.is_candidate_parent(bp.parts[i][j]):
                    continue

                if i > 0 and bp.parts[i - 1][j] is None:
                    candidates.append(((i, j), (i - 1, j)))

                if i < len(bp.parts) - 1 and bp.parts[i + 1][j] is None:
                    candidates.append(((i, j), (i + 1, j)))

                if j > 0 and bp.parts[i][j - 1] is None:
                    candidates.append(((i, j), (i, j - 1)))

                if j < len(bp.parts[i]) - 1 and bp.parts[i][j + 1] is None:
                    candidates.append(((i, j), (i, j + 1)))

        if len(candidates) is 0:
            log.logmsg("No candidate parents", log.LOG_INFO)
            return

        candidate = candidates[random.randint(0, len(candidates) - 1)]
        child = candidate[1]
        parent = candidate[0]

        if name is None:
            derp = random.randint(0, 3)
            if derp == 0:
                name = THRUSTER
            elif derp == 1:
                name = BLASTER
            else:
                name = ARMOR
        if name is THRUSTER:
            self.added_a_thruster = True

        bp.set_part(child, name)
        bp.attach_parts(child, parent)
Пример #6
0
    def add_part(self, bp, name=None):

        candidates = []
        for i in range(len(bp.parts)):
            for j in range(len(bp.parts[i])):
                if not self.is_candidate_parent(bp.parts[i][j]):
                    continue

                if i > 0 and bp.parts[i - 1][j] is None:
                    candidates.append(((i, j), (i - 1, j)))

                if i < len(bp.parts) - 1 and bp.parts[i + 1][j] is None:
                    candidates.append(((i, j), (i + 1, j)))

                if j > 0 and bp.parts[i][j - 1] is None:
                    candidates.append(((i, j), (i, j - 1)))

                if j < len(bp.parts[i]) - 1 and bp.parts[i][j + 1] is None:
                    candidates.append(((i, j), (i, j + 1)))

        if len(candidates) is 0:
            log.logmsg("No candidate parents", log.LOG_INFO)
            return

        candidate = candidates[random.randint(0, len(candidates) - 1)]
        child = candidate[1]
        parent = candidate[0]

        if name is None:
            derp = random.randint(0, 3)
            if derp == 0:
                name = THRUSTER
            elif derp == 1:
                name = BLASTER
            else:
                name = ARMOR
        if name is THRUSTER:
            self.added_a_thruster = True

        bp.set_part(child, name)
        bp.attach_parts(child, parent)
Пример #7
0
	def _cache(self, tint, rotation):
		cache_miss = False
		new_tint = False
		
		if self._cached_tint != tint:
			cache_miss = True
			new_tint = True

			# throw away angle based on previous tint
			self._cached_angle = 0

			self._cached_tint = tint
			if tint is not None:
				self._tinted = self._raw.copy()
				self._tinted.fill(tint, special_flags=pygame.BLEND_RGB_MULT)
				self._unrotated = self._tinted
				self._transformed = self._tinted
			else:
				self._tinted = None
				self._unrotated = self._raw
				self._transformed = self._raw

		# if new angle or need to redraw angle
		angle_difference = rotation - self._cached_angle
		min_difference = 1
		if angle_difference > min_difference or angle_difference < -min_difference or new_tint:
			cache_miss = True

			self._cached_angle = rotation
			self._rotated = pygame.transform.rotate(self._unrotated, rotation)
			self._transformed = self._rotated

		if cache_miss:
			self.width = self._transformed.get_width()
			self.height = self._transformed.get_height()
			self._data = self._transformed.convert_alpha() 
			if self._print_cache_misses:
				log.logmsg("Cache miss", log.LOG_INFO)