Skip to content

Commit b7eb92d

Browse files
committed
part 11 - ads
1 parent 00a2f73 commit b7eb92d

File tree

8 files changed

+111
-12
lines changed

8 files changed

+111
-12
lines changed

Main.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func _ready():
1414
$HUD.hide()
1515

1616
func new_game():
17+
settings.hide_ad_banner()
1718
self.score = 0
1819
level = 1
1920
$HUD.update_score(score)
@@ -60,6 +61,7 @@ func _on_Jumper_died():
6061
$HUD.hide()
6162
if settings.enable_music:
6263
$Music.stop()
64+
settings.show_ad_interstitial()
6365

6466
func load_score():
6567
var f = File.new()

UI/BaseScreen.tscn

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,18 @@ margin_bottom = 228.0
3737
custom_constants/separation = 75
3838
alignment = 1
3939

40-
[node name="Buttons2" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
40+
[node name="Buttons3" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
4141
margin_top = 378.0
4242
margin_right = 440.0
4343
margin_bottom = 378.0
4444
custom_constants/separation = 75
4545
alignment = 1
4646

47+
[node name="Buttons2" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
48+
margin_top = 528.0
49+
margin_right = 440.0
50+
margin_bottom = 528.0
51+
custom_constants/separation = 75
52+
alignment = 1
53+
4754
[node name="Tween" type="Tween" parent="."]

UI/Screens.gd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ func _on_button_pressed(button):
2222
if settings.enable_sound:
2323
$Click.play()
2424
match button.name:
25+
"Ads":
26+
settings.enable_ads = !settings.enable_ads
27+
if settings.enable_ads:
28+
button.text = "Disable Ads"
29+
else:
30+
button.text = "Enable Ads"
2531
"Home":
2632
change_screen($TitleScreen)
2733
"Play":

UI/SettingsScreen.tscn

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
[gd_scene load_steps=5 format=2]
1+
[gd_scene load_steps=12 format=2]
22

33
[ext_resource path="res://UI/BaseScreen.tscn" type="PackedScene" id=1]
44
[ext_resource path="res://assets/images/buttons/audioOn.png" type="Texture" id=2]
55
[ext_resource path="res://assets/images/buttons/musicOn.png" type="Texture" id=3]
6-
[ext_resource path="res://assets/images/buttons/return.png" type="Texture" id=4]
6+
[ext_resource path="res://assets/fonts/Xolonium-Regular.ttf" type="DynamicFontData" id=4]
7+
[ext_resource path="res://assets/images/buttons/return.png" type="Texture" id=5]
78

8-
[node name="SettingsScreen" instance=ExtResource( 1 )]
9+
[sub_resource type="StyleBoxEmpty" id=1]
10+
11+
[sub_resource type="StyleBoxEmpty" id=2]
12+
13+
[sub_resource type="StyleBoxEmpty" id=3]
14+
15+
[sub_resource type="StyleBoxEmpty" id=4]
16+
17+
[sub_resource type="StyleBoxEmpty" id=5]
18+
19+
[sub_resource type="DynamicFont" id=6]
20+
size = 48
21+
font_data = ExtResource( 4 )
22+
23+
[node name="SettingsScreen" index="0" instance=ExtResource( 1 )]
924

1025
[node name="Label" parent="MarginContainer/VBoxContainer" index="0"]
1126
text = "Settings"
@@ -29,14 +44,32 @@ margin_right = 357.0
2944
margin_bottom = 100.0
3045
texture_normal = ExtResource( 3 )
3146

32-
[node name="Buttons2" parent="MarginContainer/VBoxContainer" index="2"]
47+
[node name="Buttons3" parent="MarginContainer/VBoxContainer" index="2"]
3348
margin_top = 478.0
34-
margin_bottom = 578.0
49+
margin_bottom = 536.0
50+
51+
[node name="Ads" type="Button" parent="MarginContainer/VBoxContainer/Buttons3" index="0" groups=[
52+
"buttons",
53+
]]
54+
margin_left = 72.0
55+
margin_right = 368.0
56+
margin_bottom = 58.0
57+
custom_styles/hover = SubResource( 1 )
58+
custom_styles/pressed = SubResource( 2 )
59+
custom_styles/focus = SubResource( 3 )
60+
custom_styles/disabled = SubResource( 4 )
61+
custom_styles/normal = SubResource( 5 )
62+
custom_fonts/font = SubResource( 6 )
63+
text = "Disable Ads"
64+
65+
[node name="Buttons2" parent="MarginContainer/VBoxContainer" index="3"]
66+
margin_top = 686.0
67+
margin_bottom = 786.0
3568

3669
[node name="Home" type="TextureButton" parent="MarginContainer/VBoxContainer/Buttons2" index="0" groups=[
3770
"buttons",
3871
]]
3972
margin_left = 170.0
4073
margin_right = 270.0
4174
margin_bottom = 100.0
42-
texture_normal = ExtResource( 4 )
75+
texture_normal = ExtResource( 5 )

export_presets.cfg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ custom_features=""
77
export_filter="all_resources"
88
include_filter=""
99
exclude_filter=""
10-
export_path="/Users/chris/Documents/godot3_projects/export/circle_jump_10apk.apk"
10+
export_path="/Users/chris/Documents/godot3_projects/export/circle_jump_10.apk"
1111
patch_list=PoolStringArray( )
1212
script_export_mode=1
1313
script_encryption_key=""
@@ -16,8 +16,8 @@ script_encryption_key=""
1616

1717
graphics/32_bits_framebuffer=true
1818
one_click_deploy/clear_previous_install=true
19-
custom_package/debug=""
20-
custom_package/release=""
19+
custom_package/debug="/Users/chris/Downloads/godot_3.1.1-android-admob-share-vibration/android_debug.apk"
20+
custom_package/release="/Users/chris/Downloads/godot_3.1.1-android-admob-share-vibration/android_release.apk"
2121
command_line/extra_args=""
2222
version/code=1
2323
version/name="1.0"
@@ -39,7 +39,7 @@ launcher_icons/mdpi_48x48=""
3939
keystore/debug="/Users/chris/.android/debug.keystore"
4040
keystore/debug_user="androiddebugkey"
4141
keystore/debug_password="android"
42-
keystore/release=""
42+
keystore/release="/Users/chris/.android/org.kidscancode.keystore"
4343
keystore/release_user=""
4444
keystore/release_password=""
4545
apk_expansion/enable=false

objects/Circle.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func capture(target):
8181

8282
func _draw():
8383
if jumper:
84-
var r = ((radius - 50) / num_orbits) * (1 + num_orbits - current_orbits)
84+
var r = ((radius * 0.5) / num_orbits) * (1 + num_orbits - current_orbits)
8585
draw_circle_arc_poly(Vector2.ZERO, r, orbit_start + PI/2,
8686
$Pivot.rotation + PI/2, settings.theme["circle_fill"])
8787

project.godot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ _global_script_class_icons={
1313

1414
}
1515

16+
[android]
17+
18+
modules="org/godotengine/godot/GodotAdMob"
19+
1620
[application]
1721

1822
config/name="circle_jump"

settings.gd

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,57 @@ static func rand_weighted(weights):
4545
return i
4646
num -= weights[i]
4747

48+
var admob = null
49+
var real_ads = false
50+
var banner_top = false
51+
var ad_banner_id = ""
52+
var ad_interstitial_id = ""
53+
var enable_ads = true setget set_enable_ads
54+
55+
func _ready():
56+
if Engine.has_singleton("AdMob"):
57+
admob = Engine.get_singleton("AdMob")
58+
admob.init(real_ads, get_instance_id())
59+
admob.loadBanner(ad_banner_id, banner_top)
60+
admob.loadInterstitial(ad_interstitial_id)
61+
62+
func show_ad_banner():
63+
if admob and enable_ads:
64+
admob.showBanner()
65+
66+
func hide_ad_banner():
67+
if admob:
68+
admob.hideBanner()
69+
70+
func show_ad_interstitial():
71+
if admob and enable_ads:
72+
admob.showInterstitial()
73+
74+
func _on_interstitial_close():
75+
if admob and enable_ads:
76+
show_ad_banner()
77+
78+
func set_enable_ads(value):
79+
enable_ads = value
80+
if enable_ads:
81+
show_ad_banner()
82+
if !enable_ads:
83+
hide_ad_banner()
84+
85+
86+
4887

4988

5089

5190

5291

92+
93+
94+
95+
96+
97+
98+
99+
53100

54101

0 commit comments

Comments
 (0)