• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python sprite.spritecollide函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pygame.sprite.spritecollide函数的典型用法代码示例。如果您正苦于以下问题:Python spritecollide函数的具体用法?Python spritecollide怎么用?Python spritecollide使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_collide_mask__opaque

    def test_collide_mask__opaque(self):
        # make some fully opaque sprites that will collide with masks.
        self.s1.image.fill((255,255,255,255))
        self.s2.image.fill((255,255,255,255))
        self.s3.image.fill((255,255,255,255))

        # masks should be autogenerated from image if they don't exist.
        self.assertEqual (
            sprite.spritecollide (
                self.s1, self.ag2, dokill = False,
                collided = sprite.collide_mask
            ),
            [self.s2]
        )

        self.s1.mask = pygame.mask.from_surface(self.s1.image)
        self.s2.mask = pygame.mask.from_surface(self.s2.image)
        self.s3.mask = pygame.mask.from_surface(self.s3.image)

        # with set masks.
        self.assertEqual (
            sprite.spritecollide (
                self.s1, self.ag2, dokill = False,
                collided = sprite.collide_mask
            ),
            [self.s2]
        )
开发者ID:NardinelHD,项目名称:PixelBuild,代码行数:27,代码来源:sprite_test.py


示例2: update

    def update(self, dt):
        self.player.update(dt)
        self.coins.update(dt)

        # lock player in bounds
        self.player.rect.clamp_ip(self.bounds)

        spritecollide(self.player, self.coins, True)
开发者ID:RMeiselman,项目名称:CS112-Spring2012,代码行数:8,代码来源:level.py


示例3: update

    def update(self, dt):
        self.player.update(dt)
        self.cookies.update(dt)

        # lock player in bounds
        self.player.rect.clamp_ip(self.bounds)

        # collide player with coins
        spritecollide(self.player, self.cookies, True)
开发者ID:RMeiselman,项目名称:CS112-Spring2012,代码行数:9,代码来源:main.py


示例4: update

    def update(self, time, player_group, platform_group):
        if self.KILL:
            self.explode()
        hit_players = PS.spritecollide(self, player_group, False)
        hit_platforms = PS.spritecollide(self, platform_group, False)

        if hit_players:
            for this_player in hit_players:
                self.react(this_player)

        if hit_platforms:
            for this_platform in hit_platforms:
                self.rect.centery = (this_platform.get_top() - self.rect.height/4)
开发者ID:rogerzxu,项目名称:OrganDonor,代码行数:13,代码来源:bone.py


示例5: update

    def update(self):
        dt = self.clock.tick(FPS)

        # basic update
        self.player.update(dt)
        self.coins.update(dt)

        # check if the player is on the path
        onpath = spritecollide(self.player, self.level.path, False)
        self.player.on_path(onpath)

        # collide coins
        for coin in spritecollide(self.player, self.coins, True):
            self.score += 1

        self.cam.update(self.player.rect)
开发者ID:AKilgore,项目名称:CS112-Spring2012,代码行数:16,代码来源:game.py


示例6: kill_people

	def kill_people(self, scene):
		hitted_players = sprite.spritecollide(self, scene.enemyGroup, False)
		# scene.bulletGroup.remove(self)
		for player in hitted_players:
			player.hit_by_bullet(self.atk)
			# A bullet should not be capable of going through an infinite amount of bodies
			scene.bulletGroup.remove(self)
开发者ID:martinaLopez,项目名称:Aleph,代码行数:7,代码来源:Bullet.py


示例7: detect_collision

    def detect_collision(self):
        collisions = spritecollide(self.player, self.obstacle_group, True)

        for c in collisions:
            self.collision_strategy_factory.get_strategy(c).on_collision()
            self.obstacles.remove(c)
            c.kill()
开发者ID:mlefebvre,项目名称:ArcadeCS2014,代码行数:7,代码来源:obstacle_manager.py


示例8: useportal

 def useportal(self):
     # check for portals
     portalbox = spritecollide(self,self.level.portal_list,False)
     if portalbox != []:
         return portalbox[0].destination
     else:
         return 0
开发者ID:achang6,项目名称:wallstory,代码行数:7,代码来源:player.py


