Separate score display from map
This commit is contained in:
parent
789be9c5d8
commit
1d5b9bd148
3 changed files with 12 additions and 7 deletions
|
@ -5,7 +5,8 @@ FONT_COLOR = 250, 250, 250
|
||||||
|
|
||||||
MAP_SIZE = 41, 31
|
MAP_SIZE = 41, 31
|
||||||
TILE_SIZE = 20
|
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
|
INITIAL_SNAKE_SIZE = 3
|
||||||
|
|
||||||
|
|
6
main.py
6
main.py
|
@ -5,7 +5,9 @@ import pickle
|
||||||
import pygame
|
import pygame
|
||||||
from pygame import locals as pglocals
|
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 objects import Snake, Apple
|
||||||
from utils import get_score_text, Direction
|
from utils import get_score_text, Direction
|
||||||
|
|
||||||
|
@ -44,6 +46,8 @@ def main():
|
||||||
score_text, score_rect = get_score_text(score)
|
score_text, score_rect = get_score_text(score)
|
||||||
screen.blit(score_text, score_rect)
|
screen.blit(score_text, score_rect)
|
||||||
|
|
||||||
|
screen.fill(FONT_COLOR, pygame.Rect(0, MAP_RESOLUTION[1], MAP_RESOLUTION[0], 5))
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
10
objects.py
10
objects.py
|
@ -2,7 +2,7 @@ import logging
|
||||||
|
|
||||||
import pygame
|
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
|
from utils import make_slot, Direction, random_slot
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -27,14 +27,14 @@ class Snake:
|
||||||
self.dead = True
|
self.dead = True
|
||||||
return []
|
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)
|
new_head = pygame.Rect(0, new_head.top, TILE_SIZE, TILE_SIZE)
|
||||||
elif new_head.left < 0:
|
elif new_head.left < 0:
|
||||||
new_head = pygame.Rect(RESOLUTION[0] - TILE_SIZE, new_head.top, TILE_SIZE, TILE_SIZE)
|
new_head = pygame.Rect(MAP_RESOLUTION[0] - TILE_SIZE, new_head.top, TILE_SIZE, TILE_SIZE)
|
||||||
if new_head.bottom > RESOLUTION[1]:
|
if new_head.bottom > MAP_RESOLUTION[1]:
|
||||||
new_head = pygame.Rect(new_head.left, 0, TILE_SIZE, TILE_SIZE)
|
new_head = pygame.Rect(new_head.left, 0, TILE_SIZE, TILE_SIZE)
|
||||||
elif new_head.top < 0:
|
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)
|
self.slots.insert(0, new_head)
|
||||||
screen.fill(SNAKE_COLOR, new_head)
|
screen.fill(SNAKE_COLOR, new_head)
|
||||||
|
|
Loading…
Reference in a new issue