~johanvandegriff/ruegolike

ref: d88bd6e38831cd898c9ec7dc76745a56d714da93 ruegolike/generate.go -rw-r--r-- 696 bytes
d88bd6e3Johan Vandegriff moved level gen to its own function 1 year, 6 months ago
                                                                                
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
package main

import "math/rand"

func generate() ([width][height]int32, [width][height]bool, int, int) {
	var level [width][height]int32
	var explored [width][height]bool

	//simple terrain generation
	for x := 0; x < width; x++ {
		for y := 0; y < height; y++ {
			if rand.Intn(100) < 40 {
				level[x][y] = '#' //wall, 40%
			} else {
				level[x][y] = '.' //empty, 60%
			}
		}
	}
	// level[5][4] = '£'
	// level[5][6] = '#'
	// level[5][6] = '@'

	//start the player on an empty square
	var playerX, playerY int
	//do while
	for ok := true; ok; ok = level[playerX][playerY] != '.' {
		playerX = rand.Intn(width)
		playerY = rand.Intn(height)
	}

	return level, explored, playerX, playerY
}