MCPcopy Index your code
hub / github.com/EngoEngine/engo / pointStringToLines

Function pointStringToLines

common/tmx_level.go:206–233  ·  view source on GitHub ↗
(str string, xOff, yOff float64)

Source from the content-addressed store, hash-verified

204}
205
206func pointStringToLines(str string, xOff, yOff float64) []*engo.Line {
207 pts := strings.Split(str, " ")
208 floatPts := make([][]float64, len(pts))
209 for i, x := range pts {
210 pt := strings.Split(x, ",")
211 floatPts[i] = make([]float64, 2)
212 floatPts[i][0], _ = strconv.ParseFloat(pt[0], 64)
213 floatPts[i][1], _ = strconv.ParseFloat(pt[1], 64)
214 }
215
216 lines := make([]*engo.Line, len(floatPts)-1)
217
218 // Now to globalize line coordinates
219 for i := 0; i < len(floatPts)-1; i++ {
220 x1 := float32(floatPts[i][0] + xOff)
221 y1 := float32(floatPts[i][1] + yOff)
222 x2 := float32(floatPts[i+1][0] + xOff)
223 y2 := float32(floatPts[i+1][1] + yOff)
224
225 p1 := engo.Point{X: x1, Y: y1}
226 p2 := engo.Point{X: x2, Y: y2}
227 newLine := &engo.Line{P1: p1, P2: p2}
228
229 lines[i] = newLine
230 }
231
232 return lines
233}
234
235func (l *Level) unpackTiles(x, y, w, h int, d []tmx.Data) []*Tile {
236 var ret []*Tile

Callers 1

createLevelFromTmxFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected