Separate score display from map

master
Gabriel Augendre 5 years ago
parent 789be9c5d8
commit 1d5b9bd148
No known key found for this signature in database
GPG Key ID: F360212F958357D4
  1. 3
      config.py
  2. 6
      main.py
  3. 10
      objects.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

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

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

Loading…
Cancel
Save