Compare commits
No commits in common. "8de3ee2c9a720bdc9b8f2c8eec88901dbed9db24" and "3262a8899c40a2678813c882aaaa909444ef23ed" have entirely different histories.
8de3ee2c9a
...
3262a8899c
|
|
@ -1,23 +0,0 @@
|
|||
extends Node
|
||||
|
||||
var screen_size = Vector2(1920.0, 1080.0) # Default screen size (this is a float for some reason)
|
||||
var viewport_size
|
||||
|
||||
func _ready() -> void:
|
||||
viewport_size = get_viewport().get_visible_rect().size
|
||||
|
||||
# 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 +0,0 @@
|
|||
uid://vsbibc5fanou
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
extends CharacterBody2D
|
||||
|
||||
@export var speed = 200
|
||||
var screen_size
|
||||
var damage = 1
|
||||
|
||||
func _ready() -> void:
|
||||
var screen_size = get_viewport_rect().size
|
||||
GameManager.init_screen_size(screen_size.x, screen_size.y)
|
||||
func _ready():
|
||||
screen_size = get_viewport_rect().size
|
||||
|
||||
func _process(delta):
|
||||
velocity = Vector2.ZERO
|
||||
|
|
@ -20,5 +20,15 @@ func _process(delta):
|
|||
|
||||
move_and_collide(speed * velocity * delta)
|
||||
#position += speed * velocity * delta
|
||||
position = GameManager.get_boundaried_position(position)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -2,39 +2,22 @@ extends AbstractPrey2D
|
|||
|
||||
@onready var sprite = get_node("AnimatedSprite2D")
|
||||
|
||||
# Mirroed sprites for periodic boundary
|
||||
var mirrorSprite1: Node2D
|
||||
var mirrorSprite2: Node2D
|
||||
var mirrorSprite3: Node2D
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
$AnimatedSprite2D.animation = "Healthy"
|
||||
$AnimatedSprite2D.play()
|
||||
|
||||
mirrorSprite1 = sprite.duplicate()
|
||||
mirrorSprite2 = sprite.duplicate()
|
||||
mirrorSprite3 = sprite.duplicate()
|
||||
|
||||
add_child(mirrorSprite1)
|
||||
add_child(mirrorSprite2)
|
||||
add_child(mirrorSprite3)
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
# Boundary mirroring
|
||||
_handle_wrapping()
|
||||
return
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
self.move(Vector3(randfn(0, 1), randfn(0, 1), 0))
|
||||
|
||||
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 move(destination: Vector3) -> void:
|
||||
move_and_collide(Vector2(destination.x, destination.y))
|
||||
|
||||
func die() -> void:
|
||||
sprite.play("Dying")
|
||||
|
|
@ -56,94 +39,3 @@ func handle_collision_player(player):
|
|||
self.die()
|
||||
else:
|
||||
sprite.play("Injured")
|
||||
|
||||
# FIXME: Doesn't work with injured sprite
|
||||
# Mirroring table:
|
||||
# |---|---|---|---|
|
||||
# | 4 | 3 | 4 | 3 |
|
||||
# |---|===|===|---|
|
||||
# | 1 ǁ 2 | 1 ǁ 2 |
|
||||
# |---ǁ---|---ǁ---|
|
||||
# | 4 ǁ 3 | 4 ǁ 3 |
|
||||
# |---|===|===|---|
|
||||
# | 1 | 2 | 1 | 2 |
|
||||
# |---|---|---|---|
|
||||
# If less than viewport size away from an edge, mirror over that edge (for seamless boundary)
|
||||
# NOTE: For this to look correctly the camera size should be smaller than half the screen port (in
|
||||
# any one dimension. Ideally, the difference between camera size and half the screen port is
|
||||
# at least the size of the prey sprite)
|
||||
func _handle_wrapping():
|
||||
mirrorSprite1.visible = false
|
||||
mirrorSprite2.visible = false
|
||||
mirrorSprite3.visible = false
|
||||
|
||||
# TODO: Assume viewport size << screen size and only draw according to GameManager.viewport_size
|
||||
# Find corresponding section of the screen
|
||||
if position.x < GameManager.screen_size.x/2 and position.y < GameManager.screen_size.y/2:
|
||||
# 2
|
||||
mirrorSprite1.visible = true
|
||||
mirrorSprite2.visible = true
|
||||
mirrorSprite3.visible = true
|
||||
|
||||
# Right
|
||||
#mirrorSprite1.position = Vector2(sprite.position.x + GameManager.screen_size.x, sprite.position.y)
|
||||
mirrorSprite1.position = Vector2(GameManager.screen_size.x, 0)
|
||||
# Diag
|
||||
#mirrorSprite2.position = Vector2(sprite.position.x + GameManager.screen_size.x, sprite.position.y + GameManager.screen_size.y)
|
||||
mirrorSprite3.position = Vector2(GameManager.screen_size.x, GameManager.screen_size.y)
|
||||
# Bottom
|
||||
#mirrorSprite3.position = Vector2(sprite.position.x, sprite.position.y + GameManager.screen_size.y)
|
||||
mirrorSprite2.position = Vector2(0, GameManager.screen_size.y)
|
||||
|
||||
|
||||
elif position.x < GameManager.screen_size.x/2:
|
||||
# 3
|
||||
mirrorSprite1.visible = true
|
||||
mirrorSprite2.visible = true
|
||||
mirrorSprite3.visible = true
|
||||
|
||||
# Top
|
||||
#mirrorSprite1.position = Vector2(sprite.position.x, sprite.position.y - GameManager.screen_size.y)
|
||||
mirrorSprite1.position = Vector2(0, - GameManager.screen_size.y)
|
||||
# Diag
|
||||
#mirrorSprite2.position = Vector2(sprite.position.x + GameManager.screen_size.x, sprite.position.y - GameManager.screen_size.y)
|
||||
mirrorSprite2.position = Vector2(GameManager.screen_size.x, - GameManager.screen_size.y)
|
||||
# Right
|
||||
#mirrorSprite3.position = Vector2(sprite.position.x + GameManager.screen_size.x, sprite.position.y)
|
||||
mirrorSprite3.position = Vector2(GameManager.screen_size.x, 0)
|
||||
|
||||
|
||||
elif position.y < GameManager.screen_size.y/2:
|
||||
# 1
|
||||
mirrorSprite1.visible = true
|
||||
mirrorSprite2.visible = true
|
||||
mirrorSprite3.visible = true
|
||||
|
||||
# Left
|
||||
#mirrorSprite1.position = Vector2(sprite.position.x - GameManager.screen_size.x, sprite.position.y)
|
||||
mirrorSprite1.position = Vector2(- GameManager.screen_size.x, 0)
|
||||
# Bottom
|
||||
#mirrorSprite2.position = Vector2(sprite.position.x, sprite.position.y + GameManager.screen_size.y)
|
||||
mirrorSprite2.position = Vector2(0, GameManager.screen_size.y)
|
||||
# Diag
|
||||
#mirrorSprite3.position = Vector2(sprite.position.x - GameManager.screen_size.x, sprite.position.y + GameManager.screen_size.y)
|
||||
mirrorSprite3.position = Vector2(- GameManager.screen_size.x, GameManager.screen_size.y)
|
||||
|
||||
|
||||
else:
|
||||
# 4
|
||||
mirrorSprite1.visible = true
|
||||
mirrorSprite2.visible = true
|
||||
mirrorSprite3.visible = true
|
||||
|
||||
# Left
|
||||
#mirrorSprite1.position = Vector2(sprite.position.x - GameManager.screen_size.x, sprite.position.y)
|
||||
mirrorSprite1.position = Vector2(- GameManager.screen_size.x, 0)
|
||||
# Diag
|
||||
#mirrorSprite2.position = Vector2(sprite.position.x - GameManager.screen_size.x, sprite.position.y - GameManager.screen_size.y)
|
||||
mirrorSprite2.position = Vector2(- GameManager.screen_size.x, - GameManager.screen_size.y)
|
||||
# Top
|
||||
#mirrorSprite3.position = Vector2(sprite.position.x, sprite.position.y - GameManager.screen_size.y)
|
||||
mirrorSprite3.position = Vector2(0, - GameManager.screen_size.y)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -25,4 +25,3 @@ func spawn_creature(scene, position: Vector2) -> void:
|
|||
var instance = scene.instantiate()
|
||||
instance.position = position
|
||||
add_child(instance)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,10 +15,6 @@ 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."
|
||||
|
|
|
|||
Loading…
Reference in New Issue