Skip to content

Commit

Permalink
part 13 - bonus multiplier
Browse files Browse the repository at this point in the history
  • Loading branch information
cbscribe committed Jun 20, 2019
1 parent a73f9d3 commit d94f6bd
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 29 deletions.
26 changes: 22 additions & 4 deletions Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ var Jumper = preload("res://objects/Jumper.tscn")
var player
var score = 0 setget set_score
var highscore = 0
var new_highscore = false
var level = 0
var bonus = 0 setget set_bonus

func _ready():
randomize()
load_score()
$HUD.hide()
$Background/ColorRect.color = settings.theme["background"]

func new_game():
new_highscore = false
settings.hide_ad_banner()
self.score = 0
self.bonus = 0
level = 1
$HUD.update_score(score)
$Camera2D.position = $StartPosition.position
Expand All @@ -28,6 +33,7 @@ func new_game():
$HUD.show()
$HUD.show_message("Go!")
if settings.enable_music:
$Music.volume_db = 0
$Music.play()

func spawn_circle(_position=null):
Expand All @@ -37,16 +43,21 @@ func spawn_circle(_position=null):
var y = rand_range(-500, -400)
_position = player.target.position + Vector2(x, y)
add_child(c)
c.connect("full_orbit", self, "set_bonus", [1])
c.init(_position, level)

func _on_Jumper_captured(object):
$Camera2D.position = object.position
object.capture(player)
call_deferred("spawn_circle")
self.score += 1
self.score += 1 * bonus
self.bonus += 1

func set_score(value):
score = value
if score > highscore and !new_highscore:
$HUD.show_message("New Record!")
new_highscore = true
$HUD.update_score(score)
if score > 0 and score % settings.circles_per_level == 0:
level += 1
Expand All @@ -60,7 +71,7 @@ func _on_Jumper_died():
$Screens.game_over(score, highscore)
$HUD.hide()
if settings.enable_music:
$Music.stop()
fade_music()
settings.show_ad_interstitial()

func load_score():
Expand All @@ -76,6 +87,13 @@ func save_score():
f.store_var(highscore)
f.close()

func fade_music():
$MusicFade.interpolate_property($Music, "volume_db",
0, -50, 1.0, Tween.TRANS_SINE, Tween.EASE_IN)
$MusicFade.start()
yield($MusicFade, "tween_all_completed")
$Music.stop()



func set_bonus(value):
bonus = value
$HUD.update_bonus(bonus)
2 changes: 2 additions & 0 deletions Main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ smoothing_speed = 8.0
stream = ExtResource( 4 )

[node name="Background" parent="." instance=ExtResource( 5 )]

[node name="MusicFade" type="Tween" parent="."]
[connection signal="start_game" from="Screens" to="." method="new_game"]
2 changes: 1 addition & 1 deletion UI/Background.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ layer = -1
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
color = Color( 0, 0, 0, 1 )
color = Color( 0.3, 0.33, 0.37, 1 )

[node name="CPUParticles2D" type="CPUParticles2D" parent="."]
modulate = Color( 1, 1, 1, 0.396078 )
Expand Down
14 changes: 7 additions & 7 deletions UI/BaseScreen.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ margin_left = 20.0
margin_top = 20.0
margin_right = 460.0
margin_bottom = 834.0
custom_constants/separation = 150
custom_constants/separation = 125

[node name="Label" type="Label" parent="MarginContainer/VBoxContainer"]
margin_right = 440.0
Expand All @@ -31,23 +31,23 @@ text = "Title"
align = 1

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

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

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

Expand Down
10 changes: 9 additions & 1 deletion UI/HUD.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ func show_message(text):

func hide():
$ScoreBox.hide()
$BonusBox.hide()

func show():
$ScoreBox.show()
$BonusBox.show()

func update_score(value):
$ScoreBox/HBoxContainer/Score.text = str(value)
$ScoreBox/HBoxContainer/Score.text = str(value)

func update_bonus(value):
$BonusBox/Bonus.text = str(value) + "x"
if value > 1:
$AnimationPlayer.play("bonus")

54 changes: 53 additions & 1 deletion UI/HUD.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=10 format=2]

[ext_resource path="res://UI/HUD.gd" type="Script" id=1]
[ext_resource path="res://assets/fonts/Xolonium-Regular.ttf" type="DynamicFontData" id=2]
Expand All @@ -9,10 +9,43 @@ size = 32
extra_spacing_top = 10
font_data = ExtResource( 2 )

