예제 #1
0
func (f *GameField) FreeForObject(x, y float64) bool {
	tl := geometry.MakePoint(x-consts.OBJECT_HALF, y-consts.OBJECT_HALF)
	br := geometry.MakePoint(x+consts.OBJECT_HALF, y+consts.OBJECT_HALF)
	tr := geometry.MakePoint(x+consts.OBJECT_HALF, y-consts.OBJECT_HALF)
	bl := geometry.MakePoint(x-consts.OBJECT_HALF, y+consts.OBJECT_HALF)
	rect := geometry.MakeRectangle(tl, br)
	var pts = []*geometry.Point{tl, br, bl, tr}
	blockeds := make([]*geometry.Rectangle, 0, 100)
	for _, point := range pts {
		col, row := int(point.X), int(point.Y)
		if f.IsBlocked(col, row) {
			blockeds = append(blockeds, f.GetCellRectangle(col, row))
		}
	}
	for _, blocked := range blockeds {
		if rect.CrossedByRect(blocked) {
			return false
		}
	}
	for _, point := range pts {
		for _, actor := range f.GetActors(int(point.X), int(point.Y)) {
			r := actor.GetRectangle()
			if rect.CrossedByRect(&r) {
				return false
			}
		}
	}
	return true
}
예제 #2
0
func (g *Game) putItem(json consts.JsonType) consts.JsonType {
	res := utils.JsonAction("putItem", "badAction")
	if *consts.TEST && consts.TEST_MODE {
		var requiredFields = map[string]string{
			"x":    "badPlacing",
			"y":    "badPlacing",
			"item": "badItem",
		}
		var ok bool
		if ok, _ = utils.CheckJsonRequest(json, requiredFields); ok {
			itemDesc, ok1 := json["item"].(map[string]interface{})
			pt, isGoodPoint := utils.GetPointFromJson(json)
			if isGoodPoint && !g.field.IsBlocked(int(pt.X), int(pt.Y)) {
				res["result"] = "badInventory"
				if ok1 {
					item := gameObjectsBase.ItemFromJson(itemDesc)
					if item != nil {
						item.ForcePlace(*geometry.MakePoint(pt.X, pt.Y))
						g.items.addItem(item)
						g.field.LinkToCells(item)
						res["id"] = item.GetID()
						res["result"] = "ok"
					}
				}
			} else {
				res["result"] = "badPlacing"
			}
		}
	}
	return res
}
예제 #3
0
func (pm *ProjectileManager) CheckCollision(p pM.Projectiler, dx, dy float64) (bool, gameObjectsBase.Activer) {
	center := p.GetCenter()
	newCenter := geometry.MakePoint(center.X+dx, center.Y+dy)
	rects := make([]*geometry.Rectangle, 0, 100)
	rect2obj := make(map[*geometry.Rectangle]gameObjectsBase.Activer)
	for i := int(math.Min(center.Y, newCenter.Y)); i <= int(math.Max(center.Y, newCenter.Y)); i++ {
		for j := int(math.Min(center.X, newCenter.X)); j <= int(math.Max(center.X, newCenter.X)); j++ {
			if pm.field.IsBlocked(j, i) {
				rects = append(rects, pm.field.GetCellRectangle(j, i))
			} else {
				for _, actor := range pm.field.GetActors(j, i) {
					r := actor.GetRectangle()
					rects = append(rects, &r)
					rect2obj[&r] = actor
				}
			}
		}
	}
	s := geometry.MakeSegment(center.X, center.Y, center.X+dx, center.Y+dy)
	for _, rect := range rects {
		if rect.CrossedBySegment(s) {
			return true, rect2obj[rect]
		}
	}
	return false, nil
}
예제 #4
0
func (ml *mobList) initializeMobsGenerators(filename string) {
	areas, _ := os.Open(consts.PATH_TO_MAPS + filename)
	defer areas.Close()
	reader := bufio.NewReader(areas)
	for {
		bytes, _, err := reader.ReadLine()
		if err == nil {
			data := strings.Split(string(bytes), ":")
			l, r := utils.ParseFloat(data[0]), utils.ParseFloat(data[1])
			t, b := utils.ParseFloat(data[2]), utils.ParseFloat(data[3])
			depth := utils.ParseInt64(data[4])
			duration := utils.ParseFloat(data[5])
			area := geometry.MakeRectangle(geometry.MakePoint(l, t), geometry.MakePoint(r, b))
			if kinds, isExist := ml.mobsDepth[depth]; isExist {
				ml.addGen(NewMobGenerator(&kinds, area, depth, duration, ml.pipeline))
			}
		} else {
			break
		}
	}
}
예제 #5
0
func (g *Game) useSkillAction(json consts.JsonType) consts.JsonType {
	res := utils.JsonAction("useSkill", "badPoint")
	x, ok1 := json["x"].(float64)
	y, ok2 := json["y"].(float64)
	if ok1 && ok2 {
		p := g.players.getPlayerBySession(json["sid"].(string))
		start := p.GetCenter()
		damage := p.GetCharacteristic(consts.CHARACTERISTIC_INTELLEGENCE) * consts.FIREBALL_DAMAGE_MULTIPLIER
		g.projectileManager.NewFireBallProjectile(&start, geometry.MakePoint(x, y), damage, consts.FIREBALL_RADIUS, p)
		res["result"] = "ok"
	}
	return res
}
예제 #6
0
func (f *GameField) GetCellRectangle(col, row int) *geometry.Rectangle {
	return geometry.MakeRectangle(geometry.MakePoint(float64(col), float64(row)), geometry.MakePoint(float64(col+1), float64(row+1)))
}
예제 #7
0
func (obj *ActiveObject) SetAttackPoint(x, y float64) {
	obj.AttackPoint = geometry.MakePoint(x, y)
}