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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
import random, os.path
import util
import pygame
import pygame.font
from pygame.locals import *
import string
def run():
#Must initialize pygame before doing anything else
pygame.init()
random.seed()
display_flags = DOUBLEBUF
#XO laptop is 1200x900 resolution
width, height = 1200, 900
if pygame.display.mode_ok((width, height), display_flags ):
screen = pygame.display.set_mode((width, height), display_flags)
clock = pygame.time.Clock()
run = 1
pygame.display.set_caption('OLPC Math Game')
#level two setup
background = util.load_image('fork.bmp')
map_bg = util.load_image('map.bmp')
map_foreground = util.load_image('map_foreground2.bmp')
house1 = util.load_image('house_map.bmp')
colorkey = house1.get_at((0, 0))
house1.set_colorkey(colorkey)
tower = util.load_image('tower_map.bmp')
tower.set_colorkey((255,255,255))
tower.convert_alpha()
house2 = util.load_image('house2_map.bmp')
colorkey = house2.get_at((0, 0))
house2.set_colorkey(colorkey)
stonehedge = util.load_image('stonehedge_map.bmp')
colorkey = stonehedge.get_at((0, 0))
stonehedge.set_colorkey(colorkey)
map_image = [house1,house2,stonehedge]
screen.blit(background,(0,0))
state = (2,1)
bg_draw=1
map_points = [(480,230), (715,295),(812,218), (818,307), (812,451)]
win = 0
rand_array = [random.randint(0,2),random.randint(0,2),random.randint(0,2),random.randint(0,2),random.randint(0,2)]
tower_spot = random.randint(0,4)
tower_xy = map_points[tower_spot]
win_coord = ["F3","E6","F7","E7","C7"]
while run:
events = pygame.event.get()
for event in events:
#User decides to exit program
if event.type == QUIT:
run = 0 #stop running
pygame.quit()
if state == (2,1):
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_loc = list(event.pos)
(x, y) = pygame.mouse.get_pos()
if x > 100+220-15 and x < 100+220+15 and y > 80 and y < 110:
state = (2,2)
if state == (2,3):
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_loc = list(event.pos)
(x, y) = pygame.mouse.get_pos()
if x > 100+220-15 and x < 100+220+15 and y > 80 and y < 110:
run = 0
#end events
if state == (2,1): #level one, intro
#background = load_image('bridge_bg_2.bmp')
screen.blit(background, (0, 0))
font = pygame.font.Font(None, 24)
intro_string = "There is a fork in the road; it is a good thing we picked up that map! Find the tower on the map by entering the closest coordinant"
text_rect = pygame.Rect((100,20),(440,100))
text_box = util.render_textrect(intro_string,font,text_rect,(255,255,255),0,0)
screen.blit(text_box,text_rect.topleft)
ok_box = pygame.Rect((100+220-15,80),(30,30))
ok_box_surf = pygame.Surface(ok_box.size)
ok_box_surf.fill((255,255,255))
screen.blit(ok_box_surf,ok_box.topleft)
ok_text = font.render("OK",1,(0,0,0))
(x,y) = ok_box.topleft
x += 3
y += 5
screen.blit(ok_text,(x,y))
if state == (2,2):
if bg_draw==1:
screen.blit(background,(0,0))
bg_draw=0
map_bg.set_colorkey((0,0,0))
screen.blit(map_bg, (100,100))
font = pygame.font.Font(None, 24)
screen.blit(map_foreground,(279,200))
screen.blit(tower,tower_xy)
for i in range(0,5):
if map_points[i] != tower_xy:
screen.blit(map_image[rand_array[i]],map_points[i])
pygame.draw.line(screen, [0,0,0], (275,200+13*40),(915,13*40+200),7)
pygame.draw.line(screen, [0,0,0], (275,200),(275,720),7)
for i in range(0,7): # down
y_coord = font.render("%s" % chr(i+65), 1, (255, 0, 0))
screen.blit(y_coord,(255,670-i*80))
pygame.draw.line(screen, [0,0,0], (275,i*80+200),(915,i*80+200))
for i in range(0,9): # across
x_coord = font.render("%s" % i, 1, (255, 0, 0))
screen.blit(x_coord,(270+i*80,725))
pygame.draw.line(screen, [0,0,0], (275+i*80,200),(275+i*80,720))
text_rect = pygame.Rect(500,815,300,30)
text_box = util.render_textrect("Hint: The red dot is on coordinent a3",font,text_rect,(255,255,255),0,0)
#text_box.set_colorkey((0,0,0))
screen.blit(text_box,text_rect.topleft)
pygame.draw.circle(screen, (255,0,0),(515,678),10)
coord = util.ask(screen,"What coordinant is the tower closest to?",500,775,300)
if coord == win_coord[tower_spot]:
state = (2,3)
else:
bg_draw=1
if state == (2,3):
screen.blit(background, (0, 0))
font = pygame.font.Font(None, 24)
intro_string = "Great job finding the tower on the map! Now we know which path to take...and it's the scary one"
text_rect = pygame.Rect((100,20),(440,100))
text_box = util.render_textrect(intro_string,font,text_rect,(255,255,255),0,0)
screen.blit(text_box,text_rect.topleft)
ok_box = pygame.Rect((100+220-15,80),(30,30))
ok_box_surf = pygame.Surface(ok_box.size)
ok_box_surf.fill((255,255,255))
screen.blit(ok_box_surf,ok_box.topleft)
ok_text = font.render("OK",1,(0,0,0))
(x,y) = ok_box.topleft
x += 3
y += 5
screen.blit(ok_text,(x,y))
pygame.display.flip()
clock.tick(40) #limits to 40 FPS
def main():
run()
#runs main if called via other naming convention
if __name__ == '__main__': main()
|