• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang engine.EntityDB类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/kirbywarp/rogue/engine.EntityDB的典型用法代码示例。如果您正苦于以下问题:Golang EntityDB类的具体用法?Golang EntityDB怎么用?Golang EntityDB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了EntityDB类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: CreateMap

/*
CreateMap creates a new map region entity and returns it
*/
func CreateMap(db *engine.EntityDB) engine.Entity {
	retval := db.New("map")

	// Register a chunk generator on the map
	emap := db.Get(retval, "map").(*base.EntityMap)
	emap.RegisterChunkGenerator(NewStoneFieldGenerator(db, .05))

	return retval
}
开发者ID:kirbywarp,项目名称:rogue,代码行数:12,代码来源:main.go


示例2: RegisterTypes

func RegisterTypes(db *engine.EntityDB) {
	db.Register("ai", CreateAI, CloneAI)
	db.Register("art", CreateArt, CloneArt)
	db.Register("position", CreatePosition, ClonePosition)
	db.Register("movement", CreateMovement, CloneMovement)
	db.Register("map", CreateEntityMap, CloneEntityMap)
	db.Register("health", CreateHealth, CloneHealth)
	db.Register("attack", CreateAttack, CloneAttack)
}
开发者ID:kirbywarp,项目名称:rogue,代码行数:9,代码来源:components.go


示例3: RenderMapAt

/*
RenderMapAt draws a portion of the map centered at the given entity
*/
func RenderMapAt(db *engine.EntityDB, eid engine.Entity) {
	width, height := termbox.Size()

	pos := db.Get(eid, "position").(*base.Position)
	emap := db.Get(pos.R, "map").(*base.EntityMap)

	for y := 0; y < height; y++ {
		py := pos.Y + int64(y-height/2)
		for x := 0; x < width; x++ {
			px := pos.X + int64(x-width/2)

			// Search for the highest entity on the map in the same general layer
			//  as the passed entity that can be drawn.  This will need to be more
			//  formal in the future (not hardcoded knowing the player is on z level
			//  1, tiles are on z level 0, and the bat at z level 2)
			topArt := &base.Art{}
			for i := int64(1); i >= -1; i-- {
				entity := emap.Get(px, py, pos.Z+i)
				if db.Has(entity, "art") {
					topArt = db.Get(entity, "art").(*base.Art)
					break
				}
			}

			// And draw the found art, which will be an empty black square
			//  if nothing was found
			Draw(x, height-1-y, topArt.Symbol, topArt.Fg, topArt.Bg)
		}
	}
	termbox.Flush()
}
开发者ID:kirbywarp,项目名称:rogue,代码行数:34,代码来源:main.go


示例4: NewStoneFieldGenerator

func NewStoneFieldGenerator(db *engine.EntityDB, fill float64) *StoneFieldGenerator {
	grass := db.New()
	db.Set(grass, "art", base.NewArt('.', 0, 1, 0, 0, 0, 0))
	stone := db.New()
	db.Set(stone, "art", base.NewArt('#', .7, .7, .7, 0, 0, 0))
	return &StoneFieldGenerator{stone: stone, grass: grass, fill: fill}
}
开发者ID:kirbywarp,项目名称:rogue,代码行数:7,代码来源:main.go


示例5: Act

func (ai *FollowAI) Act(db *engine.EntityDB, eid engine.Entity) {
	epos := db.Get(eid, "position").(*base.Position)
	tpos := db.Get(ai.Target, "position").(*base.Position)

	dx, dy := int64(0), int64(0)
	if epos.X > tpos.X+1 || epos.X < tpos.X-1 {
		dx = int64(math.Copysign(1, float64(tpos.X-epos.X)))
	}
	if epos.Y > tpos.Y+1 || epos.Y < tpos.Y-1 {
		dy = int64(math.Copysign(1, float64(tpos.Y-epos.Y)))
	}

	// Since the bat is situated at z-level 2, it will never find
	// a wall with art symbol '#' at one level below, so this move
	// function still allows the bat to fly over stones! ^_^
	// Hence the "+1" for the z; so the bat stays one level above
	//  the player.
	base.HelperMove(db, eid, dx, dy, tpos.Z-epos.Z+1)
}
开发者ID:kirbywarp,项目名称:rogue,代码行数:19,代码来源:main.go


示例6: HelperPlace

/*
HelperPlace puts an entity on to the map at a particular position
*/
func HelperPlace(db *engine.EntityDB, eid engine.Entity, r engine.Entity, x, y, z int64) {
	if !db.Has(r, "map") {
		return
	}

	db.Get(r, "map").(*EntityMap).Set(x, y, z, eid)
	pos := db.Create(eid, "position").(*Position)
	pos.R, pos.X, pos.Y, pos.Z = r, x, y, z
}
开发者ID:kirbywarp,项目名称:rogue,代码行数:12,代码来源:helpers.go


示例7: SystemMove

/*
SystemMove applies makes every entity with movement try to move in the map
*/
func SystemMove(db *engine.EntityDB) {
	for _, eid := range db.Search("movement", "position") {
		pos := db.Get(eid, "position").(*Position)
		mov := db.Get(eid, "movement").(*Movement)
		emap := db.Get(pos.R, "map").(*EntityMap)

		// Prevent entities from moving on top of each other, temporarily
		if emap.Get(pos.X+mov.Dx, pos.Y+mov.Dy, pos.Z+mov.Dz) != 0 {
			continue
		}

		// Move and update the map
		emap.Set(pos.X, pos.Y, pos.Z, 0)
		pos.X += mov.Dx
		pos.Y += mov.Dy
		pos.Z += mov.Dz
		emap.Set(pos.X, pos.Y, pos.Z, eid)
	}
}
开发者ID:kirbywarp,项目名称:rogue,代码行数:22,代码来源:systems.go


示例8: HelperMove

/*
HelperMove validates an entity's attempt to move and sets the entity's
movement component appropriately.  Returns true if the entity could move
*/
func HelperMove(db *engine.EntityDB, eid engine.Entity, dx, dy, dz int64) bool {
	if !db.Has(eid, "movement", "position") {
		return false
	}

	pos := db.Get(eid, "position").(*Position)
	emap := db.Get(pos.R, "map").(*EntityMap)
	mov := db.Get(eid, "movement").(*Movement)

	// TODO: fix layer system and make it real.
	// Check the entities in the layer beneath the move target
	// to see if the entity is a wall (with art symbol '#')
	target := emap.Get(pos.X+dx, pos.Y+dy, pos.Z+dz-1)
	if db.Has(target, "art") && db.Get(target, "art").(*Art).Symbol == '#' {
		mov.Dx = 0
		mov.Dy = 0
		mov.Dz = 0
		return false
	}

	// Move can be done!
	mov.Dx = dx
	mov.Dy = dy
	mov.Dz = dz
	return true
}
开发者ID:kirbywarp,项目名称:rogue,代码行数:30,代码来源:helpers.go


示例9: SystemAct

/*
SystemAct allows each entity with an AI to attempt to act
*/
func SystemAct(db *engine.EntityDB) {
	for _, eid := range db.Search("ai", "position") {
		ai := db.Get(eid, "ai").(*AI)
		ai.Controller.Act(db, eid)
	}
}
开发者ID:kirbywarp,项目名称:rogue,代码行数:9,代码来源:systems.go



注:本文中的github.com/kirbywarp/rogue/engine.EntityDB类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang pt.Scene类代码示例发布时间:2022-05-23
下一篇:
Golang s3.New函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap