-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntroScreen.py
More file actions
129 lines (105 loc) · 4.21 KB
/
Copy pathIntroScreen.py
File metadata and controls
129 lines (105 loc) · 4.21 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
import pygame, os, sys
from pygame.locals import *
import time
def load_image(image_name):
''' The proper way to load an image '''
try:
image = pygame.image.load(image_name)
except pygame.error, message:
print "Cannot load image: " + image_name
raise SystemExit, message
return image.convert_alpha()
def toMoveOn():
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
if event.key == K_RETURN:
return True
return False
def playKey():
try:
sound = pygame.mixer.Sound('assets/typewriter_key.wav')
sound.play()
except pygame.error, message:
print "Error"
pass
def PlayIntroScreen(screen):
nextScreen = False #start off with a intro screen
allPrinted = False
#this will loop until user presses enter or quits
while nextScreen == False:
#the text positions, to be changed as they bounce around
instr1_x = 100
instr1_y = 300
instr2_x = 200
instr2_y = 330
instr3_x = 290
instr3_y = 360
#background star image
introImage = load_image("assets/space_small.jpg")
screen.blit(introImage, (0, 0))
text1 = "WELCOME TO BATTLESHIP:THE EVIL PEARS"
text2 = "Kill as many Evil Pears as possible"
text3 = "Press ENTER to play"
printText1, printText2, printText3 = "", "", ""
font1 = pygame.font.Font(None, 36)
font2 = pygame.font.Font(None, 30)
#these for statements slowly print out the text like someone is typing
#they have to continually check to see if the user has pressed enter
if allPrinted == False:
for char in text1:
printText1 = printText1 + char
instructions1 = font1.render(printText1, 1, (255, 255, 255))
screen.blit(instructions1, (instr1_x, instr1_y))
pygame.display.update()
if char != " ":
playKey()
time.sleep(.05)
nextScreen = toMoveOn()
if nextScreen == True:
break
time.sleep(.2)
if nextScreen == False:
for char in text2:
printText2 = printText2 + char
instructions2 = font2.render(printText2, 1, (255, 255, 255))
screen.blit(instructions2, (instr2_x, instr2_y))
pygame.display.update()
if char != " ":
playKey()
time.sleep(.05)
nextScreen = toMoveOn()
if nextScreen == True:
break
time.sleep(0.2)
if nextScreen == False:
for char in text3:
printText3 = printText3 + char
instructions3 = font2.render(printText3, 1, (255, 255, 255))
screen.blit(instructions3, (instr3_x, instr3_y))
pygame.display.update()
if char != " ":
playKey()
time.sleep(.05)
nextScreen = toMoveOn()
if nextScreen == True:
break
time.sleep(0.2)
allPrinted = True
instructions1 = font1.render(text1, 1, (255, 255, 255))
screen.blit(instructions1, (instr1_x, instr1_y))
instructions2 = font2.render(text2, 1, (255,255,255))
screen.blit(instructions2, (instr2_x, instr2_y))
instructions3 = font2.render(text3, 1, (255,255,255))
screen.blit(instructions3, (instr3_x, instr3_y))
#print control text
font = pygame.font.Font(None, 24)
text = font.render("f - rotate clockwise, d - rotate counter clockwise, space - fire lasers, arrow keys - move", 1, (255, 255, 255))
screen.blit(text, ((screen.get_size()[0]/2) - 340, 500))
pygame.display.update()
nextScreen = toMoveOn()