Skip to content

Commit

Permalink
Added a win counter and only ending the match after it reaches 5 for …
Browse files Browse the repository at this point in the history
…either player
  • Loading branch information
RichoM committed Sep 7, 2022
1 parent df6079c commit d6e3566
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 2 deletions.
19 changes: 18 additions & 1 deletion end.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,37 @@ extends Node2D

var client = Client
var winner = null
var match_over = false
var return_scene = "res://menu.tscn"
onready var p0 = $players/p0
onready var p1 = $players/p1
onready var p0_title = $GUI/purple_wins
onready var p1_title = $GUI/yellow_wins
onready var scores = $GUI/scores
onready var play_button = $GUI/play_button

func _ready():
if winner == "p0":
p0.play("alive")
p1.play("dead")
p0_title.visible = true
else:
p1.play("alive")
p0.play("dead")

scores.text = str(Globals.scores[0]) + " - " + str(Globals.scores[1])

if Globals.scores[0] >= 5:
p0_title.visible = true
match_over = true
elif Globals.scores[1] >= 5:
p1_title.visible = true
match_over = true

if match_over:
# Move the scores label down to the center
scores.margin_top = get_viewport().size.y/2 - scores.rect_size.y/2
play_button.text = "REMATCH!"

func _process(delta):
if Globals.mode == Globals.ONLINE_MULTIPLAYER:
# Discard old packets
Expand All @@ -33,5 +48,7 @@ func _process(delta):
print("ERROR!")

func _on_play_button_pressed():
if match_over:
Globals.scores = [0, 0]
get_tree().change_scene(return_scene)
get_tree().get_root().remove_child(self)
21 changes: 20 additions & 1 deletion end.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=22 format=2]
[gd_scene load_steps=23 format=2]

[ext_resource path="res://pixel-line-platformer/dead.png" type="Texture" id=1]
[ext_resource path="res://pixel-line-platformer/Tilemap/tilemap_packed.png" type="Texture" id=2]
Expand Down Expand Up @@ -29,6 +29,12 @@ outline_size = 5
outline_color = Color( 0.937255, 0.72549, 0.0941176, 1 )
font_data = ExtResource( 7 )

[sub_resource type="DynamicFont" id=13]
size = 89
outline_size = 5
outline_color = Color( 0.0941176, 0.937255, 0.384314, 1 )
font_data = ExtResource( 7 )

[sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 3 )
shader_param/Shift_Hue = -0.514
Expand Down Expand Up @@ -126,6 +132,18 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="scores" type="Label" parent="GUI"]
anchor_right = 1.0
margin_top = 69.0
margin_bottom = 176.0
custom_fonts/font = SubResource( 13 )
text = "0 - 0"
align = 1
valign = 1
__meta__ = {
"_edit_use_anchors_": false
}

[node name="background" type="Node2D" parent="."]
scale = Vector2( 5, 5 )

Expand Down Expand Up @@ -165,6 +183,7 @@ position = Vector2( 55, 0 )
scale = Vector2( 3, 3 )
frames = SubResource( 6 )
animation = "alive"
frame = 1
playing = true
flip_h = true

Expand Down
3 changes: 3 additions & 0 deletions game_local.gd
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ func _on_player1_tree_exited():
call_deferred("winner", "p0")

func winner(winner):
var winner_idx = 0 if winner == "p0" else 1
Globals.scores[winner_idx] = Globals.scores[winner_idx] + 1

var root = get_tree().get_root()

# Remove the current level
Expand Down
3 changes: 3 additions & 0 deletions game_online.gd
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ func _on_player1_tree_exited():
call_deferred("winner", "p0")

func winner(winner):
var winner_idx = 0 if winner == "p0" else 1
Globals.scores[winner_idx] = Globals.scores[winner_idx] + 1

var root = get_tree().get_root()

# Remove the current level
Expand Down
1 change: 1 addition & 0 deletions globals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var level = 1
var player = null
var server_url = null
var mode = LOCAL_MULTIPLAYER
var scores = [0, 0]

func _ready():
#server_url = "ws://localhost:3000"
Expand Down
1 change: 1 addition & 0 deletions menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func _ready():
map["p1_left"] = $static/p1/left
map["p1_right"] = $static/p1/right
map["p1_action"] = $static/p1/down
Globals.scores = [0, 0]

func _process(_delta):
for key in map.keys():
Expand Down

0 comments on commit d6e3566

Please sign in to comment.