示例9: handle_collision

 def handle_collision(self, bg, m_back=False):
     if m_back:
         face_copy = self.face
         self.face = self.move_face
     collisions = PS.spritecollide(self, bg, False)
     if 'r' in self.face:
         for collision in collisions:
             if(self.rect.x +
                self.rect.width) >= collision.rect.left:
                 self.rect.x = collision.rect.left - self.rect.width
     elif 'l' in self.face:
         for collision in collisions:
             if (self.rect.x) <= (collision.rect.left +
                                  collision.rect.width):
                 self.rect.x = collision.rect.left + \
                     collision.rect.width
     elif 'd' in self.face:
         for collision in collisions:
             if(self.rect.y +
                self.rect.height) >= collision.rect.top:
                 self.rect.y = collision.rect.top - self.rect.height
     elif 'u' in self.face:
         for collision in collisions:
             if (self.rect.y <= (collision.rect.top +
                                 collision.rect.height)):
                 self.rect.y = collision.rect.top + \
                     collision.rect.height
     if m_back:
         self.face = face_copy
     return (collisions is None)
开发者ID:fryingpan,项目名称:Assignment2,代码行数:30,代码来源:Enemy.py


示例10: handle_player

 def handle_player(self, player):
     player.sprites()[0].set_attacking_rect()
     collisions = PS.spritecollide(self, player, False)
     if(len(collisions) == 1 and isinstance(collisions[0], Player)):
         if(Globals.INVINCIBILITY_COUNT == 0):
             self.attacked_player = True
     player.sprites()[0].reset_attacking_rect()
开发者ID:fryingpan,项目名称:Assignment2,代码行数:7,代码来源:Enemy.py


示例11: update

 def update(self):
     BouncySprite.update(self)
     if sprite.spritecollide(self, self.game.monsters, True):
         self.kill()
     self.life -= 1
     if self.life <= 0:
         self.kill()
开发者ID:DrJosh9000,项目名称:RobotGame,代码行数:7,代码来源:robotgame.py


示例12: execute

    def execute(self):
        '''Controls the actor movement as a regular object under Newton's laws. Checks collisions with grounds'''
        actor=self.__parent
        self.velocity=self.velocity+(actor.steering_acceleration+PS_freefall.GRAVITY)*self.time_step
        
        self.position=self.position+self.velocity*self.time_step
        if self.i==4:
            for floor in spritecollide(actor, actor.get_level().floors, False):
                if not actor.crect.colliderect(floor.crect):
                    continue
                if -16<floor.crect.top-actor.crect.bottom<3 and self.velocity[1]>=0:
                    self.velocity[1]=0
                    actor.standing_on=floor
                    self.position[1]=floor.crect.top-actor.rect.height/2
                    self.__parent_PM.set_state(PS_walking)
                    continue
                
                elif -16<floor.crect.left-actor.crect.right<3 and self.velocity[0]>0:
                    self.velocity[0]=-self.velocity[0]
                elif -3<floor.crect.right-actor.crect.left<16 and self.velocity[0]<0:
                    self.velocity[0]=-self.velocity[0]
                elif -3<floor.crect.bottom-actor.crect.top<16 and self.velocity[1]<0:
                    self.velocity[1]=-self.velocity[1]
            self.i=0
        else: self.i+=1

        actor.set_position([self.position[0], self.position[1]])
开发者ID:kakila,项目名称:cavemen,代码行数:27,代码来源:physics_states.py


示例13: update

	def update(self, time, scene):
		self.floatX += self.speedX * time * GRENADE_SPEED
		self.floatY += self.speedY * time * GRENADE_SPEED
		self.rect.x = roundToInt(self.floatX)
		self.rect.y = roundToInt(self.floatY)

		self.timeToBoom -= time

		if self.timeToBoom <= 0:
			scene.bulletGroup.remove(self)
			scene.bulletGroup.add(Explosion(self.rect.x, self.rect.y))

			# Kill people!
			originalRect = self.rect.copy()
			self.rect.inflate_ip(80, 80)  # 80x80 area damage
			
			enemies_hit = sprite.spritecollide(self, scene.enemyGroup, False)

			for enemy in enemies_hit:
				# Friendly fire
				if self.creator.__class__.__name__ == enemy.__class__.__name__:
					continue
				enemy.receive_attack(self.atk)

			if sprite.collide_rect(self, scene.player):
				scene.player.receive_attack(self.atk)

			self.rect = originalRect  # Restore the real rect

		self.timeToStop -= time

		if self.timeToStop <= 0:
			self.speedX = 0
			self.speedY = 0
