diff --git a/WikiJam/Player/Player.gd b/WikiJam/Player/Player.gd index c482360..2782da5 100644 --- a/WikiJam/Player/Player.gd +++ b/WikiJam/Player/Player.gd @@ -55,6 +55,10 @@ func _process(_delta): func _process_input(): + #exit + if Input.is_action_pressed("ui_cancel"): + _interface.gameOver() + # Walking var input_movement_vector = Vector2() if Input.is_action_pressed("move_fwrd"): @@ -65,7 +69,7 @@ func _process_input(): input_movement_vector.x -= 1 if Input.is_action_pressed("move_right"): input_movement_vector.x += 1 - + # look around with mouse _dir = Vector3() var camera_transform = _camera.get_global_transform() diff --git a/WikiJam/Player/Player.tscn b/WikiJam/Player/Player.tscn index efd8d30..2bac2cb 100644 --- a/WikiJam/Player/Player.tscn +++ b/WikiJam/Player/Player.tscn @@ -74,10 +74,58 @@ pitch_scale = 1.5 [node name="HUD" parent="." instance=ExtResource( 4 )] script = ExtResource( 5 ) label_nodepath = NodePath("LabelScore") +popup_nodepath = NodePath("PopupWon") [node name="LabelScore" type="Label" parent="HUD"] margin_left = 15.0 margin_top = 15.0 margin_right = 115.0 margin_bottom = 30.0 -text = "Score: %score%" +text = "Score: 0" + +[node name="PopupWon" type="Popup" parent="HUD"] +visible = true +margin_left = 383.0 +margin_top = 187.0 +margin_right = 530.0 +margin_bottom = 289.0 + +[node name="PanelFail" type="Panel" parent="HUD/PopupWon"] +modulate = Color( 0.996078, 0, 0, 1 ) +margin_left = -383.0 +margin_top = -187.36 +margin_right = 641.0 +margin_bottom = 412.64 + +[node name="PanelWon" type="Panel" parent="HUD/PopupWon"] +modulate = Color( 0.0313726, 0, 0.996078, 1 ) +margin_left = -383.0 +margin_top = -187.36 +margin_right = 641.0 +margin_bottom = 412.64 + +[node name="LabelWon" type="Label" parent="HUD/PopupWon"] +margin_left = 87.064 +margin_top = 24.4867 +margin_right = 169.064 +margin_bottom = 72.4867 +text = "Gratulations! + + You Won!" + +[node name="LabelFail" type="Label" parent="HUD/PopupWon"] +margin_left = 88.9828 +margin_top = 28.0094 +margin_right = 168.983 +margin_bottom = 76.0094 +text = " You died! + +Game over" + +[node name="Button" type="Button" parent="HUD/PopupWon"] +margin_left = 86.5054 +margin_top = 144.902 +margin_right = 179.505 +margin_bottom = 181.902 +text = "play again" +[connection signal="pressed" from="HUD/PopupWon/Button" to="HUD" method="_on_Button_pressed"] diff --git a/WikiJam/Player/UI/HUD.gd b/WikiJam/Player/UI/HUD.gd index d68cafb..35fb2d8 100644 --- a/WikiJam/Player/UI/HUD.gd +++ b/WikiJam/Player/UI/HUD.gd @@ -1,10 +1,12 @@ extends Control export(NodePath) var label_nodepath +export(NodePath) var popup_nodepath const SCORE = 100 var _labelScore: Label +var _popup: Popup var _score: int = 0 @@ -12,10 +14,39 @@ func _ready(): _labelScore = get_node(label_nodepath) as Label assert(null != _labelScore) + _popup = get_node(popup_nodepath) as Popup + assert(null != _popup) + func increaseScore(): _score += SCORE _labelScore.text = "Score: " + String(_score) - if (_score / SCORE == Collector.getCount()): + Logger.info(String(_score) + " of " + String(Collector.getCount() * SCORE) + " possible points") + if (_score >= (Collector.getCount() * SCORE)): Logger.info("YOU WON!") - \ No newline at end of file + success() + + +func gameOver(): + _endGame(false) + + +func success(): + _endGame(true) + + +func _endGame (value): + Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + + Collector.Clear() + + _popup.get_node("LabelWon").visible = value + _popup.get_node("LabelFail").visible = !value + + _popup.get_node("PanelWon").visible = value + _popup.get_node("PanelFail").visible = !value + _popup.show() + + +func _on_Button_pressed(): + get_tree().reload_current_scene() diff --git a/WikiJam/Util/Collector.gd b/WikiJam/Util/Collector.gd index c504a8e..6286ef4 100644 --- a/WikiJam/Util/Collector.gd +++ b/WikiJam/Util/Collector.gd @@ -5,9 +5,13 @@ var _collectibles: Array func addCollectible (coll): Logger.info("appending new collectible: " + String(coll.get_instance_id())) - Logger.info("current collection count: " + String(Collector.getCount())) _collectibles.append(coll) + Logger.info("current collection count: " + String(Collector.getCount())) func getCount (): - return _collectibles.size() \ No newline at end of file + return _collectibles.size() + + +func Clear (): + return _collectibles.clear() \ No newline at end of file