Periodic boundary now applies to prey too
This commit is contained in:
19
evolve-die-repeat/game_manager.gd
Normal file
19
evolve-die-repeat/game_manager.gd
Normal file
@@ -0,0 +1,19 @@
|
||||
extends Node
|
||||
|
||||
var screen_size = Vector2(1920.0, 1080.0) # Default screen size (this is a float for some reason)
|
||||
|
||||
# TODO: This needs to be called from a script inheriting a CharacterBody2D (e.g. the player)
|
||||
# Alternative would be to pass the player reference to this script (which might be better?)
|
||||
func init_screen_size(x:float, y:float) -> void:
|
||||
screen_size.x = x
|
||||
screen_size.y = y
|
||||
|
||||
# This can take a vector of any size (but should be 2d, other components are unused)
|
||||
func get_boundaried_position(position):
|
||||
## clamp
|
||||
#return position.clamp(Vector2.ZERO, screen_size)
|
||||
|
||||
## periodic
|
||||
position.x = wrapf(position.x, 0, screen_size.x)
|
||||
position.y = wrapf(position.y, 0, screen_size.y)
|
||||
return position
|
||||
1
evolve-die-repeat/game_manager.gd.uid
Normal file
1
evolve-die-repeat/game_manager.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://vsbibc5fanou
|
||||
@@ -1,11 +1,11 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
@export var speed = 200
|
||||
var screen_size
|
||||
var damage = 1
|
||||
|
||||
func _ready():
|
||||
screen_size = get_viewport_rect().size
|
||||
var screen_size = get_viewport_rect().size
|
||||
GameManager.init_screen_size(screen_size.x, screen_size.y)
|
||||
|
||||
func _process(delta):
|
||||
velocity = Vector2.ZERO
|
||||
@@ -20,15 +20,5 @@ func _process(delta):
|
||||
|
||||
move_and_collide(speed * velocity * delta)
|
||||
#position += speed * velocity * delta
|
||||
position = get_boundaried_position(position)
|
||||
position = GameManager.get_boundaried_position(position)
|
||||
|
||||
# periodic boundary
|
||||
|
||||
func get_boundaried_position(position):
|
||||
## clamp
|
||||
#return position.clamp(Vector2.ZERO, screen_size)
|
||||
|
||||
## periodic
|
||||
position.x = wrapf(position.x, 0, screen_size.x)
|
||||
position.y = wrapf(position.y, 0, screen_size.y)
|
||||
return position
|
||||
|
||||
@@ -16,8 +16,11 @@ func _process(delta: float) -> void:
|
||||
func _physics_process(delta: float) -> void:
|
||||
self.move(Vector3(randfn(0, 1), randfn(0, 1), 0))
|
||||
|
||||
func move(destination: Vector3) -> void:
|
||||
move_and_collide(Vector2(destination.x, destination.y))
|
||||
func move(motion: Vector3) -> void:
|
||||
move_and_collide(Vector2(motion.x, motion.y)) # Moves along the given vector
|
||||
|
||||
# Apply boundary to new position
|
||||
position = GameManager.get_boundaried_position(position)
|
||||
|
||||
func die() -> void:
|
||||
sprite.play("Dying")
|
||||
|
||||
@@ -15,6 +15,10 @@ run/main_scene="uid://drgv154ei1vrl"
|
||||
config/features=PackedStringArray("4.5", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[autoload]
|
||||
|
||||
GameManager="*res://game_manager.gd"
|
||||
|
||||
[global_group]
|
||||
|
||||
player="All scenes that constitute players should be added here."
|
||||
|
||||
Reference in New Issue
Block a user