Skip to content

Commit

Permalink
part 06 sound and colors
Browse files Browse the repository at this point in the history
  • Loading branch information
cbscribe committed May 4, 2019
1 parent 9b31c6f commit ed6ca2c
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func new_game():
spawn_circle($StartPosition.position)
$HUD.show()
$HUD.show_message("Go!")
if settings.enable_music:
$Music.play()

func spawn_circle(_position=null):
var c = Circle.instance()
Expand All @@ -43,4 +45,6 @@ func _on_Jumper_died():
get_tree().call_group("circles", "implode")
$Screens.game_over()
$HUD.hide()
if settings.enable_music:
$Music.stop()

6 changes: 5 additions & 1 deletion Main.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=5 format=2]

[ext_resource path="res://Main.gd" type="Script" id=1]
[ext_resource path="res://UI/Screens.tscn" type="PackedScene" id=2]
[ext_resource path="res://UI/HUD.tscn" type="PackedScene" id=3]
[ext_resource path="res://assets/audio/Music_Light-Puzzles.ogg" type="AudioStream" id=4]

[node name="Main" type="Node"]
script = ExtResource( 1 )
Expand All @@ -20,4 +21,7 @@ smoothing_speed = 8.0
[node name="Screens" parent="." instance=ExtResource( 2 )]

[node name="HUD" parent="." instance=ExtResource( 3 )]

