Skip to content

Instantly share code, notes, and snippets.

@Wavesonics
Created October 20, 2019 22:22
Show Gist options
  • Save Wavesonics/e36436feaec1cfe4dbc0f5e014d59009 to your computer and use it in GitHub Desktop.
Save Wavesonics/e36436feaec1cfe4dbc0f5e014d59009 to your computer and use it in GitHub Desktop.
####################
# Map_00.gd
####################
func _ready():
create_players(Network.players)
func create_players(players):
for player_id in players:
var player = players[player_id]
match player.type:
Network.PlayerType.Seeker:
create_seeker(player_id, player)
Network.PlayerType.Hider:
create_seeker(player_id, player)
func create_seeker(id, player):
var scene = preload("res://actors/seeker/Seeker.tscn")
var node = scene.instance()
node.set_name(str(id))
node.set_network_master(id)
node.position = Vector2(220, 470)
players.add_child(node)
####################
# Seeker.gd
####################
extends KinematicBody2D
class_name Seeker
export (int) var speed = 200
export (float) var rotation_speed = 1.5
var velocity = Vector2()
var rotation_dir = 0
func get_input():
rotation_dir = 0
velocity = Vector2()
if Input.is_action_pressed('ui_right'):
rotation_dir += 1
if Input.is_action_pressed('ui_left'):
rotation_dir -= 1
if Input.is_action_pressed('ui_down'):
velocity = Vector2(-speed, 0).rotated(rotation)
if Input.is_action_pressed('ui_up'):
velocity = Vector2(speed, 0).rotated(rotation)
func _physics_process(delta):
if not is_network_master():
return
get_input()
rotation += rotation_dir * rotation_speed * delta
velocity = move_and_slide(velocity)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment