2022-03-08 20:27:24 +01:00
|
|
|
import pygame
|
2022-03-09 20:55:12 +01:00
|
|
|
import random
|
2022-03-08 20:27:24 +01:00
|
|
|
|
2022-03-11 03:02:29 +01:00
|
|
|
import field
|
|
|
|
import settings
|
|
|
|
import common
|
|
|
|
import agent
|
|
|
|
|
2022-03-08 22:30:31 +01:00
|
|
|
AGENT_IMG = pygame.image.load("dot-22-433567.png")
|
|
|
|
AGENT = pygame.transform.scale(AGENT_IMG, (50, 50))
|
2022-03-11 03:02:29 +01:00
|
|
|
|
|
|
|
DIRT_IMG = pygame.image.load("assets/fields/plant/dirt.jpg")
|
|
|
|
# DIRT = pygame.transform.scale(DIRT_IMG, (50, 50))
|
|
|
|
# DIRT_BLOCK_IMG = pygame.image.load("assets/fields/plant/dirt_block.jpg")
|
|
|
|
# DIRT_BLOCK = pygame.transform.scale(DIRT_BLOCK_IMG, (800, 800))
|
|
|
|
|
|
|
|
DIRT = field.Dirt().tile.object
|
|
|
|
DIRT_BLOCK = field.Dirt().block.object
|
|
|
|
|
|
|
|
GRASS_IMG = pygame.image.load("assets/fields/default/grass.png")
|
2022-03-09 20:55:12 +01:00
|
|
|
GRASS = pygame.transform.scale(GRASS_IMG, (50, 50))
|
2022-03-11 03:02:29 +01:00
|
|
|
GRASS_BLOCK_IMG = pygame.image.load("assets/fields/default/grass_block.jpeg")
|
|
|
|
GRASS_BLOCK = pygame.transform.scale(GRASS_BLOCK_IMG, (800, 800))
|
|
|
|
|
2022-03-09 20:55:12 +01:00
|
|
|
SAND_IMG = pygame.image.load("sand.jpeg")
|
|
|
|
SAND = pygame.transform.scale(SAND_IMG, (50, 50))
|
|
|
|
SAND_BLOCK_IMG = pygame.image.load("sand_block.jpg")
|
|
|
|
SAND_BLOCK = pygame.transform.scale(SAND_BLOCK_IMG, (800, 800))
|
2022-03-11 03:02:29 +01:00
|
|
|
|
|
|
|
COBBLE_IMG = pygame.image.load("assets/fields/special/cobble.jpg")
|
|
|
|
COBBLE = pygame.transform.scale(COBBLE_IMG, (50, 50))
|
|
|
|
COBBLE_BLOCK_IMG = pygame.image.load("assets/fields/special/cobble_block.jpg")
|
2022-03-09 20:55:12 +01:00
|
|
|
COBBLE_BLOCK = pygame.transform.scale(COBBLE_BLOCK_IMG, (800, 800))
|
|
|
|
|
|
|
|
|
|
|
|
def randomize_map():
|
2022-03-11 03:02:29 +01:00
|
|
|
possible_fields = [
|
|
|
|
field.Dirt().tile.object,
|
|
|
|
GRASS,
|
|
|
|
SAND,
|
|
|
|
COBBLE
|
|
|
|
]
|
2022-03-09 20:55:12 +01:00
|
|
|
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):
|
2022-03-11 03:02:29 +01:00
|
|
|
window = common.get('window')
|
|
|
|
coords = agent.current_field_pos()
|
|
|
|
current_field = fields[coords['x']][coords['y']]
|
|
|
|
|
|
|
|
if current_field == GRASS:
|
|
|
|
window.blit(GRASS_BLOCK, (0, 0))
|
|
|
|
elif current_field == field.Dirt().tile.object:
|
|
|
|
window.blit(DIRT_BLOCK, (0, 0))
|
|
|
|
elif current_field == SAND:
|
|
|
|
window.blit(SAND_BLOCK, (0, 0))
|
|
|
|
elif current_field == COBBLE:
|
|
|
|
window.blit(COBBLE_BLOCK, (0, 0))
|
2022-03-09 20:55:12 +01:00
|
|
|
pygame.display.update()
|
|
|
|
pygame.time.delay(2000)
|
|
|
|
|
|
|
|
|
2022-03-11 03:02:29 +01:00
|
|
|
def draw_window(agent, fields):
|
|
|
|
window = common.get('window')
|
|
|
|
rect = agent.rect
|
|
|
|
for i in range(16):
|
|
|
|
for j in range(16):
|
|
|
|
window.blit(fields[i][j], (i * settings.Field.size(), j * settings.Field.size()))
|
|
|
|
window.blit(AGENT, (rect.x, rect.y))
|
|
|
|
pygame.display.update()
|
|
|
|
|
|
|
|
|
|
|
|
common = common.Instance()
|
|
|
|
agent = agent.Instance()
|
2022-03-09 18:59:50 +01:00
|
|
|
|
2022-03-08 20:27:24 +01:00
|
|
|
|
|
|
|
def main():
|
2022-03-11 03:02:29 +01:00
|
|
|
common.set('game_running', True)
|
|
|
|
common.set('state_imgShown', True)
|
|
|
|
common.set(
|
|
|
|
'window',
|
|
|
|
pygame.display.set_mode((
|
|
|
|
settings.Pygame.width(),
|
|
|
|
settings.Pygame.height())))
|
|
|
|
|
|
|
|
pygame.display.set_caption(settings.Pygame.display_name())
|
|
|
|
|
2022-03-09 20:55:12 +01:00
|
|
|
fields = randomize_map()
|
2022-03-11 03:02:29 +01:00
|
|
|
|
|
|
|
while common.get('game_running'):
|
|
|
|
pygame.time.Clock().tick(settings.Pygame.fps())
|
2022-03-08 20:27:24 +01:00
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
2022-03-11 03:02:29 +01:00
|
|
|
common.set('game_running', False)
|
|
|
|
|
|
|
|
if not common.get('state_imgShown'):
|
|
|
|
read_img(agent, fields)
|
|
|
|
else:
|
|
|
|
draw_window(agent, fields)
|
|
|
|
|
|
|
|
agent.move()
|
2022-03-09 20:55:12 +01:00
|
|
|
|
2022-03-08 20:27:24 +01:00
|
|
|
pygame.quit()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2022-03-11 03:02:29 +01:00
|
|
|
main()
|