blob: 81a9fc52e13441d0a63ecc74bef80029c3993585 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
extends Spatial
onready var flag = $flag_mesh
const flag_high : float = 5.4
const flag_low : float = 1.0
var capture_speed : float = 1
var state = "IDLE_HIGH" #IDLE_HIGH, IDLE_LOW, CAPTURING, HOISTING. capturing cannot be blocked, hoisting can
var teams_in_zone = []
var foreign_in_zone = false
var team = "NONE"
# Called when the node enters the scene tree for the first time.
func _ready():
$flag_mesh/Label.text = team
remotesync func update_text(text):
$flag_mesh/Label.text = text
remote func update_position(height):
flag.transform.origin.y = height
remotesync func capture():
$flag_mesh/capture_audio.play()
func _physics_process(delta):
if is_network_master():
teams_in_zone = []
foreign_in_zone = false
for body in $CaptureArea.get_overlapping_bodies():
if body.is_in_group("player") and !(body.team in teams_in_zone):
if body.team != team:
foreign_in_zone = true
teams_in_zone.append(body.team)
if state == "IDLE_HIGH" and foreign_in_zone:
state = "CAPTURING"
if state == "CAPTURING" and !foreign_in_zone:
state = "IDLE_HIGH"
if state == "IDLE_LOW" and team in teams_in_zone:
state = "HOISTING"
if state == "HOISTING" and !(team in teams_in_zone):
state = "IDLE_LOW"
if state == "CAPTURING":
if flag.transform.origin.y > flag_low:
flag.transform.origin.y -= delta * capture_speed
rpc("update_position",flag.transform.origin.y)
else:
flag.transform.origin.y = flag_low
state = "IDLE_LOW"
team = "NONE"
rpc("update_text",team)
if state == "IDLE_HIGH":
if flag.transform.origin.y <= flag_high:
flag.transform.origin.y += delta * capture_speed
rpc("update_position",flag.transform.origin.y)
if state == "IDLE_LOW":
if flag.transform.origin.y > flag_low:
flag.transform.origin.y -= delta * capture_speed
rpc("update_position",flag.transform.origin.y)
else:
team = "NONE"
rpc("update_text",team)
flag.transform.origin.y = flag_low
if team == "NONE" and len(teams_in_zone) == 1:
team = teams_in_zone[0]
rpc("update_text",team)
state = "HOISTING"
if state == "HOISTING":
if len(teams_in_zone) == 1:
flag.transform.origin.y += delta * capture_speed
rpc("update_position",flag.transform.origin.y)
if flag.transform.origin.y >= flag_high:
rpc("capture")
state = "IDLE_HIGH"
func mp_init(init_info):
flag.transform.origin.y = init_info["height"]
team = init_info["team"]
$flag_mesh/Label.text = team
func get_init_info(): #info necessary to replicate item
return {"height" : flag.transform.origin.y, "team" : team }
|