当前位置: 首页>>代码示例>>Python>>正文


Python Sprite.draw方法代码示例

本文整理汇总了Python中sprite.Sprite.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Sprite.draw方法的具体用法?Python Sprite.draw怎么用?Python Sprite.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sprite.Sprite的用法示例。


在下文中一共展示了Sprite.draw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: draw

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import draw [as 别名]
 def draw(self, surface, camera):
     camerax, cameray = camera.getPosition()
     pygame.draw.rect(surface, CELL_TYPE_COLORS[self.cell_type_id], (self.x - camerax, self.y - cameray, CELL_SIZE, CELL_SIZE)) 
     if (self.material != None):
         Sprite.draw(self, surface, camera)
     if (self.treasure != None):
         self.treasure.draw(surface, camera)
开发者ID:reiknight,项目名称:ld29,代码行数:9,代码来源:cell.py

示例2: DodgeballScene

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import draw [as 别名]
class DodgeballScene(Scene):
	def __init__(self):
		Scene.__init__(self)

		self.font = pygame.font.Font("visitor1.ttf", 20)

	def create(self):
		self.bg = Sprite(Vector2(0, 0))
		self.bg.addStaticImage(content.images["background.png"])
		self.particles = ParticleContainer(100)
		self.particles.layerIndex = 0
		self.add(self.particles)
		self.victoryMessage = ""

	def draw(self, screen):
		self.bg.draw(screen)
		map(lambda x:x.drawShadow(screen), self.sceneEntities)
		
		sortedEntities = sorted(self.sceneEntities, cmp = layeringSort)
		map(lambda x:x.draw(screen), sortedEntities)
	
		surf = self.font.render(str(g.game.score[0]) + " - " + str(g.game.score[1]), False, (255, 255, 255))
		w, h = surf.get_size()
		screen.blit(surf, (160 - w / 2, 9))

		if self.victoryMessage != "":
			surf = self.font.render(self.victoryMessage, False, (39, 65, 62))
			w, h = surf.get_size()
			w += 10
			pygame.draw.rect(screen, (39, 65, 62), (160 - w / 2 - 1, 100 - h / 2 - 1, w + 2, h + 2), 1)
			pygame.draw.rect(screen, (255, 255, 255), (160 - w / 2, 100 - h / 2, w, h), 0)
			w -= 10
			screen.blit(surf, (160 - w / 2, 100 - h / 2))
开发者ID:morganq,项目名称:dodgeball-game,代码行数:35,代码来源:dodgeballscene.py

示例3: draw

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import draw [as 别名]
	def draw(self, screen):
		Sprite.draw(self, screen)
		x = self.position.x - 7
		y = self.position.y - 20
		w = min(max(self.health, 0) / 100.0 * 14, 13)
		if self.health > 0:
			pygame.draw.rect(screen, (39,65,62), (x-1,y-1, 16, 3), 0)
			pygame.draw.line(screen, (255, 255, 255), (x, y), (x + 13, y))
			pygame.draw.line(screen, (67,102,125), (x, y), (x + w, y))

		if self.charge > 0:
			md = 10.0
			c = int(min(self.charge+1, 2.0) * 10.0)
			#pygame.draw.line(screen, (173,0,0), (x-1,y-2),(x + c, y-2))
			p1 = self.position + self.chargeDir * md
			p2 = self.position + self.chargeDir * (md + c)
			pa1 = p2 - self.chargeDir * 3 + self.chargeDir.sideways() * 3
			pa2 = p2 - self.chargeDir * 3 - self.chargeDir.sideways() * 3
			r = 100 + self.charge * 155
			pygame.draw.line(screen, (r, 0, 0), p1.asIntTuple(), p2.asIntTuple())
			pygame.draw.line(screen, (r, 0, 0), p2.asIntTuple(), pa1.asIntTuple())
			pygame.draw.line(screen, (r, 0, 0), p2.asIntTuple(), pa2.asIntTuple())

		if self.chatTimer > 0:
			surf = self.chatFont.render(self.chatText, False, (39, 65, 62))
			if self.flipHorizontal:
				x = x - 4 - surf.get_width()
			else:
				x = x + 18
			screen.blit(surf, (x, y + 2))
