Added main menu
This commit is contained in:
parent
ae936275b7
commit
18b2a3491c
7 changed files with 89 additions and 30 deletions
|
@ -4,12 +4,10 @@ extends Node2D
|
||||||
func _ready():
|
func _ready():
|
||||||
process_mode = Node.PROCESS_MODE_ALWAYS
|
process_mode = Node.PROCESS_MODE_ALWAYS
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
func _process(delta):
|
|
||||||
pass
|
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
if event.is_action_pressed("restart"):
|
if event.is_action_pressed("restart") and $Clock/Label/HTTPRequest.get_http_client_status() == HTTPClient.STATUS_DISCONNECTED:
|
||||||
get_tree().paused = false
|
get_tree().paused = false
|
||||||
get_tree().reload_current_scene()
|
get_tree().reload_current_scene()
|
||||||
|
if event.is_action_pressed("quit") and $Clock/Label/HTTPRequest.get_http_client_status() == HTTPClient.STATUS_DISCONNECTED:
|
||||||
|
get_tree().paused = false
|
||||||
|
get_tree().change_scene_to_file("res://main_menu.tscn")
|
||||||
|
|
2
Gun.gd
2
Gun.gd
|
@ -3,7 +3,7 @@ extends Marker2D
|
||||||
@export var bullet: PackedScene
|
@export var bullet: PackedScene
|
||||||
|
|
||||||
func shoot():
|
func shoot():
|
||||||
print("Shooting")
|
#print("Shooting")
|
||||||
var node = bullet.instantiate()
|
var node = bullet.instantiate()
|
||||||
node.global_position = global_position
|
node.global_position = global_position
|
||||||
node.linear_velocity = Vector2(500, 0).rotated(global_rotation)
|
node.linear_velocity = Vector2(500, 0).rotated(global_rotation)
|
||||||
|
|
|
@ -1,17 +1,24 @@
|
||||||
extends Label
|
extends Label
|
||||||
|
|
||||||
@export var stopwatch: Stopwatch
|
@export var stopwatch: Stopwatch
|
||||||
|
var config = ConfigFile.new()
|
||||||
|
|
||||||
const API_BASE = "https://flask-hello-world-nine-psi.vercel.app"
|
var API_BASE = "https://flask-hello-world-nine-psi.vercel.app" if not OS.is_debug_build() else "http://192.168.2.120:5001"
|
||||||
|
|
||||||
|
func make_urlsafe(data: String):
|
||||||
|
return data.replace("+", "-").replace("/", "_")
|
||||||
|
|
||||||
func get_scores():
|
func get_scores():
|
||||||
$HTTPRequest.request(API_BASE + "/leaderboard")
|
$HTTPRequest.request(API_BASE + "/leaderboard")
|
||||||
|
|
||||||
func submit_score():
|
func submit_score():
|
||||||
var encrypted_score = "EGH" + Marshalls.utf8_to_base64(str(stopwatch.time_elapsed))
|
var err = config.load("user://settings.cfg")
|
||||||
|
if not (err == OK and config.has_section_key("config", "username")):
|
||||||
|
text = "Error: No Username!\nSet a username in settings to submit scores"
|
||||||
|
var encrypted_score = "EGH" + make_urlsafe(Marshalls.utf8_to_base64(str(stopwatch.time_elapsed))) + "eHa" + make_urlsafe(Marshalls.utf8_to_base64(config.get_value("config", "username")))
|
||||||
print(encrypted_score)
|
print(encrypted_score)
|
||||||
$HTTPRequest.request_completed.connect(_on_request_completed)
|
$HTTPRequest.request_completed.connect(_on_request_completed)
|
||||||
$HTTPRequest.request(API_BASE + "https://flask-hello-world-nine-psi.vercel.app/leaderboard?score=%s" % encrypted_score, [], HTTPClient.METHOD_POST)
|
$HTTPRequest.request(API_BASE + "/leaderboard?score=%s" % encrypted_score, [], HTTPClient.METHOD_POST)
|
||||||
|
|
||||||
func _on_request_completed(result, response_code, headers, body):
|
func _on_request_completed(result, response_code, headers, body):
|
||||||
if body.get_string_from_utf8() == "OK":
|
if body.get_string_from_utf8() == "OK":
|
||||||
|
@ -20,12 +27,15 @@ func _on_request_completed(result, response_code, headers, body):
|
||||||
var json = JSON.parse_string(body.get_string_from_utf8())
|
var json = JSON.parse_string(body.get_string_from_utf8())
|
||||||
#print(json)
|
#print(json)
|
||||||
if json and "scores" in json:
|
if json and "scores" in json:
|
||||||
var scores = json["scores"]
|
var scoredata = json["scores"]
|
||||||
#print(scores)
|
var scores = []
|
||||||
|
for score in scoredata:
|
||||||
|
scores.append(float(score[1]))
|
||||||
|
print(scores)
|
||||||
var score = stopwatch.time_elapsed
|
var score = stopwatch.time_elapsed
|
||||||
|
print(score)
|
||||||
var placement = closest(score, scores)
|
var placement = closest(score, scores)
|
||||||
print(placement)
|
print(placement)
|
||||||
print(len(scores))
|
|
||||||
|
|
||||||
if placement < 50:
|
if placement < 50:
|
||||||
text = "You placed #%d\n" % [placement]
|
text = "You placed #%d\n" % [placement]
|
||||||
|
@ -33,7 +43,7 @@ func _on_request_completed(result, response_code, headers, body):
|
||||||
text = "You placed top %d%%\n" % [(float(placement) / len(scores)) * 100]
|
text = "You placed top %d%%\n" % [(float(placement) / len(scores)) * 100]
|
||||||
var n = 1
|
var n = 1
|
||||||
while n <= 5 and n <= len(scores):
|
while n <= 5 and n <= len(scores):
|
||||||
text += "%d. %s\n" % [ n, seconds2mmss(scores[n-1]) ]
|
text += "%d. %s: %s\n" % [ n, scoredata[n-1][0], seconds2mmss(scores[n-1]) ]
|
||||||
n += 1
|
n += 1
|
||||||
|
|
||||||
func closest(my_number:int, my_array:Array)->int:
|
func closest(my_number:int, my_array:Array)->int:
|
||||||
|
@ -44,7 +54,9 @@ func closest(my_number:int, my_array:Array)->int:
|
||||||
var temp_delta:int = 0
|
var temp_delta:int = 0
|
||||||
# Loop through entire array
|
# Loop through entire array
|
||||||
for i in range(my_array.size()):
|
for i in range(my_array.size()):
|
||||||
if my_array[i] == my_number: return my_array[i] # exact match found!
|
if my_array[i] == my_number:
|
||||||
|
print("Exact Match!")
|
||||||
|
return my_array[i] # exact match found!
|
||||||
temp_delta = int(abs(my_array[i]-my_number))
|
temp_delta = int(abs(my_array[i]-my_number))
|
||||||
if closest_delta == 0 or temp_delta < closest_delta:
|
if closest_delta == 0 or temp_delta < closest_delta:
|
||||||
closest_num = my_array[i]
|
closest_num = my_array[i]
|
||||||
|
|
|
@ -25,8 +25,6 @@ func _physics_process(delta):
|
||||||
func _input(event):
|
func _input(event):
|
||||||
if event.is_action_pressed("jump"):
|
if event.is_action_pressed("jump"):
|
||||||
global_position = get_global_mouse_position()
|
global_position = get_global_mouse_position()
|
||||||
if event.is_action_pressed("switch_input"):
|
|
||||||
absolute_movement = true
|
|
||||||
if event.is_action_pressed("quare"):
|
if event.is_action_pressed("quare"):
|
||||||
if num_quares >= max_quares:
|
if num_quares >= max_quares:
|
||||||
notifier.notify("All Quares in Use!")
|
notifier.notify("All Quares in Use!")
|
||||||
|
|
|
@ -24,7 +24,7 @@ hinting=1
|
||||||
subpixel_positioning=1
|
subpixel_positioning=1
|
||||||
oversampling=0.0
|
oversampling=0.0
|
||||||
Fallbacks=null
|
Fallbacks=null
|
||||||
fallbacks=[]
|
fallbacks=[Resource("res://TwitterColorEmoji-SVGinOT-14.0.2/TwitterColorEmoji-SVGinOT.ttf")]
|
||||||
Compress=null
|
Compress=null
|
||||||
compress=true
|
compress=true
|
||||||
preload=[]
|
preload=[]
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
[gd_scene load_steps=6 format=3 uid="uid://ck1db6d8whbac"]
|
[gd_scene load_steps=9 format=3 uid="uid://ck1db6d8whbac"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://MainMenu.gd" id="1_omrmt"]
|
[ext_resource type="Script" path="res://MainMenu.gd" id="1_omrmt"]
|
||||||
[ext_resource type="Gradient" uid="uid://c41berdx2rqpw" path="res://gradient.tres" id="2_fq3us"]
|
[ext_resource type="Gradient" uid="uid://c41berdx2rqpw" path="res://gradient.tres" id="2_fq3us"]
|
||||||
[ext_resource type="Script" path="res://InfiniteGradient.gd" id="3_7u2sq"]
|
[ext_resource type="Script" path="res://InfiniteGradient.gd" id="3_7u2sq"]
|
||||||
[ext_resource type="FontFile" uid="uid://dsw5w316y4v54" path="res://Preahvihear/Preahvihear-Regular.ttf" id="3_swfwl"]
|
[ext_resource type="FontFile" uid="uid://dsw5w316y4v54" path="res://Preahvihear/Preahvihear-Regular.ttf" id="3_swfwl"]
|
||||||
|
[ext_resource type="FontFile" uid="uid://tun7rjjlknsf" path="res://TwitterColorEmoji-SVGinOT-14.0.2/TwitterColorEmoji-SVGinOT.ttf" id="5_bjfro"]
|
||||||
|
[ext_resource type="Script" path="res://Settings.gd" id="5_sarwv"]
|
||||||
|
[ext_resource type="Script" path="res://EmojiValidator.gd" id="6_ojb71"]
|
||||||
|
|
||||||
[sub_resource type="GradientTexture1D" id="GradientTexture1D_jya8r"]
|
[sub_resource type="GradientTexture1D" id="GradientTexture1D_jya8r"]
|
||||||
gradient = ExtResource("2_fq3us")
|
gradient = ExtResource("2_fq3us")
|
||||||
|
@ -102,6 +105,7 @@ text = " PLAY "
|
||||||
flat = true
|
flat = true
|
||||||
|
|
||||||
[node name="Settings Panel" type="ColorRect" parent="."]
|
[node name="Settings Panel" type="ColorRect" parent="."]
|
||||||
|
visible = false
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
|
@ -109,8 +113,27 @@ anchor_bottom = 1.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
color = Color(0, 0, 0, 0.619608)
|
color = Color(0, 0, 0, 0.619608)
|
||||||
|
script = ExtResource("5_sarwv")
|
||||||
|
|
||||||
[node name="GridContainer" type="GridContainer" parent="Settings Panel"]
|
[node name="Close" type="Button" parent="Settings Panel"]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 7
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_top = 1.0
|
||||||
|
anchor_right = 0.5
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
offset_left = -72.0
|
||||||
|
offset_top = -159.0
|
||||||
|
offset_right = 72.0
|
||||||
|
offset_bottom = -59.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 0
|
||||||
|
theme_override_fonts/font = ExtResource("3_swfwl")
|
||||||
|
theme_override_font_sizes/font_size = 50
|
||||||
|
text = "SAVE"
|
||||||
|
flat = true
|
||||||
|
|
||||||
|
[node name="Menu" type="GridContainer" parent="Settings Panel"]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 13
|
anchors_preset = 13
|
||||||
anchor_left = 0.5
|
anchor_left = 0.5
|
||||||
|
@ -124,17 +147,38 @@ grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
columns = 2
|
columns = 2
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="Settings Panel/GridContainer"]
|
[node name="Label" type="Label" parent="Settings Panel/Menu"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 0
|
size_flags_horizontal = 0
|
||||||
theme_override_font_sizes/font_size = 80
|
theme_override_font_sizes/font_size = 80
|
||||||
text = "Balls"
|
text = "Useremoji"
|
||||||
|
|
||||||
[node name="TextEdit" type="TextEdit" parent="Settings Panel/GridContainer"]
|
[node name="Username" type="LineEdit" parent="Settings Panel/Menu"]
|
||||||
custom_minimum_size = Vector2(400, 2.08165e-12)
|
custom_minimum_size = Vector2(100, 0)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
theme_override_font_sizes/font_size = 60
|
size_flags_horizontal = 8
|
||||||
placeholder_text = "kill you self"
|
theme_override_fonts/font = ExtResource("5_bjfro")
|
||||||
|
theme_override_font_sizes/font_size = 54
|
||||||
|
alignment = 1
|
||||||
|
script = ExtResource("6_ojb71")
|
||||||
|
pattern = "\\p{Emoji}"
|
||||||
|
|
||||||
|
[node name="Label2" type="Label" parent="Settings Panel/Menu"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 0
|
||||||
|
theme_override_font_sizes/font_size = 80
|
||||||
|
text = "Movement "
|
||||||
|
|
||||||
|
[node name="Controls" type="OptionButton" parent="Settings Panel/Menu"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_fonts/font = ExtResource("3_swfwl")
|
||||||
|
theme_override_font_sizes/font_size = 54
|
||||||
|
item_count = 2
|
||||||
|
selected = 0
|
||||||
|
popup/item_0/text = "Relative"
|
||||||
|
popup/item_0/id = 0
|
||||||
|
popup/item_1/text = "Absolute"
|
||||||
|
popup/item_1/id = 1
|
||||||
|
|
||||||
[node name="Tutorial Text" type="Label" parent="."]
|
[node name="Tutorial Text" type="Label" parent="."]
|
||||||
visible = false
|
visible = false
|
||||||
|
@ -162,7 +206,7 @@ grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
color = Color(0, 0, 0, 0.654902)
|
color = Color(0, 0, 0, 0.654902)
|
||||||
|
|
||||||
[node name="Button" type="Button" parent="Tutorial Text"]
|
[node name="Close" type="Button" parent="Tutorial Text"]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
offset_left = 24.0
|
offset_left = 24.0
|
||||||
offset_top = 6.0
|
offset_top = 6.0
|
||||||
|
@ -173,6 +217,11 @@ theme_override_font_sizes/font_size = 50
|
||||||
text = "X"
|
text = "X"
|
||||||
flat = true
|
flat = true
|
||||||
|
|
||||||
|
[connection signal="pressed" from="Settings" to="Settings Panel" method="show"]
|
||||||
[connection signal="pressed" from="Tutorial" to="Tutorial Text" method="show"]
|
[connection signal="pressed" from="Tutorial" to="Tutorial Text" method="show"]
|
||||||
[connection signal="pressed" from="Play" to="." method="play"]
|
[connection signal="pressed" from="Play" to="." method="play"]
|
||||||
[connection signal="pressed" from="Tutorial Text/Button" to="Tutorial Text" method="hide"]
|
[connection signal="pressed" from="Settings Panel/Close" to="Settings Panel" method="save"]
|
||||||
|
[connection signal="pressed" from="Settings Panel/Close" to="Settings Panel" method="hide"]
|
||||||
|
[connection signal="text_changed" from="Settings Panel/Menu/Username" to="Settings Panel" method="check_valid"]
|
||||||
|
[connection signal="text_changed" from="Settings Panel/Menu/Username" to="Settings Panel/Menu/Username" method="check"]
|
||||||
|
[connection signal="pressed" from="Tutorial Text/Close" to="Tutorial Text" method="hide"]
|
||||||
|
|
|
@ -72,9 +72,9 @@ exagon={
|
||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
switch_input={
|
quit={
|
||||||
"deadzone": 0.5,
|
"deadzone": 0.5,
|
||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":77,"key_label":0,"unicode":109,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,3 +82,5 @@ switch_input={
|
||||||
|
|
||||||
renderer/rendering_method="gl_compatibility"
|
renderer/rendering_method="gl_compatibility"
|
||||||
renderer/rendering_method.mobile="gl_compatibility"
|
renderer/rendering_method.mobile="gl_compatibility"
|
||||||
|
anti_aliasing/screen_space_roughness_limiter/enabled=false
|
||||||
|
anti_aliasing/quality/screen_space_aa=1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue