Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/mizuPublic

Entity Component System framework for Ebitengine

License

NotificationsYou must be signed in to change notification settings

sedyh/mizu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mizu Mizu

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.

Contents

Features

  • Very low boilerplate in exchange for a certain amount of reflection.
  • Scene management.
  • Compile defined components and entities.

Examples

To check all examples, visitthis page.

Installation

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

Usage

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)}

Wiki

Please visit ourwiki for a helpful articles and best practices about Mizu.


[8]ページ先頭

©2009-2025 Movatter.jp