예제 #1
0
파일: player.go 프로젝트: BenLubar/Rnoadm
func (pi *PlayerInstances) Get(pos *world.Tile) world.Instance {
	pi.mtx.Lock()
	defer pi.mtx.Unlock()

	if pi.instances == nil {
		pi.instances = make(map[instanceLocation]*PlayerInstance)
	}
	z := pos.Zone()
	tx, ty := pos.Position()
	loc := instanceLocation{ZoneX: z.X, ZoneY: z.Y, TileX: tx, TileY: ty}
	if i, ok := pi.instances[loc]; ok {
		return i
	}
	i := &PlayerInstance{}
	pi.instances[loc] = i
	return i
}
예제 #2
0
파일: critter.go 프로젝트: BenLubar/Rnoadm
func (c *Critter) NotifyPosition(old, new *world.Tile) {
	if old == nil || new == nil {
		c.mtx.Lock()
		c.animationTicks = 0
		c.animation = ""
		c.facing = 0
		c.mtx.Unlock()
		return
	}
	ox, oy := old.Position()
	nx, ny := new.Position()

	c.mtx.Lock()
	switch {
	case ox-1 == nx && oy == ny:
		c.animationTicks = 3
		c.animation = "wa" // walk (alternating)
		c.facing = 6
	case ox+1 == nx && oy == ny:
		c.animationTicks = 3
		c.animation = "wa" // walk (alternating)
		c.facing = 9
	case ox == nx && oy-1 == ny:
		c.animationTicks = 3
		c.animation = "wa" // walk (alternating)
		c.facing = 3
	case ox == nx && oy+1 == ny:
		c.animationTicks = 3
		c.animation = "wa" // walk (alternating)
		c.facing = 0
	}
	c.mtx.Unlock()

	new.Zone().Update(new, c.Outer())
}
예제 #3
0
파일: hero.go 프로젝트: BenLubar/Rnoadm
func (h *Hero) NotifyPosition(old, new *world.Tile) {
	if old == nil || new == nil {
		h.mtx.Lock()
		h.animationTicks = 0
		h.animation = ""
		h.facing = 0
		h.mtx.Unlock()
		return
	}
	ox, oy := old.Position()
	nx, ny := new.Position()

	h.mtx.Lock()
	switch {
	case ox-1 == nx && oy == ny:
		h.animationTicks = 3
		h.animation = "wa" // walk (alternating)
		h.facing = 6
	case ox+1 == nx && oy == ny:
		h.animationTicks = 3
		h.animation = "wa" // walk (alternating)
		h.facing = 9
	case ox == nx && oy-1 == ny:
		h.animationTicks = 3
		h.animation = "wa" // walk (alternating)
		h.facing = 3
	case ox == nx && oy+1 == ny:
		h.animationTicks = 3
		h.animation = "wa" // walk (alternating)
		h.facing = 0
	}
	h.mtx.Unlock()

	new.Zone().Update(new, h.Outer())
}