Exemplo n.º 1
0
func (ai *PlayerAI) Act(db *engine.EntityDB, eid engine.Entity) {
	// RENDERING
	RenderMapAt(db, eid)

	// INPUT HANDLING
	event := termbox.PollEvent()

	var dx, dy, dz int64

	switch event.Ch {
	case 'h':
		dx = -1
	case 'j':
		dy = -1
	case 'k':
		dy = 1
	case 'l':
		dx = 1
	case 'y':
		dx = -1
		dy = 1
	case 'u':
		dx = 1
		dy = 1
	case 'b':
		dx = -1
		dy = -1
	case 'n':
		dx = 1
		dy = -1
	case '>':
		dz = -4
	case '<':
		dz = 4
	case 0:
		switch event.Key {
		case termbox.KeyCtrlQ:
			done = true
		}
	}

	base.HelperMove(db, eid, dx, dy, dz)
}
Exemplo n.º 2
0
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)
}