Exemplo n.º 1
0
func (g *Game) NotifyAboutAttack(attacker, target gameObjectsBase.Activer, msg consts.JsonType) {
	g.notifyInRadius(attacker.GetCenter().X, attacker.GetCenter().Y, msg)
	t, isMob := target.(*gameObjects.Mob)
	if msg["killed"] == true && isMob {
		go g.mobs.takeAwayMob(t)
	}
}
Exemplo n.º 2
0
func (m *MoveFlag) checkCollisionWithActors(obj gameObjectsBase.Activer, dir int, shift float64) (bool, geometry.Point) {
	segment, pos := obj.GetCollisionableSide(dir, shift)
	col1, row1 := int(segment.Point1.X), int(segment.Point1.Y)
	col2, row2 := int(segment.Point2.X), int(segment.Point2.Y)
	res := m.checkCollisionWithActorsInCell(col1, row1, &segment) || m.checkCollisionWithActorsInCell(col2, row2, &segment)
	if res {
		pos = obj.GetCenter()
	}
	return res, pos
}
Exemplo n.º 3
0
func (m *MoveFlag) checkCollisionWithWalls(obj gameObjectsBase.Activer, dir int, shift float64) (bool, geometry.Point) {
	pos := obj.GetShiftedFrontSide(dir, shift)
	if m.field.IsBlocked(int(math.Floor(pos.X)), int(math.Floor(pos.Y))) {
		switch dir {
		case consts.NORTH_DIR:
			pos.Y = math.Ceil(pos.Y) + consts.OBJECT_HALF
		case consts.SOUTH_DIR:
			pos.Y = math.Floor(pos.Y) - consts.OBJECT_HALF
		case consts.EAST_DIR:
			pos.X = math.Floor(pos.X) - consts.OBJECT_HALF
		case consts.WEST_DIR:
			pos.X = math.Ceil(pos.X) + consts.OBJECT_HALF
		}
		return false, pos
	}
	eps := consts.SLIDE_THRESHOLD
	side, pos := obj.GetCollisionableSide(dir, shift)
	res1 := m.field.IsBlocked(int(side.Point1.X), int(side.Point1.Y))
	res2 := m.field.IsBlocked(int(side.Point2.X), int(side.Point2.Y))
	var near float64
	if res1 || res2 {
		switch dir {
		case consts.NORTH_DIR, consts.SOUTH_DIR:
			if res1 {
				near = math.Ceil(side.Point1.X) - side.Point1.X
			} else {
				near = math.Floor(side.Point1.X) - side.Point1.X
			}
			if math.Abs(near) <= eps {
				side.Point1.X = side.Point1.X + near
				side.Point2.X = side.Point2.X + near
			} else {
				return false, obj.GetCenter()
			}
			pos.X = (side.Point1.X + side.Point2.X) / 2
		case consts.EAST_DIR, consts.WEST_DIR:
			if res1 {
				near = math.Ceil(side.Point1.Y) - side.Point1.Y
			} else {
				near = math.Floor(side.Point1.Y) - side.Point1.Y
			}
			if math.Abs(near) <= eps {
				side.Point1.Y = side.Point1.Y + near
				side.Point2.Y = side.Point2.Y + near
			} else {
				return false, obj.GetCenter()
			}
			pos.Y = (side.Point1.Y + side.Point2.Y) / 2
		}
	}
	return true, pos
}
Exemplo n.º 4
0
func (h *HateFlag) Do(obj gameObjectsBase.Activer) {
	if _, exists := obj.GetTarget(); exists {
		return
	}
	center := obj.GetCenter()
	lt, rb := h.field.GetSquareArea(center.X, center.Y, obj.GetRadiusVision())
	for i := int(lt.Y); i < int(rb.Y); i++ {
		for j := int(lt.X); j < int(rb.X); j++ {
			for _, m := range h.field.GetActors(j, i) {
				if m.GetKind().GetRace() == h.hated && obj.GetID() != m.GetID() {
					obj.SetTarget(m)
					return
				}
			}
		}
	}
}