forked from davidMcneil/Space-Invaders
/
splash.py
109 lines (106 loc) · 3.27 KB
/
splash.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import pygame
import load_resources
from pygame.locals import *
class start_button(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.x = 400
self.y = 450
self.font = pygame.font.Font(None, 32)
self.text = "START"
self.color = 255, 255, 255
self.image = self.font.render(self.text, False, (self.color))
self.rect = self.image.get_rect()
self.rect.center= self.x, self.y
def update(self):
self.image = self.font.render(self.text, False, (self.color))
class quit_button(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.x = 400
self.y = 550
self.font = pygame.font.Font(None, 32)
self.text = "QUIT"
self.color = 255, 255, 255
self.image = self.font.render(self.text, False, (self.color))
self.rect = self.image.get_rect()
self.rect.center= self.x, self.y
def update(self):
self.image = self.font.render(self.text, False, (self.color))
class highscore_button(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.x = 400
self.y = 500
self.font = pygame.font.Font(None, 32)
self.text = "HIGH SCORES"
self.color = 255, 255, 255
self.image = self.font.render(self.text, False, (self.color))
self.rect = self.image.get_rect()
self.rect.center= self.x, self.y
def update(self):
self.image = self.font.render(self.text, False, (self.color))
def show_splash(screen):
s = start_button()
q = quit_button()
h = highscore_button()
sprites= pygame.sprite.RenderUpdates(s, q, h)
clock = pygame.time.Clock()
splash = True
bg_image= pygame.image.load("graphics/splash/background.png").convert()
screen.blit(bg_image, (0, 0))
pygame.display.flip()
title = load_resources.load_image("graphics/splash/title.png", -1)
points = load_resources.load_image("graphics/splash/points.png", -1)
screen.blit(title, (250, 50))
screen.blit(points, (290, 250))
pygame.display.flip()
play = True
file = "code/highscores.txt"
while splash:
for event in pygame.event.get():
if event.type == QUIT:
splash = False
play = False
if event.type == pygame.KEYDOWN:
if event.key== K_q:
splash = False
play = False
elif event.key== K_ESCAPE:
splash = False
play = False
if event.type == MOUSEBUTTONDOWN:
x, y = event.pos
distance_s= ((x - s.x)**2 + (y - s.y)**2)** 0.5
if distance_s < 25:
splash = False
distance_q= ((x - q.x)**2 + (y - q.y)**2)** 0.5
if distance_q < 20:
splash = False
play = False
distance_h= ((x - h.x)**2 + (y - h.y)**2)** 0.5
if distance_h < 25:
pass
if event.type == MOUSEMOTION:
x, y = event.pos
distance_s= ((x - s.x)**2 + (y - s.y)**2)** 0.5
if distance_s < 25:
s.color= 0, 255, 0
else:
s.color= 255, 255, 255
distance_q= ((x - q.x)**2 + (y - q.y)**2)** 0.5
if distance_q < 20:
q.color= 0, 255, 0
else:
q.color= 255, 255, 255
distance_h= ((x - h.x)**2 + (y - h.y)**2)** 0.5
if distance_h < 25:
h.color= 0, 255, 0
else:
h.color= 255, 255, 255
sprites.clear(screen, bg_image)
sprites.update()
rectlist = sprites.draw(screen)
pygame.display.update(rectlist)
clock.tick(15)
return play