當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Entity.Component方法代碼示例

本文整理匯總了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
	}

}
開發者ID:EtienneBruines,項目名稱:engi,代碼行數:28,代碼來源:headless.go

示例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
}
開發者ID:EtienneBruines,項目名稱:engi,代碼行數:7,代碼來源:falling.go

示例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()
	}
}
開發者ID:EtienneBruines,項目名稱:bcigame,代碼行數:34,代碼來源:move.go

示例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)
	}
}
開發者ID:EtienneBruines,項目名稱:engi,代碼行數:11,代碼來源:hide.go

示例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)
	}
}
開發者ID:EtienneBruines,項目名稱:engi,代碼行數:12,代碼來源:mouse.go

示例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)
	}
}
開發者ID:EtienneBruines,項目名稱:engi,代碼行數:15,代碼來源:anim.go

示例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)
}
開發者ID:EtienneBruines,項目名稱:engi,代碼行數:21,代碼來源:scenes.go


注:本文中的github.com/paked/engi/ecs.Entity.Component方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。