-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
507 lines (416 loc) · 14.2 KB
/
main.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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
from kivy.properties import ObjectProperty, NumericProperty, BoundedNumericProperty, ReferenceListProperty, StringProperty, ListProperty
from kivy.uix.widget import Widget
from kivy.vector import Vector
from kivy.clock import Clock
from kivy.uix.image import Image
from kivy.core.text import LabelBase
from game import BlipGame
from app import *
from stores import *
import datetime
from time import time
from os import listdir # for getting files in directories and making directories
from urllib2 import urlopen, URLError # for getting data from url request
from math import sqrt
FONTS = [
{
'name': 'odin',
'fn_regular': 'assets/font/Odin-Rounded-Regular.ttf',
'fn_bold': 'assets/font/Odin-Rounded-Bold.ttf'
},
{
'name': 'gemelli',
'fn_regular': 'assets/font/gemelli.regular.ttf'
}
]
for i in FONTS: ## register new fonts
LabelBase.register(**i)
class Ball(Widget):
vel_x = NumericProperty(0)
vel_y = NumericProperty(0)
vel = ReferenceListProperty(vel_x,vel_y)
moving = False
falling = False
rotation = NumericProperty(0)
rotate = -4
turning = False
tex = StringProperty(check_store['ball']['active'])
def move(self):
if self.moving:
self.pos = Vector(*self.vel) + self.pos
if self.turning:
self.rotation += self.rotate
class Platform(Widget):
moving = False
moved = False
looped = False
rotation = NumericProperty(0)
side_pos = -1 ## -1 = left, 1 = right ##
tex = StringProperty('assets/levels/platform_g.png')
def move(self):
if self.moving:
self.y -= self.height
class Spike(Widget):
moving = False
speed = 10
shifting = False
x_dir = 0.05
y_dir = 0
change = 1
delta = BoundedNumericProperty(0,min=-2,max=2)
def move(self):
if self.moving:
self.y -= self.speed
if self.y < -self.height:
self.moving = False
elif self.shifting:
self.x += self.x_dir * self.width
self.y += self.y_dir * self.width
try:
self.delta += max(abs(self.x_dir),abs(self.y_dir)) * self.change
except ValueError:
self.x_dir *= -1
self.y_dir *= -1
self.change *= -1
class Coin(Widget):
pass
class TitleCanvas(Widget):
def play(self):
global blip
blip.m.current = 'game'
if check_store.exists('last_game') and check_store.get('last_game')['level'] > 0:
blip.m.game.resuming = True
blip.m.game.reset()
def nav(self,l):
blip.m.current = l
class Dot(Widget):
y_inc = BoundedNumericProperty(0,min=0,max=20)
y_dir = 1
def __init__(self, *args, **kwargs):
super(Dot, self).__init__(*args, **kwargs)
Clock.schedule_interval(self.update, 1 / 20)
def update(self,t):
try:
self.y_inc += self.y_dir
self.y += self.y_dir
except ValueError:
self.y_dir *= -1
class Title(Widget):
pass
class BackButton(Widget):
def back(self):
blip.m.current = 'menu'
class Music(Widget):
if check_store['settings']['music']:
speaker_source = StringProperty('assets/gui/music_icon_on.png')
music = True
else:
speaker_source = StringProperty('assets/gui/music_icon_off.png')
music = False
def no_audio(self):
if self.music:
blip.m.game.sounds['background_music'].volume = 0
self.speaker_source = 'assets/gui/music_icon_off.png'
check_store.put('settings',music=False,audio=check_store['settings']['audio'])
self.music = False
else:
blip.m.game.sounds['background_music'].volume = 1
self.speaker_source = 'assets/gui/music_icon_on.png'
check_store.put('settings',music=True,audio=check_store['settings']['audio'])
self.music = True
class Speaker(Widget):
if check_store['settings']['audio']:
speaker_source = StringProperty('assets/gui/sound_icon_on.png')
audio = True
else:
speaker_source = StringProperty('assets/gui/sound_icon_off.png')
audio = False
def no_audio(self):
if self.audio:
for i,j in blip.m.game.sounds.iteritems():
if i != 'background_music':
j.volume = 0
self.speaker_source = 'assets/gui/sound_icon_off.png'
check_store.put('settings',audio=False,music=check_store['settings']['music'])
self.audio = False
else:
for i,j in blip.m.game.sounds.iteritems():
if i != 'background_music':
j.volume = 1
self.speaker_source = 'assets/gui/sound_icon_on.png'
check_store.put('settings',audio=True,music=check_store['settings']['music'])
self.audio = True
class LinkButton(Widget):
col = ListProperty([1,1,1,0])
def link(self,u):
open_url(u)
class Information(Widget):
pass
class Tutorial(Widget):
tut = ObjectProperty(Image(source='assets/gui/instructions.zip',anim_delay=-1))
class AimBall(Widget):
rotation = BoundedNumericProperty(0,min=-86,max=86)
class ContinueButton(Widget):
start_angle = BoundedNumericProperty(0,min=0,max=360)
label = ObjectProperty(None)
def __init__(self, *args, **kwargs):
super(ContinueButton, self).__init__(*args, **kwargs)
Clock.schedule_interval(self.update, 1 / 20)
def update(self,t):
if check_store['retry']['remaining'] > 0:
blip.m.go.continuebutton.label.opacity = 0
blip.m.go.continuebutton.contlabel.opacity = 1
try:
self.start_angle += 1.5
self.active = True
except ValueError:
self.start_angle = 360
self.active = False
self.opacity = 0
else:
blip.m.go.continuebutton.label.opacity = 1
blip.m.go.continuebutton.contlabel.opacity = 0
blip.m.go.continuebutton.start_angle = 360
self.active = False
if blip.m.game.retried:
self.opacity = 0
if time() - check_store['retry']['time'] > 86399: # checks if a day has passed since a replay was used
check_store.put('retry',remaining=MAX_RETRIES,time=check_store['retry']['time'])
if time() - check_store['store']['time'] > 86399: # checks if a day has passed since an ad was used in the store (put here to avoid repetition)
check_store.put('store',remaining=2,time=check_store['store']['time'])
def back(self):
if not PREMIUM:
try:
resp = urlopen('http://google.com',timeout=4)
except URLError:
blip.m.go.continuebutton.contlabel.text = 'No internet. Please try again later'
self.active = False
if (not blip.m.game.retried) and self.active:
if adverts and not PREMIUM:
AdBuddiz.showAd(PythonActivity.mActivity)
blip.m.current = 'game'
blip.m.game.retried = True
blip.m.game.cache()
if check_store.get('retry')['remaining'] == MAX_RETRIES:
check_store.put('retry',remaining=check_store['retry']['remaining'],time=time())
remain = check_store['retry']['remaining']
check_store.put('retry',remaining=remain-1,time=check_store['retry']['time'])
class GameOver(Widget):
hs = ObjectProperty(None)
d = store
def play(self):
global blip
blip.m.current = 'game'
blip.m.game.reset()
def nav(self,l):
blip.m.current = l
class Information(Widget):
tut = ObjectProperty(None)
class StoreScreen(Widget):
scroll = ObjectProperty(None)
coincounter = ObjectProperty(None)
d = store
class InfoButton(Widget):
icon = ObjectProperty(Image(source='assets/gui/info.zip',anim_delay=0.05))
def change(self):
blip.m.info.tut.tut.anim_delay = 0.03
blip.m.current = 'info'
class AdButton(Widget):
img = StringProperty('assets/store/ad_button.png')
inet = True
if not PREMIUM:
try:
inet = True
resp = urlopen('http://google.com',timeout=4)
except URLError:
img = StringProperty('assets/store/connection.png')
inet = False
if check_store['store']['remaining'] <= 0:
img = StringProperty('assets/store/back_later.png')
t = 0
def do_ad(self):
try:
self.inet = True
resp = urlopen('http://google.com',timeout=4)
self.img = 'assets/store/ad_button.png'
except URLError:
self.img = 'assets/store/connection.png'
self.inet = False
if self.inet and check_store['store']['remaining'] > 0 and time() - self.t > 2.5:
if adverts and not PREMIUM:
AdBuddiz.showAd(PythonActivity.mActivity)
coins = check_store.get('coins')['value']
check_store.put('coins',value=coins+10)
store.put('coins',value=coins+10)
self.t = time()
print('done an ad')
if check_store.get('store')['remaining'] == 2:
check_store.put('store',remaining=check_store['store']['remaining'],time=time())
remain = check_store['store']['remaining']
check_store.put('store',remaining=remain-1,time=check_store['store']['time'])
if check_store['store']['remaining'] <= 0:
self.img = 'assets/store/back_later.png'
class StoreScroll(Widget):
offset_x = NumericProperty(0)
touched = 0,0
initial_touch = 0,0
touching = False
touch_time = time()
t = time()
try:
date = urlopen('http://just-the-time.appspot.com').read().split(' ')[0].split('-',1)[1]
month = int(date.split('-')[0])
day = int(date.split('-')[1])
except:
month = datetime.date.today().month
day = datetime.date.today().day
print(month)
print(day)
def __init__(self,*args,**kwargs):
super(StoreScroll,self).__init__(*args,**kwargs)
Clock.schedule_interval(self.resize,1/10)
def start(self):
textures = listdir('assets/balls')
textures.sort()
for _ in range(10):
for item in textures:
if item.endswith('.meta'):
print(item)
textures.remove(item)
textures.reverse()
print(textures)
for tex in textures:
if tex[0] != '_' or 'assets/balls/' + tex in store['ball']['unlocked']:
b = StoreButtons('assets/balls/' + tex,size_hint=(None,None))
if 'assets/balls/' + tex in store['ball']['unlocked']:
b.lock = 'assets/store/unlock.png'
b.locked = False
else:
tier = [line for line in open('assets/balls/' + tex + '.meta','r') if line.startswith('tier=')]
print(tier)
tier = tier[0].strip()
print(tier)
tier = tier.split('=')
print(tier)
tier = int(tier[1])
b.lock = ['assets/store/unlock.png','assets/store/150.png','assets/store/200.png','assets/store/300.png','assets/store/400.png'][tier]
b.tier = [0,150,200,300,400][tier]
self.add_widget(b)
else: # if the ball is limited edition and not unlocked yet
days = range(1,32)
months = range(1,13)
meta = open('assets/balls/' + tex + '.meta','r')
for line in meta:
if line.startswith('month='):
l = line.split('=',1)[1]
l = l.rstrip()
months = l.split(',')
months = map(int,months)
print(months)
elif line.startswith('day='):
l = line.split('=',1)[1]
l = l.rstrip()
days = l.split(',')
days = map(int,days)
print(days)
if self.day in days and self.month in months:
b = StoreButtons('assets/balls/' + tex,size_hint=(None,None))
b.lock = 'assets/store/400.png'
b.tier = 400
self.add_widget(b)
for c in self.children:
if c.tex == check_store['ball']['active']:
c.lock = 'assets/store/selected.png'
self.active = c
def resize(self,t):
if not self.touching:
mi,ma = self.get_min_max()
if ma.right < self.width - self.width * 1 / 25:
self.offset_x += sqrt(self.width - ma.right)
elif self.offset_x > 0:
self.offset_x -= sqrt(mi.right)
xpos = self.width * 1 / 25
ypos = [0,self.height * 1 / 5 + self.width * 1 / 25,0]
yselector = 1
for c in self.children:
c.height = self.height / 5
c.width = self.height / 5
c.pos = xpos + self.offset_x, ypos[yselector] + c.width * 1 / 5
yselector *= -1
if yselector > -1:
xpos += c.width * 6 / 5
if -c.width < c.x < self.width:
c.opacity = 1
else:
c.opacity = 0
blip.m.store.coincounter.text = 'COINS: ' + str(store['coins']['value'])
if time() - self.t < 0.2:
blip.m.store.coincounter.color = 1,0,0,1
else:
blip.m.store.coincounter.color = 1,1,1,1
def invalid(self):
self.t = time()
def get_min_max(self):
mi = self.children[0]
ma = self.children[0]
for c in self.children:
if c.x < mi.x:
mi = c
elif c.x > ma.x:
ma = c
return mi,ma
def get_button(self,x,y):
for c in self.children:
if c.x < x < c.right and c.y < y < c.top:
return c
def on_touch_down(self,touch):
self.initial_touch = touch.x,touch.y
self.touched = touch.x,touch.y
self.touching = True
self.touch_time = time()
def on_touch_move(self,touch):
self.offset_x += touch.x - self.touched[0]
self.touched = touch.x,touch.y
def on_touch_up(self,touch):
self.touching = False
dx = abs(touch.x - self.initial_touch[0])
dy = abs(touch.y - self.initial_touch[1])
d = dx + dy
if time() - self.touch_time < 1.5 and d < self.width / 100:
try:
b = self.get_button(touch.x,touch.y)
if not b.locked:
self.active.lock = 'assets/store/unlock.png'
self.active = b
b.purchase()
except AttributeError:
pass
class StoreButtons(Widget):
tex = StringProperty('assets/balls/a.png')
lock = StringProperty('assets/store/200.png')
locked = True
tier = 200
def __init__(self,texture,*args,**kwargs):
super(StoreButtons,self).__init__(*args,**kwargs)
self.tex = texture
def purchase(self):
if self.locked:
coins = store['coins']['value']
if coins >= self.tier:
coins -= self.tier
check_store.put('coins',value=coins)
store.put('coins',value=coins)
self.locked = False
self.lock = 'assets/store/unlock.png'
s = store['ball']['unlocked']
s.append(self.tex)
check_store.put('ball',active=check_store['ball']['active'],unlocked=s)
store.put('ball',active=store['ball']['active'],unlocked=s)
else:
blip.m.store.scroll.invalid()
else:
blip.m.game.ball.tex = self.tex
self.lock = 'assets/store/selected.png'
check_store.put('ball',active=self.tex,unlocked=check_store['ball']['unlocked'])
store.put('ball',active=self.tex,unlocked=store['ball']['unlocked'])
blip.run()