- Notifications
You must be signed in to change notification settings - Fork4
Entity Component System framework for Ebitengine
License
sedyh/mizu
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Mizu is Entity Component System framework for Ebitengine.
Mizu is based onento, which is made bywfranczyk.
The name is short for Mizutaki, a japenese dish,where chicken pieces and vegetables stewed in asimple stock, and eaten with dipping sauce suchas ponzu.
- Very low boilerplate in exchange for a certain amount of reflection.
- Scene management.
- Compile defined components and entities.
To check all examples, visitthis page.
Mizu uses Go 1.20 at the current moment.
Getting the latest versionreflection API
:
go get -u github.com/sedyh/mizu
Getting the latest versiongenerics API
:
go get -u github.com/sedyh/mizu@experimental
Import this package
import"github.com/sedyh/mizu/pkg/engine"
Define components, attributes of your game objects.
// Position for any entity, if it needstypePosstruct {X,Yfloat64// Just a 2D point}// Velocity for any entity, if it needstypeVelstruct {L,Mfloat64// Also, 2D point}// Radius for any entity, if it needstypeRadstruct {Valuefloat64// Width value}
Define entities, your game objects.
// Your game objecttypeBallstruct {Pos// Ball positionVel// Ball velocityRad// Ball radius}
Define systems, your game mechanics that will work for aspecific set of components.
// You can go through all entities that have a certain set of// components specifying the requirements in the fields of the systemtypeVelocitystruct {*Pos// Current entity position*Vel// Current entity velocity}// Apply velocity for each entity that has Pos and Velfunc (v*Velocity)Update(w engine.World) {// If they are registered components, they will not be nilv.Pos.X+=v.Vel.Lv.Pos.Y+=v.Vel.M}// When you need many sets of components// in one system, you can use the viewstypeRenderstruct {}// Render one framefunc (r*Render)Draw(w engine.World,screen*ebiten.Image) {// But choose the right entities yourselfview:=w.View(Pos{},Rad{})view.Each(func(entity engine.Entity) {varpos*Posvarrad*Radentity.Get(&pos,&rad)ebitenutil.DrawRect(screen,pos.X-rad.Value/2,pos.Y-rad.Value/2,rad.Value,rad.Value,colornames.Aliceblue, ) })}
Define scenes, where will all this live.
typeGamestruct{}// Main scene, you can use that for settings or main menufunc (g*Game)Setup(w engine.World) {w.AddComponents(Pos{},Vel{},Rad{})w.AddEntities(&Ball{Pos{0,0},Vel{4,4},Rad{10}})w.AddSystems(&Velocity{},&Render{})}
Run the game.
// Provides its own ebiten.Game implementationg:=engine.NewGame(&Game{})iferr:=ebiten.RunGame(g);err!=nil {log.Fatal(err)}
Please visit ourwiki for a helpful articles and best practices about Mizu.
About
Entity Component System framework for Ebitengine