开发者ID:morganq,项目名称:udpgame,代码行数:32,代码来源:player.py

示例4: __init__

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import draw [as 别名]
class Character:

    """
    Represents an in-game character: player, npc, enemy, etc.  This class
    _should not_ be used directly!  It should rather be inherited by the classes
    that will use it.
    """

    def __init__(self, filename, spawnpoint):
        """
        The filename is simply used to generate a sprite
        Spawnpoint is used for the initial position
        """

        self.spawnpoint = spawnpoint
        self.sprite = Sprite(filename, spawnpoint)
        self.health = 100
        self.alive = True

    def draw(self):
        self.sprite.draw()

    def update(self):
        pass

    def kill(self):
        pass

    def hurt(self, dmg):
        if self.health - dmg <= 0:
            self.alive = 0
            self.health = 0
        else:
            self.health -= dmg
开发者ID:alveyworld-dev,项目名称:game,代码行数:36,代码来源:character.py

示例5: PyGMObj

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import draw [as 别名]
class PyGMObj(object):
	"""Generic PYGMObj"""
	instances = []

	def __init__(self, position, sprite=None):
		super(PyGMObj, self).__init__()
		self.create()
		self.position = position
		if sprite is not None:
			self.sprite = Sprite(sprite, PyGM.screen)
		PyGM.objects.append(self)

	def create(self):
		pass

	def update(self):
		if self.sprite is not None:
			self.sprite.rect.move(self.position.tuple())

	def draw(self):
		if self.sprite is not None:
			self.sprite.draw(self.position)

	@classmethod
	def instances(cls):
		"""Returns a list of all instances of type and children of type"""
		return [i for i in PyGM.objects if isinstance(i, cls)]
开发者ID:Widdershin,项目名称:PyGM,代码行数:29,代码来源:core.py

示例6: ImageMenuItem

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import draw [as 别名]
class ImageMenuItem (BaseMenuItem):
    """ A menu item that shows a selectable Image """
    def __init__ (self, name, callback_func, *args, **kwargs):
        self.image = pyglet.resource.image (name)
        super (ImageMenuItem, self).__init__(callback_func, *args, **kwargs)

    def generateWidgets (self, pos_x, pos_y, font_item, font_item_selected):
        anchors = {'left': 0, 'center': 0.5, 'right': 1, 'top': 1, 'bottom': 0}
        anchor=(anchors[font_item['anchor_x']] * self.image.width,
                anchors[font_item['anchor_y']] * self.image.height)
        self.item = Sprite(self.image, anchor=anchor, opacity=255,
                           color=font_item['color'][:3])
        self.item.scale = font_item['font_size'] / float(self.item.height )
        self.item.position = int(pos_x), int(pos_y)
        self.selected_item = Sprite(self.image, anchor=anchor,
                                    color=font_item_selected['color'][:3])
        self.selected_item.scale = (font_item_selected['font_size'] /
                                     float(self.selected_item.height))
        self.selected_item.position = int(pos_x), int(pos_y)

    def draw (self):
        glPushMatrix()
        self.transform()
        if self.is_selected:
            self.selected_item.draw()
        else:
            self.item.draw()
        glPopMatrix()
开发者ID:eevee,项目名称:cocos2d-mirror,代码行数:30,代码来源:menu.py

示例7: __init__

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import draw [as 别名]
class BackgroundLayer:
    """
    Encapsulates a scrolling layer of the background.  It will move left
    at a given speed, and loop once it exits the screen.  Multiple layers
    with multiple speeds can be used to create a parallax effect, or to
    allow many-layered backgrounds
    """

    def __init__(self, filename, scroll_speed):
        pos = (0, 0)

        self.s1 = Sprite(filename, pos)
        self.s2 = Sprite(filename, (1280, pos[1]))

        self.filename = filename
        self.position = pos
        self.speed    = scroll_speed

    def draw(self):
        self.s1.draw()
        self.s2.draw()

    def update(self):
        self.s1.rect.x -= self.speed

        if self.s1.rect.x <= 0:
            self.s2.rect.x -= self.speed

        if self.s2.rect.x <= 0:
            self.s1.rect.x = 0
            self.s2.rect.x = 1280
