added main menu and mm script

added main menu into game scene
added input action for pausing
commented on some sections of wiper.gd
master
Zac 4 years ago
parent 1756b73824
commit 3758447ce6

@ -1,8 +1,9 @@
[gd_scene load_steps=7 format=2]
[gd_scene load_steps=8 format=2]
[ext_resource path="res://_scenes/car.tscn" type="PackedScene" id=1]
[ext_resource path="res://audio/Rain_Heavy_Quiet_Interior.ogg" type="AudioStream" id=2]
[ext_resource path="res://audio/Driving_in_Car_Interior.ogg" type="AudioStream" id=3]
[ext_resource path="res://_scenes/MainMenu.tscn" type="PackedScene" id=1]
[ext_resource path="res://_scenes/car.tscn" type="PackedScene" id=2]
[ext_resource path="res://audio/Rain_Heavy_Quiet_Interior.ogg" type="AudioStream" id=3]
[ext_resource path="res://audio/Driving_in_Car_Interior.ogg" type="AudioStream" id=4]
[sub_resource type="Curve" id=1]
@ -60,7 +61,16 @@ _sections_unfolded = [ "Color", "Emission Shape" ]
[node name="Game" type="Node2D" index="0"]
[node name="outside" type="ColorRect" parent="." index="0"]
[node name="Menu" parent="." index="0" instance=ExtResource( 1 )]
scale = Vector2( 1, 1 )
transform = Transform2D( 1, 0, 0, 1, 0, 0 )
[node name="background" type="Node2D" parent="." index="1"]
editor/display_folded = true
[node name="outside" type="ColorRect" parent="background" index="0"]
show_behind_parent = true
anchor_left = 0.0
@ -78,7 +88,7 @@ size_flags_vertical = 1
color = Color( 0, 0, 0, 0.547608 )
_sections_unfolded = [ "Visibility" ]
[node name="rain_particles" type="Particles2D" parent="." index="1"]
[node name="rain_particles" type="Particles2D" parent="background" index="1"]
show_behind_parent = true
position = Vector2( 333.076, -157.333 )
@ -103,13 +113,11 @@ normal_map = null
h_frames = 1
v_frames = 1
[node name="car" parent="." index="2" instance=ExtResource( 1 )]
scale = Vector2( 1, 1 )
[node name="car" parent="." index="2" instance=ExtResource( 2 )]
[node name="RainSFX" type="AudioStreamPlayer" parent="." index="3"]
stream = ExtResource( 2 )
stream = ExtResource( 3 )
volume_db = 0.0
pitch_scale = 1.0
autoplay = true
@ -118,7 +126,7 @@ bus = "Rain"
[node name="CarSFX" type="AudioStreamPlayer" parent="." index="4"]
stream = ExtResource( 3 )
stream = ExtResource( 4 )
volume_db = 0.0
pitch_scale = 1.0
autoplay = true

