Beispiel #1
0
// SetObjectXY sets an objects x and y value.
func (a *Area) SetObjectXY(m Mover, x, y int) (col *Collision, err error) {
	c := coord.Coord{x, y}
	p := coord.Plane{a.Width, a.Height, 0, 0}
	if !p.Contains(c) {
		return nil, errutil.Newf("out of bounds.")
	}

	// remove the object from the old position, add to the new position and
	// update both positions.
	if !a.Terrain[x][y].IsPathable() {
		return &Collision{a.Terrain[x][y], x, y}, nil
	}

	// test if an non-Pather object is already on that location.
	if mob := a.Monsters[c]; mob != nil {
		if !mob.IsPathable() {
			return &Collision{mob, x, y}, nil
		}
	}

	// Update old position.
	c = coord.Coord{m.X(), m.Y()}
	if a.Monsters[c] != nil {
		a.Monsters[c] = nil
	}

	// Update new position.
	m.SetX(x)
	m.SetY(y)

	c = coord.Coord{m.X(), m.Y()}
	a.Monsters[c] = m

	return nil, nil
}
Beispiel #2
0
func (a Area) drawMemory(x, y int, cameraX, cameraY int, scr screen.Screen) {
	c := coord.Coord{x + scr.XOffset, y + scr.YOffset}
	p := coord.Plane{scr.Width + scr.XOffset, scr.Height + scr.YOffset, scr.XOffset, scr.YOffset}
	if !p.Contains(c) {
		return
	}
	termbox.SetCell(x+scr.XOffset, y+scr.YOffset, a.Terrain[x+cameraX][y+cameraY].Graphic().Ch, termbox.ColorBlack+termbox.AttrBold, termbox.ColorDefault)
}
Beispiel #3
0
// DrawCell draws a drawable object to the screen.
func DrawCell(x, y int, d Drawable, scr screen.Screen) {
	// Check if the coordinate exists on the plane.
	// Since the screen isn't always located at (0, 0) we have to take
	// the offsets into account.
	c := coord.Coord{x + scr.XOffset, y + scr.YOffset}
	p := coord.Plane{scr.Width + scr.XOffset, scr.Height + scr.YOffset, scr.XOffset, scr.YOffset}
	if !p.Contains(c) {
		return
	}
	termbox.SetCell(x+scr.XOffset, y+scr.YOffset, d.Graphic().Ch, d.Graphic().Fg, d.Graphic().Bg)
}
Beispiel #4
0
func (a Area) ExistsXY(x, y int) bool {
	c := coord.Coord{x, y}
	p := coord.Plane{a.Width, a.Height, 0, 0}
	return p.Contains(c)
}