You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"math/rand/v2""github.com/mlange-42/ark/ecs"
)
// Position componenttypePositionstruct {
X, Yfloat64
}
// Velocity componenttypeVelocitystruct {
DX, DYfloat64
}
funcmain() {
// Create a new Worldworld:=ecs.NewWorld()
// Create a component mapper// Save mappers permanently and re-use them for best performancemapper:= ecs.NewMap2[Position, Velocity](world)
// Create entities with componentsforrange1000 {
_=mapper.NewEntity(
&Position{X: rand.Float64() *100, Y: rand.Float64() *100},
&Velocity{DX: rand.NormFloat64(), DY: rand.NormFloat64()},
)
}
// Create a filter// Save filters permanently and re-use them for best performancefilter:= ecs.NewFilter2[Position, Velocity](world)
// Time loopforrange5000 {
// Get a fresh query and iterate itquery:=filter.Query()
forquery.Next() {
// Component access through the Querypos, vel:=query.Get()
// Update component fieldspos.X+=vel.DXpos.Y+=vel.DY
}
}
}
Tools
ark-serde provides JSON serialization and deserialization for Ark's World.
ark-tools provides systems, a scheduler, and other useful stuff for Ark.
ark-pixel provides OpenGL graphics and live plots via the Pixel game engine.