[sub_resource type="DynamicFont" id=5]
size = 48
font_data = ExtResource( 2 )

[sub_resource type="DynamicFont" id=2]
size = 69
font_data = ExtResource( 2 )

[sub_resource type="Animation" id=6]
resource_name = "bonus"
length = 0.15
step = 0.01
tracks/0/type = "value"
tracks/0/path = NodePath("BonusBox/Bonus:rect_scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.07, 0.15 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 0,
"values": [ Vector2( 1, 1 ), Vector2( 1.25, 1.25 ), Vector2( 1, 1 ) ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("BonusBox/Bonus:custom_colors/font_color")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0, 0.07, 0.15 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ), Color( 1, 0, 0, 1 ), Color( 1, 1, 1, 1 ) ]
}

[sub_resource type="Animation" id=3]
resource_name = "init"
length = 0.1
Expand Down Expand Up @@ -119,6 +152,24 @@ size_flags_vertical = 5
custom_fonts/font = ExtResource( 3 )
text = "100"

[node name="BonusBox" type="MarginContainer" parent="."]
anchor_right = 1.0
margin_bottom = 40.0
custom_constants/margin_right = 20
custom_constants/margin_top = 20
custom_constants/margin_left = 20
custom_constants/margin_bottom = 20

[node name="Bonus" type="Label" parent="BonusBox"]
margin_left = 20.0
margin_top = 20.0
margin_right = 460.0
margin_bottom = 78.0
size_flags_vertical = 5
custom_fonts/font = SubResource( 5 )
custom_colors/font_color = Color( 1, 1, 1, 1 )
text = "1x"

[node name="Message" type="Label" parent="."]
anchor_top = 0.5
anchor_right = 1.0
Expand All @@ -134,5 +185,6 @@ clip_text = true

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
autoplay = "init"
anims/bonus = SubResource( 6 )
anims/init = SubResource( 3 )
anims/show_message = SubResource( 4 )
Binary file added logo1_64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions logo1_64.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/logo1_64.png-8fba6b5cdfc29fca6cc5d8faf01e4fe9.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://logo1_64.png"
dest_files=[ "res://.import/logo1_64.png-8fba6b5cdfc29fca6cc5d8faf01e4fe9.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Binary file added logo2_64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions logo2_64.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/logo2_64.png-480a88e14b461ba68e5087b7b3af8a34.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://logo2_64.png"
dest_files=[ "res://.import/logo2_64.png-480a88e14b461ba68e5087b7b3af8a34.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
31 changes: 19 additions & 12 deletions objects/Circle.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
extends Area2D

signal full_orbit

onready var orbit_position = $Pivot/OrbitPosition
onready var move_tween = $MoveTween

Expand Down Expand Up @@ -44,44 +46,49 @@ func set_mode(_mode):
$Label.hide()
color = settings.theme["circle_static"]
MODES.LIMITED:
current_orbits = num_orbits
$Label.text = str(current_orbits)
$Label.text = str(num_orbits)
$Label.show()
color = settings.theme["circle_limited"]
$Sprite.material.set_shader_param("color", color)

func _process(delta):
$Pivot.rotation += rotation_speed * delta
if mode == MODES.LIMITED and jumper:
if jumper:
check_orbits()
update()

func check_orbits():
if abs($Pivot.rotation - orbit_start) > 2 * PI:
current_orbits -= 1
if settings.enable_sound:
$Beep.play()
$Label.text = str(current_orbits)
if current_orbits <= 0:
jumper.die()
jumper = null
implode()
current_orbits += 1
emit_signal("full_orbit")
if mode == MODES.LIMITED:
if settings.enable_sound:
$Beep.play()
$Label.text = str(num_orbits - current_orbits)
if current_orbits <= 0:
jumper.die()
jumper = null
implode()
orbit_start = $Pivot.rotation

func implode():
jumper = null
$AnimationPlayer.play("implode")
yield($AnimationPlayer, "animation_finished")
queue_free()

func capture(target):
current_orbits = 0
jumper = target
$AnimationPlayer.play("capture")
$Pivot.rotation = (jumper.position - position).angle()
orbit_start = $Pivot.rotation

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

Expand Down
2 changes: 1 addition & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ modules="org/godotengine/godot/GodotAdMob"

config/name="circle_jump"
run/main_scene="res://Main.tscn"
config/icon="res://icon.png"
config/icon="res://logo1_64.png"

[autoload]

Expand Down
Loading

0 comments on commit d94f6bd

Please sign in to comment.