From b7eb92da6c002c2ea82d8e951db9cf60a3ab4012 Mon Sep 17 00:00:00 2001 From: Chris Bradfield Date: Wed, 12 Jun 2019 14:32:51 -0700 Subject: [PATCH] part 11 - ads --- Main.gd | 2 ++ UI/BaseScreen.tscn | 9 +++++++- UI/Screens.gd | 6 ++++++ UI/SettingsScreen.tscn | 45 ++++++++++++++++++++++++++++++++++------ export_presets.cfg | 8 +++---- objects/Circle.gd | 2 +- project.godot | 4 ++++ settings.gd | 47 ++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 111 insertions(+), 12 deletions(-) diff --git a/Main.gd b/Main.gd index cf29179..42c2524 100644 --- a/Main.gd +++ b/Main.gd @@ -14,6 +14,7 @@ func _ready(): $HUD.hide() func new_game(): + settings.hide_ad_banner() self.score = 0 level = 1 $HUD.update_score(score) @@ -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() diff --git a/UI/BaseScreen.tscn b/UI/BaseScreen.tscn index 7dcdc7e..eab2960 100644 --- a/UI/BaseScreen.tscn +++ b/UI/BaseScreen.tscn @@ -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="."] diff --git a/UI/Screens.gd b/UI/Screens.gd index 7a46f1b..ebc341c 100644 --- a/UI/Screens.gd +++ b/UI/Screens.gd @@ -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": diff --git a/UI/SettingsScreen.tscn b/UI/SettingsScreen.tscn index 06042bc..d7399a0 100644 --- a/UI/SettingsScreen.tscn +++ b/UI/SettingsScreen.tscn @@ -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" @@ -29,9 +44,27 @@ 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", @@ -39,4 +72,4 @@ margin_bottom = 578.0 margin_left = 170.0 margin_right = 270.0 margin_bottom = 100.0 -texture_normal = ExtResource( 4 ) +texture_normal = ExtResource( 5 ) diff --git a/export_presets.cfg b/export_presets.cfg index 17fdd85..03e33f3 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -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="" @@ -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" @@ -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 diff --git a/objects/Circle.gd b/objects/Circle.gd index 2361bfa..9bac644 100644 --- a/objects/Circle.gd +++ b/objects/Circle.gd @@ -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"]) diff --git a/project.godot b/project.godot index 6fdcee0..3f72dc3 100644 --- a/project.godot +++ b/project.godot @@ -13,6 +13,10 @@ _global_script_class_icons={ } +[android] + +modules="org/godotengine/godot/GodotAdMob" + [application] config/name="circle_jump" diff --git a/settings.gd b/settings.gd index 7a4acb8..991c67f 100644 --- a/settings.gd +++ b/settings.gd @@ -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() + + + + + + + + + + + \ No newline at end of file