From 9c71bd0312b52832c862d55a9472b77092bf831b Mon Sep 17 00:00:00 2001 From: Arthur 'Grizzly' Grisel-Davy Date: Wed, 6 May 2020 19:04:21 -0400 Subject: [PATCH] Remove hardcoded data and create config file --- config.yaml | 15 +++++++++++++++ main.py | 1 - models.py | 11 +++++++---- utils.py | 9 +++++---- 4 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 config.yaml diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..5b6c6e0 --- /dev/null +++ b/config.yaml @@ -0,0 +1,15 @@ +### Tangled Mind +### Author: Arthur 'Grizzly' Grisel-Davy + + +# Map +room_side : 1000 + + +# Player +cap_speed : 10 +acceleration : 2 +deceleration : 1.1 + +# Projectile +max_fire_rate : 10 \ No newline at end of file diff --git a/main.py b/main.py index a41e2f5..93d0cea 100644 --- a/main.py +++ b/main.py @@ -26,7 +26,6 @@ carte = Carte(n=5) # possible positions: 300,300: 1400,1000: 2700,400, 2800,1600 # click = 323 start_pos = carte.player_start_pos -print(start_pos) player = Player('Alice',start_pos,center_screen,pygame.K_z,pygame.K_s,pygame.K_q,pygame.K_d,323,'perso.png','canon.png','projectile1_right.png') camera = Camera(start_pos,screen_width,screen_height,0.3) #enemies = [Enemy('Plop',(300,300),'perso.png')] diff --git a/models.py b/models.py index 9239680..8149413 100644 --- a/models.py +++ b/models.py @@ -11,11 +11,14 @@ from utils import * img_path = 'asset/' -max_fire_rate = 10 # in fires per seconds -cap_speed = 10 -acceleration = 2 -deceleration = 1.1 +with open(r'./config.yaml') as file: + data = yaml.load(file,Loader=yaml.FullLoader) + + max_fire_rate = data['max_fire_rate'] # in fires per seconds + cap_speed = data['cap_speed'] + acceleration = data['acceleration'] + deceleration = data['deceleration'] diff --git a/utils.py b/utils.py index bcac41f..4d67709 100644 --- a/utils.py +++ b/utils.py @@ -6,6 +6,7 @@ from glob import glob import random import pygame +import yaml def fetch_rooms(path): """Fetch all the basic tiles asset from the path. @@ -53,7 +54,10 @@ def map_generator(n): """Map generator generate a map with a main path of n rooms """ - room_side = 1000 + with open(r'./config.yaml') as file: + data = yaml.load(file,Loader=yaml.FullLoader) + room_side = data['room_side'] + change_side = {'T':'D','R':'L','D':'T','L':'R'} deplacements = {'T':[0,-1],'R':[1,0],'D':[0,1],'L':[-1,0]} @@ -136,9 +140,6 @@ def map_generator(n): background = pygame.image.load(back_path).convert() - print("Open paths:") - print(open_paths) - if not check_map(carte): raise ValueError("Invalid Map after closing paths.")