mirror of
https://github.com/Yadciel1/2048-Shooter.git
synced 2025-06-16 11:15:23 +02:00
Score
This commit is contained in:
@ -5,6 +5,7 @@ const SlotClass = preload("res:///Objects/Slot.gd")
|
||||
var Panzer_Temp = preload("res://Objects/Panzer.tscn")
|
||||
onready var game_slots = $VBoxContainer/PanzerSlots
|
||||
onready var overlay_node = find_node("Overlay")
|
||||
var score_file = "user://highscore_2048Shooter.save"
|
||||
var holding_item = null
|
||||
var buy_panzer_left = 0
|
||||
var life = 100
|
||||
@ -30,6 +31,7 @@ func _ready():
|
||||
|
||||
func _process(delta):
|
||||
if $Panel/Area2D/LifeBar.value == 0:
|
||||
save_score()
|
||||
get_tree().change_scene("res://Main Scenes/GameOver.tscn")
|
||||
|
||||
func slot_gui_input(event: InputEvent, slot: SlotClass):
|
||||
@ -146,7 +148,24 @@ func drag_drop_handle(hover):
|
||||
var temp2 = holding_item
|
||||
hover.pickFromSlot()
|
||||
hover.putIntoSlot(holding_item)
|
||||
print(holding_item.old_slot)
|
||||
temp2.old_slot.putIntoSlot(temp)
|
||||
holding_item = null
|
||||
|
||||
elif holding_item.old_slot == null:
|
||||
var temp = hover.Panzer
|
||||
var temp2 = holding_item
|
||||
hover.pickFromSlot()
|
||||
hover.putIntoSlot(holding_item)
|
||||
holding_item = temp
|
||||
holding_item.global_position = get_global_mouse_position()
|
||||
holding_item.old_slot = null
|
||||
|
||||
func save_score():
|
||||
var highscoreNode = find_node("Score")
|
||||
var f = File.new()
|
||||
if f.file_exists(score_file):
|
||||
f.open(score_file, File.READ)
|
||||
if (f.get_var() as int) > 0:
|
||||
f.close()
|
||||
f.open(score_file,File.WRITE)
|
||||
f.store_var(highscoreNode.text)
|
||||
f.close()
|
||||
|
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=5 format=2]
|
||||
[gd_scene load_steps=6 format=2]
|
||||
|
||||
[ext_resource path="res://Font/super-legend-boy-font/SuperLegendBoy-4w8Y.ttf" type="DynamicFontData" id=1]
|
||||
[ext_resource path="res://retrowave.png" type="Texture" id=2]
|
||||
@ -6,7 +6,7 @@
|
||||
[sub_resource type="GDScript" id=2]
|
||||
script/source = "extends Node2D
|
||||
|
||||
|
||||
var score_file = \"user://highscore_2048Shooter.save\"
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = \"text\"
|
||||
@ -14,6 +14,7 @@ script/source = "extends Node2D
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
load_score()
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
@ -25,12 +26,27 @@ func _ready():
|
||||
func _on_Start_pressed():
|
||||
get_tree().change_scene(\"res://Main Scenes/Game.tscn\")
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
func load_score():
|
||||
var f = File.new()
|
||||
if f.file_exists(score_file):
|
||||
$Control/Score.visible = true
|
||||
f.open(score_file, File.READ)
|
||||
$Control/Score.text = \"Score: \" + f.get_var() as String
|
||||
f.close()
|
||||
else:
|
||||
$Control/Score.text = '0'
|
||||
"
|
||||
|
||||
[sub_resource type="DynamicFont" id=1]
|
||||
font_data = ExtResource( 1 )
|
||||
|
||||
[node name="Node2D" type="Node2D"]
|
||||
[sub_resource type="DynamicFont" id=3]
|
||||
size = 40
|
||||
font_data = ExtResource( 1 )
|
||||
|
||||
[node name="MainMenu" type="Node2D"]
|
||||
script = SubResource( 2 )
|
||||
|
||||
[node name="Background" type="Sprite" parent="."]
|
||||
@ -54,9 +70,9 @@ anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
margin_left = -180.0
|
||||
margin_top = -12.0
|
||||
margin_top = 244.0
|
||||
margin_right = 140.0
|
||||
margin_bottom = 140.0
|
||||
margin_bottom = 396.0
|
||||
|
||||
[node name="Button" type="Button" parent="Control/VBoxContainer"]
|
||||
margin_right = 320.0
|
||||
@ -65,4 +81,12 @@ rect_min_size = Vector2( 0, 70 )
|
||||
custom_fonts/font = SubResource( 1 )
|
||||
text = "Start"
|
||||
|
||||
[node name="Score" type="Label" parent="Control"]
|
||||
margin_left = -264.0
|
||||
margin_top = -424.0
|
||||
margin_right = -69.0
|
||||
margin_bottom = -368.0
|
||||
custom_fonts/font = SubResource( 3 )
|
||||
text = "Score: "
|
||||
|
||||
[connection signal="pressed" from="Control/VBoxContainer/Button" to="." method="_on_Start_pressed"]
|
||||
|
Reference in New Issue
Block a user