开发者ID:16pagejonm,项目名称:game,代码行数:33,代码来源:world.py

示例8: draw

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import draw [as 别名]
 def draw(self,surface,camera,is_shadow=True):
     Sprite.draw(self,surface,camera,is_shadow)
     #surface.blit(self.team.image, camera.proj([self.pos[0],self.pos[1],self.pos[2]],self.team.image.get_width(),self.team.image.get_height()*3))
     if (self.is_saying_timer>0) and (self.is_saying!=""):
         message_pos=[]
         message_pos[:]=self.pos[:]
         surface.blit(Player.speech_image[self.is_saying], camera.proj(message_pos,-self.image.get_width(),50))
开发者ID:andru255,项目名称:pyNekketsu,代码行数:9,代码来源:player.py

示例9: ColorChangingBlock

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import draw [as 别名]
class ColorChangingBlock(PhysicsObject):

	PATTERN_SIZE = 3

	def __init__(self, pos, interval, exclude_color):
		PhysicsObject.__init__(self, (pos[0] + 16, pos[1] + 16), (0, 0), (32, 32), BODY_STATIC)
		self.sprite = Sprite('./assets/img/blocks.png', (32, 32), 0.1)

		self.id = ID_OBJ

		self.timer = 0.0
		self.interval = float(interval)

		self.colors = ['red', 'green', 'blue']
		self.exclude_color = self.colors.index(exclude_color)

		# create a pattern for changing colors
		self.pattern = []

		while len(self.pattern) < self.PATTERN_SIZE:
			color = random.randint(0, 2)
			if not color == self.exclude_color and self.pattern.count(color) < 2:
				self.pattern.append(color)

		self.pattern_color_pointer = random.randint(0, self.PATTERN_SIZE - 1)
		self.previous_active_color = 0
		self.active_color = self.colors[ self.pattern[self.pattern_color_pointer] ]
		self.sprite.use_frames([ self.pattern[self.pattern_color_pointer] ])

	def on_collide_obj(self, obj):
		return True

	def on_collide_platform(self, plat):
		return True

	def update(self, dt):
		self.sprite.update(dt)
		self.timer += dt

		self.previous_active_color = self.active_color
		
		if self.timer >= self.interval:
			self.timer = 0
			self.previous_pointer = self.pattern_color_pointer
			self.pattern_color_pointer += 1

			if self.pattern_color_pointer >= self.PATTERN_SIZE:
				self.pattern_color_pointer = 0

			next_color = self.pattern[self.pattern_color_pointer]
			self.sprite.use_frames([next_color])
			self.active_color = self.colors[next_color]

	def draw(self, screen, view_rect):
		rect = Rect(self.rect.left, self.rect.top, self.rect.width, self.rect.height)
		rect.left -= view_rect.left - rect.width / 2
		rect.top -= view_rect.top

		self.sprite.draw(screen, rect)
开发者ID:glhrmfrts,项目名称:rgb,代码行数:61,代码来源:play_scene.py

示例10: __init__

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import draw [as 别名]
class Fist:
    def __init__(self):
        self.sprite = Sprite("fist.png", (25, 25))
        self.level = 1
        print("Level 1 fist created") # for debugging

    def draw(self):
        self.sprite.draw()
开发者ID:ProgramQ,项目名称:monkeypunch,代码行数:10,代码来源:fist.py

示例11: draw

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import draw [as 别名]
 def draw(self):
     self.screen.blit(self.background, (0,0))
     
     # network data draw
     if network_received is not None:
         for player in network_received:
             sp = Sprite(self, sprite_image_filename)
             sp.image = self.image
             sp.position = Vector2(player['pos'][0], player['pos'][1])
             sp.draw()
     
     pygame.display.update()
开发者ID:leotada,项目名称:pygame-async,代码行数:14,代码来源:main.py

