diff --git a/cobble.jpeg b/cobble.jpeg new file mode 100644 index 0000000..da425d3 Binary files /dev/null and b/cobble.jpeg differ diff --git a/cobble_block.jpeg b/cobble_block.jpeg new file mode 100644 index 0000000..ab10800 Binary files /dev/null and b/cobble_block.jpeg differ diff --git a/dirt.jpg b/dirt.jpg new file mode 100644 index 0000000..9497730 Binary files /dev/null and b/dirt.jpg differ diff --git a/dirt_block.jpg b/dirt_block.jpg new file mode 100644 index 0000000..06f5dd0 Binary files /dev/null and b/dirt_block.jpg differ diff --git a/grass.png b/grass.png new file mode 100644 index 0000000..eaa5a7d Binary files /dev/null and b/grass.png differ diff --git a/grass_block.jpeg b/grass_block.jpeg new file mode 100644 index 0000000..a57efd9 Binary files /dev/null and b/grass_block.jpeg differ diff --git a/main.py b/main.py index a7efd65..0df1e06 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import pygame +import random WIDTH, HEIGHT = 800, 800 WIN = pygame.display.set_mode((WIDTH, HEIGHT)) @@ -6,37 +7,92 @@ pygame.display.set_caption("Sztuczna Inteligencja") FPS = 30 AGENT_IMG = pygame.image.load("dot-22-433567.png") AGENT = pygame.transform.scale(AGENT_IMG, (50, 50)) +DIRT_IMG = pygame.image.load("dirt.jpg") +DIRT = pygame.transform.scale(DIRT_IMG, (50, 50)) +GRASS_IMG = pygame.image.load("grass.png") +GRASS = pygame.transform.scale(GRASS_IMG, (50, 50)) +SAND_IMG = pygame.image.load("sand.jpeg") +SAND = pygame.transform.scale(SAND_IMG, (50, 50)) +COBBLE_IMG = pygame.image.load("cobble.jpeg") +COBBLE = pygame.transform.scale(COBBLE_IMG, (50, 50)) +DIRT_BLOCK_IMG = pygame.image.load("dirt_block.jpg") +DIRT_BLOCK = pygame.transform.scale(DIRT_BLOCK_IMG, (800, 800)) +GRASS_BLOCK_IMG = pygame.image.load("grass_block.jpeg") +GRASS_BLOCK = pygame.transform.scale(GRASS_BLOCK_IMG, (800, 800)) +SAND_BLOCK_IMG = pygame.image.load("sand_block.jpg") +SAND_BLOCK = pygame.transform.scale(SAND_BLOCK_IMG, (800, 800)) +COBBLE_BLOCK_IMG = pygame.image.load("cobble_block.jpeg") +COBBLE_BLOCK = pygame.transform.scale(COBBLE_BLOCK_IMG, (800, 800)) + + +def randomize_map(): + possible_fields = [DIRT, GRASS, SAND, COBBLE] + field_array_big = [] + field_array_small = [] + for i in range(16): + for j in range(16): + field_array_small.append(random.choice(possible_fields)) + field_array_big.append(field_array_small) + field_array_small = [] + return field_array_big + + +def read_img(agent, fields): + if fields[int(agent.x / 50)][int(agent.y / 50)] == GRASS: + WIN.blit(GRASS_BLOCK, (0, 0)) + elif fields[int(agent.x / 50)][int(agent.y / 50)] == DIRT: + WIN.blit(DIRT_BLOCK, (0, 0)) + elif fields[int(agent.x / 50)][int(agent.y / 50)] == SAND: + WIN.blit(SAND_BLOCK, (0, 0)) + elif fields[int(agent.x / 50)][int(agent.y / 50)] == COBBLE: + WIN.blit(COBBLE_BLOCK, (0, 0)) + pygame.display.update() + pygame.time.delay(2000) + + +def draw_window(agent, fields, image_shown): + if image_shown: + for i in range(16): + for j in range(16): + WIN.blit(fields[i][j], (i * 50, j * 50)) + WIN.blit(AGENT, (agent.x, agent.y)) + pygame.display.update() + else: + read_img(agent, fields) + def agent_movement(keys_pressed, agent): if keys_pressed[pygame.K_LEFT] and agent.x > 0: agent.x -= 50 - if keys_pressed[pygame.K_RIGHT] and agent.x < 750: + return False + elif keys_pressed[pygame.K_RIGHT] and agent.x < 750: agent.x += 50 - if keys_pressed[pygame.K_UP] and agent.y > 0: + return False + elif keys_pressed[pygame.K_UP] and agent.y > 0: agent.y -= 50 - if keys_pressed[pygame.K_DOWN] and agent.y < 750: + return False + elif keys_pressed[pygame.K_DOWN] and agent.y < 750: agent.y += 50 + return False + else: + return True -def draw_window(agent): - WIN.fill((255,255,255)) - WIN.blit(AGENT, (agent.x, agent.y)) - pygame.display.update() - def main(): clock = pygame.time.Clock() run = True agent = pygame.Rect(0, 0, 50, 50) - + fields = randomize_map() + image_shown = True while run: clock.tick(FPS) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False - draw_window(agent) keys_pressed = pygame.key.get_pressed() - agent_movement(keys_pressed, agent) - + draw_window(agent, fields, image_shown) + image_shown = agent_movement(keys_pressed, agent) + pygame.quit() diff --git a/sand.jpeg b/sand.jpeg new file mode 100644 index 0000000..be2f713 Binary files /dev/null and b/sand.jpeg differ diff --git a/sand_block.jpg b/sand_block.jpg new file mode 100644 index 0000000..b25d7ce Binary files /dev/null and b/sand_block.jpg differ