Skip to content

Commit

Permalink
part 11 - ads
Browse files Browse the repository at this point in the history
  • Loading branch information
cbscribe committed Jun 12, 2019
1 parent 00a2f73 commit b7eb92d
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func _ready():
$HUD.hide()

func new_game():
settings.hide_ad_banner()
self.score = 0
level = 1
$HUD.update_score(score)
Expand Down Expand Up @@ -60,6 +61,7 @@ func _on_Jumper_died():
$HUD.hide()
if settings.enable_music:
$Music.stop()
settings.show_ad_interstitial()

func load_score():
var f = File.new()
Expand Down
9 changes: 8 additions & 1 deletion UI/BaseScreen.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@ margin_bottom = 228.0
custom_constants/separation = 75
alignment = 1

[node name="Buttons2" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
[node name="Buttons3" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
margin_top = 378.0
margin_right = 440.0
margin_bottom = 378.0
custom_constants/separation = 75
alignment = 1

[node name="Buttons2" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
margin_top = 528.0
margin_right = 440.0
margin_bottom = 528.0
custom_constants/separation = 75
alignment = 1

[node name="Tween" type="Tween" parent="."]
6 changes: 6 additions & 0 deletions UI/Screens.gd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ func _on_button_pressed(button):
if settings.enable_sound:
$Click.play()
match button.name:
"Ads":
settings.enable_ads = !settings.enable_ads
if settings.enable_ads:
button.text = "Disable Ads"
else:
button.text = "Enable Ads"
"Home":
change_screen($TitleScreen)
"Play":
Expand Down
45 changes: 39 additions & 6 deletions UI/SettingsScreen.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=12 format=2]

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

[node name="SettingsScreen" instance=ExtResource( 1 )]
[sub_resource type="StyleBoxEmpty" id=1]

[sub_resource type="StyleBoxEmpty" id=2]

[sub_resource type="StyleBoxEmpty" id=3]

[sub_resource type="StyleBoxEmpty" id=4]

[sub_resource type="StyleBoxEmpty" id=5]

[sub_resource type="DynamicFont" id=6]
size = 48
font_data = ExtResource( 4 )

[node name="SettingsScreen" index="0" instance=ExtResource( 1 )]

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

[node name="Buttons2" parent="MarginContainer/VBoxContainer" index="2"]
[node name="Buttons3" parent="MarginContainer/VBoxContainer" index="2"]
margin_top = 478.0
margin_bottom = 578.0
margin_bottom = 536.0

[node name="Ads" type="Button" parent="MarginContainer/VBoxContainer/Buttons3" index="0" groups=[
"buttons",
]]
margin_left = 72.0
margin_right = 368.0
margin_bottom = 58.0
custom_styles/hover = SubResource( 1 )
custom_styles/pressed = SubResource( 2 )
custom_styles/focus = SubResource( 3 )
custom_styles/disabled = SubResource( 4 )
custom_styles/normal = SubResource( 5 )
custom_fonts/font = SubResource( 6 )
text = "Disable Ads"

[node name="Buttons2" parent="MarginContainer/VBoxContainer" index="3"]
margin_top = 686.0
margin_bottom = 786.0

[node name="Home" type="TextureButton" parent="MarginContainer/VBoxContainer/Buttons2" index="0" groups=[
"buttons",
]]
margin_left = 170.0
margin_right = 270.0
margin_bottom = 100.0
texture_normal = ExtResource( 4 )
texture_normal = ExtResource( 5 )
8 changes: 4 additions & 4 deletions export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="/Users/chris/Documents/godot3_projects/export/circle_jump_10apk.apk"
export_path="/Users/chris/Documents/godot3_projects/export/circle_jump_10.apk"
patch_list=PoolStringArray( )
script_export_mode=1
script_encryption_key=""
Expand All @@ -16,8 +16,8 @@ script_encryption_key=""

graphics/32_bits_framebuffer=true
one_click_deploy/clear_previous_install=true
custom_package/debug=""
custom_package/release=""
custom_package/debug="/Users/chris/Downloads/godot_3.1.1-android-admob-share-vibration/android_debug.apk"
custom_package/release="/Users/chris/Downloads/godot_3.1.1-android-admob-share-vibration/android_release.apk"
command_line/extra_args=""
version/code=1
version/name="1.0"
Expand All @@ -39,7 +39,7 @@ launcher_icons/mdpi_48x48=""
keystore/debug="/Users/chris/.android/debug.keystore"
keystore/debug_user="androiddebugkey"
keystore/debug_password="android"
keystore/release=""
keystore/release="/Users/chris/.android/org.kidscancode.keystore"
keystore/release_user=""
keystore/release_password=""
apk_expansion/enable=false
Expand Down
2 changes: 1 addition & 1 deletion objects/Circle.gd
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func capture(target):

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

Expand Down
4 changes: 4 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ _global_script_class_icons={

}

[android]

modules="org/godotengine/godot/GodotAdMob"

[application]

config/name="circle_jump"
Expand Down
47 changes: 47 additions & 0 deletions settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,57 @@ static func rand_weighted(weights):
return i
num -= weights[i]

var admob = null
var real_ads = false
var banner_top = false
var ad_banner_id = ""
var ad_interstitial_id = ""
var enable_ads = true setget set_enable_ads

func _ready():
if Engine.has_singleton("AdMob"):
admob = Engine.get_singleton("AdMob")
admob.init(real_ads, get_instance_id())
admob.loadBanner(ad_banner_id, banner_top)
admob.loadInterstitial(ad_interstitial_id)

func show_ad_banner():
if admob and enable_ads:
admob.showBanner()

func hide_ad_banner():
if admob:
admob.hideBanner()

func show_ad_interstitial():
if admob and enable_ads:
admob.showInterstitial()

func _on_interstitial_close():
if admob and enable_ads:
show_ad_banner()

func set_enable_ads(value):
enable_ads = value
if enable_ads:
show_ad_banner()
if !enable_ads:
hide_ad_banner()


















0 comments on commit b7eb92d

Please sign in to comment.