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-24 15:12:58 +01:00
|
|
|
AGENT_IMG = pygame.image.load('./assets/tracktor/tractor.png')
|
2022-03-11 03:34:20 +01:00
|
|
|
AGENT = pygame.transform.scale(AGENT_IMG, (settings.Field.size(), settings.Field.size()))
|
2022-03-11 03:02:29 +01:00
|
|
|
|
2022-03-11 03:34:20 +01:00
|
|
|
possibleFields = {
|
|
|
|
'dirt': field.Dirt(),
|
|
|
|
'grass': field.Grass(),
|
|
|
|
'cobble': field.Cobble(),
|
|
|
|
'sand': field.Sand(),
|
|
|
|
}
|
2022-03-09 20:55:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
def randomize_map():
|
2022-03-11 03:34:20 +01:00
|
|
|
fields_array = []
|
|
|
|
for i in possibleFields:
|
|
|
|
fields_array.append(possibleFields[i].tile.object)
|
|
|
|
|
2022-03-09 20:55:12 +01:00
|
|
|
field_array_big = []
|
|
|
|
field_array_small = []
|
2022-03-11 03:34:20 +01:00
|
|
|
for i in range(settings.Field.horizontal_count()):
|
|
|
|
for j in range(settings.Field.vertical_count()):
|
|
|
|
field_array_small.append(random.choice(fields_array))
|
2022-03-09 20:55:12 +01:00
|
|
|
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')
|
2022-03-11 03:34:20 +01:00
|
|
|
current_field = fields[agent.x()][agent.y()]
|
|
|
|
|
|
|
|
if current_field == possibleFields['grass'].tile.object:
|
|
|
|
window.blit(possibleFields['grass'].block.object, (0, 0))
|
|
|
|
elif current_field == possibleFields['dirt'].tile.object:
|
|
|
|
window.blit(possibleFields['dirt'].block.object, (0, 0))
|
|
|
|
elif current_field == possibleFields['sand'].tile.object:
|
|
|
|
window.blit(possibleFields['sand'].block.object, (0, 0))
|
|
|
|
elif current_field == possibleFields['cobble'].tile.object:
|
|
|
|
window.blit(possibleFields['cobble'].block.object, (0, 0))
|
2022-03-09 20:55:12 +01:00
|
|
|
pygame.display.update()
|
|
|
|
pygame.time.delay(2000)
|
2022-03-11 03:34:20 +01:00
|
|
|
common.set('state_imgShown', False)
|
|
|
|
|
|
|
|
|
|
|
|
def agent_action(action: str):
|
|
|
|
if action == 'open_window':
|
|
|
|
common.set('state_imgShown', True)
|
2022-03-09 20:55:12 +01:00
|
|
|
|
|
|
|
|
2022-03-11 03:02:29 +01:00
|
|
|
def draw_window(agent, fields):
|
|
|
|
window = common.get('window')
|
|
|
|
rect = agent.rect
|
2022-03-11 03:34:20 +01:00
|
|
|
for i in range(settings.Field.horizontal_count()):
|
|
|
|
for j in range(settings.Field.vertical_count()):
|
2022-03-11 03:02:29 +01:00
|
|
|
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)
|
2022-03-11 03:34:20 +01:00
|
|
|
common.set('state_imgShown', False)
|
2022-03-11 03:02:29 +01:00
|
|
|
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)
|
|
|
|
|
2022-03-11 03:34:20 +01:00
|
|
|
if common.get('state_imgShown'):
|
2022-03-11 03:02:29 +01:00
|
|
|
read_img(agent, fields)
|
|
|
|
else:
|
|
|
|
draw_window(agent, fields)
|
|
|
|
|
2022-03-11 03:34:20 +01:00
|
|
|
agent_action(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()
|