summaryrefslogtreecommitdiff
path: root/godot/scenes/environment/CaptureFlag.gd
diff options
context:
space:
mode:
authorAnson Bridges <bridges.anson@gmail.com>2022-09-07 14:07:30 -0400
committerAnson Bridges <bridges.anson@gmail.com>2022-09-07 14:07:30 -0400
commitc232b92e2dde1277324d1f89d0e75ae641e4ac3b (patch)
treee11a5dd52f259c1cc7345baa40b372b304417f00 /godot/scenes/environment/CaptureFlag.gd
parenta0967ebe815cd229b69fb9578f2288b95b2ddb28 (diff)
reorganized, ladders, vehicle control
Diffstat (limited to 'godot/scenes/environment/CaptureFlag.gd')
-rw-r--r--godot/scenes/environment/CaptureFlag.gd84
1 files changed, 84 insertions, 0 deletions
diff --git a/godot/scenes/environment/CaptureFlag.gd b/godot/scenes/environment/CaptureFlag.gd
new file mode 100644
index 0000000..81a9fc5
--- /dev/null
+++ b/godot/scenes/environment/CaptureFlag.gd
@@ -0,0 +1,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 }