Medieval simulation and city builder game for the browser. Built with a custom ECS, declarative UI and rendering to a 2D canvas.
Note
This game is currently in development. There will be things that are broken/not working/not implemented.
You can either clone this repository and run it based on the instructions on how to run the game below, or try the last version out at https://kingdomarchitect.netlify.app
- Gather resources build buildings
- Discover new lands
- Spawn heroes and defend against enemy mobs
Tap the item you would like to select or activate
WASD
: Use the W,A,S,D keys to move the cursor or selected items directionallyEscape
: Go back, cancel or unselectE
: Activate the current selection or action1-9
: Activate the n'th actionbar buttonM
: Cycle between focus groupsJ
: Activate the first secondary actionbar itemK
: Activate the second secondary actionbar item
Kingdom architects is intended to be a combined simulation and city building game around building your own kingdom and protecting it from hordes of evil monsters. Explore, build and complete quests. It is intended to be single or multi-player and playable both on mobile screens and desktop size clients. Your kingdom might last for decades or only seconds, who knows what the legends of your reign will be.
- Make it fun.
- Play both using the keyboard and mouse/touch.
- Only depend on browser-apis, no extra libraries or third party frameworks.
- Progress in some way should be able to be carried over into future kingdoms, rogue-lite style.
A declarative UI for making UI's. Features non global hooks, state reconciliation and a combined layout and composition phase.
Example:
const healthbar = createComponent<{ initialHealth: number }>(
({ props, withState, withEffect }) => {
withEffect(() => {
console.log('mounted!')
return () => {
console.log('disposed!');
}
})
const [health, setHealth] = withState(props.initialHealth)
return uiColumn({
children: [
uiText({
content: `current health: ${health}`,
textStyle: defaultTextStyle,
}),
uiButton({
label: 'increase hp',
onClick: () => {
setHealth(health + 1)
}
})
],
height: wrapUiSize,
width: fillUiSize,
})
},
);
An implementation of an ECS system with behaviours organised as systems and an entity tree that can be queried for components.
A rendering system with drawing for shapes, nine-patch sprites and animations via generated spritesheets.
A HUD state system for navigation.
Mulitplayer and singleplayer is generalised using a server running either remote or in a webworker.
Great, if you feel like it aligns with the about and goal for the project open a thread under discussion with some details on your idea.
Fantastic, getting bug reports is important. File an issue with steps to reproduce π.
Wow, thanks! First see if there are any open issues or open a thread under discussion on the improvement or contribution you would like to make.
- Node v20 or higher
- An editor to edit typescript with
Install the required development packages (typescript and rolldown) with npm i
. Build and bundle the typescript source with npm run build
. npm run start
will start a development server and give you a link to test out the game locally. Use your favourite IDE to edit any typescript game code. If you want to contribute on the development on the game, here follows some notes on the architecture for the game/application and some tools used during development.
The architecture of the game is loosely based around three concepts:
- A timer ticking each second
- An entity tree and component system
- A state system for the HUD with a declarative UI
Every second a timer invokes two code paths for most of the game components. An update function and a draw function. The update function should only be invoked once per timer tick, but the draw method can be called multiple. Be wary of putting logic depending on a timed update in the draw code path as it will be invoked potentially more than one time per tick when input events happen or other actions are perfomed. Panning the gameworld is a good example of when the draw method of the different classes are invoked, this method is executed on each drag event from the browser.
A entity component system is in the works where all items in the world are tied to an entity with some amount of componets on it handle updates and draw actions. Some exceptions exists like tiles where all tiles belong to the same entity with a component that is responsible for drawing and handling all the tiles. All new game world items and data will be stored in components on entities. If you create new components or jobs, remember to run the Typelistgen tooling
Items that are not directly connected to the game world, like menus and screens are considered InteractionStates
these are screens that can be navigated to and from in a stack. States can draw custom actions and handle events as well as setting up complex views using the custom UI system
Folder name | Function |
---|---|
asset | code related to load and lookup of assets can be found here. |
common | generic code that can be used across the whole application |
data | defintions and lists for the items/buildings in game |
game | the game logic, both hud and world code |
input | code related to recieveing input from the browser |
path | pathfinding and graphing code |
persistence | logic for saving and loading state |
rendering | code related to drawing pixels on the game canvas |
ui | a custom ui system for setting up GUI elements and screens |
Typescript and rollup is used for transpiling, typechecking and bundling the code.
This is performed with the build
npm task.
Note: The test suite uses the node test runner and requires node >=20.
Some tests already exists for the game, these are made with the built in node test runner. Note that files are not automatically built when tests are run. These needs to be built independently (however the npm test
script includes the tsc step before the tests are run). Some files are currently just scaffold and some contain actuall test code. Tests can be run with npm test
.
- Task:
spritepack
- Note: typescript sources needs to be built before the task can run
To optimize, remove unused parts of images and bundling them together into a spritebin the spritepack
npm task can be used. If you update any of the images in asset
you need to run this task to get the updated version to show up in game. The source for this can be found in ts/tool/spritepack
.
No questions so far