-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAdManager.py
More file actions
44 lines (40 loc) · 1.56 KB
/
AdManager.py
File metadata and controls
44 lines (40 loc) · 1.56 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
import Android.simpleam as simpleam
import pygame as pg
import Settings
class AdManager():
def __init__(self):
simpleam.simpleam_init()
self.ad = simpleam.Interstitial(Settings.INTERSTITIAL_ID)
self.banner = simpleam.Banner(Settings.BANNER_ID, "BOTTOM", "BANNER")
self.banner.load_ad()
self.banner.set_visibility(True)
# self.ad = simpleam.Rewarded()
self.timeout = False
self.loaded = False
self.showed = True
def may_show(self):
print(f'AdManager : may_show : timeout : {self.timeout}, ad loaded : {self.ad.is_loaded()}')
if self.timeout and self.ad.is_loaded():
print('AdManager : show')
self.ad.show()
self.timeout = False
self.loaded = False
self.showed = True
def reload(self):
print('AdManager : reloading')
if not self.banner.is_loading() and not self.banner.is_loaded():
self.banner.load_ad()
if self.ad.is_loading():
return
if not self.loaded or not self.ad.is_loaded():
print('AdManager : reload ad')
self.ad.load_ad()
self.loaded = True
if self.showed:
print('AdManager : reset timer')
self.showed = False
pg.time.set_timer(Settings.EVENT_AD, Settings.AD_TIME_MS)
self.timeout = False
def on_timeout(self):
print('AdManager : timeout')
self.timeout = True