-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.py
More file actions
136 lines (96 loc) · 2.91 KB
/
Copy pathcode.py
File metadata and controls
136 lines (96 loc) · 2.91 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import pygame
import pygame.freetype
from pygame.locals import *
pygame.init()
bg = pygame.image.load("resized-image-Promo.jpeg")
bgg = pygame.transform.scale(bg,(900,720))
yellow = (255, 255, 0)
red = (255, 0, 0)
white = (255,255,255)
black = (0,0,0)
width = 720
bg1 = pygame.image.load("frame_0_delay-0.07s.gif")
bg2 = pygame.transform.scale(bg1, (900,720))
screen_width = 900
screen_height = 720
screen=pygame.display.set_mode((screen_width, screen_height))
font_size = 40
title_font = pygame.font.Font("Absolute_Zero.otf",50)
button_font = pygame.font.Font("Absolute_Zero.otf",font_size)
titleX = 270
titleY = 250
startX = 340
startY = 340
#Title
def show_title(x,y):
title = title_font.render("Car Game", True, white)
screen.blit(title,(270, y))
back_g = True
def background():
i = 0
while back_g:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
screen.fill((0,0,0))
screen.blit(bg2, (0, i))
screen.blit(bg2, (0, width + i))
if i == - width:
screen.blit(bg2, (0, width + i))
i = 0
i -= 3
pygame.display.update()
start_text = button_font.render("Start", True, red)
quit_text = button_font.render("Quit", True, white)
class Button():
def __init__(self, x, y, text):
self.text = text
self.rect = self.text.get_rect()
self.rect.topleft = (x,y)
self.clicked = False
def draw(self):
action = False
#Get mouse position
pos = pygame.mouse.get_pos()
#Check Mouseover
if self.rect.collidepoint(pos):
font_size = 50
if pygame.mouse.get_pressed()[0] == 1 and self.clicked == False:
self.clicked = True
action = True
if pygame.mouse.get_pressed()[0] == 0:
self.clicked = False
#Draw Buttons
screen.blit(self.text, (self.rect.x, self.rect.y))
return action
#Button Instances
start_button = Button(340,460, start_text)
quit_button = Button(370,560, quit_text)
def main_menu():
menu = True
while menu == True:
screen.blit(bgg,(0,0))
show_title(titleX,titleY)
if start_button.draw() == True:
#menu = False
background()
if quit_button.draw():
pygame.quit()
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
pygame.display.update()
run = True
def game_loop():
while run:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
screen.fill(black)
main_menu()
pygame.display.update()
pygame.display.update()
main_menu()
game_loop()