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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
# g.py - spirolaterals globals
"""
Copyright (C) 2010 Peter Hewitt
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
"""
import pygame
import logging
import utils
XO = False # affects the pygame.display.set_mode() call only
app = 'Spirolaterals'
ver = '1.0'
ver = '1.1'
# new system - 32x24 display to allow scaling
ver = '1.2'
# smooth scaling, nos display, mouse, utils
ver = '1.3'
# moved nos & right buttons up .5 - looks better on XO
# smiley on win
ver = '1.4'
# utils.message now has drop shadow
# global gdelay & pause before 1st turtle move by setting tu.ms to current time
# improved smiley
# help on magician click
# gwins - add 1 to level each 5
ver = '1.5' # <<<< Release 2
# no image scaling if factor = 1.0 ie on XO box
ver = '1.6'
# fixed for widescreen
# smiley on left
ver = '2.0'
# new style - i.e g.py etc
# sugar cursor
# save level
# scale font
# no music
# right button -> decrease nos
ver = '2.1'
# floating point comparisons necessary on XO resolution
ver = '2.2'
# check cyan button b4 magician pic
ver = '2.3'
# cursor off on button press
ver = '2.4'
# speed -/+ (saved)
# No Esc on XO
# click on player pic for Big Pic - click to return
# blue button delay fixed
# black button funny fixed
# green & cyan buttons alternate
# smaller smiley
# help & score implemented
ver = '2.5'
# pattern library
# speed slider
# uses mouse_on_image for magician pic - see utils.ImgClickClass
ver = '2.6'
# fixed number click bug
ver = '2.7'
# no number glow when pattern finished
# smiley - less glow
ver = '2.8' # <<<<Release 11
# pattern number displayed
ver = '2.9'
# help only on wrong digits
ver = '3.0'
# sugar
ver = '3.1'
# redraw implented
ver = '3.2'
# crash only shows after mouse move - fixed - g.crash_drawn
# red mouse after crash + help - fixed
# change help # -> 2 numbers - fixed
# blue button = new pattern but run button fails - fixed
ver = '3.2'
# help - if all correct, still show path
ver = '4.0'
# proper sugar cursor
# no frame rate
ver = '4.1'
# no version display on XO
# doesn't bother with pygame.mouse.get_focused() in run()
# help starts off by ensuring current numbers are in self.tu.current
ver = '4.2'
# drop g.current
ver = '4.3'
# g.help2 limit check fixed
# magician "holes" filled
ver = '21'
# flush_queue() added after button press and key press
ver = '22'
# flush_queue() doesn't use gtk on non-XO
ver = '23'
# removed patterns 9 & 10 - now have 122 patterns
ver = '24'
# sugar style
UP = (264, 273)
DOWN = (258, 274)
LEFT = (260, 276)
RIGHT = (262, 275)
CROSS = (259, 120)
CIRCLE = (265, 111)
SQUARE = (263, 32)
TICK = (257, 13)
def init(): # called by main()
global redraw
global screen, w, h, font1, font2, font3, clock
global factor, offset, imgf, message, version_display
global pos, pointer
redraw = True
version_display = False
screen = pygame.display.get_surface()
pygame.display.set_caption(app)
screen.fill((70, 0, 70))
pygame.display.flip()
w, h = screen.get_size()
if float(w) / float(h) > 1.5: # widescreen
offset = (w - 4 * h / 3) / 2 # we assume 4:3 - centre on widescreen
else:
h = int(.75 * w) # allow for toolbar - works to 4:3
offset = 0
clock = pygame.time.Clock()
factor = float(h) / 24 # measurement scaling factor (32x24 = design units)
imgf = float(h) / 900 # image scaling factor; images built for 1200x900
if pygame.font:
t = int(54 * imgf)
font1 = pygame.font.Font(None, t)
t = int(72 * imgf)
font2 = pygame.font.Font(None, t)
t = int(46 * imgf)
font3 = pygame.font.Font(None, t)
message = ''
pos = pygame.mouse.get_pos()
pointer = utils.load_image('pointer.png', True)
pygame.mouse.set_visible(False)
# this activity only
global x0, y0, x1, y1, goal, steps, pattern, delay, help1, help2, show_help
global big, big_surface, score, slider, level, finale, player_surface
global crash_drawn, magician, magician_c
global bgd, box, dd, magician, turtle, crash, smiley, n, n_glow
global n_cx0, n_cy0
global n_dx, bw, sparkle
x0 = sx(2.0)
y0 = sy(1.1) # left frame
w, h = screen.get_size()
if w > h:
x1 = sx(16.8)
y1 = sy(1.1) # right frame
else:
x1 = sx(2.0)
y1 = sy(17) # right frame
goal = []
steps = 40 # number of steps to draw pic
pattern = 1
level = 1
delay = (3 - level) * 400
help1 = 0
help2 = 0
show_help = False
score = 0
finale = False
crash_drawn = True # used to make sure crash is drawn
magician = utils.load_image('magician.png', True)
magician_c = (sx(5.5), sy(20))
sparkle = utils.load_image('sparkle.png', True)
bgd = utils.load_image('sunset.jpg')
box = utils.load_image('box.png', True)
bw = box.get_width()
s = bw - 2 * sy(1)
player_surface = pygame.Surface((s, s))
big = False
big_surface = None
dd = box.get_width() / 8 # turtle step size
turtle = utils.load_image('turtle.png', True)
crash = utils.load_image('crash.png', True)
smiley = utils.load_image('smiley.png', True)
n = [] # 1, 2, 3, 4, 5 images
n_glow = [] # ... with glow
for i in range(5):
img = utils.load_image(str(i + 1) + '.png', True)
n.append(img)
img = utils.load_image(str(i + 1) + 'g.png', True)
n_glow.append(img)
if w > h:
n_cx0 = sx(17.4) + n[3].get_width() / 2 # "4" is widest
n_cy0 = sy(17)
n_dx = sy(2.6)
else:
n_cx0 = sx(2.6) + n[3].get_width() / 2 # "4" is widest
n_cy0 = sy(34)
n_dx = sy(2.6)
def sx(f): # scale x function
return f * factor + offset
def sy(f): # scale y function
return f * factor
|