func (l *LocalData) thinkAbility(g *Game, abs *personalAbilities, gid Gid) { if abs.activeAbility == nil { return } var mouse linear.Vec2 if l.mode == LocalModeArchitect { mx, my := l.sys.GetCursorPos() mouse.X = float64(mx) mouse.Y = float64(my) mouse = mouse.Sub(l.architect.camera.regionPos) mouse.X /= l.architect.camera.regionDims.X mouse.Y /= l.architect.camera.regionDims.Y mouse.X *= l.architect.camera.current.dims.X mouse.Y *= l.architect.camera.current.dims.Y mouse = mouse.Sub(l.architect.camera.current.dims.Scale(0.5)) mouse = mouse.Add(l.architect.camera.current.mid) } events, die := abs.activeAbility.Think(gid, g, mouse) for _, event := range events { l.engine.ApplyEvent(event) } if die { base.Log().Printf("Deactivate on die") more_events := abs.activeAbility.Deactivate(gid) abs.activeAbility = nil for _, event := range more_events { l.engine.ApplyEvent(event) } } }
func fireDoLine(c *cmwc.Cmwc, pos linear.Vec2, angle, stored float64, speed int, level *game.Level) fireExplosion { rng := rand.New(c) ray := (linear.Vec2{1, 0}) // ray.Scale(math.Abs(rng.NormFloat64()/10) + 50) scale := (stored/5 + 50) * (1 + rng.Float64()*(0.2+stored/2000)) ray = ray.Rotate(angle).Rotate(rng.NormFloat64() * (0.2 + stored/7500)).Scale(scale) seg := linear.Seg2{pos, pos.Add(ray)} base.DoOrdered(level.Room.Walls, func(a, b string) bool { return a < b }, func(_ string, poly linear.Poly) { for i := range poly { if seg.DoesIsect(poly.Seg(i)) { isect := seg.Isect(poly.Seg(i)) seg.Q = isect } } }) p1 := rng.Intn(speed) p2 := rng.Intn(speed) p3 := rng.Intn(speed) return fireExplosion{ Pos: seg.Q, Radius: rng.Float64()*40 + 30, Timer: 0, Start: 1*speed + p1, Peak: 4*speed + p1 + p2, End: 5*speed + p1 + p2 + p3, } }
func (camera *cameraInfo) FocusRegion(g *Game, side int) { min := linear.Vec2{1e9, 1e9} max := linear.Vec2{-1e9, -1e9} player := g.Ents[g.local.Gid] if player == nil { min.X = 0 min.Y = 0 max.X = float64(g.Level.Room.Dx) max.Y = float64(g.Level.Room.Dy) } else { min.X = player.Pos().X - player.Stats().Vision() min.Y = player.Pos().Y - player.Stats().Vision() if min.X < 0 { min.X = 0 } if min.Y < 0 { min.Y = 0 } max.X = player.Pos().X + player.Stats().Vision() max.Y = player.Pos().Y + player.Stats().Vision() if max.X > float64(g.Level.Room.Dx) { max.X = float64(g.Level.Room.Dx) } if max.Y > float64(g.Level.Room.Dy) { max.Y = float64(g.Level.Room.Dy) } } mid := min.Add(max).Scale(0.5) dims := max.Sub(min) if dims.X/dims.Y < camera.regionDims.X/camera.regionDims.Y { dims.X = dims.Y * camera.regionDims.X / camera.regionDims.Y } else { dims.Y = dims.X * camera.regionDims.Y / camera.regionDims.X } camera.target.dims = dims camera.target.mid = mid camera.approachTarget() }
func (g *Game) AddCreeps(pos linear.Vec2, count, side int, params map[string]interface{}) { if side < 0 || side >= len(g.Level.Room.SideData) { base.Error().Fatalf("Got side %d, but this level only supports sides from 0 to %d.", side, len(g.Level.Room.SideData)-1) return } for i := 0; i < count; i++ { var c CreepEnt c.StatsInst = stats.Make(stats.Base{ Health: 100, Mass: 250, Acc: 50.0, Rate: 0.0, Size: 8, Vision: 400, }) // Evenly space the players on a circle around the starting position. randAngle := rand.New(g.Rng).Float64() * math.Pi rot := (linear.Vec2{15, 0}).Rotate(randAngle + float64(i)*2*3.1415926535/float64(count)) c.Position = pos.Add(rot) c.Side_ = side c.Gid = g.NextGid() c.Abilities_ = append( c.Abilities_, ability_makers["asplode"](map[string]float64{"startRadius": 40, "endRadius": 70, "durationThinks": 50, "dps": 5})) // if playerData.gid[0:2] == "Ai" { // c.BindAi("simple", g.local.Engine) // } g.AddEnt(&c) c.BindAi("creep", g.local.Engine) for name, value := range params { c.ai.SetParam(name, value) } } }
func BasicOperationsSpec(c gospec.Context) { a := linear.Vec2{3, 4} b := linear.Vec2{5, 6} c.Specify("Make sure adding vectors works.", func() { VecExpect(c, a.Add(b), Equals, linear.Vec2{8, 10}) }) c.Specify("Make sure subtracting vectors works.", func() { VecExpect(c, a.Sub(b), Equals, linear.Vec2{-2, -2}) }) c.Specify("Make sure dotting vectors works.", func() { c.Expect(a.Dot(b), IsWithin(1e-9), 39.0) }) c.Specify("Make sure crossing vectors works.", func() { VecExpect(c, a.Cross(), Equals, linear.Vec2{-4, 3}) }) c.Specify("Make sure taking the magnitude of vectors works.", func() { c.Expect(a.Mag(), IsWithin(1e-9), 5.0) c.Expect(a.Mag2(), IsWithin(1e-9), 25.0) }) c.Specify("Make sure scaling vectors works.", func() { VecExpect(c, a.Scale(3), Equals, linear.Vec2{9, 12}) }) }
func (camera *cameraInfo) doInvadersFocusRegion(g *Game, side int) { min := linear.Vec2{1e9, 1e9} max := linear.Vec2{-1e9, -1e9} hits := 0 for _, ent := range g.temp.AllEnts { if ent.Side() != side { continue } if player, ok := ent.(*PlayerEnt); ok { hits++ pos := player.Pos() if pos.X < min.X { min.X = pos.X } if pos.Y < min.Y { min.Y = pos.Y } if pos.X > max.X { max.X = pos.X } if pos.Y > max.Y { max.Y = pos.Y } } } if hits == 0 { min.X = 0 min.Y = 0 max.X = float64(g.Levels[GidInvadersStart].Room.Dx) max.Y = float64(g.Levels[GidInvadersStart].Room.Dy) } else { min.X -= stats.LosPlayerHorizon + 50 min.Y -= stats.LosPlayerHorizon + 50 if min.X < 0 { min.X = 0 } if min.Y < 0 { min.Y = 0 } max.X += stats.LosPlayerHorizon + 50 max.Y += stats.LosPlayerHorizon + 50 if max.X > float64(g.Levels[GidInvadersStart].Room.Dx) { max.X = float64(g.Levels[GidInvadersStart].Room.Dx) } if max.Y > float64(g.Levels[GidInvadersStart].Room.Dy) { max.Y = float64(g.Levels[GidInvadersStart].Room.Dy) } } mid := min.Add(max).Scale(0.5) dims := max.Sub(min) if dims.X/dims.Y < camera.regionDims.X/camera.regionDims.Y { dims.X = dims.Y * camera.regionDims.X / camera.regionDims.Y } else { dims.Y = dims.X * camera.regionDims.Y / camera.regionDims.X } camera.target.dims = dims camera.target.mid = mid if camera.current.mid.X == 0 && camera.current.mid.Y == 0 { // On the very first frame the current midpoint will be (0,0), which should // never happen after the game begins. In this one case we'll immediately // set current to target so we don't start off by approaching it from the // origin. camera.current = camera.target } else { // speed is in (0, 1), the higher it is, the faster current approaches target. speed := 0.1 camera.current.dims = camera.current.dims.Scale(1 - speed).Add(camera.target.dims.Scale(speed)) camera.current.mid = camera.current.mid.Scale(1 - speed).Add(camera.target.mid.Scale(speed)) } }