Added fail state and restart loop

This commit is contained in:
Luke Hubmayer-Werner 2020-04-21 00:24:02 +09:30
parent afa41007bf
commit 524eced2db
5 changed files with 267 additions and 10 deletions

6
GUI.gd
View File

@ -26,10 +26,8 @@ func _draw():
draw_texture(cursor, pos1, Color.yellow) draw_texture(cursor, pos1, Color.yellow)
if p1_s > 0: if p1_s > 0:
var mouse_pos = get_viewport().get_mouse_position() var mouse_pos = get_parent().get_cursor_snapped_position()
if $Hotbar.get_rect().has_point(mouse_pos): if mouse_pos.x >= 0: # Not much point checking y too
return
mouse_pos = Vector2(floor(mouse_pos.x/8)*8, floor(mouse_pos.y/8)*8)
draw_texture(cursor_sprites[p1_s], mouse_pos, Color(0.75, 0.75, 0.75, 0.75)) draw_texture(cursor_sprites[p1_s], mouse_pos, Color(0.75, 0.75, 0.75, 0.75))

229
GameoverSplash.tscn Normal file
View File

@ -0,0 +1,229 @@
[gd_scene load_steps=24 format=2]
[ext_resource path="res://FranticFactoryLogo.png" type="Texture" id=1]
[ext_resource path="res://assets/UI_Start_Button.tres" type="DynamicFont" id=2]
[ext_resource path="res://assets/styles/MainSplashButton.tres" type="StyleBox" id=3]
[ext_resource path="res://assets/styles/MainSplashButtonYellow.tres" type="StyleBox" id=4]
[ext_resource path="res://assets/styles/MainSplashButtonBlack.tres" type="StyleBox" id=5]
[ext_resource path="res://MainSplash.gd" type="Script" id=6]
[ext_resource path="res://assets/UI_Youdied.tres" type="DynamicFont" id=7]
[sub_resource type="VisualShaderNodeInput" id=1]
input_name = "color"
[sub_resource type="VisualShaderNodeColorOp" id=2]
output_port_for_preview = 0
operator = 2
[sub_resource type="VisualShaderNodeScalarFunc" id=3]
output_port_for_preview = 0
function = 0
[sub_resource type="VisualShaderNodeScalarOp" id=4]
[sub_resource type="VisualShaderNodeScalarFunc" id=5]
output_port_for_preview = 0
function = 12
[sub_resource type="VisualShaderNodeScalarOp" id=6]
default_input_values = [ 0, 0.0, 1, 0.15708 ]
operator = 2
[sub_resource type="VisualShaderNodeInput" id=7]
input_name = "time"
[sub_resource type="VisualShaderNodeInput" id=8]
input_name = "screen_uv"
[sub_resource type="VisualShaderNodeScalarOp" id=9]
operator = 1
[sub_resource type="VisualShaderNodeVectorDecompose" id=10]
[sub_resource type="VisualShaderNodeScalarOp" id=11]
[sub_resource type="VisualShaderNodeScalarFunc" id=12]
function = 17
[sub_resource type="VisualShaderNodeScalarOp" id=13]
output_port_for_preview = 0
default_input_values = [ 0, 0.0, 1, 0.33 ]
operator = 9
[sub_resource type="VisualShaderNodeScalarOp" id=14]
default_input_values = [ 0, 0.0, 1, 20.0 ]
operator = 2
[sub_resource type="VisualShader" id=15]
code = "shader_type canvas_item;
void vertex() {
// Output:0
}
void fragment() {
// Input:10
vec3 n_out10p0 = COLOR.rgb;
// Input:3
vec3 n_out3p0 = vec3(SCREEN_UV, 0.0);
// VectorDecompose:5
float n_out5p0 = n_out3p0.x;
float n_out5p1 = n_out3p0.y;
float n_out5p2 = n_out3p0.z;
// ScalarOp:4
float n_out4p0 = n_out5p0 - n_out5p1;
// ScalarOp:9
float n_in9p1 = 20.00000;
float n_out9p0 = n_out4p0 * n_in9p1;
// Input:2
float n_out2p0 = TIME;
// ScalarOp:15
float n_in15p1 = 0.15708;
float n_out15p0 = n_out2p0 * n_in15p1;
// ScalarFunc:12
float n_out12p0 = sin(n_out15p0);
// ScalarOp:13
float n_out13p0 = n_out2p0 + n_out12p0;
// ScalarOp:6
float n_out6p0 = n_out9p0 + n_out13p0;
// ScalarFunc:7
float n_out7p0 = fract(n_out6p0);
// ScalarFunc:14
float n_out14p0 = abs(n_out12p0);
// ScalarOp:8
float n_out8p0 = step(n_out7p0, n_out14p0);
// ColorOp:11
vec3 n_out11p0 = min(n_out10p0, vec3(n_out8p0));
// Output:0
COLOR.rgb = n_out11p0;
}
void light() {
// Output:0
}
"
mode = 1
flags/light_only = false
nodes/fragment/0/position = Vector2( 1120, 20 )
nodes/fragment/2/node = SubResource( 7 )
nodes/fragment/2/position = Vector2( 20, 220 )
nodes/fragment/3/node = SubResource( 8 )
nodes/fragment/3/position = Vector2( 0, 60 )
nodes/fragment/4/node = SubResource( 9 )
nodes/fragment/4/position = Vector2( 220, 40 )
nodes/fragment/5/node = SubResource( 10 )
nodes/fragment/5/position = Vector2( 0, 120 )
nodes/fragment/6/node = SubResource( 11 )
nodes/fragment/6/position = Vector2( 500, 160 )
nodes/fragment/7/node = SubResource( 12 )
nodes/fragment/7/position = Vector2( 620, 80 )
nodes/fragment/8/node = SubResource( 13 )
nodes/fragment/8/position = Vector2( 800, 80 )
nodes/fragment/9/node = SubResource( 14 )
nodes/fragment/9/position = Vector2( 380, 40 )
nodes/fragment/10/node = SubResource( 1 )
nodes/fragment/10/position = Vector2( 780, 20 )
nodes/fragment/11/node = SubResource( 2 )
nodes/fragment/11/position = Vector2( 960, 20 )
nodes/fragment/12/node = SubResource( 3 )
nodes/fragment/12/position = Vector2( 180, 300 )
nodes/fragment/13/node = SubResource( 4 )
nodes/fragment/13/position = Vector2( 320, 180 )
nodes/fragment/14/node = SubResource( 5 )
nodes/fragment/14/position = Vector2( 360, 320 )
nodes/fragment/15/node = SubResource( 6 )
nodes/fragment/15/position = Vector2( 20, 280 )
nodes/fragment/connections = PoolIntArray( 5, 0, 4, 0, 5, 1, 4, 1, 6, 0, 7, 0, 7, 0, 8, 0, 4, 0, 9, 0, 10, 0, 11, 0, 8, 0, 11, 1, 11, 0, 0, 0, 3, 0, 5, 0, 2, 0, 13, 0, 9, 0, 6, 0, 13, 0, 6, 1, 12, 0, 14, 0, 14, 0, 8, 1, 12, 0, 13, 1, 15, 0, 12, 0, 2, 0, 15, 0 )
[sub_resource type="ShaderMaterial" id=16]
shader = SubResource( 15 )
[node name="MainSplash" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource( 6 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ColorRect" type="ColorRect" parent="."]
material = SubResource( 16 )
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 1, 0, 0, 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="MainLogo" type="TextureRect" parent="."]
modulate = Color( 1, 1, 1, 0.486275 )
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 4
size_flags_vertical = 4
texture = ExtResource( 1 )
expand = true
stretch_mode = 6
__meta__ = {
"_edit_use_anchors_": false
}
[node name="StartButton" type="Button" parent="."]
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
margin_left = -50.0
margin_top = -40.0
margin_right = 50.0
margin_bottom = -10.0
focus_mode = 0
custom_styles/hover = ExtResource( 3 )
custom_styles/pressed = ExtResource( 4 )
custom_styles/normal = ExtResource( 5 )
custom_fonts/font = ExtResource( 2 )
shortcut_in_tooltip = false
text = "Restart"
__meta__ = {
"_edit_lock_": true,
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="."]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
grow_horizontal = 2
grow_vertical = 2
size_flags_vertical = 1
custom_fonts/font = ExtResource( 7 )
custom_colors/font_color = Color( 0, 0, 0, 1 )
text = "A machine overheated
You died"
align = 1
valign = 1
[connection signal="pressed" from="StartButton" to="." method="_on_StartButton_pressed"]

29
Main.gd
View File

@ -25,26 +25,45 @@ func update_cursor(size):
var game_starting_tween = null var game_starting_tween = null
func _on_MainSplash_start_pressed(): func _on_MainSplash_start_pressed():
if not game_starting_tween: if (not game_starting_tween) and splash:
start_game() start_game()
onready var splash = $"GUI/MainSplash"
var map = null
const splash_scroll_time = 0.67 const splash_scroll_time = 0.67
func start_game(): func start_game():
game_starting_tween = Tween.new() game_starting_tween = Tween.new()
add_child(game_starting_tween) add_child(game_starting_tween)
game_starting_tween.interpolate_property($"GUI/MainSplash", "anchor_top", 0, 1, splash_scroll_time) game_starting_tween.interpolate_property(splash, "anchor_top", 0, 1, splash_scroll_time)
game_starting_tween.interpolate_property($"GUI/MainSplash", "anchor_bottom", 1, 2, splash_scroll_time) game_starting_tween.interpolate_property(splash, "anchor_bottom", 1, 2, splash_scroll_time)
game_starting_tween.interpolate_property($"GUI/Hotbar", "anchor_top", 2, 1, splash_scroll_time) game_starting_tween.interpolate_property($"GUI/Hotbar", "anchor_top", 2, 1, splash_scroll_time)
game_starting_tween.interpolate_property($"GUI/Hotbar", "anchor_bottom", 2, 1, splash_scroll_time) game_starting_tween.interpolate_property($"GUI/Hotbar", "anchor_bottom", 2, 1, splash_scroll_time)
game_starting_tween.start() game_starting_tween.start()
var timer = get_tree().create_timer(splash_scroll_time) var timer = get_tree().create_timer(splash_scroll_time)
timer.connect("timeout", self, "remove_splash") timer.connect("timeout", self, "remove_splash")
add_child_below_node($bgm, map1.instance()) map = map1.instance()
add_child_below_node($bgm, map)
func remove_splash(): func remove_splash():
remove_child(game_starting_tween) remove_child(game_starting_tween)
game_starting_tween.queue_free() game_starting_tween.queue_free()
game_starting_tween = null game_starting_tween = null
var splash = $"GUI/MainSplash"
$GUI.remove_child(splash) $GUI.remove_child(splash)
splash.queue_free() splash.queue_free()
splash = null
func get_cursor_snapped_position():
var mouse_pos = get_viewport().get_mouse_position()
if $"GUI/Hotbar".get_rect().has_point(mouse_pos):
return Vector2(-1, -1)
return Vector2(floor(mouse_pos.x/8)*8, floor(mouse_pos.y/8)*8)
var gameover_splash = preload("res://GameoverSplash.tscn")
func game_over():
splash = gameover_splash.instance()
$GUI.add_child(splash)
splash.connect("start_pressed", self, "_on_MainSplash_start_pressed")
remove_child(map)
map.queue_free()
map = null

9
assets/UI_Youdied.tres Normal file
View File

@ -0,0 +1,9 @@
[gd_resource type="DynamicFont" load_steps=2 format=2]
[ext_resource path="res://assets/NotoSans.tres" type="DynamicFontData" id=1]
[resource]
size = 40
outline_size = 2
outline_color = Color( 1, 1, 0, 1 )
font_data = ExtResource( 1 )

View File

@ -67,6 +67,8 @@ func _process(delta):
return return
self.working = false self.working = false
idle_time += delta idle_time += delta
if idle_time >= max_idle_time:
$"/root/Main".game_over()
var overspeed = clamp(floor(idle_time/2)*2, 1, 8) var overspeed = clamp(floor(idle_time/2)*2, 1, 8)
$sprite.material.set_shader_param('rps', overspeed*anim_speed) $sprite.material.set_shader_param('rps', overspeed*anim_speed)
else: else: