-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnake.py
91 lines (76 loc) · 2.36 KB
/
snake.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python3
import pygame
from pygame.locals import *
import os
# Game Initialization
pygame.init()
# Center the Game Application
os.environ['SDL_VIDEO_CENTERED'] = '1'
# Game Resolution
screen_width=800
screen_height=600
screen=pygame.display.set_mode((screen_width, screen_height))
# Text Renderer
def text_format(message, textFont, textSize, textColor):
newFont=pygame.font.Font(textFont, textSize)
newText=newFont.render(message, 0, textColor)
return newText
# Colors
white=(255, 255, 255)
black=(0, 0, 0)
gray=(50, 50, 50)
red=(255, 0, 0)
green=(0, 255, 0)
blue=(0, 0, 255)
yellow=(255, 255, 0)
# Game Fonts
font = pygame.font.SysFont("Retro Gaming.ttf", 32)
# Game Framerate
clock = pygame.time.Clock()
FPS=30
# Main Menu
def main_menu():
menu=True
selected="start"
while menu:
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
quit()
if event.type==pygame.KEYDOWN:
if event.key==pygame.K_UP:
selected="start"
elif event.key==pygame.K_DOWN:
selected="quit"
if event.key==pygame.K_RETURN:
if selected=="start":
print("Start")
if selected=="quit":
pygame.quit()
quit()
# Main Menu UI
screen.fill(blue)
title=text_format("Sourcecodester", font, 90, yellow)
if selected=="start":
text_start=text_format("START", font, 75, white)
else:
text_start = text_format("START", font, 75, black)
if selected=="quit":
text_quit=text_format("QUIT", font, 75, white)
else:
text_quit = text_format("QUIT", font, 75, black)
title_rect=title.get_rect()
start_rect=text_start.get_rect()
quit_rect=text_quit.get_rect()
# Main Menu Text
screen.blit(title, (screen_width/2 - (title_rect[2]/2), 80))
screen.blit(text_start, (screen_width/2 - (start_rect[2]/2), 300))
screen.blit(text_quit, (screen_width/2 - (quit_rect[2]/2), 360))
pygame.display.update()
clock.tick(FPS)
pygame.display.set_caption("Python - Pygame Simple Main Menu Selection")
#Initialize the Game
#
main_menu()
pygame.quit()
quit()