-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawWalls.go
72 lines (65 loc) · 1.98 KB
/
drawWalls.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"image/color"
"math"
"sort"
)
func drawWall(pix PixelArray, height, x int) error {
var pos position
var myColor color.Color
if x < 0 || x > int(pix.size.x) {
return nil
}
pos.x = x
if height > int(pix.size.y) {
height = int(pix.size.y)
}
for pos.y = 0; pos.y < pix.size.y; pos.y++ {
if pos.y < ((int(pix.size.y) - height) / 2) {
myColor = color.Black
pix.SetPixel(pos, myColor)
} else if pos.y < height+((int(pix.size.y)-height)/2) {
myColor = color.White
pix.SetPixel(pos, myColor)
} else {
myColor = color.Black
pix.SetPixel(pos, myColor)
}
}
return nil
}
func createFakeScreen() (out []floatPosition) {
var prePrePos, prePos, newPos floatPosition
for i := 0; i < myData.pix.size.x; i++ {
prePrePos.x = 0.5
prePrePos.y = ((float64(myData.pix.size.x)/2 - float64(i)) / float64(myData.pix.size.x))
prePos.x = prePrePos.x*math.Cos(myData.player.angle*(math.Pi/180)) - prePrePos.y*math.Sin(myData.player.angle*(math.Pi/180))
prePos.y = prePrePos.x*math.Sin(myData.player.angle*(math.Pi/180)) + prePrePos.y*math.Cos(myData.player.angle*(math.Pi/180))
newPos.x = prePos.x + myData.player.pos.x
newPos.y = prePos.y + myData.player.pos.y
newPos.x *= float64(15)
newPos.y *= float64(15)
myData.pix.SetPixel(newPos.toIntPos(), color.White)
out = append(out, prePrePos)
}
return
}
func drawWalls() {
fakeScreen := createFakeScreen()
var vectors = make([]vect, len(fakeScreen))
var k = make([]float64, myData.theMap.size.x+myData.theMap.size.y)
// var index uint32
for x := 0; x < len(fakeScreen); x++ {
vectors[x] = vect{myData.player.pos.x - fakeScreen[x].x, myData.player.pos.y - fakeScreen[x].x}
for i := 0; i < myData.theMap.size.x; i++ {
k[i] = (float64(i) - myData.player.pos.x) / vectors[x].x
}
for i := myData.theMap.size.x; i < myData.theMap.size.x+myData.theMap.size.y; i++ {
k[i] = (float64(i) - myData.player.pos.y) / vectors[x].y
}
sort.Sort(sort.Float64Slice(k))
i := 0
for ; k[i] <= 0; i++ {
}
}
}