Python pygame.sprite() Examples
The following are 8
code examples of pygame.sprite().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pygame
, or try the search function
.
Example #1
Source File: game_functions.py From alien-invasion-game with MIT License | 6 votes |
def check_bullet_alien_collision(ai_settings: Settings, stats: GameStats, game_items: GameItems): """Update the game when a bullet hits an alien(s).""" # Get rid of bullet and aliens that have collided. collision = pygame.sprite.groupcollide(game_items.bullets, game_items.aliens, True, True) if collision: for aliens_hit_list in collision.values(): stats.score += ai_settings.alien_points * len(aliens_hit_list) game_items.sb.prep_score() check_high_score(stats, game_items) # Create new fleet after fleet is empty. if len(game_items.aliens.sprites()) == 0: game_items.bullets.empty() ai_settings.increase_speed() stats.level += 1 game_items.sb.prep_level() create_fleet(ai_settings, game_items)
Example #2
Source File: cat3.py From stuntcat with GNU Lesser General Public License v2.1 | 5 votes |
def update(self): # if self.just_happened is not None: # print(self.just_happened) from_top = 100 if self.just_happened == 'offscreen': self.dirty = True self.rect.x = -1000 self.rect.y = -1000 sfx('foot_elephant.ogg', stop=1) elif self.just_happened == 'poise left': self.rect.x = 0 self.rect.y = from_top - self.height self.dirty = True sfx('foot_elephant.ogg', play=1) elif self.just_happened == 'stomp left': self.rect.y = self.scene.cat_wire_height - self.height#(self.height - self.image.get_height()) - self.scene.cat_wire_height self.rect.x = 0 self.dirty = True if pygame.sprite.collide_rect(self, self.scene.cat): self.scene.reset_on_death() self.dirty = True elif self.just_happened == 'poise right': self.rect.x = self.width//2 self.rect.y = from_top - self.height self.dirty = True sfx('foot_elephant.ogg', play=1) elif self.just_happened == 'stomp right': self.rect.x = self.width//2 self.rect.y = self.scene.cat_wire_height - self.height self.dirty = True if pygame.sprite.collide_rect(self, self.scene.cat): self.scene.reset_on_death() self.dirty = True
Example #3
Source File: game_functions.py From alien-invasion-game with MIT License | 5 votes |
def update_aliens(ai_settings: Settings, stats: GameStats, game_items: GameItems): """Update position for each alien.""" check_fleet_edges(ai_settings, game_items.aliens) game_items.aliens.update(stats) # Collision between ship and aliens. if pygame.sprite.spritecollideany(game_items.ship, game_items.aliens): ship_hit(ai_settings, stats, game_items) check_aliens_bottom(ai_settings, stats, game_items)
Example #4
Source File: demo.py From rpi_lcars with MIT License | 5 votes |
def __init__(self, imagepath): pygame.sprite.DirtySprite.__init__(self) self.image = pygame.image.load(imagepath).convert() self.rect = self.image.get_rect()
Example #5
Source File: testsprite.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def __init__(self): ## pygame.sprite.Sprite.__init__(self) FRG.DirtySprite.__init__(self) self.image = Thingy.images[0] self.rect = self.image.get_rect() self.rect.x = randint(0, screen_dims[0]) self.rect.y = randint(0, screen_dims[1]) #self.vel = [randint(-10, 10), randint(-10, 10)] self.vel = [randint(-1, 1), randint(-1, 1)] self.dirty = 2
Example #6
Source File: testsprite.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def __init__(self): ## pygame.sprite.Sprite.__init__(self) FRG.DirtySprite.__init__(self) self.image = Thingy.images[0] self.rect = self.image.get_rect() self.rect.x = randint(0, screen_dims[0]) self.rect.y = randint(0, screen_dims[1]) #self.vel = [randint(-10, 10), randint(-10, 10)] self.vel = [randint(-1, 1), randint(-1, 1)] self.dirty = 2
Example #7
Source File: testsprite.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def __init__(self): ## pygame.sprite.Sprite.__init__(self) FRG.DirtySprite.__init__(self) self.image = Thingy.images[0] self.rect = self.image.get_rect() self.rect.x = randint(0, screen_dims[0]) self.rect.y = randint(0, screen_dims[1]) #self.vel = [randint(-10, 10), randint(-10, 10)] self.vel = [randint(-1, 1), randint(-1, 1)] self.dirty = 2
Example #8
Source File: testsprite.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def __init__(self): ## pygame.sprite.Sprite.__init__(self) FRG.DirtySprite.__init__(self) self.image = Thingy.images[0] self.rect = self.image.get_rect() self.rect.x = randint(0, screen_dims[0]) self.rect.y = randint(0, screen_dims[1]) #self.vel = [randint(-10, 10), randint(-10, 10)] self.vel = [randint(-1, 1), randint(-1, 1)] self.dirty = 2