Native Javascript, no third party libraries
Part-5 of the tutorial is about “Placing Enemies and kicking them (harmlessly)” but, I am feeling a bit non-violent at the moment, so I call it “Placing and bumping actors”.
Entity classprocgen.jsgetBlockingEntity() to mapMoveAction to check for blocking entities, rename
MoveAction a subclass of DirectionActionBumpAction subclassThe initial refactor is moving entities[] from the engine to the gameMap, including the function that renders them. Simple enough.
To patch up one of the many problems I left from Part-4, I moved Field of View creation into the movement action processing so that it does not update every frame. I also added a one-time FOV creation main.js so that the player can see things at the game start, before they first move. This small patch is here.
Some interesting bits from the next step:
undefined to be passed to the constructor, but I guess I will see what the tutorial has planned.spawn() method to entities, so they can add themselves into the entity list and be placed on the map. The tutorial uses something in Python called “deepcopy” for adding a clone of an object.The tutorial has us using a deep copy (Python copy.deepcopy() which I replace with JS structuredClone() and Object.setPrototypeOf()) of instantiated “plain objects” or “literals”. I don’t like the idea of defining data outside of my primary entrypoint in main() but, in the spirit of following the tutorial, I do it anyway. This updated method of creating actors can be seen here.