[node name="Music" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 4 )
[connection signal="start_game" from="Screens" to="." method="new_game"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ A mobile game tutorial for Godot Game Engine.

Here's a preview taken from the prototype:

![](http://kidscancode.org/godot_lessons/img/jump.gif)
![](http://kidscancode.org/godot_recipes/img/jump.gif)

Follow the development here:
[Godot Lessons: Circle Jump](http://kidscancode.org/godot_recipes/games/circle_jump/)
19 changes: 16 additions & 3 deletions UI/Screens.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ extends Node

signal start_game

var sound_buttons = {true: preload("res://assets/images/buttons/audioOn.png"),
false: preload("res://assets/images/buttons/audioOff.png")}
var music_buttons = {true: preload("res://assets/images/buttons/musicOn.png"),
false: preload("res://assets/images/buttons/musicOff.png")}

var current_screen = null

func _ready():
Expand All @@ -11,10 +16,12 @@ func _ready():
func register_buttons():
var buttons = get_tree().get_nodes_in_group("buttons")
for button in buttons:
button.connect("pressed", self, "_on_button_pressed", [button.name])
button.connect("pressed", self, "_on_button_pressed", [button])

func _on_button_pressed(name):
match name:
func _on_button_pressed(button):
if settings.enable_sound:
$Click.play()
match button.name:
"Home":
change_screen($TitleScreen)
"Play":
Expand All @@ -23,6 +30,12 @@ func _on_button_pressed(name):
emit_signal("start_game")
"Settings":
change_screen($SettingsScreen)
"Sound":
settings.enable_sound = !settings.enable_sound
button.texture_normal = sound_buttons[settings.enable_sound]
"Music":
settings.enable_music = !settings.enable_music
button.texture_normal = music_buttons[settings.enable_music]

func change_screen(new_screen):
if current_screen:
Expand Down
6 changes: 5 additions & 1 deletion UI/Screens.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=6 format=2]

[ext_resource path="res://UI/Screens.gd" type="Script" id=1]
[ext_resource path="res://UI/TitleScreen.tscn" type="PackedScene" id=2]
[ext_resource path="res://UI/SettingsScreen.tscn" type="PackedScene" id=3]
[ext_resource path="res://UI/GameOverScreen.tscn" type="PackedScene" id=4]
[ext_resource path="res://assets/audio/menu_click.wav" type="AudioStream" id=5]

[node name="Screens" type="Node"]
script = ExtResource( 1 )
Expand All @@ -13,3 +14,6 @@ script = ExtResource( 1 )
[node name="SettingsScreen" parent="." instance=ExtResource( 3 )]

[node name="GameOverScreen" parent="." instance=ExtResource( 4 )]

[node name="Click" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 5 )
10 changes: 9 additions & 1 deletion objects/Circle.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ func init(_position, _radius=radius, _mode=MODES.LIMITED):
set_mode(_mode)
position = _position
radius = _radius
$Sprite.material = $Sprite.material.duplicate()
$SpriteEffect.material = $Sprite.material
$CollisionShape2D.shape = $CollisionShape2D.shape.duplicate()
$CollisionShape2D.shape.radius = radius
var img_size = $Sprite.texture.get_size().x / 2
Expand All @@ -25,13 +27,17 @@ func init(_position, _radius=radius, _mode=MODES.LIMITED):

func set_mode(_mode):
mode = _mode
var color
match mode:
MODES.STATIC:
$Label.hide()
color = settings.theme["circle_static"]
MODES.LIMITED:
current_orbits = num_orbits
$Label.text = str(current_orbits)
$Label.show()
color = settings.theme["circle_limited"]
$Sprite.material.set_shader_param("color", color)

func _process(delta):
$Pivot.rotation += rotation_speed * delta
Expand All @@ -42,6 +48,8 @@ func _process(delta):
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()
Expand All @@ -64,7 +72,7 @@ func _draw():
if jumper:
var r = ((radius - 10) / num_orbits) * (1 + num_orbits - current_orbits)
draw_circle_arc_poly(Vector2.ZERO, r, orbit_start + PI/2,
$Pivot.rotation + PI/2, Color(1, 0, 0))
$Pivot.rotation + PI/2, settings.theme["circle_fill"])

func draw_circle_arc_poly(center, radius, angle_from, angle_to, color):
var nb_points = 32
Expand Down
6 changes: 5 additions & 1 deletion objects/Circle.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[gd_scene load_steps=10 format=2]
[gd_scene load_steps=11 format=2]

[ext_resource path="res://objects/Circle.gd" type="Script" id=1]
[ext_resource path="res://objects/color.shader" type="Shader" id=2]
[ext_resource path="res://assets/images/circle1_n.png" type="Texture" id=3]
[ext_resource path="res://assets/fonts/Xolonium-Regular.ttf" type="DynamicFontData" id=4]
[ext_resource path="res://assets/audio/89.ogg" type="AudioStream" id=5]

[sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 2 )
Expand Down Expand Up @@ -123,3 +124,6 @@ custom_fonts/font = SubResource( 5 )
text = "1"
align = 1
valign = 1

[node name="Beep" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 5 )
9 changes: 9 additions & 0 deletions objects/Jumper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ var jump_speed = 1000
var target = null
var trail_length = 25

func _ready():
$Sprite.material.set_shader_param("color", settings.theme["player_body"])
$Trail/Points.default_color = settings.theme["player_trail"]


func _unhandled_input(event):
if target and event is InputEventScreenTouch and event.pressed:
jump()
Expand All @@ -18,11 +23,15 @@ func jump():
target.implode()
target = null
velocity = transform.x * jump_speed
if settings.enable_sound:
$Jump.play()

func _on_Jumper_area_entered(area):
target = area
velocity = Vector2.ZERO
emit_signal("captured", area)
if settings.enable_sound:
$Capture.play()

func _physics_process(delta):
if trail.points.size() > trail_length:
Expand Down
12 changes: 10 additions & 2 deletions objects/Jumper.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=8 format=2]

[ext_resource path="res://objects/Jumper.gd" type="Script" id=1]
[ext_resource path="res://objects/color.shader" type="Shader" id=2]
[ext_resource path="res://assets/images/jumper.png" type="Texture" id=3]
[ext_resource path="res://assets/audio/70.ogg" type="AudioStream" id=4]
[ext_resource path="res://assets/audio/88.ogg" type="AudioStream" id=5]

[sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 2 )
Expand Down Expand Up @@ -30,9 +32,15 @@ polygon = PoolVector2Array( 19.9982, 0.0478821, -20.663, -20.0641, -20.8817, 19.
[node name="Points" type="Line2D" parent="Trail"]
z_index = -1
gradient = SubResource( 2 )
texture_mode = 0
texture_mode = 256
joint_mode = 2
begin_cap_mode = 2
end_cap_mode = 2

[node name="Jump" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 4 )

[node name="Capture" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 5 )
[connection signal="area_entered" from="." to="." method="_on_Jumper_area_entered"]
[connection signal="screen_exited" from="VisibilityNotifier2D" to="." method="_on_VisibilityNotifier2D_screen_exited"]
4 changes: 4 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ config/name="circle_jump"
run/main_scene="res://Main.tscn"
config/icon="res://icon.png"

[autoload]

settings="*res://settings.gd"

[display]

window/size/width=480
Expand Down
35 changes: 35 additions & 0 deletions settings.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
extends Node

var enable_sound = true
var enable_music = true

var circles_per_level = 5

var color_schemes = {
"NEON1": {
'background': Color8(0, 0, 0),
'player_body': Color8(203, 255, 0),
'player_trail': Color8(204, 0, 255),
'circle_fill': Color8(255, 0, 110),
'circle_static': Color8(0, 255, 102),
'circle_limited': Color8(204, 0, 255)
},
"NEON2": {
'background': Color8(0, 0, 0),
'player_body': Color8(246, 255, 0),
'player_trail': Color8(255, 255, 255),
'circle_fill': Color8(255, 0, 110),
'circle_static': Color8(151, 255, 48),
'circle_limited': Color8(127, 0, 255)
},
"NEON3": {
'background': Color8(0, 0, 0),
'player_body': Color8(255, 0, 187),
'player_trail': Color8(255, 148, 0),
'circle_fill': Color8(255, 148, 0),
'circle_static': Color8(170, 255, 0),
'circle_limited': Color8(204, 0, 255)
}
}

var theme = color_schemes["NEON1"]

0 comments on commit ed6ca2c

Please sign in to comment.