func validPoint(ix, iy int16) bool { x, y := int(ix), int(iy) chart1 := image.Pt(x, y) screen := util.ChartToScreen(chart1) chart2 := util.ScreenToChart(screen) // All points within tile rect should fall into chart. tileOffset := image.Pt(rand.Intn(util.TileW), rand.Intn(util.TileH)) chart3 := util.ScreenToChart(screen.Add(tileOffset)) if chart1 != chart3 { fmt.Println(tileOffset) return false } return chart1 == chart2 }
// Beam generates a projectile beam effect in the game world. func (f *Fx) Beam(origin space.Location, dir image.Point, length int, kind BeamKind) { // Make a footprint for the beam shape. shape := []image.Point{image.Pt(0, 0)} for i := 0; i < length; i++ { shape = append(shape, shape[len(shape)-1].Add(dir)) } footprint := space.FootprintFromPoints(f.world.Manifold, origin, shape) screenVec := util.ChartToScreen(shape[len(shape)-1]) // TODO: Different beam types. f.anim.Add( anim.Func(func(t int64, offset image.Point) { gfx.Line( sdl.Frame(), offset.Add(util.HalfTile), offset.Add(util.HalfTile).Add(screenVec), gfx.LerpCol(gfx.Gold, gfx.Black, float64(t)/float64(.5e9))) }), footprint, .2e9) }
func (a *Anim) CollectSpritesAt( sprites gfx.SpriteBatch, loc space.Location, offset image.Point, layer int) gfx.SpriteBatch { for _, oe := range a.index.At(loc) { screenPos := util.ChartToScreen(oe.Offset.Mul(-1)).Add(offset) animStore := oe.Entity.(animationStore) // Delete ended animations as we encounter them. if animStore.IsDead() { a.index.Remove(oe.Entity) continue } // Create sprites from the current frames of live animations. sprites = append( sprites, gfx.Sprite{layer, screenPos, animStore.CurrentFrame()}) } return sprites }