def main(): #create initial objects pygame.init() pygame.mixer.init() screen = pygame.display.set_mode((1408, 960), pygame.FULLSCREEN) screen_rect = screen.get_rect() timer = pygame.time.get_ticks() elapsed = 0 level_complete = False asena = Asena( pygame.image.load("Asena Sprite sheet with jump.png").convert_alpha()) background = pygame.image.load("Stone BG.png").convert_alpha() background_rect = background.get_rect() platform = Sprite(pygame.image.load("Stone Platform.png").convert_alpha()) platform_rect = platform.rect spikes = Sprite(pygame.image.load("Spikes.png").convert_alpha()) fire = Sprite(pygame.image.load("lava.png").convert_alpha()) key = Key(pygame.image.load("Key.png").convert_alpha()) door = Door(pygame.image.load("Door.png").convert_alpha()) arrow_surf = pygame.image.load("Arrow.png").convert_alpha() arrow2_surf = pygame.image.load("Arrow2.png").convert_alpha() level3_file = open("Asena's Quest/game/level_data/level_3.txt") level3 = level3_file.readlines() level3 = [line.strip() for line in level3] master_clock = pygame.time.Clock() arrow_list = [] arrow2_list = [] delta_time = 0 arrow_threshold = 1500 arrow_timer = 0 platform_list = [] spike_list = [] fire_list = [] music = pygame.mixer.music.load("Okami - Battle of Ninetails.ogg") pygame.mixer.music.play(-1) for row in range(len(level3)): for column in range(len(level3[row])): if level3[row][column] == '@': arrow_list.append( Arrow(arrow_surf, pygame.Rect(column * 64, row * 64, 64, 64))) if level3[row][column] == 'a': arrow2_list.append( Arrow2(arrow2_surf, pygame.Rect(column * 64, row * 64, 64, 64))) elif level3[row][column] == 'p': platform_list.append(pygame.Rect(column * 64, row * 64, 64, 64)) elif level3[row][column] == 's': spike_list.append(pygame.Rect(column * 64, row * 64, 64, 64)) elif level3[row][column] == 'f': fire_list.append(pygame.Rect(column * 64, row * 64, 64, 64)) screen.blit(asena.surf, asena.rect) while (asena.hp > 0) and (level_complete == False): #tick the clock master_clock.tick(100) elapsed = pygame.time.get_ticks() - timer timer = pygame.time.get_ticks() #process input for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: return False elif (event.key == pygame.K_w): asena.is_moving[2] = True elif event.key == pygame.K_s and key.rect.colliderect( asena.rect) == True: asena.has_key = True elif event.key == pygame.K_s and (asena.has_key == True) and ( door.rect.colliderect(asena.rect) == True): level_complete = True elif event.key == pygame.K_a: asena.is_moving[0] = True elif event.key == pygame.K_d: asena.is_moving[1] = True else: asena.level_complete = False if event.type == pygame.KEYUP: asena.is_moving = [False, False, False] #draw screen.fill((0, 0, 0)) screen.blit(background, background_rect) for row in range(len(level3)): for column in range(len(level3[row])): if level3[row][column] == 'p': screen.blit(platform.surf, pygame.Rect(column * 64, row * 64, 64, 64)) elif level3[row][column] == 's': screen.blit(spikes.surf, pygame.Rect(column * 64, row * 64, 64, 64)) elif level3[row][column] == 'f': screen.blit(fire.surf, pygame.Rect(column * 64, row * 64, 64, 64)) elif level3[row][column] == 'k': if asena.has_key == False: key.draw(screen) elif level3[row][column] == 'd': door.draw(screen) #shoot arrows arrow_timer += elapsed if arrow_timer >= arrow_threshold: arrow_timer = 0 for arrow2 in arrow2_list: arrow2.rect.right = 1408 for arrow2 in arrow2_list: arrow2.update(screen, elapsed) arrow2.draw(screen) arrow_timer += elapsed if arrow_timer >= arrow_threshold: arrow_timer = 0 for arrow in arrow_list: arrow.rect.left = 0 for arrow in arrow_list: arrow.update(screen, elapsed) arrow.draw(screen) asena.update(platform_list, elapsed, screen_rect, arrow_list, platform_list, spike_list, fire_list) asena.draw(screen) asena.health(screen) new = asena.rect timer = pygame.time.get_ticks() #flip buffers pygame.display.flip() return level_complete
def draw(self, screen): screen.blit(self.surf, self.rect, pygame.Rect(self.frame * 64, self.direction * 32, 64, 32))
def draw(self, screen): screen.blit(self.surf, self.rect, pygame.Rect(self.frame * 50, self.direction * 50, 64, 64))