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

Golang area.Area类代码示例

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

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



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

示例1: FOV

func (c *Creature) FOV(a *area.Area) (cs map[coord.Coord]struct{}) {
	radius := c.Sight
	cs = make(map[coord.Coord]struct{})
	for x := c.X() - radius; x <= c.X()+radius; x++ {
		for y := c.Y() - radius; y <= c.Y()+radius; y++ {
			// Distance between creature x and y coordinates and sight radius.
			dx := float64(x - c.X())
			dy := float64(y - c.Y())

			// Distance between creature and sight radius.
			dist := math.Sqrt(math.Pow(dx, 2) + math.Pow(dy, 2))

			// Discriminate coordinates which are outside of the circle.
			if dist > float64(radius) {
				continue
			}

			// Ignore hero.
			for _, p := range get_line(c.X(), c.Y(), x, y)[1:] {
				if !a.ExistsXY(p.X, p.Y) {
					break
				}

				cs[p] = struct{}{}

				// Terrain that breaks line of sight.
				if !a.IsXYPathable(p.X, p.Y) {
					break
				}
			}
		}
	}
	return cs
}
开发者ID:karlek,项目名称:reason,代码行数:34,代码来源:fov.go


示例2: Objects

// Objects is a debug function to generate objects.
func Objects(a *area.Area, num int) {
	o := make(map[coord.Coord]area.DrawPather, a.Width*a.Height)

	log.Println(len(object.Objects))
	var objectList = make([]object.Object, len(object.Objects))
	var index int
	for _, o := range object.Objects {
		objectList[index] = o
		index++
	}
	for x := 0; x < a.Width; x++ {
		for y := 0; y < a.Height; y++ {
			if num <= 0 {
				return
			}

			if util.RandInt(0, 50) != 42 {
				continue
			}

			if !a.IsXYPathable(x, y) {
				continue
			}

			c := coord.Coord{X: x, Y: y}
			o[c] = objectList[util.RandInt(0, len(objectList))].New()
		}
	}
	a.Objects = o
}
开发者ID:karlek,项目名称:reason,代码行数:31,代码来源:objects.go


示例3: Mobs

// Mobs is a debug function to add mobs to the map.
func Mobs(a *area.Area, num int) {
	var mobList = []creature.Creature{
		// creature.Beastiary["echidna"],
		creature.Beastiary["gobbal"],
		creature.Beastiary["tofu"],
		creature.Beastiary["iop"],
		creature.Beastiary["arachnee"],
	}
	for x := 0; x < a.Width; x++ {
		for y := 0; y < a.Height; y++ {
			if num <= 0 {
				return
			}

			if util.RandInt(0, 50) != 42 {
				continue
			}

			if !a.IsXYPathable(x, y) {
				continue
			}

			g := mobList[util.RandInt(0, len(mobList))]
			g.Inventory = make(creature.Inventory)

			c := coord.Coord{X: x, Y: y}

			g.SetX(x)
			g.SetY(y)

			a.Monsters[c] = &g
			num--
		}
	}
}
开发者ID:karlek,项目名称:reason,代码行数:36,代码来源:mobs.go


示例4: HeroMovement

func HeroMovement(ev termbox.Event, a *area.Area) int {
	var col *area.Collision
	var err error
	switch ev.Key {
	case ui.MoveUpKey:
		col, err = a.MoveUp(&creature.Hero)
	case ui.MoveDownKey:
		col, err = a.MoveDown(&creature.Hero)
	case ui.MoveLeftKey:
		col, err = a.MoveLeft(&creature.Hero)
	case ui.MoveRightKey:
		col, err = a.MoveRight(&creature.Hero)
	default:
		return 0
	}
	// Creature moved out of bounds.
	if err != nil {
		return 0
	}
	stk, ok := a.Items[creature.Hero.Coord()]
	if ok && stk.Len() > 0 {
		if stk.Len() > 1 {
			status.Println("You find a heap of items on the ground:", termbox.ColorWhite)
		} else {
			status.Println("You find a single item on the ground:", termbox.ColorWhite)
		}
		print := "   "
		for _, s := range []area.DrawPather(*stk) {
			i, _ := s.(item.DrawItemer)
			if stk.Len() < 4 {
				print += i.Name() + ", "
			} else {
				print += string(i.Graphic().Ch) + ", "
			}
		}
		status.Println(print[:len(print)-2], termbox.ColorBlack+termbox.AttrBold)
	}
	// Successful movement.
	if col == nil {
		return creature.Hero.Speed
	}
	// Another creature occupied that tile -> battle!
	if c, ok := col.S.(*creature.Creature); ok {
		creature.Hero.Battle(c, a)
		return creature.Hero.Speed
	}
	// Hero walked into an object.
	if obj, ok := a.Objects[col.Coord()].(*object.Object); ok {
		// If the hero walked into a door -> open!
		switch obj.Name() {
		case "door (closed)":
			a.Objects[col.Coord()] = object.Objects["door (open)"].New()
			status.Println("You open the closed door.", termbox.ColorBlack+termbox.AttrBold)
			return creature.Hero.Speed
		}
	}
	return 0
}
开发者ID:karlek,项目名称:reason,代码行数:58,代码来源:hero.go


