SuperGameOfLife Play Now!
This is an example application using Ape-ECS Entity Component System. This is a my take on Conways Game of Life; cells can pick up potions that give them bufs and nerfs.
git clone https://github.com/esromneb/SuperGameOfLife.git
cd SuperGameOfLife
npm install
npm run devOr just play now in your browser.
- WorldParent.ts
- This is a class called
WorldParent - This class holds the
Worldinstance of Ape-ECS - This class has an
update()which ticks the systems andApe-ECSin the desired order - This file builds global
Entitesduring constructions- These
Entiteshave things like the mouse position, ui mode, and board dimensions.
- These
- CellSystem.ts
- This is the core game logic
- Every tick a query is run which searches for
Entiteswith theStepSimulationComponenton them.- In order to step the simulation, create an
Entitylike this anywhere in the application and on the nexttickit sill step. - The simulation can also be stepped backwards, this is done by the
HistorySystem
- In order to step the simulation, create an
calculateLife()is the main function, a bit complicated- Depending on the
PotionEffectComponentsthat are added to cells, original or modified "Game of Life" rules are followed - Cells which are spawned from parents that have effects will inherit a portion of the effect. The parents are then diluted.
- Depending on the
- The color of cells is calculated by
cellColor()
- BoardSystem.ts
- This file has a few helpers for mouse handlers.
- InputSystem.ts
- One of the more complicated files. This controls the
modeproperty on theUIStateComponentwhich is on thegentityEntity. - The
modecontrols what the mouse doesnormalclicking will add or remove a cellmutateclicking will cycle through cell types
- HistorySystem.ts
- Keeps a history log of step. This can be undone just like an "undo" feature
- This shows example code of how you might write a save/load game.
- SpriteSystem.ts
- Drives pixi.js do display sprites
- When tint or other attributes of sprites are changed, this system will update
pixi.jsin theupdate()function - This is a really basic / bad example of using Ape-ECS/pixi.js
- Components.ts
- Components has all the components used in this game.
- These files are boilerplate
Load.tsManager.tsScene.tsmain.ts
- Any dead cell which becomes a live cell will inherit effects from it's parents.
- The full effect of the potion is applied to all neighbor cells at the next step, there is no dilution.
- Cells which will consume potions are recorded but not consumed.
- Cell spawn/kill rules apply based on current effects
- Cells that still exist will consume potions.
Assets are from
- https://kyrise.itch.io/kyrises-free-16x16-rpg-icon-pack And the loose icon files were generated into a sprite sheet with
- https://github.com/krzysztof-o/spritesheet.js
