updated the game
This commit is contained in:
parent
28b9c41bbc
commit
4750befdfb
3 changed files with 80 additions and 15 deletions
|
@ -2,8 +2,9 @@ extends RichTextLabel
|
||||||
|
|
||||||
@export var stopwatch: Stopwatch
|
@export var stopwatch: Stopwatch
|
||||||
var config = ConfigFile.new()
|
var config = ConfigFile.new()
|
||||||
|
const DEV = true
|
||||||
|
|
||||||
var API_BASE = "https://flask-hello-world-nine-psi.vercel.app"
|
var API_BASE = "https://flask-hello-world-nine-psi.vercel.app" if not DEV else "http://127.0.0.1:5001"
|
||||||
|
|
||||||
func make_urlsafe(data: String):
|
func make_urlsafe(data: String):
|
||||||
return data.replace("+", "-").replace("/", "_")
|
return data.replace("+", "-").replace("/", "_")
|
||||||
|
@ -16,17 +17,13 @@ func submit_score():
|
||||||
if not (err == OK and config.has_section_key("config", "username")):
|
if not (err == OK and config.has_section_key("config", "username")):
|
||||||
text = "Error: No Username!\nSet a username in settings to submit scores"
|
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")))
|
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)
|
|
||||||
$HTTPRequest.request_completed.connect(_on_request_completed)
|
$HTTPRequest.request_completed.connect(_on_request_completed)
|
||||||
$HTTPRequest.request(API_BASE + "/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":
|
|
||||||
get_scores()
|
|
||||||
return true
|
|
||||||
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 and "position" in json:
|
||||||
var scoredata = json["scores"]
|
var scoredata = json["scores"]
|
||||||
var scores = []
|
var scores = []
|
||||||
for score in scoredata:
|
for score in scoredata:
|
||||||
|
@ -34,16 +31,16 @@ func _on_request_completed(result, response_code, headers, body):
|
||||||
#print(scores)
|
#print(scores)
|
||||||
var score = stopwatch.time_elapsed
|
var score = stopwatch.time_elapsed
|
||||||
#print(score)
|
#print(score)
|
||||||
var placement = closest(score, scores)
|
var placement = float(json["position"])
|
||||||
#print(placement)
|
#print(placement)
|
||||||
|
|
||||||
if placement < 50:
|
if placement >= 1:
|
||||||
text = "[center]You placed #%d\n[/center]" % [placement]
|
text = "[center]You placed #%d\n[/center]" % [placement]
|
||||||
else:
|
else:
|
||||||
text = "[center]You placed top %d%%\n[/center]" % [(float(placement) / len(scores)) * 100]
|
text = "[center]You placed top %d%%\n[/center]" % [placement * 100]
|
||||||
var n = 1
|
var n = 1
|
||||||
while n <= 50 and n <= len(scores):
|
while n <= 50 and n <= len(scores):
|
||||||
text += "%d.\t\t%s:\t\t%s\n" % [ n, scoredata[n-1][0], seconds2mmss(scores[n-1]) ]
|
text += "[fill]%s #%d %s[/fill]" % [ scoredata[n-1][0], n, 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:
|
||||||
|
|
74
main.tscn
74
main.tscn
File diff suppressed because one or more lines are too long
|
@ -7,7 +7,7 @@
|
||||||
[ext_resource type="AudioStream" uid="uid://mond5sdmukan" path="res://powerUp7.ogg" id="5_bu8ku"]
|
[ext_resource type="AudioStream" uid="uid://mond5sdmukan" path="res://powerUp7.ogg" id="5_bu8ku"]
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_nxtxc"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_nxtxc"]
|
||||||
radius = 16.0
|
radius = 19.0263
|
||||||
|
|
||||||
[node name="Player" type="RigidBody2D" groups=["destructible"]]
|
[node name="Player" type="RigidBody2D" groups=["destructible"]]
|
||||||
position = Vector2(-42, 74)
|
position = Vector2(-42, 74)
|
||||||
|
@ -18,11 +18,13 @@ script = ExtResource("1_bu0dg")
|
||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||||
texture_filter = 1
|
texture_filter = 1
|
||||||
position = Vector2(-33, 0)
|
position = Vector2(-33, 0)
|
||||||
|
scale = Vector2(1.2, 1.2)
|
||||||
sprite_frames = ExtResource("2_c8tq3")
|
sprite_frames = ExtResource("2_c8tq3")
|
||||||
animation = &"gif"
|
animation = &"gif"
|
||||||
speed_scale = 0.75
|
speed_scale = 0.75
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
position = Vector2(3, 0)
|
||||||
shape = SubResource("CircleShape2D_nxtxc")
|
shape = SubResource("CircleShape2D_nxtxc")
|
||||||
|
|
||||||
[node name="DeathFX" type="AudioStreamPlayer2D" parent="."]
|
[node name="DeathFX" type="AudioStreamPlayer2D" parent="."]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue