ft: wrapping manager overhaul
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
extends CharacterBody2D
|
||||
class_name NPC2D
|
||||
extends Node
|
||||
class_name NPC
|
||||
|
||||
@export var maxHealth: int = 0
|
||||
var health: int = maxHealth
|
||||
6
evolve-die-repeat/shared/npc/abstractNPC.tscn
Normal file
6
evolve-die-repeat/shared/npc/abstractNPC.tscn
Normal file
@@ -0,0 +1,6 @@
|
||||
[gd_scene format=3 uid="uid://biup0eej85fq2"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://biu3sctw15ga" path="res://shared/npc/abstractNPC.gd" id="1_xlqdr"]
|
||||
|
||||
[node name="NPC" type="Node" unique_id=272773627]
|
||||
script = ExtResource("1_xlqdr")
|
||||
@@ -1,5 +1,5 @@
|
||||
extends NPC2D
|
||||
class_name AbstractPredator2D
|
||||
extends NPC
|
||||
class_name AbstractPredator
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
@@ -1,7 +1,7 @@
|
||||
[gd_scene format=3 uid="uid://b7wqd5owafn6g"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://biup0eej85fq2" path="res://shared/npc/npc2D.tscn" id="1_4llks"]
|
||||
[ext_resource type="Script" uid="uid://dgfimmq53whll" path="res://shared/npc/predator2D.gd" id="2_rj1ok"]
|
||||
[ext_resource type="PackedScene" uid="uid://biup0eej85fq2" path="res://shared/npc/abstractNPC.tscn" id="1_4llks"]
|
||||
[ext_resource type="Script" uid="uid://dgfimmq53whll" path="res://shared/npc/abstractPredator.gd" id="2_rj1ok"]
|
||||
|
||||
[node name="AbstractPredator" unique_id=912624667 instance=ExtResource("1_4llks")]
|
||||
script = ExtResource("2_rj1ok")
|
||||
@@ -1,5 +1,5 @@
|
||||
extends NPC2D
|
||||
class_name AbstractPrey2D
|
||||
extends NPC
|
||||
class_name AbstractPrey
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
7
evolve-die-repeat/shared/npc/abstractPrey.tscn
Normal file
7
evolve-die-repeat/shared/npc/abstractPrey.tscn
Normal file
@@ -0,0 +1,7 @@
|
||||
[gd_scene format=3 uid="uid://bvsdg1v3ksixy"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://biup0eej85fq2" path="res://shared/npc/abstractNPC.tscn" id="1_fdrej"]
|
||||
[ext_resource type="Script" uid="uid://76jxpubyd8wp" path="res://shared/npc/abstractPrey.gd" id="2_xkhwn"]
|
||||
|
||||
[node name="AbstractPrey" unique_id=1075345151 instance=ExtResource("1_fdrej")]
|
||||
script = ExtResource("2_xkhwn")
|
||||
@@ -1,10 +0,0 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://biup0eej85fq2"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://biu3sctw15ga" path="res://shared/npc/npc2D.gd" id="1_ucjfp"]
|
||||
|
||||
[node name="NPC" type="CharacterBody2D"]
|
||||
script = ExtResource("1_ucjfp")
|
||||
|
||||
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
|
||||
position = Vector2(7.215866, -0.5034294)
|
||||
polygon = PackedVector2Array(-8.831272, -2.3390446, -5.7760534, -2.3993049, -4.0230684, 0.41277456, -5.8890305, 2.9948444, -8.862037, 2.9326901, -10.268076, 0.28495264)
|
||||
@@ -1,7 +0,0 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://bvsdg1v3ksixy"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://biup0eej85fq2" path="res://shared/npc/npc2D.tscn" id="1_2m1le"]
|
||||
[ext_resource type="Script" uid="uid://76jxpubyd8wp" path="res://shared/npc/prey2D.gd" id="2_dny00"]
|
||||
|
||||
[node name="AbstractPrey" instance=ExtResource("1_2m1le")]
|
||||
script = ExtResource("2_dny00")
|
||||
@@ -30,7 +30,7 @@ func _spawn_random() -> void:
|
||||
|
||||
func _spawn_creature(position: Vector2) -> void:
|
||||
var instance = scene.instantiate()
|
||||
instance.position = position
|
||||
instance.set_position(position)
|
||||
add_child(instance)
|
||||
if instance.has_signal("died"):
|
||||
#instance.died.connect(GameManager.foodManager._spawn_food_on_position)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
class_name WrappingManager extends Node
|
||||
|
||||
@export var sprite: AnimatedSprite2D
|
||||
@export var shape: Node # FIXME (also in refactor see below) this is bad.
|
||||
@export var dupFlags: int = 15
|
||||
|
||||
# Mirrored sprites for periodic boundary
|
||||
var mirrors: Array
|
||||
@@ -10,29 +9,22 @@ var mirrors: Array
|
||||
func _ready() -> void:
|
||||
await owner.ready
|
||||
|
||||
mirrors.append(Area2D.new())
|
||||
mirrors.append(Area2D.new())
|
||||
mirrors.append(Area2D.new())
|
||||
|
||||
# TODO: npc overhaul; make npc2d (and child classes) inherit from Node instead of Area2d.
|
||||
# Each entity should have Area2d -> collisionshape2d + animatedsprite2d. We then duplicate this area2d instead of the bullshit thats happening here
|
||||
# note taht the below bs also does not work, as the (freshly instantiated) area2ds have none of the signals connected. The above refactor will fix this.
|
||||
for m in mirrors:
|
||||
for i in owner.get_groups():
|
||||
if not str(i).begins_with("_"):
|
||||
m.add_to_group(i)
|
||||
m.set_collision_layer(owner.get_collision_layer())
|
||||
m.set_collision_mask(owner.get_collision_mask())
|
||||
m.add_child(sprite.duplicate())
|
||||
m.add_child(shape.duplicate())
|
||||
owner.call_deferred("add_child", m)
|
||||
# add mirrors
|
||||
for _i in range(3):
|
||||
var dup = owner.collision.duplicate(dupFlags)
|
||||
mirrors.append(dup)
|
||||
owner.call_deferred("add_child", dup)
|
||||
#for i in owner.get_groups():
|
||||
# if not str(i).begins_with("_"):
|
||||
# m.add_to_group(i)
|
||||
if dup.has_method("duplicate_init"):
|
||||
dup.duplicate_init()
|
||||
|
||||
_handle_wrapping()
|
||||
|
||||
func play_sprite(anim: String) -> void:
|
||||
mirrors[0].get_node("AnimatedSprite2D").play(anim)
|
||||
mirrors[1].get_node("AnimatedSprite2D").play(anim)
|
||||
mirrors[2].get_node("AnimatedSprite2D").play(anim)
|
||||
for m in mirrors:
|
||||
m.get_node("Sprite").play(anim)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
_handle_wrapping()
|
||||
@@ -52,39 +44,42 @@ func _process(delta: float) -> void:
|
||||
# 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():
|
||||
func _handle_wrapping():
|
||||
for m in mirrors:
|
||||
m.global_rotation = owner.collision.global_rotation
|
||||
|
||||
# TODO: Assume viewport size << screen size and only draw according to GameManager.viewport_size
|
||||
# Find corresponding section of the screen
|
||||
if owner.position.x < GameManager.screen_size.x/2 and owner.position.y < GameManager.screen_size.y/2:
|
||||
if owner.collision.position.x < GameManager.screen_size.x/2 and owner.collision.position.y < GameManager.screen_size.y/2:
|
||||
# Right
|
||||
mirrors[0].global_position = owner.global_position + Vector2(GameManager.screen_size.x, 0)
|
||||
mirrors[0].global_position = owner.collision.global_position + Vector2(GameManager.screen_size.x, 0)
|
||||
# Diag
|
||||
mirrors[2].global_position = owner.global_position + Vector2(GameManager.screen_size.x, GameManager.screen_size.y)
|
||||
mirrors[2].global_position = owner.collision.global_position + Vector2(GameManager.screen_size.x, GameManager.screen_size.y)
|
||||
# Bottom
|
||||
mirrors[1].global_position = owner.global_position + Vector2(0, GameManager.screen_size.y)
|
||||
mirrors[1].global_position = owner.collision.global_position + Vector2(0, GameManager.screen_size.y)
|
||||
|
||||
|
||||
elif owner.position.x < GameManager.screen_size.x/2:
|
||||
elif owner.collision.position.x < GameManager.screen_size.x/2:
|
||||
# Top
|
||||
mirrors[0].global_position = owner.global_position + Vector2(0, - GameManager.screen_size.y)
|
||||
mirrors[0].global_position = owner.collision.global_position + Vector2(0, - GameManager.screen_size.y)
|
||||
# Diag
|
||||
mirrors[1].global_position = owner.global_position + Vector2(GameManager.screen_size.x, - GameManager.screen_size.y)
|
||||
mirrors[1].global_position = owner.collision.global_position + Vector2(GameManager.screen_size.x, - GameManager.screen_size.y)
|
||||
# Right
|
||||
mirrors[2].global_position = owner.global_position + Vector2(GameManager.screen_size.x, 0)
|
||||
mirrors[2].global_position = owner.collision.global_position + Vector2(GameManager.screen_size.x, 0)
|
||||
|
||||
|
||||
elif owner.position.y < GameManager.screen_size.y/2:
|
||||
elif owner.collision.position.y < GameManager.screen_size.y/2:
|
||||
# Left
|
||||
mirrors[0].global_position = owner.global_position + Vector2(- GameManager.screen_size.x, 0)
|
||||
mirrors[0].global_position = owner.collision.global_position + Vector2(- GameManager.screen_size.x, 0)
|
||||
# Bottom
|
||||
mirrors[1].global_position = owner.global_position + Vector2(0, GameManager.screen_size.y)
|
||||
mirrors[1].global_position = owner.collision.global_position + Vector2(0, GameManager.screen_size.y)
|
||||
# Diag
|
||||
mirrors[2].global_position = owner.global_position + Vector2(- GameManager.screen_size.x, GameManager.screen_size.y)
|
||||
mirrors[2].global_position = owner.collision.global_position + Vector2(- GameManager.screen_size.x, GameManager.screen_size.y)
|
||||
|
||||
else:
|
||||
# Left
|
||||
mirrors[0].global_position = owner.global_position + Vector2(- GameManager.screen_size.x, 0)
|
||||
mirrors[0].global_position = owner.collision.global_position + Vector2(- GameManager.screen_size.x, 0)
|
||||
# Diag
|
||||
mirrors[1].global_position = owner.global_position + Vector2(- GameManager.screen_size.x, - GameManager.screen_size.y)
|
||||
mirrors[1].global_position = owner.collision.global_position + Vector2(- GameManager.screen_size.x, - GameManager.screen_size.y)
|
||||
# Top
|
||||
mirrors[2].global_position = owner.global_position + Vector2(0, - GameManager.screen_size.y)
|
||||
mirrors[2].global_position = owner.collision.global_position + Vector2(0, - GameManager.screen_size.y)
|
||||
|
||||
Reference in New Issue
Block a user