开发者ID:dgalaktionov,项目名称:Aleph,代码行数:34,代码来源:ThrowedGrenade.py


示例14: test_collide_circle__no_radius_set

 def test_collide_circle__no_radius_set(self):
     # collide_circle with no radius set.
     self.assertEqual (
         sprite.spritecollide (
             self.s1, self.ag2, dokill = False, collided = sprite.collide_circle
         ),
         [self.s2]
     )
开发者ID:NardinelHD,项目名称:PixelBuild,代码行数:8,代码来源:sprite_test.py


示例15: test_spritecollide__works_if_collided_cb_is_None

 def test_spritecollide__works_if_collided_cb_is_None(self):
     # Test that sprites collide without collided function.
     self.assertEqual (
         sprite.spritecollide (
             self.s1, self.ag2, dokill = False, collided = None
         ),
         [self.s2]
     )
开发者ID:NardinelHD,项目名称:PixelBuild,代码行数:8,代码来源:sprite_test.py


示例16: test_spritecollide__collided_defaults_to_collide_rect

 def test_spritecollide__collided_defaults_to_collide_rect(self):
     # collide_rect should behave the same as default.
     self.assertEqual (
         sprite.spritecollide (
             self.s1, self.ag2, dokill = False, collided = sprite.collide_rect
         ),
         [self.s2]
     )
开发者ID:NardinelHD,项目名称:PixelBuild,代码行数:8,代码来源:sprite_test.py


示例17: grounded

 def grounded(self):
     "Check for ground underneath players feet, if not found switch to falling state"
     tmp = self.player.rect
     self.player.rect = self.player.rect.move(0, 1)
     collides = spritecollide(self.player, level.tile_group, False)
     if not collides:
         self.fall()
         
     self.player.rect = tmp
开发者ID:jodonnell,项目名称:python_game,代码行数:9,代码来源:grounded_state.py


示例18: detect_collision

    def detect_collision(self):
        if self.elements['ship'].sprite:
            self.ship_collides = spritecollideany(self.elements['ship'].sprite, self.elements['asteroids'])
            self.ship_catches = spritecollide(self.elements['ship'].sprite, self.elements['power-ups'], True)

        if groupcollide(self.elements['lasers'], self.elements['asteroids'], True, True):
            if randint(1, 20) == 1:
                self.newPU = True
            self.score_add(50)
开发者ID:JotaVeUltra,项目名称:DevInVale2015,代码行数:9,代码来源:game.py


示例19: test_collide_circle_ratio__no_radius_and_ratio_of_one

 def test_collide_circle_ratio__no_radius_and_ratio_of_one(self):
     # collide_circle_ratio with no radius set, at a 1.0 ratio.
     self.assertEqual (
         sprite.spritecollide (
             self.s1, self.ag2, dokill = False,
             collided = sprite.collide_circle_ratio(1.0)
         ),
         [self.s2]
     )
开发者ID:NardinelHD,项目名称:PixelBuild,代码行数:9,代码来源:sprite_test.py


示例20: test_collide_rect_ratio__ratio_of_one_like_default

 def test_collide_rect_ratio__ratio_of_one_like_default(self):
     # collide_rect_ratio should behave the same as default at a 1.0 ratio.
     self.assertEqual (
         sprite.spritecollide (
             self.s1, self.ag2, dokill = False,
             collided = sprite.collide_rect_ratio(1.0)
         ),
         [self.s2]
     )
开发者ID:NardinelHD,项目名称:PixelBuild,代码行数:9,代码来源:sprite_test.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sprite.Group类代码示例发布时间:2022-05-25
下一篇:
Python rect.Rect类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap