-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadMap.go
54 lines (45 loc) · 1.17 KB
/
LoadMap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"os"
"strconv"
"strings"
)
func loadMap(mapFile string) {
file, err := os.ReadFile(mapFile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
lines := strings.Split(string(file), "\n")
header := strings.Fields(lines[0])
if len(header) < 2 {
fmt.Println("Invalid map file header")
os.Exit(1)
}
mapW, _ = strconv.Atoi(header[0])
mapH, _ = strconv.Atoi(header[1])
fmt.Println("Map dimensions:", mapW, mapH)
layers = [][]string{}
layerCount := (len(lines)-1)/mapH - 1 // Liczba warstw wizualnych, ostatnia jest warstwą kolizji
// Wczytywanie warstw spritów
for l := 0; l < layerCount; l++ {
layer := []string{}
for y := 0; y < mapH; y++ {
line := lines[1+y+(l*mapH)]
tiles := strings.Fields(line)
layer = append(layer, tiles...)
}
layers = append(layers, layer)
}
// Wczytywanie warstwy kolizji
collisionLayer = []string{}
collisionStartLine := 1 + layerCount*mapH
for y := 0; y < mapH; y++ {
line := lines[collisionStartLine+y]
tiles := strings.Fields(line)
collisionLayer = append(collisionLayer, tiles...)
}
fmt.Println("Layers loaded:", layers)
fmt.Println("Collision layer loaded:", collisionLayer)
}