@ -0,0 +1,199 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://scripts/MainMenu.gd" type="Script" id=1]
[ext_resource path="res://textures/white_pixel.png" type="Texture" id=2]
[sub_resource type="Shader" id=1]
code = "shader_type canvas_item;
uniform float blur : hint_range(0, 5);
void fragment() {
COLOR = textureLod(SCREEN_TEXTURE, SCREEN_UV, blur);
}"
[sub_resource type="ShaderMaterial" id=2]
render_priority = 0
shader = SubResource( 1 )
shader_param/blur = 1.986
_sections_unfolded = [ "shader_param" ]
[node name="Menu" type="CanvasLayer"]
pause_mode = 2
layer = 1
offset = Vector2( 0, 0 )
rotation = 0.0
scale = Vector2( 1, 1 )
transform = Transform2D( 1, 0, 0, 1, 0, 0 )
script = ExtResource( 1 )
[node name="Tween" type="Tween" parent="." index="0"]
repeat = false
playback_process_mode = 1
playback_speed = 1.0
playback/active = false
playback/repeat = false
playback/speed = 1.0
[node name="blur" type="TextureRect" parent="." index="1"]
show_behind_parent = true
material = SubResource( 2 )
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 1.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
texture = ExtResource( 2 )
expand = true
stretch_mode = 0
_sections_unfolded = [ "Material" ]
[node name="MenuElements" type="Container" parent="." index="2"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 1.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
[node name="Label" type="Label" parent="MenuElements" index="0"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -190.0
margin_top = -212.0
margin_right = -150.0
margin_bottom = -198.0
rect_scale = Vector2( 10, 10 )
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
text = "Wiper"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Rect" ]
[node name="buttons" type="VBoxContainer" parent="MenuElements" index="1"]
editor/display_folded = true
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 288.0
margin_top = 280.0
margin_right = 763.0
margin_bottom = 462.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 1
_sections_unfolded = [ "Size Flags" ]
__meta__ = {
"_edit_group_": true
}
[node name="StartBtn" type="Button" parent="MenuElements/buttons" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 475.0
margin_bottom = 58.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 3
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
group = null
text = "Start"
flat = false
align = 1
[node name="AutoBtn" type="Button" parent="MenuElements/buttons" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 62.0
margin_right = 475.0
margin_bottom = 120.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 3
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
group = null
text = "Chill Mode"
flat = false
align = 1
[node name="QuitBtn" type="Button" parent="MenuElements/buttons" index="2"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 124.0
margin_right = 475.0
margin_bottom = 182.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 3
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
group = null
text = "Quit"
flat = false
align = 1
[connection signal="tween_completed" from="Tween" to="." method="_on_tween_completed"]
[connection signal="pressed" from="MenuElements/buttons/StartBtn" to="." method="_on_StartBtn_pressed"]
[connection signal="pressed" from="MenuElements/buttons/AutoBtn" to="." method="_on_AutoBtn_pressed"]
[connection signal="pressed" from="MenuElements/buttons/QuitBtn" to="." method="_on_QuitBtn_pressed"]

@ -129,6 +129,7 @@ _sections_unfolded = [ "Transform" ]
__meta__ = {
"_edit_group_": true
}
auto_play = false
dead_zones = 200
[node name="StaticBody2D" type="StaticBody2D" parent="inside/wipers/wiper" index="0"]
@ -187,6 +188,7 @@ _sections_unfolded = [ "Transform" ]
__meta__ = {
"_edit_group_": true
}
auto_play = false
dead_zones = 200
[node name="StaticBody2D" type="StaticBody2D" parent="inside/wipers/wiper2" index="0"]

@ -11,12 +11,15 @@ config_version=3
[application]
config/name="Windshield"
run/main_scene="res://_scenes/Game.tscn"
config/icon="res://icon.png"
[input]
wipe=[ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
]
pause=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777217,"unicode":0,"echo":false,"script":null)
]
[layer_names]

@ -0,0 +1,95 @@
extends CanvasLayer
#-------------------------------
# node refs
onready var _tweener = $Tween
#-------------------------------
# constants
const _OffScreen = Vector2(0, -600)
const _OnScreen = Vector2(0, 0)
#-------------------------------
# vars
var _autoplay_mode
var _started = false
#-------------------------------
# signals
signal started
#-------------------------------
# overloaded functions
func _ready():
connect("started", self, "_on_game_start")
#-------------------------------
# functions
# toggles the paused state of the game
func toggle_pause():
if is_paused():
_unpause()
_tween_screen_off()
else:
_pause()
_tween_screen_on()
# pauses the game
func _pause():
get_tree().set_paused(true)
# unpauses the game
func _unpause():
get_tree().set_paused(false)
# returns the current paused state
func is_paused():
return get_tree().paused
# callback to start the game
# TODO: make this better....
# like actually have a check inside of
# some main game function to have it start playing
func _on_game_start():
GameState.AutoPlay = _autoplay_mode
_started = true
# callback for emitting the signal that the game has started
func _on_tween_completed(object, key):
if not _started:
emit_signal("started")
# handles the start button being pressed
func _on_StartBtn_pressed():
_autoplay_mode = false
_tween_screen_off()
# handles the 'auto' button being pressed
func _on_AutoBtn_pressed():
_autoplay_mode = true
_tween_screen_off()
# handles the quit button being pressed
func _on_QuitBtn_pressed():
get_tree().quit()
# helper func to tween the menu off the screen
func _tween_screen_off():
_tweener.interpolate_property(self, "offset", offset, _OffScreen,
3, Tween.TRANS_QUART, Tween.EASE_IN_OUT)
_tweener.start()
# helper func to tween the menu on to the screen
func _tween_screen_on():
_tweener.interpolate_property(self, "offset", offset, _OnScreen,
3, Tween.TRANS_QUART, Tween.EASE_IN_OUT)
_tweener.start()

@ -3,7 +3,6 @@ extends Node2D
#-------------------------------
# exports
export var auto_play = false
export var dead_zones = 200
#-------------------------------
@ -32,6 +31,7 @@ var _sounds = {
func _ready():
_win_size.x -= dead_zones
# dynamically create our timer object
_return_timer = Timer.new()
_return_timer.set_one_shot(true)
_return_timer.set_wait_time(2)
@ -62,11 +62,17 @@ func _process(delta):
if _last_mouse_pos != 0:
_return_timer.start()
# if the last mouse position was halfway and we're going up
# and we HAVENT played the sound yet, go ahead and play the sfx
if _last_mouse_pos >= 0.5 and \
_wiping and \
not _played_sound:
_play_wiper_sfx("up")
_played_sound = true
# if the position is under halfway and we're wiping or automatically
# returning the blade and we HAVE played the sound already then we
# play the down sfx
elif _last_mouse_pos <= 0.5 and \
(_returning or _wiping) and \
_played_sound:
@ -85,10 +91,10 @@ func _physics_process(delta):
# if the wiper blades are returning to base position
if _returning:
_last_mouse_pos = max(0, _last_mouse_pos - 0.0125)
set_rotation_degrees(lerp(_limits[0],
_limits[1],
_last_mouse_pos))
_last_mouse_pos = max(0, _last_mouse_pos - 0.0125)
# if we've hit 0 then we've fully returned
if _last_mouse_pos == 0:
@ -107,8 +113,7 @@ func _get_window_coverage():
func _return_timer_timeout():
_returning = true
# plays the wiper sound effects for specified direction
func _play_wiper_sfx(dir):
_sfx_player.set_stream(_sounds[dir])
_sfx_player.play()
Loading…
Cancel
Save