示例12: __init__

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import draw [as 别名]
class Chimp:
    def __init__(self):
        self.sprite = Sprite("chimp.png", (350, 350))
        self.health = 100
        self.alive = True

    def set_health(self, value):
        self.health += value
        if self.health <= 0:
            print("Monkey dead") 
            score.total += 100
            score.monkey_deaths += 1
            self.alive = False
    
    def draw(self):
        self.sprite.draw()
开发者ID:ProgramQ,项目名称:monkeypunch,代码行数:18,代码来源:chimp.py

示例13: LavaBlock

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import draw [as 别名]
class LavaBlock(PhysicsObject):

	def __init__(self, pos):
		PhysicsObject.__init__(self, (pos[0] + 16, pos[1] + 16), (0, 0), (32, 32), BODY_STATIC)
		self.sprite = Sprite('./assets/img/blocks.png', (32, 32), 0.1)
		self.sprite.use_frames([0, 1, 2])
		self.id = ID_OBJ

	def update(self, dt):
		self.sprite.update(dt)

	def draw(self, screen, view_rect):
		rect = Rect(self.rect.left, self.rect.top, self.rect.width, self.rect.height)
		rect.left -= view_rect.left - rect.width / 2
		rect.top -= view_rect.top
		self.sprite.draw(screen, rect)
开发者ID:glhrmfrts,项目名称:rgb,代码行数:18,代码来源:play_scene.py

示例14: Game

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import draw [as 别名]
class Game(object):
    def __init__(self, height=640, width=480, fps=60):
        self.height = height
        self.width = width
        self.fps = fps

        pygame.init()
        self.graphics = Graphics(self.height, self.width)
        self.clock = pygame.time.Clock()

        self.quote = Sprite("../con/MyChar.bmp", 0, 0, 32, 32)

    def __del__(self):
        pygame.quit()

    def eventloop(self):
        running = True



        while running:
            # Handle input
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False

            # Handle everything else
            self.update()
            self.draw()

            # 60fps
            print (self.clock.get_fps())
            self.clock.tick(self.fps)

    def update(self):
        pass

    def draw(self):
        self.quote.draw(self.graphics, 55, 55)
        pygame.display.flip()
开发者ID:Spittie,项目名称:cavestory,代码行数:42,代码来源:game.py

示例15: ImpulseBlock

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import draw [as 别名]
class ImpulseBlock(PhysicsObject):

	BOUNCE_FACTOR = 1.35
	BOUNCE_MIN_INTERVAL = 0.5

	def __init__(self, pos, color, direction):
		PhysicsObject.__init__(self, (pos[0] + 16, pos[1] + 16), (0, 0), (32, 32), BODY_STATIC)
		self.sprite = Sprite('./assets/img/arrow_blocks.png', (32, 32), 0.1)
		self.id = ID_OBJ
		self.colors = COLORS + ['gray']
		color_index = self.colors.index(color)
		self.active_color = self.colors[ color_index ]
		self.sprite.use_frames([color_index])
		self.sprite.update(5)
		self.direction = direction # 1(down) or -1(up)
		self.sprite.set_direction(False, direction)

	def change_obj_velocity(self, obj):
		if obj.active_color != self.active_color:
			if obj.bounce_timer <= 0.0:
				if obj.id == ID_PLAYER:
					PLAY_SOUND(obj.sound_jump)
				obj.bounce_timer = self.BOUNCE_MIN_INTERVAL
				if obj.vel.y < 50:
					obj.vel.y = PLAYER_JUMP_FORCE
				else:
					obj.vel.y = (obj.vel.y * self.BOUNCE_FACTOR) * self.direction
			return True
		return False

	def update(self, dt):
		pass

	def draw(self, screen, view_rect):
		rect = copy.copy(self.rect)
		rect.left -= view_rect.left - rect.width / 2
		rect.top -= view_rect.top
		self.sprite.draw(screen, rect)
开发者ID:glhrmfrts,项目名称:rgb,代码行数:40,代码来源:play_scene.py


注:本文中的sprite.Sprite.draw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。