diff options
author | Daniel Weipert <code@drogueronin.de> | 2021-01-02 15:31:54 +0100 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2021-01-02 15:31:54 +0100 |
commit | 7920e8758506cd46c58ea4889c9f4fb704abfd16 (patch) | |
tree | c64c8cf57ef906123d6989742baaee97dcc7947d | |
parent | ebae6d04ffc95c6648e863d3de71835f6cd4be96 (diff) |
Level Map HUD and game end trigger
-rw-r--r-- | Global.gd | 7 | ||||
-rw-r--r-- | Levels/Level.gd | 2 | ||||
-rw-r--r-- | Network/Network.gd | 6 | ||||
-rw-r--r-- | UI/HUD/LevelMap.gd | 25 | ||||
-rw-r--r-- | UI/HUD/LevelMap.tscn | 18 | ||||
-rw-r--r-- | UI/HUD/LevelMapCell.gd | 24 | ||||
-rw-r--r-- | UI/HUD/LevelMapCell.tscn | 71 |
7 files changed, 152 insertions, 1 deletions
@@ -21,6 +21,8 @@ var Level_Map = [] func _ready(): + Network.connect("game_ended", self, "_on_game_end") + for level in self.Levels: self.Level_Map.push_back({ time = 0, @@ -110,3 +112,8 @@ func check_win(): if has_won: emit_signal("game_won", Network.player) + + +func _on_game_end(): + self.Level_Map = [] + self._ready() diff --git a/Levels/Level.gd b/Levels/Level.gd index f47f3a0..57288b2 100644 --- a/Levels/Level.gd +++ b/Levels/Level.gd @@ -14,10 +14,12 @@ var HUD = CanvasLayer.new() var timer = 0 var LabelTimer = preload("res://UI/HUD/Timer.tscn").instance() +var LevelMap = preload("res://UI/HUD/LevelMap.tscn").instance() func _ready(): self.HUD.add_child(self.LabelTimer) + self.HUD.add_child(self.LevelMap) self.add_child(self.HUD) diff --git a/Network/Network.gd b/Network/Network.gd index 0f007b4..77630a7 100644 --- a/Network/Network.gd +++ b/Network/Network.gd @@ -82,11 +82,15 @@ sync func _start_game(): func end_game(winning_player): + emit_signal("game_ended", winning_player) + rpc("_end_game", winning_player) + + +sync func _end_game(winning_player): # TODO: change scene for all to win scene and set winning player id, # so it can be displayed with self.players print(winning_player) get_tree().change_scene("res://Network/Lobby.tscn") - pass func _player_connected(id): diff --git a/UI/HUD/LevelMap.gd b/UI/HUD/LevelMap.gd new file mode 100644 index 0000000..8de38fa --- /dev/null +++ b/UI/HUD/LevelMap.gd @@ -0,0 +1,25 @@ +extends Panel + + +func _ready(): + Global.connect("level_map_updated", self, "draw") + self.draw() + + +func draw(): + var Cell = load("res://UI/HUD/LevelMapCell.tscn") + var Level = get_parent().get_parent() # HUD > Level + + for idx in range(Global.Level_Map.size()): + var cell = Cell.instance() + cell.level_idx = idx + cell.set_rect_size(150/3, 150/3) + var column = idx % 3 + var row = idx / 3 + cell.rect_position.x = cell.rect_size.x*column + cell.rect_position.y = cell.rect_size.y*row + + #if idx == Level.idx: + #cell.set_border_width_all(3) + + self.add_child(cell) diff --git a/UI/HUD/LevelMap.tscn b/UI/HUD/LevelMap.tscn new file mode 100644 index 0000000..646c96a --- /dev/null +++ b/UI/HUD/LevelMap.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://UI/HUD/LevelMap.gd" type="Script" id=1] + +[sub_resource type="StyleBoxFlat" id=1] +bg_color = Color( 0, 0, 0, 0.117647 ) + +[node name="LevelMap" type="Panel"] +margin_left = 864.0 +margin_top = 8.0 +margin_right = 1014.0 +margin_bottom = 158.0 +rect_clip_content = true +custom_styles/panel = SubResource( 1 ) +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} diff --git a/UI/HUD/LevelMapCell.gd b/UI/HUD/LevelMapCell.gd new file mode 100644 index 0000000..16ff961 --- /dev/null +++ b/UI/HUD/LevelMapCell.gd @@ -0,0 +1,24 @@ +extends Panel + + +var level_idx = 0 + + +func _ready(): + var level = Global.get_level(self.level_idx) + + $ClearMark.text = "" + if level.cleared_by.idx == Enum.PLAYER.FIRST: + $ClearMark.text = "X" + elif level.cleared_by.idx == Enum.PLAYER.SECOND: + $ClearMark.text = "O" + + $Time.text = str(level.time) + "s" + $Name.text = level.cleared_by.name + + +func set_rect_size(x, y): + self.rect_size.x = x + self.rect_size.y = y + $ClearMark.rect_size.x = x + $ClearMark.rect_size.y = y diff --git a/UI/HUD/LevelMapCell.tscn b/UI/HUD/LevelMapCell.tscn new file mode 100644 index 0000000..d933d4f --- /dev/null +++ b/UI/HUD/LevelMapCell.tscn @@ -0,0 +1,71 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://UI/LevelSelectCell.gd" type="Script" id=1] +[ext_resource path="res://Assets/Fonts/geometry-soft-pro/Geometry_Soft_Pro-Bold_N.otf" type="DynamicFontData" id=2] +[ext_resource path="res://Assets/Fonts/impact-label/Impact_Label_Reversed.ttf" type="DynamicFontData" id=3] + +[sub_resource type="StyleBoxFlat" id=1] +bg_color = Color( 0.133333, 0.372549, 0.188235, 1 ) +border_width_left = 1 +border_width_top = 1 +border_width_right = 1 +border_width_bottom = 1 + +[sub_resource type="DynamicFont" id=2] +size = 32 +font_data = ExtResource( 3 ) + +[sub_resource type="DynamicFont" id=3] +size = 8 +outline_size = 2 +outline_color = Color( 0, 0, 0, 1 ) +font_data = ExtResource( 2 ) + +[node name="LevelMapCell" type="Panel"] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_right = -974.0 +margin_bottom = -550.0 +hint_tooltip = "Select Level" +custom_styles/panel = SubResource( 1 ) +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="ClearMark" type="Label" parent="."] +margin_left = 1.0 +margin_top = 1.0 +margin_right = 50.0 +margin_bottom = 50.0 +custom_fonts/font = SubResource( 2 ) +text = "X" +align = 1 +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Time" type="Label" parent="."] +margin_left = 3.72449 +margin_top = 2.01899 +margin_right = 32.7245 +margin_bottom = 15.019 +custom_fonts/font = SubResource( 3 ) +text = "0.00s" +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Name" type="Label" parent="."] +margin_left = 3.95238 +margin_top = 31.297 +margin_right = 61.9524 +margin_bottom = 52.297 +custom_fonts/font = SubResource( 3 ) +text = "Player" +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} |