Jun-26-2021, 04:36 PM
Win 10
Python 3.9.5
I need to make collisions for my isometric game and for player
Can someone help me?
Sorry for bad english, i from Ukraine.
here is code:
Python 3.9.5
I need to make collisions for my isometric game and for player
Can someone help me?
Sorry for bad english, i from Ukraine.
here is code:
import pygame import sys import time import random WIDTH = 700 HEIGHT = 700 from pygame.constants import QUIT clock = pygame.time.Clock() pygame.init() screen = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32) pygame.display.set_caption("game base") display = pygame.Surface((300, 300)) ground_img = pygame.image.load('ground3.png') ground_img.set_colorkey((0, 0, 0)) stone_img = pygame.image.load("stone2.png").convert() stone_img.set_colorkey((0, 0, 0)) ground_dict = {} # словарь {ряд-номер клетки-номер слоя: название картинки} # читаем данные карты из файла и заполняем ими словарь with open('map.txt') as f: map_data = [[int(c) for c in row.strip()] for row in f] for y, row in enumerate(map_data): for x, tile in enumerate(row): if tile: ground_dict[f'{y}-{x}-1'] = 'stone' # для второго слоя if random.randint(0, 1): ground_dict[f'{y}-{x}-2'] = 'ground' while True: display.fill((0, 0, 0)) clock.tick(60) # проходим в цикле по словарю for key, value in ground_dict.items(): # получаем ряд, номер клетки и номер слоя y, x, n = list(map(int, key.split('-'))) # определяем нужную картинку для клетки z = stone_img if value == 'stone' else ground_img # отрисовываем в зависимости от номера слоя if n == 1: display.blit(z, (150 + x * 10 - y * 10, 100 + x * 5 + y * 5)) elif n == 2: display.blit(z, (150 + x * 10 - y * 10, 100 + x * 5 + y * 5 - 14)) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() screen.blit(pygame.transform.scale(display, screen.get_size()), (55, 55)) pygame.display.update() time.sleep(1)