本文整理汇总了Golang中github.com/paked/engi/ecs.Entity.Component方法的典型用法代码示例。如果您正苦于以下问题:Golang Entity.Component方法的具体用法?Golang Entity.Component怎么用?Golang Entity.Component使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/paked/engi/ecs.Entity
的用法示例。
在下文中一共展示了Entity.Component方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Update
func (c *ControlSystem) Update(entity *ecs.Entity, dt float32) {
//Check scheme
// -Move entity based on that
var control *ControlComponent
var space *engi.SpaceComponent
if !entity.Component(&space) || !entity.Component(&control) {
return
}
up := false
down := false
if control.Scheme == "WASD" {
up = engi.Keys.Get(engi.W).Down()
down = engi.Keys.Get(engi.S).Down()
} else {
up = engi.Keys.Get(engi.ArrowUp).Down()
down = engi.Keys.Get(engi.ArrowDown).Down()
}
if up {
space.Position.Y -= 800 * dt
}
if down {
space.Position.Y += 800 * dt
}
}
示例2: Update
func (fs *FallingSystem) Update(entity *ecs.Entity, dt float32) {
var space *engi.SpaceComponent
if !entity.Component(&space) {
return
}
space.Position.Y += 200 * dt
}
示例3: Update
func (a *MovementSystem) Update(entity *ecs.Entity, dt float32) {
var move *MovementComponent
if !entity.Component(&move) {
return
}
if !move.started {
move.started = true
move.timeLeft = float32(move.In.Seconds())
move.speedX = (move.From.X - move.To.X) / move.timeLeft
move.speedY = (move.From.Y - move.To.Y) / move.timeLeft
}
move.timeLeft -= dt
var space *engi.SpaceComponent
if !entity.Component(&space) {
return
}
space.Position.X -= move.speedX * dt
space.Position.Y -= move.speedY * dt
if move.timeLeft < 0 {
// Because we might move more than needed
space.Position.X -= move.speedX * move.timeLeft
space.Position.Y -= move.speedY * move.timeLeft
move.timeLeft = 0
}
if move.timeLeft == 0 {
entity.RemoveComponent(move)
move.Callback()
}
}
示例4: Update
func (c *HideSystem) Update(e *ecs.Entity, dt float32) {
var render *engi.RenderComponent
if !e.Component(&render) {
return
}
if rand.Int()%10 == 0 {
render.SetPriority(engi.Hidden)
} else {
render.SetPriority(engi.MiddleGround)
}
}
示例5: Update
func (c *ControlSystem) Update(entity *ecs.Entity, dt float32) {
var mouse *engi.MouseComponent
if !entity.Component(&mouse) {
return
}
if mouse.Enter {
engi.SetCursor(engi.Hand)
} else if mouse.Leave {
engi.SetCursor(engi.Arrow)
}
}
示例6: Update
func (c *ControlSystem) Update(entity *ecs.Entity, dt float32) {
var a *engi.AnimationComponent
if !entity.Component(&a) {
return
}
if engi.Keys.Get(engi.ArrowRight).Down() {
a.SelectAnimationByAction(WalkAction)
} else if engi.Keys.Get(engi.Space).Down() {
a.SelectAnimationByAction(SkillAction)
} else {
a.SelectAnimationByAction(StopAction)
}
}
示例7: Update
func (c *ScaleSystem) Update(e *ecs.Entity, dt float32) {
var render *engi.RenderComponent
if !e.Component(&render) {
return
}
var mod float32
if rand.Int()%2 == 0 {
mod = 0.1
} else {
mod = -0.1
}
if render.Scale().X+mod >= 15 || render.Scale().X+mod <= 1 {
mod *= -1
}
newScale := render.Scale()
newScale.AddScalar(mod)
render.SetScale(newScale)
}