mirror of
https://github.com/kristoferssolo/School.git
synced 2025-10-21 20:10:38 +00:00
changed font
This commit is contained in:
parent
b49a8a9f6a
commit
38171d92ea
BIN
pygame/snake/source/fonts/roboto.ttf
Normal file
BIN
pygame/snake/source/fonts/roboto.ttf
Normal file
Binary file not shown.
Binary file not shown.
@ -2,7 +2,6 @@
|
|||||||
# Date - 10.04.2022
|
# Date - 10.04.2022
|
||||||
# Title - Snake
|
# Title - Snake
|
||||||
|
|
||||||
from audioop import mul
|
|
||||||
import pygame
|
import pygame
|
||||||
from random import randrange, randint
|
from random import randrange, randint
|
||||||
from os.path import abspath, dirname, join
|
from os.path import abspath, dirname, join
|
||||||
@ -17,14 +16,17 @@ pygame.display.set_caption("Snake")
|
|||||||
|
|
||||||
BASE_PATH = abspath(dirname(__file__))
|
BASE_PATH = abspath(dirname(__file__))
|
||||||
SPRITE_PATH = join(BASE_PATH, "assets", "sprites")
|
SPRITE_PATH = join(BASE_PATH, "assets", "sprites")
|
||||||
|
FONT = join(BASE_PATH, "fonts", "roboto.ttf")
|
||||||
|
|
||||||
apple_texture = pygame.transform.scale(pygame.image.load(join(SPRITE_PATH, "golden_apple.png")), (CELL_SIZE, CELL_SIZE))
|
apple_texture = pygame.transform.scale(pygame.image.load(join(SPRITE_PATH, "golden_apple.png")), (CELL_SIZE, CELL_SIZE))
|
||||||
poison_texture = pygame.transform.scale(pygame.image.load(join(SPRITE_PATH, "poison.png")), (CELL_SIZE, CELL_SIZE))
|
poison_texture = pygame.transform.scale(pygame.image.load(join(SPRITE_PATH, "poison.png")), (CELL_SIZE, CELL_SIZE))
|
||||||
cobblestone_texture = pygame.transform.scale(pygame.image.load(join(SPRITE_PATH, "cobblestone.jpeg")), (CELL_SIZE, CELL_SIZE))
|
cobblestone_texture = pygame.transform.scale(pygame.image.load(join(SPRITE_PATH, "cobblestone.jpeg")), (CELL_SIZE, CELL_SIZE))
|
||||||
|
|
||||||
RED = (255, 0, 0)
|
RED = (255, 0, 0)
|
||||||
|
WHITE = (242, 242, 242)
|
||||||
|
GRAY = (204, 204, 204)
|
||||||
|
DARK_GRAY = (51, 51, 51)
|
||||||
BLACK = (0, 0, 0)
|
BLACK = (0, 0, 0)
|
||||||
WHITE = (255, 255, 255)
|
|
||||||
GREEN = (0, 128, 30)
|
GREEN = (0, 128, 30)
|
||||||
PURPLE = (170, 0, 255)
|
PURPLE = (170, 0, 255)
|
||||||
BLUE = (85, 85, 255)
|
BLUE = (85, 85, 255)
|
||||||
@ -230,6 +232,20 @@ def main() -> None:
|
|||||||
poison = Snack(poison_texture)
|
poison = Snack(poison_texture)
|
||||||
collision_check(snakes, poison)
|
collision_check(snakes, poison)
|
||||||
|
|
||||||
|
def redraw_window() -> None:
|
||||||
|
WINDOW.fill(BLACK)
|
||||||
|
draw_grid()
|
||||||
|
draw_score(snakes)
|
||||||
|
for snake in snakes:
|
||||||
|
snake.draw()
|
||||||
|
apple.draw_snack()
|
||||||
|
poison.draw_snack()
|
||||||
|
if walls:
|
||||||
|
for i in range(ROWS):
|
||||||
|
cobble_rect = pygame.Rect(i * CELL_SIZE, HEIGHT, WIDTH, CELL_SIZE)
|
||||||
|
WINDOW.blit(cobblestone_texture, cobble_rect)
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
while run:
|
while run:
|
||||||
clock.tick(FPS)
|
clock.tick(FPS)
|
||||||
pygame.time.delay(10)
|
pygame.time.delay(10)
|
||||||
@ -253,35 +269,24 @@ def main() -> None:
|
|||||||
for i in range(len(snake.body)):
|
for i in range(len(snake.body)):
|
||||||
if snake.body[i].pos in list(map(lambda z: z.pos, snake.body[i + 1:])):
|
if snake.body[i].pos in list(map(lambda z: z.pos, snake.body[i + 1:])):
|
||||||
run = False
|
run = False
|
||||||
|
redraw_window()
|
||||||
WINDOW.fill(BLACK)
|
|
||||||
draw_grid()
|
|
||||||
draw_score(snakes)
|
|
||||||
for snake in snakes:
|
|
||||||
snake.draw()
|
|
||||||
apple.draw_snack()
|
|
||||||
poison.draw_snack()
|
|
||||||
if walls:
|
|
||||||
for i in range(ROWS):
|
|
||||||
cobble_rect = pygame.Rect(i * CELL_SIZE, HEIGHT, WIDTH, CELL_SIZE)
|
|
||||||
WINDOW.blit(cobblestone_texture, cobble_rect)
|
|
||||||
pygame.display.update()
|
|
||||||
|
|
||||||
|
|
||||||
set_font = lambda size: pygame.font.SysFont("roboto", size) # sets font size
|
set_font = lambda size: pygame.font.Font(FONT, size) # sets font size
|
||||||
|
|
||||||
|
|
||||||
def main_menu() -> None:
|
def main_menu() -> None:
|
||||||
|
text = set_font(20).render("QUIT", 1, GRAY)
|
||||||
while True:
|
while True:
|
||||||
WINDOW.fill(BLACK)
|
WINDOW.fill(BLACK)
|
||||||
title_label = set_font(50).render("Press any key to start...", 1, WHITE)
|
title_label = set_font(50).render("Press any key to start...", 1, WHITE)
|
||||||
WINDOW.blit(title_label, (WIDTH / 2 - title_label.get_width() / 2, WINDOW_HEIGHT / 2 - title_label.get_height() / 2))
|
WINDOW.blit(title_label, (WIDTH / 2 - title_label.get_width() / 2, WINDOW_HEIGHT / 2 - title_label.get_height() / 2))
|
||||||
pygame.display.update()
|
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
quit()
|
quit()
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
main()
|
main()
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user