示例5: Action

// Action performs simple AI for a creature.
func (c *Creature) Action(a *area.Area) int {
	if i := a.Items[c.Coord()].Peek(); i != nil {
		c.PickUp(a)
		return c.Speed
	}
	if c.Equipment.MainHand == nil && len(c.Inventory) > 0 {
		for _, pos := range item.Positions {
			if i, ok := c.Inventory[pos]; ok {
				if !item.IsEquipable(i) {
					break
				}
				if i.Name() != "Iron Sword" {
					break
				}
				c.Equip(pos)
				return c.Speed
			}
		}
	}

	var col *area.Collision
	var err error
	if c.X() < Hero.X() {
		col, err = a.MoveRight(c)
	} else if c.X() > Hero.X() {
		col, err = a.MoveLeft(c)
	} else if c.Y() < Hero.Y() {
		col, err = a.MoveDown(c)
	} else if c.Y() > Hero.Y() {
		col, err = a.MoveUp(c)
	}
	if err != nil {
		// log.Println("err / collide?")
		return c.Speed
		// return 0
	}
	if col == nil {
		return c.Speed
	}
	if mob, ok := col.S.(*Creature); ok {
		if mob.IsHero() {
			c.Battle(mob, a)
			return c.Speed
		}
	}

	// If all fails, creature waits.
	return c.Speed
}
开发者ID:karlek,项目名称:reason,代码行数:50,代码来源:ai.go


示例6: Items

// Items is a debug function to add mobs to the map.
func Items(a *area.Area, num int) {
	var itemList = make([]item.DrawItemer, len(item.Items))
	var index int
	for _, i := range item.Items {
		itemList[index] = i
		index++
	}
	for x := 0; x < a.Width; x++ {
		for y := 0; y < a.Height; y++ {
			if num <= 0 {
				return
			}

			if util.RandInt(0, 50) != 42 {
				continue
			}

			if !a.IsXYPathable(x, y) {
				continue
			}

			c := coord.Coord{x, y}
			i := item.New(itemList[util.RandInt(0, len(itemList))])
			if i == nil {
				continue
			}
			i.SetX(x)
			i.SetY(y)

			if a.Items[c] == nil {
				a.Items[c] = new(area.Stack)
			}
			a.Items[c].Push(i)
			num--
		}
	}
}
开发者ID:karlek,项目名称:reason,代码行数:38,代码来源:items.go


示例7: DrawFOV

// DrawFOV draws a field of view around a creature as well as the creatures
// memory of already explored areas.
func (c Creature) DrawFOV(a *area.Area) {
	// Clear screen.
	ui.Clear()

	// Get viewport coordinate offset.
	camX, camY := camXY(c, a)

	// Draw already explored areas.
	a.DrawExplored(ui.Area, camX, camY)

	// Draw hero.
	a.Draw(c.X(), c.Y(), camX, camY, ui.Area)

	// Visible coordinates of character.
	cs := c.FOV(a)
	for p := range cs {
		// Set terrain as explored.
		a.Terrain[p.X][p.Y].IsExplored = true

		// TODO(_): refactor cam.
		a.Draw(p.X, p.Y, camX, camY, ui.Area)
	}
}
开发者ID:karlek,项目名称:reason,代码行数:25,代码来源:fov.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang core.Parser类代码示例发布时间:2022-05-23
下一篇:
Golang logger.GetLogger函数代码示例发布时间: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