Back with some game programming : if you make a dungeons & dragons world you might want to put a room inside e.g. a bag of wonders, that room could already contain the same bag of wonders. Below is some code which morphs an Gameobject which is a dimension in a place in the world e.g.
an Entity/MovingEntity becomes a EntityRec, a recursive entity. You only need an interrupt and a loop for checking whether there is recursion in the world. Note that it is perl6 :
class PaganVision2::Entity is GameObject
{
has $!staticimagelib ### StateImagelibrary.pm6
method update(%keys, %keydefs) {
}
method draw($renderer) {
$!staticimagelib.getImage().display($renderer);
}
}
class PaganVision2::MovingEntity is GameObject
{
has $!direction;
has $!moving;
has $!dx; ### move x + dx
has $!dy;
has $!leftstaticimagelib ### StateImagelibrary.pm6
has $!righttstaticimagelib
has $!upstaticimagelib
has $!downstaticimagelib
has $!leftimagelib
has $!rightimagelib
has $!upimagelib
has $!downimagelib
has $!currentlibrary;
method update(%keys, %keydefs) {
foreach $e in %keydefs.keys {
if (not $e[0]) { ### UP
$!currentlibrary = $upstaticimagelib;
} elif (not $[1]) { ### DOWN
$!currentlibrary = $downstaticimagelib
+;
} elif (not $e[2]) { ### LEFT
$!currentlibrary = $leftstaticimagelib
+;
} elif (not $e[3]) { ### RIGHT
$!currentlibrary = $rightstaticimageli
+b;
}
}
}
method draw($renderer) {
$!currentlibrary.getImage().display($renderer);
}
}
### Note that Room is a GameObject and that it can be put in e.g. a ba
+g of wonders
class PaganVision2::Room is GameObject
{
method BUILD() {
### Image $!bg_image .= new;
}
}
### This entity is recursive which means that
### it contains things that contain this entity
### If an Entity becomes recursive it
### morphs into EntityRec in the game engine
class PaganVision2::EntityRec : is Entity
{
method update(%keys, %keydefs) {
}
method draw($renderer) {
$!staticimagelib.getImage().display($renderer);
}
}