def setup_frames(self): """Put the image frames in a list to be animated""" self.frames.append(IMAGE_SLIDER.get_enemies("turtle_1")) self.frames.append(IMAGE_SLIDER.get_enemies("turtle_2")) self.frames.append(IMAGE_SLIDER.get_enemies("turtle_3"))
def setup_frames(self): """Set the frames to a list""" for num in xrange(2, -1, -1): self.frames.append( IMAGE_SLIDER.get_image('question_mark_{}'.format(num))) for num in xrange(0, 3): self.frames.append( IMAGE_SLIDER.get_image('question_mark_{}'.format(num)))
def setup_frames(self): """Put the image frames in a list to be animated""" self.frames.append(IMAGE_SLIDER.get_enemies("goomba_1")) self.frames.append(IMAGE_SLIDER.get_enemies("goomba_2")) self.frames.append(IMAGE_SLIDER.get_enemies("goomba_3")) self.frames.append(pg.transform.flip(self.frames[0], False, True))
def setup_frames(self): """Put the image frames in a list to be animated""" self.frames.append( IMAGE_SLIDER.get_enemies('turtle_1')) self.frames.append( IMAGE_SLIDER.get_enemies('turtle_2')) self.frames.append(IMAGE_SLIDER.get_enemies('turtle_3'))
def setup_frames(self): """Put the image frames in a list to be animated""" self.frames.append( IMAGE_SLIDER.get_enemies('goomba_1')) self.frames.append( IMAGE_SLIDER.get_enemies('goomba_2')) self.frames.append( IMAGE_SLIDER.get_enemies('goomba_3')) self.frames.append(pg.transform.flip(self.frames[0], False, True))
def __init__(self, x, y, image='red_floor'): pg.sprite.Sprite.__init__(self) self.image = IMAGE_SLIDER.get_image(image) self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y self.mask = pg.mask.from_surface(self.image)
def setup_frames(self): """create the frame list""" self.frames = [] image = IMAGE_SLIDER.get_image('broken_brick', multiplier=BRICK_SIZE_MULTIPLIER) reversed_image = pg.transform.flip(image, True, False) self.frames.append(image) self.frames.append(reversed_image)
def __init__(self, x, y, level): # Call the parent's constructor pygame.sprite.Sprite.__init__(self) # Set the image the player starts with # Set speed vector of player self.image = IMAGE_SLIDER.get_mario('dying') self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y self.level = level self.change_y = -PY_JUMP_Y_VELOCITY_1 * self.level.physics_info['seconds'] self.gravity = 0
def __init__(self, x, y, level, contents='6coins'): Brick.__init__(self, x, y, self.setup_frames, contents) self.frame_index = 0 self.level = level self.image = self.frames[self.frame_index] self.opened_frame = [IMAGE_SLIDER.get_image('question_mark_3')] self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y self.coin_total = 1 self.current_time = 0
def __init__(self, x, y, level): # Call the parent's constructor pygame.sprite.Sprite.__init__(self) # Set the image the player starts with # Set speed vector of player self.image = IMAGE_SLIDER.get_mario('dying') self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y self.level = level self.change_y = -PY_JUMP_Y_VELOCITY_1 * self.level.physics_info[ 'seconds'] self.gravity = 0
def __init__(self): """ Constructor function """ # Call the parent's constructor pygame.sprite.Sprite.__init__(self) # Set the image the player starts with # Set speed vector of player self.change_x = 0.0 self.speed = 0 self.gravity = 0 self.jump_physics = {'vel':0, 'antigravity': 0, 'gravity': 0} self.__anti_gravity = False self.__cutjump = False self.__change_y = 0.0 self.__max_vel = PY_MAX_MARIO_WALK_VEL self.__speed_acc = PY_MAX_WALK_ACC self.__running = False # This holds all the images for the animated walk left/right # of our player self.walking_frames_l = [] self.walking_frames_r = [] # What direction is the player facing? self.direction = PY_RIGHT # List of sprites we can bump against self.level = None self.state = MARIO_STATE_NORMAL for index in xrange(5): #print index mario_image = IMAGE_SLIDER.get_mario('small_walk_{}'.format(index)) self.walking_frames_r.append(mario_image) rotated = pygame.transform.flip(mario_image, True, False) self.walking_frames_l.append(rotated) self.image = self.walking_frames_r[0] # Set a referance to the image rect. self.rect = self.image.get_rect()
def __init__(self): """ Constructor function """ # Call the parent's constructor pygame.sprite.Sprite.__init__(self) # Set the image the player starts with # Set speed vector of player self.change_x = 0.0 self.speed = 0 self.gravity = 0 self.jump_physics = {'vel': 0, 'antigravity': 0, 'gravity': 0} self.__anti_gravity = False self.__cutjump = False self.__change_y = 0.0 self.__max_vel = PY_MAX_MARIO_WALK_VEL self.__speed_acc = PY_MAX_WALK_ACC self.__running = False # This holds all the images for the animated walk left/right # of our player self.walking_frames_l = [] self.walking_frames_r = [] # What direction is the player facing? self.direction = PY_RIGHT # List of sprites we can bump against self.level = None self.state = MARIO_STATE_NORMAL for index in xrange(5): #print index mario_image = IMAGE_SLIDER.get_mario('small_walk_{}'.format(index)) self.walking_frames_r.append(mario_image) rotated = pygame.transform.flip(mario_image, True, False) self.walking_frames_l.append(rotated) self.image = self.walking_frames_r[0] # Set a referance to the image rect. self.rect = self.image.get_rect()
def __init__(self, x, y, level): pygame.sprite.Sprite.__init__(self) self.frame_index = 0 self.frames = [] self.level = level for index in xrange(0, 4): self.frames.append(IMAGE_SLIDER.get_item('collected_coin_{}'.format(index), 1)) self.image = self.frames[self.frame_index] self.rect = self.frames[1].get_rect() #1 is the wider coin self.rect.x = x self.rect.y = y self.timeout = 1 self.gravity = 0 self.frame_count = 0 self.level.stats.coins += 1
def __init__(self, x, y, level): pygame.sprite.Sprite.__init__(self) self.frame_index = 0 self.frames = [] self.level = level for index in xrange(0, 4): self.frames.append( IMAGE_SLIDER.get_item('collected_coin_{}'.format(index), 1)) self.image = self.frames[self.frame_index] self.rect = self.frames[1].get_rect() #1 is the wider coin self.rect.x = x self.rect.y = y self.timeout = 1 self.gravity = 0 self.frame_count = 0 self.level.stats.coins += 1
def setup_frames(self): """Set the frames to a list""" self.frames.append(IMAGE_SLIDER.get_image('red_brick')) self.frames.append(IMAGE_SLIDER.get_image('empty_brick'))
def update(self): """ Move the player. """ # Gravity self.calc_grav() # Move left/right self.rect.x += self.change_x pos = self.rect.x + self.level.world_shift if self.state == MARIO_STATE_NORMAL: if self.change_x: frame = int(pos % 30 / 10) + 1 if self.direction == PY_RIGHT: self.image = self.walking_frames_r[frame] else: self.image = self.walking_frames_l[frame] else: if self.direction == PY_RIGHT: self.image = self.walking_frames_r[0] else: self.image = self.walking_frames_l[0] elif self.state == MARIO_STATE_JUMPING: self.image = IMAGE_SLIDER.get_mario("small_jumping") # See if we hit anything block_hit_list = pygame.sprite.spritecollide(self, self.level.platform_list, False) for block in block_hit_list: # If we are moving right, # set our right side to the left side of the item we hit if self.change_x > 0: self.rect.right = block.rect.left elif self.change_x < 0: # Otherwise if we are moving left, do the opposite. self.rect.left = block.rect.right #we don't walk to walk outside the map. if self.rect.x < 0: self.rect.x = 0 # Move up/down self.rect.y += self.change_y # Check and see if we hit anything block_hit_list = pygame.sprite.spritecollide(self, self.level.platform_list, False) for block in block_hit_list: # Reset our position based on the top/bottom of the object. if self.change_y > 0: self.rect.bottom = block.rect.top if self.state == MARIO_STATE_JUMPING: self.state = MARIO_STATE_NORMAL self.__cutjump = False elif self.change_y < 0: self.rect.top = block.rect.bottom self.__anti_gravity = False self.__cutjump = True if isinstance(block, Brick): block.start_bump() # Stop our vertical movement self.gravity = 0 self.change_y = 0 #let's kill some enemies. or be killed :P enemies_hit_list = pygame.sprite.spritecollide(self, self.level.enemy_list, False) for enemy in enemies_hit_list: if enemy.rect.collidepoint(self.rect.midbottom) or \ enemy.rect.collidepoint(self.rect.bottomright) or \ enemy.rect.collidepoint(self.rect.bottomleft) : #We kill it! self.change_y = -PY_ENEMY_STOMP_Y_SPEED * self.level.physics_info[ 'seconds'] self.jump_physics['vel'] = PY_ENEMY_STOMP_Y_SPEED self.gravity = 0 self.state = MARIO_STATE_JUMPING enemy.jumped_on() else: if enemy.state != JUMPED_ON: self.kill() self.level.add_animation( DyingMario(self.rect.x, self.rect.y, self.level))
def __init__(self, x, y, image ): pg.sprite.Sprite.__init__(self) self.image = IMAGE_SLIDER.get_image(image) self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y
def update(self): """ Move the player. """ # Gravity self.calc_grav() # Move left/right self.rect.x += self.change_x pos = self.rect.x + self.level.world_shift if self.state == MARIO_STATE_NORMAL: if self.change_x: frame = int(pos % 30 / 10) + 1 if self.direction == PY_RIGHT: self.image = self.walking_frames_r[frame] else: self.image = self.walking_frames_l[frame] else: if self.direction == PY_RIGHT: self.image = self.walking_frames_r[0] else: self.image = self.walking_frames_l[0] elif self.state == MARIO_STATE_JUMPING: self.image = IMAGE_SLIDER.get_mario("small_jumping") # See if we hit anything block_hit_list = pygame.sprite.spritecollide(self, self.level.platform_list, False) for block in block_hit_list: # If we are moving right, # set our right side to the left side of the item we hit if self.change_x > 0: self.rect.right = block.rect.left elif self.change_x < 0: # Otherwise if we are moving left, do the opposite. self.rect.left = block.rect.right #we don't walk to walk outside the map. if self.rect.x < 0: self.rect.x = 0 # Move up/down self.rect.y += self.change_y # Check and see if we hit anything block_hit_list = pygame.sprite.spritecollide(self, self.level.platform_list, False) for block in block_hit_list: # Reset our position based on the top/bottom of the object. if self.change_y > 0: self.rect.bottom = block.rect.top if self.state == MARIO_STATE_JUMPING: self.state = MARIO_STATE_NORMAL self.__cutjump = False elif self.change_y < 0: self.rect.top = block.rect.bottom self.__anti_gravity = False self.__cutjump = True if isinstance(block, Brick): block.start_bump() # Stop our vertical movement self.gravity = 0 self.change_y = 0 #let's kill some enemies. or be killed :P enemies_hit_list = pygame.sprite.spritecollide(self, self.level.enemy_list, False) for enemy in enemies_hit_list: if enemy.rect.collidepoint(self.rect.midbottom) or \ enemy.rect.collidepoint(self.rect.bottomright) or \ enemy.rect.collidepoint(self.rect.bottomleft) : #We kill it! self.change_y = -PY_ENEMY_STOMP_Y_SPEED * self.level.physics_info['seconds'] self.jump_physics['vel'] = PY_ENEMY_STOMP_Y_SPEED self.gravity = 0 self.state = MARIO_STATE_JUMPING enemy.jumped_on() else: if enemy.state != JUMPED_ON: self.kill() self.level.add_animation(DyingMario(self.rect.x, self.rect.y, self.level))