From 1d5b9bd148832405788cfeec4fa2083a03a6ba9a Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Mon, 30 Apr 2018 20:57:24 +0200 Subject: [PATCH] Separate score display from map --- config.py | 3 ++- main.py | 6 +++++- objects.py | 10 +++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/config.py b/config.py index af43668..7647084 100644 --- a/config.py +++ b/config.py @@ -5,7 +5,8 @@ FONT_COLOR = 250, 250, 250 MAP_SIZE = 41, 31 TILE_SIZE = 20 -RESOLUTION = MAP_SIZE[0] * TILE_SIZE, MAP_SIZE[1] * TILE_SIZE +MAP_RESOLUTION = MAP_SIZE[0] * TILE_SIZE, MAP_SIZE[1] * TILE_SIZE +RESOLUTION = MAP_RESOLUTION[0], MAP_RESOLUTION[1] + 50 INITIAL_SNAKE_SIZE = 3 diff --git a/main.py b/main.py index 885856f..4413d92 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,9 @@ import pickle import pygame from pygame import locals as pglocals -from config import RESOLUTION, SNAKE_COLOR, BACKGROUND_COLOR, FONT_COLOR, INITIAL_SNAKE_SIZE, SCORES_FILE +from config import (RESOLUTION, MAP_RESOLUTION, + SNAKE_COLOR, BACKGROUND_COLOR, FONT_COLOR, + INITIAL_SNAKE_SIZE, SCORES_FILE) from objects import Snake, Apple from utils import get_score_text, Direction @@ -44,6 +46,8 @@ def main(): score_text, score_rect = get_score_text(score) screen.blit(score_text, score_rect) + screen.fill(FONT_COLOR, pygame.Rect(0, MAP_RESOLUTION[1], MAP_RESOLUTION[0], 5)) + pygame.display.flip() while True: diff --git a/objects.py b/objects.py index 446c1c1..1e0de5f 100644 --- a/objects.py +++ b/objects.py @@ -2,7 +2,7 @@ import logging import pygame -from config import INITIAL_SNAKE_SIZE, RESOLUTION, TILE_SIZE, SNAKE_COLOR, BACKGROUND_COLOR, APPLE_COLOR +from config import INITIAL_SNAKE_SIZE, MAP_RESOLUTION, TILE_SIZE, SNAKE_COLOR, BACKGROUND_COLOR, APPLE_COLOR from utils import make_slot, Direction, random_slot logger = logging.getLogger(__name__) @@ -27,14 +27,14 @@ class Snake: self.dead = True return [] - if new_head.right > RESOLUTION[0]: + if new_head.right > MAP_RESOLUTION[0]: new_head = pygame.Rect(0, new_head.top, TILE_SIZE, TILE_SIZE) elif new_head.left < 0: - new_head = pygame.Rect(RESOLUTION[0] - TILE_SIZE, new_head.top, TILE_SIZE, TILE_SIZE) - if new_head.bottom > RESOLUTION[1]: + new_head = pygame.Rect(MAP_RESOLUTION[0] - TILE_SIZE, new_head.top, TILE_SIZE, TILE_SIZE) + if new_head.bottom > MAP_RESOLUTION[1]: new_head = pygame.Rect(new_head.left, 0, TILE_SIZE, TILE_SIZE) elif new_head.top < 0: - new_head = pygame.Rect(new_head.left, RESOLUTION[1] - TILE_SIZE, TILE_SIZE, TILE_SIZE) + new_head = pygame.Rect(new_head.left, MAP_RESOLUTION[1] - TILE_SIZE, TILE_SIZE, TILE_SIZE) self.slots.insert(0, new_head) screen.fill(SNAKE_COLOR, new_head)