本文整理匯總了Golang中github.com/kirbywarp/rogue/engine.EntityDB.Has方法的典型用法代碼示例。如果您正苦於以下問題:Golang EntityDB.Has方法的具體用法?Golang EntityDB.Has怎麽用?Golang EntityDB.Has使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/kirbywarp/rogue/engine.EntityDB
的用法示例。
在下文中一共展示了EntityDB.Has方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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()
}
示例3: 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
}