diff --git a/CODIGOATUAL b/CODIGOATUAL deleted file mode 100644 index 3cc5612..0000000 --- a/CODIGOATUAL +++ /dev/null @@ -1,356 +0,0 @@ -import pygame -import button -import csv -from os import listdir -from os.path import isfile,join - -pygame.init() -############### FABY ############################# -#GAME WINDOW -largura = 1500 -altura = 640 -#lower -margem = 100 -#side -margem_lado = 300 - - -tela = pygame.display.set_mode((largura, altura + margem)) -pygame.display.set_caption('Após a enchente') - -####### - -################### LUCAS ############################### -FPS = 30 -PLAYER_VEL = 1 -def virar(sprites): - return[pygame.transform.flip(sprite,True,False) for sprite in sprites] - -#BAIXAR AS IMAGENS DO SPRITE E TODAS AS IMAGENS DE DIREITA PARA ESQUERDA E VICE E VERSA -def baixar_sprite(dir1,width,height,direction = False): - path = join(dir1) - images = [f for f in listdir(path) if isfile(join(path,f))] - all_sprites = {} - for image in images: - sprite_sheet = pygame.image.load(join(path, image)).convert_alpha() - - sprites = [] - for i in range (sprite_sheet.get_width() // width): - surface = pygame.Surface((width,height), pygame.SRCALPHA, 32) - rect = pygame.Rect(i * width, 0, width, height) - surface.blit(sprite_sheet, (0,0), rect) - sprites.append(pygame.transform.scale(surface,(100,120)))#TAMANHO DO PERSONAGEM PRINCIPAL(LUCAS) - - if direction: - all_sprites[image.replace(".png", "") + "_direita"] = sprites - all_sprites[image.replace(".png", "") + "_esquerda"] = virar(sprites) - else: - all_sprites[image.replace(".png", "")] = sprites - return all_sprites - - -#CLASSE PERSONAGEM PRINCIPAL -class Jogador(pygame.sprite.Sprite): - GRAVITY = 0.1 - SPRITES = baixar_sprite("personagem",48,50, True) - ANIMATION_DELAY = 50 - #INICIO DAS VARIAVEIS PRINCIPAIS - def __init__(self, char_type, x, y, width, height): - self.rect = pygame.Rect(x,y,width,height) - ######## - self.char_type = char_type - self.y_vel = 0 - ##self speed - self.x_vel = 0 - self.mask = None - #mudanca - self.virar = 'esquerda' - ##### - self.attack_animation_count = 0 - self.animation_count = 0 - self.fall_count = True - self.jump_count = False - self.ataque = False - - #FUNCAO SOMA A VEL NA POSICAO PRA ANDAR - def move(self, dx, dy): - #################### - if self.char_type == 'player': - if self.rect.left + dx < -50 or self.rect.right + dx > largura + 50: - dx = 0 - self.rect.x += dx - self.rect.y += dy - def mover_esquerda(self, vel): - self.x_vel = -vel - if self.virar != 'esquerda': - self.virar = 'esquerda' - self.animation_count = 0 - - def mover_direita(self,vel): - self.x_vel = vel - if self.virar != 'direita': - self.virar = 'direita' - self.animation_count = 0 - def jump(self): - if self.jump_count == False: - ######mudanca####### - self.y_vel = -5 - self.jump_count = True - - #FUNCAO QUE VAI VERIFICAR O QUE O PERSONAGEM FAZ A CADA FRAME - def loop(self, fps): - self.y_vel += min(0.05, (self.fall_count/6*fps) * self.GRAVITY) - self.move(self.x_vel,self.y_vel) - self.checar_chao(self.y_vel) - self.fall_count += 0.3 - self.update_sprite() - - def update_sprite(self): - if self.ataque: - sprite_sheet_name = "Attack" + "_" + self.virar - sprites = self.SPRITES[sprite_sheet_name] - sprite_index = (self.attack_animation_count // self.ANIMATION_DELAY) % len(sprites) - self.sprite = sprites[sprite_index] - self.attack_animation_count += 1 - if self.attack_animation_count >= len(sprites) * self.ANIMATION_DELAY: - self.ataque = False - self.attack_animation_count = 0 - else: - sprite_sheet = "Idle" - if self.x_vel != 0: - sprite_sheet = "Walk" - sprite_sheet_name = sprite_sheet + "_" + self.virar - sprites = self.SPRITES[sprite_sheet_name] - sprite_index = (self.animation_count // self.ANIMATION_DELAY) % len(sprites) - self.sprite = sprites[sprite_index] - self.animation_count += 1 - - self.update() - - def update(self): - self.rect = self.sprite.get_rect(topleft = (self.rect.x, self.rect.y)) - self.mask = pygame.mask.from_surface(self.sprite) - def atacar(self): - if self.ataque == False: - self.ataque = True - - def draw(self,tela): - tela.blit(self.sprite, (self.rect.x,self.rect.y)) - - def checar_chao(self,dy): - if self.rect.bottom + dy > 563: - self.y_vel = 0 - self.jump_count = False - -player = Jogador('player',100,100,80,80)#tamanhos do personagem(Lucas) - -"""""class World(): - def process_data(self, data): - self.level_length = len(data[0]) - for y, row in enumerate(lista): - for x, tile in enumerate(row): - if tile >= 0: - img = img_lista[tile] - img_rect = img.get_rect() - img_rect.x = x * tamanho - img_rect.y = y * tamanho - tile_data = (img, img_rect) - if tile >= 3 and tile <= 4: - water = Water(img, x * tamanho, y * tamanho) - water_group.add(water) - if tile == 15:#create player - player = Jogador('player',100,100,80,80) -""""" - - -def movimento(self): - keys = pygame.key.get_pressed() - player.x_vel = 0 - if keys[pygame.K_LEFT]: - player.mover_esquerda(PLAYER_VEL) - if keys[pygame.K_RIGHT]: - player.mover_direita(PLAYER_VEL) - - - - -############### FABY #################### -#variaveis scrool -esquerda = False -direita = False -scroll = 4 -scroll_speed = 1 -#variaveis matriz -rows = 16 -colunas_max = 150 -#######TILE SIZE############### -tamanho = altura // rows -level = 1 -#variaveis grafico -#QUANTAS IMAGENS TEM --- tem que mudar sempre que add alguma imagem -tipo = 6 -current_tile = 0 - - -#ADD AS IMAGES -background = pygame.image.load('Esgoto/sewer.png').convert_alpha() -background = pygame.transform.scale(background, (largura,altura)) - -img_lista = [] -for x in range(tipo): - #ADIÇÃO DAS IMAGENS NO INVENTARIO - img = pygame.image.load(f'img/{x}.png').convert_alpha() - img = pygame.transform.scale(img, (tamanho, tamanho)) - img_lista.append(img) - -save_img = pygame.image.load('4.png').convert_alpha() -load_img = pygame.image.load('5.png').convert_alpha() - - -#DEFINIR CORES -BLACK = (0, 0, 0) -WHITE = (250, 250, 250) -GREEN = (144, 201, 120) - - -font = pygame.font.SysFont('Futura', 30) -#CRIAR LISTA COM OS ESPAÇOS VAZIOS -#World data -lista = [] -for row in range(rows): - r = [-1]*colunas_max - lista.append(r) - -#CRIAR CHÃO -for tile in range(0, colunas_max): - lista[rows - 2][tile] = 0 ##número da foto - -for tile in range(0, colunas_max): - lista[rows - 1][tile] = 1 ##número da foto - - -def imagens(): - tela.fill(WHITE) - width = tela.get_width() - #quantas vezes a imagem repete - for x in range(4): - tela.blit(background,((x*width) - scroll*0.7, 0)) ##0.7 == velocidade que move a tela - -#FUNÇÃO MATRIZES -def matrizes(): - #linha vertical - for j in range(colunas_max + 1): - pygame.draw.line(tela, WHITE, (j *tamanho - scroll,0), (j *tamanho - scroll, altura)) - #linha horizontal - for j in range(rows + 1): - pygame.draw.line(tela, WHITE, (0, j *tamanho), (altura, j *tamanho)) - -#FUNÇÃO PRA DESENHAR AS PLATAFORMAS -def desenhar_mundo(): - #interar entre os valores da matriz - for y, row in enumerate(lista): - for x, tile in enumerate(row): - if tile >= 0: - tela.blit(img_lista[tile], (x *tamanho - scroll, y *tamanho )) - - - -#CRIAR OS BOTÕES DAS IMAGENS -save_button = button.Button(largura // 2 + margem_lado, altura + margem - 50, save_img, 1) -load_button = button.Button(largura // 2 + 200, altura + margem - 50, load_img, 1) -botao_lista = [] -#col -botao1 = 0 -#row -botao2 = 0 - -for i in range(len(img_lista)): - ideia_botao = button.Button(altura + (75 *botao1) + 50, 75 * botao2 + 50, img_lista[i], 1) - botao_lista.append(ideia_botao) - botao1 += 1 - if botao1 == 3: - botao2 += 1 - botao1 = 0 - -rodando = True -while rodando == True: - - imagens() - matrizes() - desenhar_mundo() - - - #SALVAR OS DESENHOS - if save_button.draw(tela): - with open(f'level{level}_data.csv', 'w', newline='') as csvfile: - writer = csv.writer(csvfile, delimiter = ',') - for row in lista: - writer.writerow(row) - - #RECUPERAR O DESENHO AO ABRIR O JOGO - if load_button.draw(tela): - scroll = 0 - with open(f'level{level}_data.csv', newline='') as csvfile: - reader = csv.reader(csvfile, delimiter = ',') - for x, row in enumerate(reader): - for y, tile in enumerate(row): - lista[x][y] = int(tile) - - #painel/invetário - pygame.draw.rect(tela, WHITE, (altura, 0, margem_lado, largura)) - contador_botao = 0 - for contador_botao, i in enumerate(botao_lista): - if i.draw(tela): - current_tile = contador_botao - - #marca que fica sobre as imagens dentro do inventário - pygame.draw.rect(tela, GREEN, botao_lista[current_tile].rect, 3) - - #MAXIMO DE LARGURA DA TELA - if esquerda == True and scroll > 0: - scroll -= 5 * scroll_speed - if direita == True and scroll < (colunas_max * tamanho) - largura: #PARA PARAR A LARGURA NA DIREITA - scroll += 5 * scroll_speed - - #FAZER O MOUSE PUXAR A IMAGEM PARA POR NA GRADE - posicao = pygame.mouse.get_pos() - x = (posicao[0] + scroll) // tamanho - y = posicao[1] // tamanho - - #VER SE O CLIQUE ESTÁ SENDO NA ALTURA E LARGURA DO JOGO - if posicao[0] < largura and posicao[1] < altura: - if pygame.mouse.get_pressed()[0] == 1: - if lista[y][x] != current_tile: - lista[y][x] = current_tile - #CLICAR COM O BOTÃO DIREITO E APAGA O QUE FOI FEITO - if pygame.mouse.get_pressed()[2] == 1: - lista[y][x] = -1 - - #MOVER A TELA - for event in pygame.event.get(): - if event.type == pygame.QUIT: - rodando = False - #pressionar teclas - if event.type == pygame.KEYDOWN: - if event.key == pygame.K_LEFT: - esquerda = True - if event.key == pygame.K_RIGHT: - direita = True - if event.key == pygame.K_UP: #pulo do personagem - player.jump() - if event.key == pygame.K_SPACE: - player.atacar() - if event.type == pygame.KEYUP: - if event.key == pygame.K_LEFT: - esquerda = False - if event.key == pygame.K_RIGHT: - direita = False - - - # parte do personagem carreagndo na tela(Lucas) - player.loop(FPS) - movimento(player) - player.draw(tela) - pygame.display.update() - -pygame.quit() diff --git a/MOSTRAR HJ b/MOSTRAR HJ deleted file mode 100644 index 81b033e..0000000 --- a/MOSTRAR HJ +++ /dev/null @@ -1,343 +0,0 @@ -import pygame -import button -import csv -from os import listdir -from os.path import isfile,join - -pygame.init() -############### FABY ############################# -#GAME WINDOW -largura = 1500 -altura = 640 -#lower -margem = 100 -#side -margem_lado = 300 - - -tela = pygame.display.set_mode((largura, altura + margem)) -pygame.display.set_caption('Após a enchente') - -####### - -################### LUCAS ############################### -FPS = 30 -PLAYER_VEL = 1 -def virar(sprites): - return[pygame.transform.flip(sprite,True,False) for sprite in sprites] - -#BAIXAR AS IMAGENS DO SPRITE E TODAS AS IMAGENS DE DIREITA PARA ESQUERDA E VICE E VERSA -def baixar_sprite(dir1,width,height,direction = False): - path = join(dir1) - images = [f for f in listdir(path) if isfile(join(path,f))] - all_sprites = {} - for image in images: - sprite_sheet = pygame.image.load(join(path, image)).convert_alpha() - - sprites = [] - for i in range (sprite_sheet.get_width() // width): - surface = pygame.Surface((width,height), pygame.SRCALPHA, 32) - rect = pygame.Rect(i * width, 0, width, height) - surface.blit(sprite_sheet, (0,0), rect) - sprites.append(pygame.transform.scale(surface,(100,120)))#TAMANHO DO PERSONAGEM PRINCIPAL(LUCAS) - - if direction: - all_sprites[image.replace(".png", "") + "_direita"] = sprites - all_sprites[image.replace(".png", "") + "_esquerda"] = virar(sprites) - else: - all_sprites[image.replace(".png", "")] = sprites - return all_sprites - - -#CLASSE PERSONAGEM PRINCIPAL -class Jogador(pygame.sprite.Sprite): - GRAVITY = 0.1 - SPRITES = baixar_sprite("personagem",48,50, True) - ANIMATION_DELAY = 80 - #INICIO DAS VARIAVEIS PRINCIPAIS - def __init__(self, char_type, x, y, width, height): - self.rect = pygame.Rect(x,y,width,height) - ######## - self.char_type = char_type - self.y_vel = 0 - ##self speed - self.x_vel = 0 - self.mask = None - #mudanca - self.virar = 'esquerda' - ##### - self.animation_count = 0 - self.animation_attack_count = 0 - self.fall_count = True - self.jump_count = False - self.ataque = False - - #FUNCAO SOMA A VEL NA POSICAO PRA ANDAR - def move(self, dx, dy): - #################### - if self.char_type == 'player': - if self.rect.left + dx < -50 or self.rect.right + dx > largura + 50: - dx = 0 - self.rect.x += dx - self.rect.y += dy - def mover_esquerda(self, vel): - self.x_vel = -vel - if self.virar != 'esquerda': - self.virar = 'esquerda' - self.animation_count = 0 - - def mover_direita(self,vel): - self.x_vel = vel - if self.virar != 'direita': - self.virar = 'direita' - self.animation_count = 0 - def jump(self): - if self.jump_count == False: - self.y_vel = -3.5 - self.jump_count = True - def checar_chao(self,dy): - if self.rect.bottom + dy > 563: - self.y_vel = 0 - self.jump_count = False - #FUNCAO QUE VAI VERIFICAR O QUE O PERSONAGEM FAZ A CADA FRAME - def loop(self, fps): - self.y_vel += min(0.03, (self.fall_count/fps) * self.GRAVITY) - self.move(self.x_vel,self.y_vel) - self.checar_chao(self.y_vel) - self.fall_count += 0.3 - self.update_sprite() - - def atacar(self): - sprite_sheet = "Attack" - sprite_sheet_name = sprite_sheet + "_" + self.virar - sprites = self.SPRITES[sprite_sheet_name] - for i in range(len(sprites)): - self.sprite = sprites[i] - self.update() - print(self.sprite) - - def draw(self,tela): - tela.blit(self.sprite, (self.rect.x,self.rect.y)) - - def update_sprite(self): - sprite_sheet = "Idle" - if self.x_vel != 0: - sprite_sheet = "Walk" - sprite_sheet_name = sprite_sheet + "_" + self.virar - sprites = self.SPRITES[sprite_sheet_name] - sprite_index = (self.animation_count // self.ANIMATION_DELAY) % len(sprites) - self.sprite = sprites[sprite_index] - self.animation_count += 1 - self.update() - - - def update(self): - self.rect = self.sprite.get_rect(topleft = (self.rect.x, self.rect.y)) - self.mask = pygame.mask.from_surface(self.sprite) - - -player = Jogador('player',100,100,80,80)#tamanhos do personagem(Lucas) - -def movimento(self): - keys = pygame.key.get_pressed() - player.x_vel = 0 - if keys[pygame.K_LEFT]: - player.mover_esquerda(PLAYER_VEL) - if keys[pygame.K_RIGHT]: - player.mover_direita(PLAYER_VEL) - -############### FABY #################### -#variaveis scrool -esquerda = False -direita = False -scroll = 4 -scroll_speed = PLAYER_VEL -#variaveis matriz -rows = 16 -colunas_max = 150 -#######TILE SIZE############### -tamanho = altura // rows -level = 0 -#variaveis grafico -#QUANTAS IMAGENS TEM --- tem que mudar sempre que add alguma imagem -tipo = 7 -current_tile = 0 - - -#ADD AS IMAGES -background = pygame.image.load('Esgoto/sewer.png').convert_alpha() -background = pygame.transform.scale(background, (largura,altura)) - -img_lista = [] -for x in range(tipo): - #ADIÇÃO DAS IMAGENS NO INVENTARIO - img = pygame.image.load(f'img/{x}.png').convert_alpha() - img = pygame.transform.scale(img, (tamanho, tamanho)) - img_lista.append(img) - -save_img = pygame.image.load('4.png').convert_alpha() -load_img = pygame.image.load('5.png').convert_alpha() - - -#DEFINIR CORES -BLACK = (0, 0, 0) -WHITE = (250, 250, 250) -GREEN = (144, 201, 120) - - -font = pygame.font.SysFont('Futura', 30) -#CRIAR LISTA COM OS ESPAÇOS VAZIOS -#World data -lista = [] -for row in range(rows): - r = [-1]*colunas_max - lista.append(r) - -#CRIAR CHÃO -for tile in range(0, colunas_max): - lista[rows - 2][tile] = 0 ##número da foto - -for tile in range(0, colunas_max): - lista[rows - 1][tile] = 1 ##número da foto - - -def imagens(): - tela.fill(WHITE) - width = tela.get_width() - #quantas vezes a imagem repete - for x in range(4): - tela.blit(background,((x*width) - scroll*0.7, 0)) ##0.7 == velocidade que move a tela - -#FUNÇÃO MATRIZES -def matrizes(): - #linha vertical - for j in range(colunas_max + 1): - pygame.draw.line(tela, WHITE, (j *tamanho - scroll,0), (j *tamanho - scroll, altura)) - #linha horizontal - for j in range(rows + 1): - pygame.draw.line(tela, WHITE, (0, j *tamanho), (altura, j *tamanho)) - -#FUNÇÃO PRA DESENHAR AS PLATAFORMAS -def desenhar_mundo(): - #interar entre os valores da matriz - for y, row in enumerate(lista): - for x, tile in enumerate(row): - if tile >= 0: - tela.blit(img_lista[tile], (x *tamanho - scroll, y *tamanho )) - - - -#CRIAR OS BOTÕES DAS IMAGENS -save_button = button.Button(largura // 2 + margem_lado, altura + margem - 50, save_img, 1) -load_button = button.Button(largura // 2 + 200, altura + margem - 50, load_img, 1) -botao_lista = [] -#col -botao1 = 0 -#row -botao2 = 0 - -for i in range(len(img_lista)): - ideia_botao = button.Button(altura + (75 *botao1) + 50, 75 * botao2 + 50, img_lista[i], 1) - botao_lista.append(ideia_botao) - botao1 += 1 - if botao1 == 3: - botao2 += 1 - botao1 = 0 - -rodando = True -while rodando == True: - - imagens() - matrizes() - desenhar_mundo() - - - #SALVAR OS DESENHOS - if save_button.draw(tela): - with open(f'level{level}_data.csv', 'w', newline='') as csvfile: - writer = csv.writer(csvfile, delimiter = ',') - for row in lista: - writer.writerow(row) - - #RECUPERAR O DESENHO AO ABRIR O JOGO - if load_button.draw(tela): - scroll = 0 - with open(f'level{level}_data.csv', newline='') as csvfile: - reader = csv.reader(csvfile, delimiter = ',') - for x, row in enumerate(reader): - for y, tile in enumerate(row): - lista[x][y] = int(tile) - - #painel/invetário - pygame.draw.rect(tela, WHITE, (altura, 0, margem_lado, largura)) - contador_botao = 0 - for contador_botao, i in enumerate(botao_lista): - if i.draw(tela): - current_tile = contador_botao - - #marca que fica sobre as imagens dentro do inventário - pygame.draw.rect(tela, GREEN, botao_lista[current_tile].rect, 3) - - #MAXIMO DE LARGURA DA TELA - if esquerda == True and scroll > 0: - scroll -= 5 * scroll_speed - if direita == True and scroll < (colunas_max * tamanho) - largura: #PARA PARAR A LARGURA NA DIREITA - scroll += 5 * scroll_speed - - #FAZER O MOUSE PUXAR A IMAGEM PARA POR NA GRADE - posicao = pygame.mouse.get_pos() - x = (posicao[0] + scroll) // tamanho - y = posicao[1] // tamanho - - #VER SE O CLIQUE ESTÁ SENDO NA ALTURA E LARGURA DO JOGO - if posicao[0] < largura and posicao[1] < altura: - if pygame.mouse.get_pressed()[0] == 1: - if lista[y][x] != current_tile: - lista[y][x] = current_tile - #CLICAR COM O BOTÃO DIREITO E APAGA O QUE FOI FEITO - if pygame.mouse.get_pressed()[2] == 1: - lista[y][x] = -1 - - #MOVER A TELA - for event in pygame.event.get(): - if event.type == pygame.QUIT: - rodando = False - #pressionar teclas - if event.type == pygame.KEYDOWN: - if event.key == pygame.K_LEFT: - esquerda = True - if event.key == pygame.K_RIGHT: - direita = True - if event.key == pygame.K_UP: #pulo do personagem - player.jump() - if event.key == pygame.K_SPACE: - player.atacar() - if event.type == pygame.KEYUP: - if event.key == pygame.K_LEFT: - esquerda = False - if event.key == pygame.K_RIGHT: - direita = False - - - # parte do personagem carreagndo na tela(Lucas) - player.loop(FPS) - movimento(player) - player.draw(tela) - pygame.display.update() - -pygame.quit() - -"""class World(): - def process_data(self, data): - self.level_length = len(data[0]) - for y, row in enumerate(lista): - for x, tile in enumerate(row): - if tile >= 0: - img = img_lista[tile] - img_rect = img.get_rect() - img_rect.x = x * TILE_SIZE - img_rect.y = y * TILE_SIZE - tile_data = (img, img_rect) - elif tile == 15:#create player - player = Jogador('player', x * tamanho, y * tamanho 1.65, 5, 20, 5) -""" diff --git a/__pycache__/button.cpython-310.pyc b/__pycache__/button.cpython-310.pyc new file mode 100644 index 0000000..010f9ed Binary files /dev/null and b/__pycache__/button.cpython-310.pyc differ diff --git a/__pycache__/button.cpython-311.pyc b/__pycache__/button.cpython-311.pyc index 2c8f511..533310d 100644 Binary files a/__pycache__/button.cpython-311.pyc and b/__pycache__/button.cpython-311.pyc differ diff --git a/__pycache__/enemies.cpython-310.pyc b/__pycache__/enemies.cpython-310.pyc new file mode 100644 index 0000000..348c8d1 Binary files /dev/null and b/__pycache__/enemies.cpython-310.pyc differ diff --git a/__pycache__/enemies.cpython-311.pyc b/__pycache__/enemies.cpython-311.pyc new file mode 100644 index 0000000..700b678 Binary files /dev/null and b/__pycache__/enemies.cpython-311.pyc differ diff --git "a/__pycache__/fun\303\247oes.cpython-310.pyc" "b/__pycache__/fun\303\247oes.cpython-310.pyc" new file mode 100644 index 0000000..98f7837 Binary files /dev/null and "b/__pycache__/fun\303\247oes.cpython-310.pyc" differ diff --git "a/__pycache__/fun\303\247oes.cpython-311.pyc" "b/__pycache__/fun\303\247oes.cpython-311.pyc" new file mode 100644 index 0000000..75d45eb Binary files /dev/null and "b/__pycache__/fun\303\247oes.cpython-311.pyc" differ diff --git a/__pycache__/jogador.cpython-310.pyc b/__pycache__/jogador.cpython-310.pyc new file mode 100644 index 0000000..0ca2e1f Binary files /dev/null and b/__pycache__/jogador.cpython-310.pyc differ diff --git a/__pycache__/jogador.cpython-311.pyc b/__pycache__/jogador.cpython-311.pyc new file mode 100644 index 0000000..50974fe Binary files /dev/null and b/__pycache__/jogador.cpython-311.pyc differ diff --git a/__pycache__/life.cpython-310.pyc b/__pycache__/life.cpython-310.pyc new file mode 100644 index 0000000..d0f5a05 Binary files /dev/null and b/__pycache__/life.cpython-310.pyc differ diff --git a/__pycache__/life.cpython-311.pyc b/__pycache__/life.cpython-311.pyc new file mode 100644 index 0000000..fccf174 Binary files /dev/null and b/__pycache__/life.cpython-311.pyc differ diff --git a/__pycache__/main.cpython-311.pyc b/__pycache__/main.cpython-311.pyc new file mode 100644 index 0000000..58dc39a Binary files /dev/null and b/__pycache__/main.cpython-311.pyc differ diff --git a/__pycache__/potion.cpython-311.pyc b/__pycache__/potion.cpython-311.pyc new file mode 100644 index 0000000..4ed791b Binary files /dev/null and b/__pycache__/potion.cpython-311.pyc differ diff --git a/__pycache__/water.cpython-311.pyc b/__pycache__/water.cpython-311.pyc new file mode 100644 index 0000000..a87d0fa Binary files /dev/null and b/__pycache__/water.cpython-311.pyc differ diff --git a/__pycache__/world.cpython-311.pyc b/__pycache__/world.cpython-311.pyc new file mode 100644 index 0000000..723d07e Binary files /dev/null and b/__pycache__/world.cpython-311.pyc differ diff --git a/CODIGORUSS b/codigoruss.py similarity index 95% rename from CODIGORUSS rename to codigoruss.py index b1a5163..c887ad9 100644 --- a/CODIGORUSS +++ b/codigoruss.py @@ -165,7 +165,7 @@ def __init__(self, char_type, x, y, scale, speed, ammo, grenades): self.idling = False self.idling_counter = 0 - #load all images for the players +"""" #load all images for the players animation_types = ['Idle', 'Run', 'Jump', 'Death'] for animation in animation_types: #reset temporary list of images @@ -182,7 +182,7 @@ def __init__(self, char_type, x, y, scale, speed, ammo, grenades): self.rect = self.image.get_rect() self.rect.center = (x, y) self.width = self.image.get_width() - self.height = self.image.get_height() + self.height = self.image.get_height()"""" ####PRECISAMOSSS##### def update(self): @@ -192,6 +192,21 @@ def update(self): if self.shoot_cooldown > 0: self.shoot_cooldown -= 1 ############################## + def update_animation(self): + #update animation + ANIMATION_COOLDOWN = 100 + #update image depending on current frame + self.image = self.animation_list[self.action][self.frame_index] + #check if enough time has passed since the last update + if pygame.time.get_ticks() - self.update_time > ANIMATION_COOLDOWN: + self.update_time = pygame.time.get_ticks() + self.frame_index += 1 + #if the animation has run out the reset back to the start + if self.frame_index >= len(self.animation_list[self.action]): + if self.action == 3: + self.frame_index = len(self.animation_list[self.action]) - 1 + else: + self.frame_index = 0 ############JA TEMOS########## def move(self, moving_left, moving_right): @@ -281,15 +296,6 @@ def move(self, moving_left, moving_right): - def shoot(self): - if self.shoot_cooldown == 0 and self.ammo > 0: - self.shoot_cooldown = 20 - bullet = Bullet(self.rect.centerx + (0.75 * self.rect.size[0] * self.direction), self.rect.centery, self.direction) - bullet_group.add(bullet) - #reduce ammo - self.ammo -= 1 - shot_fx.play() - def ai(self): if self.alive and player.alive: @@ -328,32 +334,6 @@ def ai(self): self.rect.x += screen_scroll - def update_animation(self): - #update animation - ANIMATION_COOLDOWN = 100 - #update image depending on current frame - self.image = self.animation_list[self.action][self.frame_index] - #check if enough time has passed since the last update - if pygame.time.get_ticks() - self.update_time > ANIMATION_COOLDOWN: - self.update_time = pygame.time.get_ticks() - self.frame_index += 1 - #if the animation has run out the reset back to the start - if self.frame_index >= len(self.animation_list[self.action]): - if self.action == 3: - self.frame_index = len(self.animation_list[self.action]) - 1 - else: - self.frame_index = 0 - - - - def update_action(self, new_action): - #check if the new action is different to the previous one - if new_action != self.action: - self.action = new_action - #update the animation settings - self.frame_index = 0 - self.update_time = pygame.time.get_ticks() - def check_alive(self): @@ -368,6 +348,12 @@ def draw(self): screen.blit(pygame.transform.flip(self.image, self.flip, False), self.rect) + + + + + + class World(): def __init__(self): self.obstacle_list = [] @@ -388,21 +374,12 @@ def process_data(self, data): elif tile >= 9 and tile <= 10: water = Water(img, x * TILE_SIZE, y * TILE_SIZE) water_group.add(water) - elif tile >= 11 and tile <= 14: - decoration = Decoration(img, x * TILE_SIZE, y * TILE_SIZE) - decoration_group.add(decoration) elif tile == 15:#create player player = Soldier('player', x * TILE_SIZE, y * TILE_SIZE, 1.65, 5, 20, 5) health_bar = HealthBar(10, 10, player.health, player.health) elif tile == 16:#create enemies enemy = Soldier('enemy', x * TILE_SIZE, y * TILE_SIZE, 1.65, 2, 20, 0) enemy_group.add(enemy) - elif tile == 17:#create ammo box - item_box = ItemBox('Ammo', x * TILE_SIZE, y * TILE_SIZE) - item_box_group.add(item_box) - elif tile == 18:#create grenade box - item_box = ItemBox('Grenade', x * TILE_SIZE, y * TILE_SIZE) - item_box_group.add(item_box) elif tile == 19:#create health box item_box = ItemBox('Health', x * TILE_SIZE, y * TILE_SIZE) item_box_group.add(item_box) diff --git a/personagemback.py b/editing_level.py similarity index 51% rename from personagemback.py rename to editing_level.py index c533e4f..110bf35 100644 --- a/personagemback.py +++ b/editing_level.py @@ -1,321 +1,201 @@ -import pygame -import button -import csv -from os import listdir -from os.path import isfile,join - -pygame.init() -############### FABY ############################# -#GAME WINDOW -largura = 1500 -altura = 640 -#lower -margem = 100 -#side -margem_lado = 300 - -tela = pygame.display.set_mode((largura, altura + margem)) -pygame.display.set_caption('Após a enchente') - -################### LUCAS ############################### -FPS = 30 -PLAYER_VEL = 1 -def virar(sprites): - return[pygame.transform.flip(sprite,True,False) for sprite in sprites] - -#BAIXAR AS IMAGENS DO SPRITE E TODAS AS IMAGENS DE DIREITA PARA ESQUERDA E VICE E VERSA -def baixar_sprite(dir1,width,height,direction = False): - path = join(dir1) - images = [f for f in listdir(path) if isfile(join(path,f))] - all_sprites = {} - for image in images: - sprite_sheet = pygame.image.load(join(path, image)).convert_alpha() - - sprites = [] - for i in range (sprite_sheet.get_width() // width): - surface = pygame.Surface((width,height), pygame.SRCALPHA, 32) - rect = pygame.Rect(i * width, 0, width, height) - surface.blit(sprite_sheet, (0,0), rect) - sprites.append(pygame.transform.scale(surface,(100,120)))#TAMANHO DO PERSONAGEM PRINCIPAL(LUCAS) - - if direction: - all_sprites[image.replace(".png", "") + "_direita"] = sprites - all_sprites[image.replace(".png", "") + "_esquerda"] = virar(sprites) - else: - all_sprites[image.replace(".png", "")] = sprites - return all_sprites - - -#CLASSE PERSONAGEM PRINCIPAL -class Jogador(pygame.sprite.Sprite): - GRAVITY = 0.1 - SPRITES = baixar_sprite("personagem",48,50, True) - ANIMATION_DELAY = 50 - #INICIO DAS VARIAVEIS PRINCIPAIS - def __init__(self, x, y, width, height): - self.rect = pygame.Rect(x,y,width,height) - self.x_vel = 0 - self.y_vel = 0 - self.mask = None - self.direction = "esquerda" - self.animation_count = 0 - self.fall_count = 0 - self.jump_count = 0 - self.ataque = False - - #FUNCAO SOMA A VEL NA POSICAO PRA ANDAR - def move(self,dx,dy): - self.rect.x += dx - self.rect.y += dy - #DEFINIR A DIRECAO DA ANDADA PRA ESQUERDA E CHAMAR AS SPRITES DA ESQUERDA - def mover_esquerda(self,vel): - self.x_vel = -vel - if self.direction != "esquerda": - self.direction = "esquerda" - self.animation_count = 0 - #DEFINIR A DIRECAO DA ANDADA PRA ESQUERDA E CHAMAR AS SPRITES DA ESQUERDA - def mover_direita(self,vel): - self.x_vel = vel - if self.direction != "direita": - self.direction = "direita" - self.animation_count = 0 - #FUNCAO DE PULAR - def jump(self): - if self.jump_count == 0: - self.y_vel = -self.GRAVITY * 42 - self.jump_count = 1 - #FUNCAO QUE VAI VERIFICAR O QUE O PERSONAGEM FAZ A CADA FRAME - def loop(self, fps): - self.y_vel += min(0.05, (self.fall_count/6*fps) * self.GRAVITY) - self.move(self.x_vel,self.y_vel) - self.checar_chao(self.y_vel) - self.fall_count += 0.3 - self.update_sprite() - - def update_sprite(self): - sprite_sheet = "Idle" - if self.x_vel != 0: - sprite_sheet = "Walk" - sprite_sheet_name = sprite_sheet + "_" + self.direction - sprites = self.SPRITES[sprite_sheet_name] - sprite_index = (self.animation_count // self.ANIMATION_DELAY) % len(sprites) - self.sprite = sprites[sprite_index] - self.animation_count += 1 - if self.ataque == True: - self.ataque = False - sprite_sheet = "Attack" - sprite_sheet_name = sprite_sheet + "_" + self.direction - sprites = self.SPRITES[sprite_sheet_name] - sprite_index = (self.animation_count // self.ANIMATION_DELAY) % len(sprites) - self.sprite = sprites[sprite_index] - self.animation_count += 1 - self.update() - - def update(self): - self.rect = self.sprite.get_rect(topleft = (self.rect.x, self.rect.y)) - self.mask = pygame.mask.from_surface(self.sprite) - def atacar(self): - if self.ataque == False: - self.ataque = True - - def draw(self,tela): - tela.blit(self.sprite, (self.rect.x,self.rect.y)) - - def checar_chao(self,dy): - if self.rect.bottom + dy > 563: - self.y_vel = 0 - self.jump_count = 0 - -player = Jogador(100,100,80,80)#tamanhos do personagem(Lucas) - -def movimento(player): - keys = pygame.key.get_pressed() - player.x_vel = 0 - if keys[pygame.K_LEFT]: - player.mover_esquerda(PLAYER_VEL) - if keys[pygame.K_RIGHT]: - player.mover_direita(PLAYER_VEL) - - - - -############### FABY #################### -#variaveis scrool -esquerda = False -direita = False -scroll = 0 -scroll_speed = 1 -#variaveis matriz -rows = 16 -colunas_max = 150 -tamanho = altura // rows -level = 0 -#variaveis grafico -#QUANTAS IMAGENS TEM --- tem que mudar sempre que add alguma imagem -tipo = 7 -current_tile = 0 - - -#ADD AS IMAGES -background = pygame.image.load('Esgoto/sewer.png').convert_alpha() -background = pygame.transform.scale(background, (largura,altura)) - -img_lista = [] -for x in range(tipo): - #ADIÇÃO DAS IMAGENS NO INVENTARIO - img = pygame.image.load(f'img/{x}.png').convert_alpha() - img = pygame.transform.scale(img, (tamanho, tamanho)) - img_lista.append(img) - -save_img = pygame.image.load('4.png').convert_alpha() -load_img = pygame.image.load('5.png').convert_alpha() - - -#DEFINIR CORES -BLACK = (0, 0, 0) -WHITE = (250, 250, 250) -GREEN = (144, 201, 120) - - -font = pygame.font.SysFont('Futura', 30) -#CRIAR LISTA COM OS ESPAÇOS VAZIOS -#World data -lista = [] -for row in range(rows): - r = [-1]*colunas_max - lista.append(r) - -#CRIAR CHÃO -for tile in range(0, colunas_max): - lista[rows - 2][tile] = 0 ##número da foto - -for tile in range(0, colunas_max): - lista[rows - 1][tile] = 1 ##número da foto - - - -#FUNÇÃO PARA AS IMAGENS -def imagens(): - tela.fill(WHITE) - width = tela.get_width() - #quantas vezes a imagem repete - for x in range(4): - tela.blit(background,((x*width) - scroll * 0.09,0)) ##0.7 == velocidade que move a tela - -#FUNÇÃO MATRIZES -def matrizes(): - #linha vertical - for j in range(colunas_max + 1): - pygame.draw.line(tela, WHITE, (j *tamanho - scroll,0), (j *tamanho - scroll, altura)) - #linha horizontal - for j in range(rows + 1): - pygame.draw.line(tela, WHITE, (0, j *tamanho), (altura, j *tamanho)) - -#FUNÇÃO PRA DESENHAR AS PLATAFORMAS -def desenhar_mundo(): - #interar entre os valores da matriz - for y, row in enumerate(lista): - for x, tile in enumerate(row): - if tile >= 0: - tela.blit(img_lista[tile], (x *tamanho - scroll, y *tamanho )) - - - -#CRIAR OS BOTÕES DAS IMAGENS -save_button = button.Button(largura // 2 + margem_lado, altura + margem - 50, save_img, 1) -load_button = button.Button(largura // 2 + 200, altura + margem - 50, load_img, 1) -botao_lista = [] -#col -botao1 = 0 -#row -botao2 = 0 - -for i in range(len(img_lista)): - ideia_botao = button.Button(altura + (75 *botao1) + 50, 75 * botao2 + 50, img_lista[i], 1) - botao_lista.append(ideia_botao) - botao1 += 1 - if botao1 == 3: - botao2 += 1 - botao1 = 0 - -rodando = True -while rodando == True: - - imagens() - matrizes() - desenhar_mundo() - - #SALVAR OS DESENHOS - if save_button.draw(tela): - with open(f'level{level}_data.csv', 'w', newline='') as csvfile: - writer = csv.writer(csvfile, delimiter = ',') - for row in lista: - writer.writerow(row) - - #RECUPERAR O DESENHO AO ABRIR O JOGO - if load_button.draw(tela): - scroll = 0 - with open(f'level{level}_data.csv', newline='') as csvfile: - reader = csv.reader(csvfile, delimiter = ',') - for x, row in enumerate(reader): - for y, tile in enumerate(row): - lista[x][y] = int(tile) - - #painel/invetário - pygame.draw.rect(tela, WHITE, (altura, 0, margem_lado, largura)) - contador_botao = 0 - for contador_botao, i in enumerate(botao_lista): - if i.draw(tela): - current_tile = contador_botao - - #marca que fica sobre as imagens dentro do inventário - pygame.draw.rect(tela, GREEN, botao_lista[current_tile].rect, 3) - - #MAXIMO DE LARGURA DA TELA - if esquerda == True and scroll > 0: - scroll -= 5 * scroll_speed - if direita == True and scroll < (colunas_max * tamanho) - largura: #PARA PARAR A LARGURA NA DIREITA - scroll += 5 * scroll_speed - - #FAZER O MOUSE PUXAR A IMAGEM PARA POR NA GRADE - posicao = pygame.mouse.get_pos() - x = (posicao[0] + scroll) // tamanho - y = posicao[1] // tamanho - - #VER SE O CLIQUE ESTÁ SENDO NA ALTURA E LARGURA DO JOGO - if posicao[0] < largura and posicao[1] < altura: - if pygame.mouse.get_pressed()[0] == 1: - if lista[y][x] != current_tile: - lista[y][x] = current_tile - #CLICAR COM O BOTÃO DIREITO E APAGA O QUE FOI FEITO - if pygame.mouse.get_pressed()[2] == 1: - lista[y][x] = -1 - - #MOVER A TELA - for event in pygame.event.get(): - if event.type == pygame.QUIT: - rodando = False - #pressionar teclas - if event.type == pygame.KEYDOWN: - if event.key == pygame.K_LEFT: - esquerda = True - if event.key == pygame.K_RIGHT: - direita = True - if event.key == pygame.K_UP and player.jump_count < 2: #pulo do personagem - player.jump() - if event.key == pygame.K_SPACE: - player.atacar() - if event.type == pygame.KEYUP: - if event.key == pygame.K_LEFT: - esquerda = False - if event.key == pygame.K_RIGHT: - direita = False - - - # parte do personagem carreagndo na tela(Lucas) - player.loop(FPS) - movimento(player) - player.draw(tela) - pygame.display.update() - -pygame.quit() +import pygame +import button +import csv +from os import listdir +from os.path import isfile,join +from jogador import Jogador + +pygame.init() +############### FABY ############################# +#GAME WINDOW +largura = 1500 +altura = 640 +#lower +margem = 100 +#side +margem_lado = 300 + + +tela = pygame.display.set_mode((largura, altura + margem)) +pygame.display.set_caption('Após a enchente') + +####### + +################### LUCAS ############################### +FPS = 30 + + +############### FABY #################### +#variaveis scrool +esquerda = False +direita = False +scroll = 4 +scroll_speed = 1 +#variaveis matriz +rows = 16 +colunas_max = 150 +#######TILE SIZE############### +tamanho = altura // rows +level = 1 +#variaveis grafico +#QUANTAS IMAGENS TEM --- tem que mudar sempre que add alguma imagem +tipo = 10 +current_tile = 0 + + +#ADD AS IMAGES +background = pygame.image.load('Esgoto/sewer.png').convert_alpha() +background = pygame.transform.scale(background, (largura,altura)) + +img_lista = [] +for x in range(tipo): + #ADIÇÃO DAS IMAGENS NO INVENTARIO + img = pygame.image.load(f'img/{x}.png').convert_alpha() + img = pygame.transform.scale(img, (tamanho, tamanho)) + img_lista.append(img) + +save_img = pygame.image.load('4.png').convert_alpha() +load_img = pygame.image.load('5.png').convert_alpha() + + +#DEFINIR CORES +BLACK = (0, 0, 0) +WHITE = (250, 250, 250) +GREEN = (144, 201, 120) + + +font = pygame.font.SysFont('Futura', 30) +#CRIAR LISTA COM OS ESPAÇOS VAZIOS +#World data +lista = [] +for row in range(rows): + r = [-1]*colunas_max + lista.append(r) + +#CRIAR CHÃO +for tile in range(0, colunas_max): + lista[rows - 2][tile] = 0 ##número da foto + +for tile in range(0, colunas_max): + lista[rows - 1][tile] = 1 ##número da foto + + +def imagens(): + tela.fill(WHITE) + width = tela.get_width() + #quantas vezes a imagem repete + for x in range(4): + tela.blit(background,((x*width) - scroll*0.7, 0)) ##0.7 == velocidade que move a tela + +#FUNÇÃO MATRIZES +def matrizes(): + #linha vertical + for j in range(colunas_max + 1): + pygame.draw.line(tela, WHITE, (j *tamanho - scroll,0), (j *tamanho - scroll, altura)) + #linha horizontal + for j in range(rows + 1): + pygame.draw.line(tela, WHITE, (0, j *tamanho), (altura, j *tamanho)) + +#FUNÇÃO PRA DESENHAR AS PLATAFORMAS +def desenhar_mundo(): + #interar entre os valores da matriz + for y, row in enumerate(lista): + for x, tile in enumerate(row): + if tile >= 0: + tela.blit(img_lista[tile], (x *tamanho - scroll, y *tamanho )) + + + +#CRIAR OS BOTÕES DAS IMAGENS +save_button = button.Button(largura // 2 + margem_lado, altura + margem - 50, save_img, 1) +load_button = button.Button(largura // 2 + 200, altura + margem - 50, load_img, 1) +botao_lista = [] +#col +botao1 = 0 +#row +botao2 = 0 + +for i in range(len(img_lista)): + ideia_botao = button.Button(altura + (75 *botao1) + 50, 75 * botao2 + 50, img_lista[i], 1) + botao_lista.append(ideia_botao) + botao1 += 1 + if botao1 == 3: + botao2 += 1 + botao1 = 0 + +rodando = True +while rodando == True: + + imagens() + matrizes() + desenhar_mundo() + + + #SALVAR OS DESENHOS + if save_button.draw(tela): + with open(f'level{level}_data.csv', 'w', newline='') as csvfile: + writer = csv.writer(csvfile, delimiter = ',') + for row in lista: + writer.writerow(row) + + #RECUPERAR O DESENHO AO ABRIR O JOGO + if load_button.draw(tela): + scroll = 0 + with open(f'level{level}_data.csv', newline='') as csvfile: + reader = csv.reader(csvfile, delimiter = ',') + for x, row in enumerate(reader): + for y, tile in enumerate(row): + lista[x][y] = int(tile) + + #painel/invetário + pygame.draw.rect(tela, WHITE, (altura, 0, margem_lado, largura)) + contador_botao = 0 + for contador_botao, i in enumerate(botao_lista): + if i.draw(tela): + current_tile = contador_botao + + #marca que fica sobre as imagens dentro do inventário + pygame.draw.rect(tela, GREEN, botao_lista[current_tile].rect, 3) + + #MAXIMO DE LARGURA DA TELA + if esquerda == True and scroll > 0: + scroll -= 5 * scroll_speed + if direita == True and scroll < (colunas_max * tamanho) - largura: #PARA PARAR A LARGURA NA DIREITA + scroll += 5 * scroll_speed + + #FAZER O MOUSE PUXAR A IMAGEM PARA POR NA GRADE + posicao = pygame.mouse.get_pos() + x = (posicao[0] + scroll) // tamanho + y = posicao[1] // tamanho + + #VER SE O CLIQUE ESTÁ SENDO NA ALTURA E LARGURA DO JOGO + if posicao[0] < largura and posicao[1] < altura: + if pygame.mouse.get_pressed()[0] == 1: + if lista[y][x] != current_tile: + lista[y][x] = current_tile + #CLICAR COM O BOTÃO DIREITO E APAGA O QUE FOI FEITO + if pygame.mouse.get_pressed()[2] == 1: + lista[y][x] = -1 + + #MOVER A TELA + for event in pygame.event.get(): + if event.type == pygame.QUIT: + rodando = False + #pressionar teclas + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_LEFT: + esquerda = True + if event.key == pygame.K_RIGHT: + direita = True + if event.type == pygame.KEYUP: + if event.key == pygame.K_LEFT: + esquerda = False + if event.key == pygame.K_RIGHT: + direita = False + + + # parte do personagem carreagando na tela(Lucas) + + pygame.display.update() + +pygame.quit() diff --git a/enemies.py b/enemies.py new file mode 100644 index 0000000..0611d55 --- /dev/null +++ b/enemies.py @@ -0,0 +1,49 @@ +import pygame + +class Enemy(pygame.sprite.Sprite): + walkRight = [pygame.image.load('rato/walk/walk_01.png'), pygame.image.load('rato/walk/walk_02.png'), pygame.image.load('rato/walk/walk_03.png'), pygame.image.load('rato/walk/walk_04.png')] + walkLeft = [pygame.image.load('rato/walk/walk_05.png'), pygame.image.load('rato/walk/walk_06.png'), pygame.image.load('rato/walk/walk_07.png'), pygame.image.load('rato/walk/walk_08.png')] + def __init__(self, char_type,img,tamanho, x, y, width, height, end): + pygame.sprite.Sprite.__init__(self) + self.x = x + self.y = y + self.char_type = char_type + self.width = width + self.height = height + self.path = [x, end] + self.walkCount = 0 + self.vel = 3 + self.image = img + self.rect = self.image.get_rect() + self.rect.midtop = (x + tamanho // 2, y + (tamanho - self.image.get_height())) + + def draw(self, win): + self.move() + if self.walkCount + 1 >= 12: + self.walkCount = 0 + + if self.vel > 0: + win.blit(pygame.transform.scale(self.walkRight[self.walkCount//3], (64, 64)), (self.x,self.y)) + self.walkCount += 1 + else: + win.blit(pygame.transform.scale(self.walkLeft[self.walkCount//3], (64, 64)), (self.x,self.y)) + self.walkCount += 1 + + def move(self): + if self.vel > 0: + if self.x < self.path[1] + self.vel: + self.x += self.vel + else: + self.vel = self.vel * -1 + self.x += self.vel + self.walkCount = 0 + else: + if self.x > self.path[0] - self.vel: + self.x += self.vel + else: + self.vel = self.vel * -1 + self.x += self.vel + self.walkCount = 0 + + def update(self,scroll): + self.rect.x += scroll diff --git "a/fun\303\247oes.py" "b/fun\303\247oes.py" new file mode 100644 index 0000000..70d4835 --- /dev/null +++ "b/fun\303\247oes.py" @@ -0,0 +1,28 @@ +import pygame +from os import listdir +from os.path import isfile,join + +def virar(sprites): + return[pygame.transform.flip(sprite,True,False) for sprite in sprites] + +#BAIXAR AS IMAGENS DO SPRITE E TODAS AS IMAGENS DE DIREITA PARA ESQUERDA E VICE E VERSA +def baixar_sprite(dir1,width,height,direction = False): + path = join(dir1) + images = [f for f in listdir(path) if isfile(join(path,f))] + all_sprites = {} + for image in images: + sprite_sheet = pygame.image.load(join(path, image)).convert_alpha() + + sprites = [] + for i in range (sprite_sheet.get_width() // width): + surface = pygame.Surface((width,height), pygame.SRCALPHA, 32) + rect = pygame.Rect(0, 0, width, height) + surface.blit(sprite_sheet, (0,0), rect) + sprites.append(pygame.transform.scale(surface,(100,120)))#TAMANHO DO PERSONAGEM PRINCIPAL(LUCAS) + + if direction: + all_sprites[image.replace(".png", "") + "_direita"] = sprites + all_sprites[image.replace(".png", "") + "_esquerda"] = virar(sprites) + else: + all_sprites[image.replace(".png", "")] = sprites + return all_sprites diff --git a/img/2.png b/img/2.png index 99fdcc2..4828416 100644 Binary files a/img/2.png and b/img/2.png differ diff --git a/img/6.png b/img/6.png index 737332d..ff9ec9a 100644 Binary files a/img/6.png and b/img/6.png differ diff --git a/img/7.png b/img/7.png index 334fb87..7812624 100644 Binary files a/img/7.png and b/img/7.png differ diff --git a/img/8.png b/img/8.png new file mode 100644 index 0000000..63a81a0 Binary files /dev/null and b/img/8.png differ diff --git a/img/9.png b/img/9.png new file mode 100644 index 0000000..51954d3 Binary files /dev/null and b/img/9.png differ diff --git a/jogador.py b/jogador.py new file mode 100644 index 0000000..7bf9cf3 --- /dev/null +++ b/jogador.py @@ -0,0 +1,117 @@ +import pygame +from os import listdir +from os.path import isfile,join +from funçoes import * + +pygame.init() +#GAME WINDOW +largura = 1500 +altura = 640 +#lower +margem = 100 +#side +margem_lado = 300 +PLAYER_VEL = 1 + +tela = pygame.display.set_mode((largura, altura + margem)) + +#CLASSE PERSONAGEM PRINCIPAL +class Jogador(pygame.sprite.Sprite): + GRAVITY = 0.1 + SPRITES = baixar_sprite("personagem",48,50, True) + ANIMATION_DELAY = 50 + #INICIO DAS VARIAVEIS PRINCIPAIS + def __init__(self, char_type, x, y, width, height): + self.rect = pygame.Rect(x,y,width,height) + ######## + self.char_type = char_type + self.y_vel = 0 + ##self speed + self.x_vel = 0 + self.mask = None + #mudanca + self.virar = 'esquerda' + ##### + self.attack_animation_count = 0 + self.animation_count = 0 + self.fall_count = True + self.jump_count = False + self.ataque = False + + #FUNCAO SOMA A VEL NA POSICAO PRA ANDAR + def move(self, dx, dy): + #################### + if self.char_type == 'player': + if self.rect.left + dx < -50 or self.rect.right + dx > largura + 50: + dx = 0 + self.rect.x += dx + self.rect.y += dy + def mover_esquerda(self, vel): + self.x_vel = -vel + if self.virar != 'esquerda': + self.virar = 'esquerda' + self.animation_count = 0 + + def mover_direita(self,vel): + self.x_vel = vel + if self.virar != 'direita': + self.virar = 'direita' + self.animation_count = 0 + def jump(self): + if self.jump_count == False: + ######mudanca####### + self.y_vel = -5 + self.jump_count = True + + #FUNCAO QUE VAI VERIFICAR O QUE O PERSONAGEM FAZ A CADA FRAME + def loop(self, fps): + self.y_vel += min(0.05, (self.fall_count/6*fps) * self.GRAVITY) + self.move(self.x_vel,self.y_vel) + self.checar_chao(self.y_vel) + self.fall_count += 0.3 + self.update_sprite() + + def update_sprite(self): + if self.ataque: + sprite_sheet_name = "Attack" + "_" + self.virar + sprites = self.SPRITES[sprite_sheet_name] + sprite_index = (self.attack_animation_count // self.ANIMATION_DELAY) % len(sprites) + self.sprite = sprites[sprite_index] + self.attack_animation_count += 1 + if self.attack_animation_count >= len(sprites) * self.ANIMATION_DELAY: + self.ataque = False + self.attack_animation_count = 0 + else: + sprite_sheet = "Idle" + if self.x_vel != 0: + sprite_sheet = "Walk" + sprite_sheet_name = sprite_sheet + "_" + self.virar + sprites = self.SPRITES[sprite_sheet_name] + sprite_index = (self.animation_count // self.ANIMATION_DELAY) % len(sprites) + self.sprite = sprites[sprite_index] + self.animation_count += 1 + + self.update() + + def update(self): + self.rect = self.sprite.get_rect(topleft = (self.rect.x, self.rect.y)) + self.mask = pygame.mask.from_surface(self.sprite) + def atacar(self): + if self.ataque == False: + self.ataque = True + + def draw(self,tela): + tela.blit(self.sprite, (self.rect.x,self.rect.y)) + + def checar_chao(self,dy): + if self.rect.bottom + dy > 563: + self.y_vel = 0 + self.jump_count = False + + def movimento(self): + keys = pygame.key.get_pressed() + self.x_vel = 0 + if keys[pygame.K_LEFT]: + self.mover_esquerda(PLAYER_VEL) + if keys[pygame.K_RIGHT]: + self.mover_direita(PLAYER_VEL) \ No newline at end of file diff --git a/level1_data.csv b/level1_data.csv index 4df41c6..c9afac4 100644 --- a/level1_data.csv +++ b/level1_data.csv @@ -1,16 +1,16 @@ -1,-1,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,-1,-1,-1,-1,-1 --1,-1,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,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,0 +1,31 @@ +import pygame + +RED = (255,0,0) +GREEN = (0,255,0) + +largura = 1500 +altura = 640 +tela = pygame.display.set_mode((largura, altura)) + + +class HealthBar(): + + def __init__(self, x, y, health, max_health): + self.x = x #Coordinates of the health bar + self.y = y #Coordinates of the health bar + self.health = health + self.max_health = max_health + + + def draw(self, health): + #update with new health + self.health = health + #draws a RED rectangle with max_health + #Health bar size (bar_width, bar_height) + #Use (150, 20) for player and smaller for enemies + ratio = self.health / self.max_health + pygame.draw.rect(tela, RED, (self.x, self.y, 150, 20)) + pygame.draw.rect(tela, GREEN, (self.x, self.y, 150 * ratio, 20)) + +#Desenhar a health bar do jogador no loop principal do jogo +#Desenhar a health bar de cada inimigo \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..b90e8fa --- /dev/null +++ b/main.py @@ -0,0 +1,324 @@ +import pygame +import button +import csv +import os +from os.path import isfile,join +from enemies import enemy + +largura = 1500 +altura = 640 +margem = 100 +margem_lado = 300 +pygame.init() +############### FABY ############################# +tela = pygame.display.set_mode((largura, altura)) +pygame.display.set_caption('Após a enchente') + +################### LUCAS ############################### +FPS = 60 +clock = pygame.time.Clock() +PLAYER_VEL = 3 +SCROLL_THRESH = 300 +GRAVITY = 0.1 + +############### FABY #################### +#variaveis scrool +esquerda = False +direita = False +scroll = 0 +bg_scroll = 0 +scroll = 0 +#variaveis matriz +rows = 16 +colunas_max = 150 +#######TILE SIZE############### +tamanho = altura // rows +level = 1 +#variaveis grafico +#QUANTAS IMAGENS TEM --- tem que mudar sempre que add alguma imagem +tipo = 9 +current_tile = 0 +mover_esquerda = False +mover_direita = False + +#ADD AS IMAGES +background = pygame.image.load('Esgoto/sewer.png').convert_alpha() +background = pygame.transform.scale(background, (largura,altura)) +img_lista = [] +for x in range(tipo): + #ADIÇÃO DAS IMAGENS NO INVENTARIO + img = pygame.image.load(f'img/{x}.png').convert_alpha() + img = pygame.transform.scale(img, (tamanho, tamanho)) + img_lista.append(img) + + +#DEFINIR CORES +BLACK = (0, 0, 0) +WHITE = (250, 250, 250) +GREEN = (144, 201, 120) + + +font = pygame.font.SysFont('Futura', 30) + +def imagens(): + tela.fill(WHITE) + width = tela.get_width() + #quantas vezes a imagem repete + for x in range(4): + tela.blit(background,((x*width) - bg_scroll*0.7, 0)) ##0.7 == velocidade que move a tela + +def reset_level(): + water_group.empty() + data = [] + for row in range(rows): + r = [-1]*colunas_max + data.append(r) + + return data + + +class World(): + def __init__(self): + self.lista_obstaculos = [] + def process_data(self, data): + self.level_length = len(data[0]) + for y, row in enumerate(data): + for x, tile in enumerate(row): + if tile >= 0: + img = img_lista[tile] + img_rect = img.get_rect() + img_rect.x = x * tamanho + img_rect.y = y * tamanho + tile_data = (img, img_rect) + if tile == 0 or tile == 2 or tile == 4 or tile == 5 or tile == 1: + self.lista_obstaculos.append(tile_data) + if tile == 3: + water = Water(img, x * tamanho, y * tamanho) + water_group.add(water) + if tile == 7 or tile == 8: + pass #inimigos + if tile == 6: + player = Jogador('player', x * tamanho, y *tamanho,PLAYER_VEL,2.50)#tamanhos do personagem(Lucas) + + return player + def draw(self): + for tile in self.lista_obstaculos: + tile[1][0] += scroll + tela.blit(tile[0], tile[1]) + +class Jogador(pygame.sprite.Sprite): + PLAYER_VEL = 1 + #INICIO DAS VARIAVEIS PRINCIPAIS + def __init__(self, char_type, x, y,vel, scale): + pygame.sprite.Sprite.__init__(self) + self.char_type = char_type + ##self speed + self.x_vel = vel + self.y_vel = 0 + self.mask = None + ##### + self.animation_list = [] + #mudanca + self.flip = False + self.virar = 1 + ##### + self.fall = False + self.jump_count = False + self.ataque = False + self.width = 55 + self.height = 120 + #### + self.action = 0 + self.frame_index = 0 + self.update_time = pygame.time.get_ticks() + +###CARREGAR IMAGENS DO PERSONAGEM####### + animações_personagem = ['Idle', 'Walk', 'Attack', 'Death', 'Hurt'] + for animation in animações_personagem: + #reset temporary list of images + temp_list = [] + #count number of files in the folder + numero_frames = len(os.listdir(f'personagem/{animation}')) + for i in range(numero_frames): + img = pygame.image.load(f'personagem/{animation}/{i}.png').convert_alpha() + img = pygame.transform.scale(img, (int(img.get_width() * scale), int(img.get_height() * scale))) + temp_list.append(img) + self.animation_list.append(temp_list) + + self.image = self.animation_list[self.action][self.frame_index] + self.rect = self.image.get_rect() + self.rect.center = (x, y) + self.width = self.image.get_width() + self.height = self.image.get_height() + + + def update(self): + self.update_animation() + + def update_animation(self): + #update animation + ANIMATION_DELAY = 130 + #update image depending on current frame + self.image = self.animation_list[self.action][self.frame_index] + #check if enough time has passed since the last update + if pygame.time.get_ticks() - self.update_time > ANIMATION_DELAY: + self.update_time = pygame.time.get_ticks() + self.frame_index += 1 + #if the animation has run out the reset back to the start + if self.frame_index >= len(self.animation_list[self.action]): + if self.action == 3: + self.frame_index = len(self.animation_list[self.action]) - 1 + else: + self.frame_index = 0 + + def update_action(self, new_action): + #check if the new action is different to the previous one + if new_action != self.action: + self.action = new_action + #update the animation settings + self.frame_index = 0 + self.update_time = pygame.time.get_ticks() + + + #FUNCAO SOMA A VEL NA POSICAO PRA ANDAR + def move(self, mover_esquerda,mover_direita): + dx = 0 + dy = self.y_vel + if mover_esquerda: + dx = -self.x_vel + self.flip = True + self.virar = -1 + + if mover_direita: + dx = self.x_vel + self.flip = False + self.virar = 1 + + if self.jump_count == True and self.fall == False: + self.y_vel = -4 + self.jump_count = False + self.fall = True + + self.y_vel += GRAVITY + if self.y_vel > 10: + self.y_vel + dy += self.y_vel + + + #check for collision + scroll = 0 + for tile in world.lista_obstaculos: + #check collision in the x direction + if tile[1].colliderect(self.rect.x + dx, self.rect.y, self.width, self.height): + dx = 0 + + if tile[1].colliderect(self.rect.x, self.rect.y + dy, self.width, self.height): + #check if below the ground, i.e. jumping + if self.y_vel < 0: + self.y_vel = 0 + dy = tile[1].bottom - self.rect.top + #check if above the ground, i.e. falling + elif self.y_vel >= 0: + self.y_vel = 0 + self.fall = False + self.jump_count = False + dy = tile[1].top - self.rect.bottom + #check for collision with water + if pygame.sprite.spritecollide(self, water_group, False): + self.health = 0 + if self.char_type == 'player': + if self.rect.left + dx < 0 or self.rect.right + dx > largura + 0: + dx = 0 + self.rect.x += dx + self.rect.y += dy + + #update scroll based on player position + if self.char_type == 'player': + if (self.rect.right > largura - SCROLL_THRESH and bg_scroll < (world.level_length * tamanho) - largura) or (self.rect.left < SCROLL_THRESH and bg_scroll > abs(dx)): + self.rect.x -= dx + scroll = -dx + return scroll + + + def atacar(self): + if self.ataque == False: + self.ataque = True + + def draw(self): + tela.blit(pygame.transform.flip(self.image, self.flip, False), self.rect) + + +class Water(pygame.sprite.Sprite): + def __init__(self, img, x, y): + pygame.sprite.Sprite.__init__(self) + self.image = img + self.rect = self.image.get_rect() + self.rect.midtop = (x + tamanho // 2, y + (tamanho - self.image.get_height())) + + def update(self): + self.rect.x += scroll + +#CRIAR GROUPS +water_group = pygame.sprite.Group() +#World data +lista = [] +for row in range(rows): + r = [-1]*colunas_max + lista.append(r) +#load in level data and create world +with open(f'level{level}_data.csv', newline='') as csvfile: + reader = csv.reader(csvfile, delimiter=',') + for x, row in enumerate(reader): + for y, tile in enumerate(row): + lista[x][y] = int(tile) + +world = World() +player = world.process_data(lista) +rato = enemy(1000, 496, 32, 32, 1300) +rodando = True +while rodando == True: + imagens() + world.draw() + clock.tick(FPS) + + player.update() + player.draw() + rato.draw(tela) + + water_group.update() + water_group.draw(tela) + + if (mover_direita or mover_esquerda) and player.fall == False: + player.update_action(1) #walk + else: + player.update_action(0)#0: idle + + + scroll = player.move(mover_esquerda,mover_direita) + bg_scroll -= scroll + + + #MOVER A TELA + for event in pygame.event.get(): + if event.type == pygame.QUIT: + rodando = False + #pressionar teclas + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_LEFT: + mover_esquerda = True + if event.key == pygame.K_RIGHT: + mover_direita = True + if event.key == pygame.K_UP: #pulo do personagem + player.jump_count = True + if event.key == pygame.K_SPACE: + player.atacar() + if event.type == pygame.KEYUP: + if event.key == pygame.K_LEFT: + mover_esquerda = False + if event.key == pygame.K_RIGHT: + mover_direita = False + + pygame.display.update() + + +pygame.quit() \ No newline at end of file diff --git a/personagem/Attack.png b/personagem/Attack.png deleted file mode 100644 index 3c95b0b..0000000 Binary files a/personagem/Attack.png and /dev/null differ diff --git a/personagem/Attack/0.png b/personagem/Attack/0.png new file mode 100644 index 0000000..1ccaf9f Binary files /dev/null and b/personagem/Attack/0.png differ diff --git a/personagem/Attack/1.png b/personagem/Attack/1.png new file mode 100644 index 0000000..20cbf90 Binary files /dev/null and b/personagem/Attack/1.png differ diff --git a/personagem/Attack/2.png b/personagem/Attack/2.png new file mode 100644 index 0000000..0915bdd Binary files /dev/null and b/personagem/Attack/2.png differ diff --git a/personagem/Attack/3.png b/personagem/Attack/3.png new file mode 100644 index 0000000..9d7e4e1 Binary files /dev/null and b/personagem/Attack/3.png differ diff --git a/personagem/Attack/4.png b/personagem/Attack/4.png new file mode 100644 index 0000000..24b8e82 Binary files /dev/null and b/personagem/Attack/4.png differ diff --git a/personagem/Attack/5.png b/personagem/Attack/5.png new file mode 100644 index 0000000..87d28b4 Binary files /dev/null and b/personagem/Attack/5.png differ diff --git a/personagem/Death.png b/personagem/Death.png deleted file mode 100644 index 89bb2bc..0000000 Binary files a/personagem/Death.png and /dev/null differ diff --git a/personagem/Death/0.png b/personagem/Death/0.png new file mode 100644 index 0000000..1ccaf9f Binary files /dev/null and b/personagem/Death/0.png differ diff --git a/personagem/Death/1.png b/personagem/Death/1.png new file mode 100644 index 0000000..ee0dd59 Binary files /dev/null and b/personagem/Death/1.png differ diff --git a/personagem/Death/2.png b/personagem/Death/2.png new file mode 100644 index 0000000..7e6d923 Binary files /dev/null and b/personagem/Death/2.png differ diff --git a/personagem/Death/3.png b/personagem/Death/3.png new file mode 100644 index 0000000..3591d40 Binary files /dev/null and b/personagem/Death/3.png differ diff --git a/personagem/Death/4.png b/personagem/Death/4.png new file mode 100644 index 0000000..d97974f Binary files /dev/null and b/personagem/Death/4.png differ diff --git a/personagem/Death/5.png b/personagem/Death/5.png new file mode 100644 index 0000000..9af0591 Binary files /dev/null and b/personagem/Death/5.png differ diff --git a/personagem/Hurt.png b/personagem/Hurt.png deleted file mode 100644 index 0673e02..0000000 Binary files a/personagem/Hurt.png and /dev/null differ diff --git a/personagem/Hurt/0.png b/personagem/Hurt/0.png new file mode 100644 index 0000000..1ccaf9f Binary files /dev/null and b/personagem/Hurt/0.png differ diff --git a/personagem/Hurt/1.png b/personagem/Hurt/1.png new file mode 100644 index 0000000..932e242 Binary files /dev/null and b/personagem/Hurt/1.png differ diff --git a/personagem/Idle.png b/personagem/Idle.png deleted file mode 100644 index 737332d..0000000 Binary files a/personagem/Idle.png and /dev/null differ diff --git a/personagem/Idle/0.png b/personagem/Idle/0.png new file mode 100644 index 0000000..1ccaf9f Binary files /dev/null and b/personagem/Idle/0.png differ diff --git a/personagem/Idle/1.png b/personagem/Idle/1.png new file mode 100644 index 0000000..38d036c Binary files /dev/null and b/personagem/Idle/1.png differ diff --git a/personagem/Idle/2.png b/personagem/Idle/2.png new file mode 100644 index 0000000..06d715a Binary files /dev/null and b/personagem/Idle/2.png differ diff --git a/personagem/Idle/3.png b/personagem/Idle/3.png new file mode 100644 index 0000000..4f2cf36 Binary files /dev/null and b/personagem/Idle/3.png differ diff --git a/personagem/Walk.png b/personagem/Walk.png deleted file mode 100644 index 81d3ab9..0000000 Binary files a/personagem/Walk.png and /dev/null differ diff --git a/personagem/Walk/0.png b/personagem/Walk/0.png new file mode 100644 index 0000000..bd834dd Binary files /dev/null and b/personagem/Walk/0.png differ diff --git a/personagem/Walk/1.png b/personagem/Walk/1.png new file mode 100644 index 0000000..65c3582 Binary files /dev/null and b/personagem/Walk/1.png differ diff --git a/personagem/Walk/2.png b/personagem/Walk/2.png new file mode 100644 index 0000000..5cbd588 Binary files /dev/null and b/personagem/Walk/2.png differ diff --git a/personagem/Walk/3.png b/personagem/Walk/3.png new file mode 100644 index 0000000..42a7012 Binary files /dev/null and b/personagem/Walk/3.png differ diff --git a/personagem/Walk/4.png b/personagem/Walk/4.png new file mode 100644 index 0000000..219d3c5 Binary files /dev/null and b/personagem/Walk/4.png differ diff --git a/personagem/Walk/5.png b/personagem/Walk/5.png new file mode 100644 index 0000000..a2264c0 Binary files /dev/null and b/personagem/Walk/5.png differ diff --git a/potion.py b/potion.py new file mode 100644 index 0000000..5c4b904 --- /dev/null +++ b/potion.py @@ -0,0 +1,16 @@ +import pygame +import os +from os.path import isfile,join +class Potion(pygame.sprite.Sprite): + + def __init__(self,img, x, y,tamanho): + pygame.sprite.Sprite.__init__(self) + self.image = img + self.rect = self.image.get_rect() + self.rect.midtop = (x + tamanho // 2, y + (tamanho - self.image.get_height())) + + def update(self,scroll): + self.rect.x += scroll + + def kill(self): + self.kill() diff --git a/rato/Idle.png b/rato/Idle.png deleted file mode 100644 index 334fb87..0000000 Binary files a/rato/Idle.png and /dev/null differ diff --git a/rato/death/0.png b/rato/death/0.png new file mode 100644 index 0000000..fd1c048 Binary files /dev/null and b/rato/death/0.png differ diff --git a/rato/death/1.png b/rato/death/1.png new file mode 100644 index 0000000..beaa4f9 Binary files /dev/null and b/rato/death/1.png differ diff --git a/rato/Death.png b/rato/death/Death.png similarity index 100% rename from rato/Death.png rename to rato/death/Death.png diff --git a/rato/Hurt.png b/rato/hurt/Hurt.png similarity index 100% rename from rato/Hurt.png rename to rato/hurt/Hurt.png diff --git a/rato/idle/0.png b/rato/idle/0.png new file mode 100644 index 0000000..fd1c048 Binary files /dev/null and b/rato/idle/0.png differ diff --git a/rato/idle/1.png b/rato/idle/1.png new file mode 100644 index 0000000..f281559 Binary files /dev/null and b/rato/idle/1.png differ diff --git a/rato/idle/2.png b/rato/idle/2.png new file mode 100644 index 0000000..8f0080b Binary files /dev/null and b/rato/idle/2.png differ diff --git a/rato/idle/3.png b/rato/idle/3.png new file mode 100644 index 0000000..1e6b943 Binary files /dev/null and b/rato/idle/3.png differ diff --git a/rato/idle/4.png b/rato/idle/4.png new file mode 100644 index 0000000..64d81d5 Binary files /dev/null and b/rato/idle/4.png differ diff --git a/rato/idle/5.png b/rato/idle/5.png new file mode 100644 index 0000000..eb0308a Binary files /dev/null and b/rato/idle/5.png differ diff --git a/rato/idle/6.png b/rato/idle/6.png new file mode 100644 index 0000000..cc0d93a Binary files /dev/null and b/rato/idle/6.png differ diff --git a/rato/idle/7.png b/rato/idle/7.png new file mode 100644 index 0000000..c7c464d Binary files /dev/null and b/rato/idle/7.png differ diff --git a/rato/Walk.png b/rato/walk/Walk.png similarity index 100% rename from rato/Walk.png rename to rato/walk/Walk.png diff --git a/rato/walk/walk_01.png b/rato/walk/walk_01.png new file mode 100644 index 0000000..fd1c048 Binary files /dev/null and b/rato/walk/walk_01.png differ diff --git a/rato/walk/walk_02.png b/rato/walk/walk_02.png new file mode 100644 index 0000000..571cb8a Binary files /dev/null and b/rato/walk/walk_02.png differ diff --git a/rato/walk/walk_03.png b/rato/walk/walk_03.png new file mode 100644 index 0000000..d0038e0 Binary files /dev/null and b/rato/walk/walk_03.png differ diff --git a/rato/walk/walk_04.png b/rato/walk/walk_04.png new file mode 100644 index 0000000..50e74df Binary files /dev/null and b/rato/walk/walk_04.png differ diff --git a/rato/walk/walk_05.png b/rato/walk/walk_05.png new file mode 100644 index 0000000..64d81d5 Binary files /dev/null and b/rato/walk/walk_05.png differ diff --git a/rato/walk/walk_06.png b/rato/walk/walk_06.png new file mode 100644 index 0000000..f11d16c Binary files /dev/null and b/rato/walk/walk_06.png differ diff --git a/rato/walk/walk_07.png b/rato/walk/walk_07.png new file mode 100644 index 0000000..ae44ce6 Binary files /dev/null and b/rato/walk/walk_07.png differ diff --git a/rato/walk/walk_08.png b/rato/walk/walk_08.png new file mode 100644 index 0000000..d6a1458 Binary files /dev/null and b/rato/walk/walk_08.png differ diff --git a/teste_vida.py b/teste_vida.py new file mode 100644 index 0000000..5ac369b --- /dev/null +++ b/teste_vida.py @@ -0,0 +1,353 @@ +import pygame +import button +import csv +import os +from os.path import isfile,join +from life import HealthBar +from enemies import Enemy +from potion import Potion + + +largura = 1500 +altura = 640 +margem = 100 +margem_lado = 300 +pygame.init() +############### FABY ############################# +tela = pygame.display.set_mode((largura, altura)) +pygame.display.set_caption('Após a enchente') + +################### LUCAS ############################### +FPS = 60 +clock = pygame.time.Clock() +PLAYER_VEL = 4 +SCROLL_THRESH = 300 +GRAVITY = 0.1 + +############### FABY #################### +#variaveis scrool +esquerda = False +direita = False +scroll = 0 +bg_scroll = 0 +scroll = 0 +#variaveis matriz +rows = 16 +colunas_max = 150 +#######TILE SIZE############### +tamanho = altura // rows +level = 1 +#variaveis grafico +#QUANTAS IMAGENS TEM --- tem que mudar sempre que add alguma imagem +tipo = 10 +current_tile = 0 +mover_esquerda = False +mover_direita = False + +#ADD AS IMAGES +background = pygame.image.load('Esgoto/sewer.png').convert_alpha() +background = pygame.transform.scale(background, (largura,altura)) +img_lista = [] +for x in range(tipo): + #ADIÇÃO DAS IMAGENS NO INVENTARIO + img = pygame.image.load(f'img/{x}.png').convert_alpha() + img = pygame.transform.scale(img, (tamanho, tamanho)) + img_lista.append(img) + + +#DEFINIR CORES +BLACK = (0, 0, 0) +WHITE = (250, 250, 250) +GREEN = (144, 201, 120) + + +font = pygame.font.SysFont('Futura', 30) + +def imagens(): + tela.fill(WHITE) + width = tela.get_width() + #quantas vezes a imagem repete + for x in range(4): + tela.blit(background,((x*width) - bg_scroll*0.7, 0)) ##0.7 == velocidade que move a tela + +def reset_level(): + water_group.empty() + enemy_group.empty() + cure_potion_group.empty() + data = [] + for row in range(rows): + r = [-1]*colunas_max + data.append(r) + + return data + + +class World(): + def __init__(self): + self.lista_obstaculos = [] + def process_data(self, data): + self.level_length = len(data[0]) + for y, row in enumerate(data): + for x, tile in enumerate(row): + if tile >= 0: + img = img_lista[tile] + img_rect = img.get_rect() + img_rect.x = x * tamanho + img_rect.y = y * tamanho + tile_data = (img, img_rect) + if tile == 0 or tile == 2 or tile == 4 or tile == 5 or tile == 1: + self.lista_obstaculos.append(tile_data) + if tile == 3: + water = Water(img, x * tamanho, y * tamanho) + water_group.add(water) + if tile == 7 or tile == 8: + enemy = Enemy('enemy',img,tamanho, 1000, 496, 32, 32, 1300) + enemy_group.add(enemy) + if tile == 6: + player = Jogador('player', x * tamanho, y *tamanho,PLAYER_VEL,2.50)#tamanhos do personagem(Lucas) + health_bar = HealthBar(10, 10, player.health, player.health) + if tile == 9: + cure_potion = Potion(img, x * tamanho, y * tamanho,tamanho) + cure_potion_group.add(cure_potion) + + + return player, health_bar + def draw(self): + for tile in self.lista_obstaculos: + tile[1][0] += scroll + tela.blit(tile[0], tile[1]) + +class Jogador(pygame.sprite.Sprite): + PLAYER_VEL = 1 + #INICIO DAS VARIAVEIS PRINCIPAIS + def __init__(self, char_type, x, y,vel, scale): + pygame.sprite.Sprite.__init__(self) + self.char_type = char_type + ##self speed + self.x_vel = vel + self.y_vel = 0 + self.mask = None + ##### + self.animation_list = [] + #mudanca + self.flip = False + ##### + self.fall = False + self.jump_count = False + self.ataque = False + self.width = 55 + self.height = 120 + #### + self.health = 100 + self.action = 0 + self.frame_index = 0 + self.update_time = pygame.time.get_ticks() + self.walkCount = 0 + +###CARREGAR IMAGENS DO PERSONAGEM####### + animações_personagem = ['Idle', 'Walk', 'Attack', 'Death', 'Hurt'] + for animation in animações_personagem: + #reset temporary list of images + temp_list = [] + #count number of files in the folder + numero_frames = len(os.listdir(f'personagem/{animation}')) + for i in range(numero_frames): + img = pygame.image.load(f'personagem/{animation}/{i}.png').convert_alpha() + img = pygame.transform.scale(img, (int(img.get_width() * scale), int(img.get_height() * scale))) + temp_list.append(img) + self.animation_list.append(temp_list) + + self.image = self.animation_list[self.action][self.frame_index] + self.rect = self.image.get_rect() + self.rect.center = (x, y) + self.width = self.image.get_width() + self.height = self.image.get_height() + + + def update(self): + self.update_animation() + + def update_animation(self): + #update animation + ANIMATION_DELAY = 130 + #update image depending on current frame + self.image = self.animation_list[self.action][self.frame_index] + #check if enough time has passed since the last update + if pygame.time.get_ticks() - self.update_time > ANIMATION_DELAY: + self.update_time = pygame.time.get_ticks() + self.frame_index += 1 + #if the animation has run out the reset back to the start + if self.frame_index >= len(self.animation_list[self.action]): + if self.action == 3: + self.frame_index = len(self.animation_list[self.action]) - 1 + else: + self.frame_index = 0 + + def update_action(self, new_action): + #check if the new action is different to the previous one + if new_action != self.action: + self.action = new_action + #update the animation settings + self.frame_index = 0 + self.update_time = pygame.time.get_ticks() + + + #FUNCAO SOMA A VEL NA POSICAO PRA ANDAR + def move(self, mover_esquerda,mover_direita): + dx = 0 + dy = self.y_vel + if mover_esquerda: + dx = -self.x_vel + self.flip = True + + if mover_direita: + dx = self.x_vel + self.flip = False + + if self.jump_count == True and self.fall == False: + self.y_vel = -4 + self.jump_count = False + self.fall = True + + + self.y_vel += GRAVITY + if self.y_vel > 10: + self.y_vel + dy += self.y_vel + + + #check for collision + scroll = 0 + for tile in world.lista_obstaculos: + #check collision in the x direction + if tile[1].colliderect(self.rect.x + dx, self.rect.y, self.width, self.height): + dx = 0 + + if self.char_type == 'enemy': + print("inimigo") + self.flip = False + self.walkCount = 0 + + if tile[1].colliderect(self.rect.x, self.rect.y + dy, self.width, self.height): + #check if below the ground, i.e. jumping + if self.y_vel < 0: + self.y_vel = 0 + dy = tile[1].bottom - self.rect.top + #check if above the ground, i.e. falling + elif self.y_vel >= 0: + self.y_vel = 0 + self.fall = False + self.jump_count = False + dy = tile[1].top - self.rect.bottom + #check for collision with water + if pygame.sprite.spritecollide(self, water_group, False): + self.health = 0 + if self.rect.bottom > altura: + self.health -= 10 + if self.char_type == 'player': + if self.rect.left + dx < 0 or self.rect.right + dx > largura + 0: + dx = 0 + self.rect.x += dx + self.rect.y += dy + #check collision with health potion + if pygame.sprite.spritecollide(self, cure_potion_group, False): + self.health += 25 + + #update scroll based on player position + if self.char_type == 'player': + if (self.rect.right > largura - SCROLL_THRESH and bg_scroll < (world.level_length * tamanho) - largura) or (self.rect.left < SCROLL_THRESH and bg_scroll > abs(dx)): + self.rect.x -= dx + scroll = -dx + return scroll + + def draw(self): + tela.blit(pygame.transform.flip(self.image, self.flip, False), self.rect) + + +class Water(pygame.sprite.Sprite): + def __init__(self, img, x, y): + pygame.sprite.Sprite.__init__(self) + self.image = img + self.rect = self.image.get_rect() + self.rect.midtop = (x + tamanho // 2, y + (tamanho - self.image.get_height())) + + def update(self): + self.rect.x += scroll + +#CRIAR GROUPS +water_group = pygame.sprite.Group() +enemy_group = pygame.sprite.Group() +cure_potion_group = pygame.sprite.Group() + +#World data +lista = [] +for row in range(rows): + r = [-1]*colunas_max + lista.append(r) +#load in level data and create world +with open(f'level{level}_data.csv', newline='') as csvfile: + reader = csv.reader(csvfile, delimiter=',') + for x, row in enumerate(reader): + for y, tile in enumerate(row): + lista[x][y] = int(tile) + +world = World() +player, health_bar = world.process_data(lista) + +rodando = True +while rodando == True: + imagens() + world.draw() + clock.tick(FPS) + health_bar.draw(player.health) + player.update() + player.draw() + + water_group.update() + water_group.draw(tela) + + cure_potion_group.update(scroll) + cure_potion_group.draw(tela) + + if (mover_direita or mover_esquerda) and player.fall == False and player.ataque == False: + player.update_action(1) #walk + elif player.ataque: + player.update_action(2) #attack + else: + player.update_action(0)#0: idle + + + scroll = player.move(mover_esquerda,mover_direita) + bg_scroll -= scroll + + for enemy in enemy_group: + enemy.update(scroll) + enemy.draw(tela) + + + #MOVER A TELA + for event in pygame.event.get(): + if event.type == pygame.QUIT: + rodando = False + #pressionar teclas + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_LEFT: + mover_esquerda = True + if event.key == pygame.K_RIGHT: + mover_direita = True + if event.key == pygame.K_UP: #pulo do personagem + player.jump_count = True + if event.key == pygame.K_SPACE: + player.ataque = True + if event.type == pygame.KEYUP: + if event.key == pygame.K_LEFT: + mover_esquerda = False + if event.key == pygame.K_RIGHT: + mover_direita = False + if event.key == pygame.K_SPACE: + player.ataque = False + + pygame.display.update() + + +pygame.quit()