Separate score display from map

This commit is contained in:
Gabriel Augendre 2018-04-30 20:57:24 +02:00
parent 789be9c5d8
commit 1d5b9bd148
No known key found for this signature in database
GPG key ID: F360212F958357D4
3 changed files with 12 additions and 7 deletions

View file

@ -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

View file

@ -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:

View file

@ -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)