notSpore/evolve-die-repeat/molecular/molecular_player.gd

35 lines
811 B
GDScript

extends CharacterBody2D
@export var speed = 200
var screen_size
var damage = 1
func _ready():
screen_size = get_viewport_rect().size
func _process(delta):
velocity = Vector2.ZERO
if Input.is_action_pressed("move_right"):
velocity.x += 1
if Input.is_action_pressed("move_left"):
velocity.x -= 1
if Input.is_action_pressed("move_down"):
velocity.y += 1
if Input.is_action_pressed("move_up"):
velocity.y -= 1
move_and_collide(speed * velocity * delta)
#position += speed * velocity * delta
position = 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