added basic map with agent and randomized fields
This commit is contained in:
commit
0a18d1a656
3
.idea/.gitignore
vendored
Normal file
3
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
BIN
cobble.jpeg
Normal file
BIN
cobble.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.3 KiB |
BIN
garbage-truck-nbg.png
Normal file
BIN
garbage-truck-nbg.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 147 KiB |
70
main.py
Normal file
70
main.py
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
import pygame
|
||||||
|
import random
|
||||||
|
|
||||||
|
pygame.init()
|
||||||
|
WIDTH, HEIGHT = 800, 800
|
||||||
|
window = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||||
|
pygame.display.set_caption("Intelligent Garbage Collector")
|
||||||
|
AGENT_IMG = pygame.image.load("garbage-truck-nbg.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))
|
||||||
|
FPS = 10
|
||||||
|
|
||||||
|
|
||||||
|
def randomize_map(): # tworzenie mapy z losowymi polami
|
||||||
|
fields_list = [DIRT, GRASS, SAND, COBBLE]
|
||||||
|
field_array_1 = []
|
||||||
|
field_array_2 = []
|
||||||
|
for i in range(16):
|
||||||
|
for j in range(16):
|
||||||
|
field_array_2.append(random.choice(fields_list))
|
||||||
|
field_array_1.append(field_array_2)
|
||||||
|
field_array_2 = []
|
||||||
|
return field_array_1
|
||||||
|
|
||||||
|
|
||||||
|
def draw_window(agent, fields):
|
||||||
|
for i in range(16):
|
||||||
|
for j in range(16):
|
||||||
|
window.blit(fields[i][j], (i * 50, j * 50))
|
||||||
|
window.blit(AGENT, (agent.x, agent.y)) # wyswietlanie agenta
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
|
|
||||||
|
def agent_movement(keys_pressed, agent): # sterowanie
|
||||||
|
if keys_pressed[pygame.K_LEFT] and agent.x > 0:
|
||||||
|
agent.x -= 50
|
||||||
|
if keys_pressed[pygame.K_RIGHT] and agent.x < 750:
|
||||||
|
agent.x += 50
|
||||||
|
if keys_pressed[pygame.K_UP] and agent.y > 0:
|
||||||
|
agent.y -= 50
|
||||||
|
if keys_pressed[pygame.K_DOWN] and agent.y < 750:
|
||||||
|
agent.y += 50
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
clock = pygame.time.Clock()
|
||||||
|
run = True
|
||||||
|
agent = pygame.Rect(0, 0, 50, 50) # tworzenie pola dla agenta
|
||||||
|
fields = randomize_map()
|
||||||
|
while run:
|
||||||
|
clock.tick(FPS)
|
||||||
|
for event in pygame.event.get(): # przechwycanie zamknięcia okna
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
run = False
|
||||||
|
keys_pressed = pygame.key.get_pressed()
|
||||||
|
draw_window(agent, fields)
|
||||||
|
agent_movement(keys_pressed, agent)
|
||||||
|
|
||||||
|
pygame.quit()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user