Distance counter and player switching implemented.
This commit is contained in:
parent
d31d027b80
commit
047f64fef6
4 changed files with 44 additions and 6 deletions
17
scripts/mapscript.gd
Normal file
17
scripts/mapscript.gd
Normal file
|
@ -0,0 +1,17 @@
|
|||
extends Node2D
|
||||
|
||||
var playerAmount=2
|
||||
var playerIndex=0
|
||||
var objectName
|
||||
|
||||
func _ready():
|
||||
next()
|
||||
|
||||
func next():
|
||||
if playerIndex >= playerAmount:
|
||||
playerIndex = 0
|
||||
objectName= "player%d" % playerIndex
|
||||
print(objectName)
|
||||
get_node(objectName).start()
|
||||
playerIndex += 1
|
||||
|
|
@ -1,11 +1,26 @@
|
|||
extends CharacterBody2D
|
||||
|
||||
@export var speed = 200
|
||||
var toCalculate = position
|
||||
var distanceTo = 0
|
||||
var active = false
|
||||
|
||||
func get_input():
|
||||
var input_direction = Input.get_vector("left", "right", "up", "down")
|
||||
velocity = input_direction * speed
|
||||
|
||||
func _physics_process(delta):
|
||||
get_input()
|
||||
move_and_slide()
|
||||
if active:
|
||||
get_input()
|
||||
move_and_slide()
|
||||
distanceTo = position.distance_to(toCalculate)
|
||||
if distanceTo > 500 and active:
|
||||
active = false
|
||||
$camera.enabled = false
|
||||
get_parent().next()
|
||||
|
||||
|
||||
func start():
|
||||
$camera.enabled = true
|
||||
active = true
|
||||
toCalculate = position
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue