-
Notifications
You must be signed in to change notification settings - Fork 0
/
borders.go
149 lines (130 loc) · 3.23 KB
/
borders.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package main
import (
"image"
"github.com/hajimehoshi/ebiten"
)
// BorderType is a type for the tyletype enum
type BorderType int
const (
// CornerBorder ... BORDERTYPE ENUM [1]
CornerBorder BorderType = iota + 1
// SideWallBorder ... BORDERTYPE ENUM [2]
SideWallBorder
// BottomWallBorder ... BORDERTYPE ENUM [3]
BottomWallBorder
)
func (b BorderType) String() string {
return [...]string{"Unknown", "CornerBorder", "SideWallBorder", "BottomWallBorder"}[b]
}
// ^ TILETYPE ENUM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Border is the borders on the sides of the screen
type Border struct {
position Vec2f
rotation float64
flipped Vec2b
borderType BorderType
sprite Sprite
image *ebiten.Image
}
func createBorder(position Vec2f, rotation float64, flipped Vec2b, borderType BorderType, image *ebiten.Image) Border {
rotationAsRadians := rotation * (Pi / 180)
// Corner border
sprite := createSprite(newVec2i(17, 51), newVec2i(34, 61), newVec2i(17, 10), itileSpritesheet)
switch borderType {
case (SideWallBorder):
sprite = createSprite(newVec2i(0, 82), newVec2i(17, 328), newVec2i(17, 246), itileSpritesheet)
break
case (BottomWallBorder):
sprite = createSprite(newVec2i(0, 329), newVec2i(228, 346), newVec2i(228, 17), itileSpritesheet)
break
}
return Border{
position,
rotationAsRadians,
flipped,
borderType,
sprite,
image,
}
}
func (b *Border) render(screen *ebiten.Image) {
op := &ebiten.DrawImageOptions{}
// FLIP DECIDER
flip := newVec2f(1, 1)
if b.flipped.x {
flip.x = -1
}
if b.flipped.y {
flip.y = 1
}
// ROTATE & FLIP
op.GeoM.Translate(float64(0-b.sprite.size.x)/2, float64(0-b.sprite.size.y)/2)
op.GeoM.Scale(flip.x, flip.y)
op.GeoM.Rotate(b.rotation)
op.GeoM.Translate(float64(b.sprite.size.x)/2, float64(b.sprite.size.y)/2)
// POSITION
op.GeoM.Translate(float64(b.position.x), float64(b.position.y))
op.Filter = ebiten.FilterNearest // Maybe fix rotation grossness?
borderRect := image.Rect(
b.sprite.startPosition.x,
b.sprite.startPosition.y,
b.sprite.endPosition.x,
b.sprite.endPosition.y,
)
screen.DrawImage(b.image.SubImage(borderRect).(*ebiten.Image), op)
}
func (b *Border) update() {
}
func generateBorders(image *ebiten.Image) []Border {
corner1 := createBorder(
newVec2f(0, 0),
0,
newVec2b(false, false),
CornerBorder,
image,
)
corner2 := createBorder(
newVec2f(screenWidth-float64(corner1.sprite.size.x), 0),
0,
newVec2b(true, false),
CornerBorder,
image,
)
sideWall1 := createBorder(
newVec2f(0, float64(corner1.sprite.size.y)),
0,
newVec2b(true, false),
SideWallBorder,
image,
)
sideWall2 := createBorder(
newVec2f(screenWidth-float64(sideWall1.sprite.size.x), float64(corner1.sprite.size.y)),
0,
newVec2b(false, false),
SideWallBorder,
image,
)
bottomWall1 := createBorder(
newVec2f(0, screenHeight),
0,
newVec2b(false, false),
BottomWallBorder,
image,
)
bottomWall1.position.y -= float64(bottomWall1.sprite.size.y)
bottomWall2 := createBorder(
newVec2f(float64(bottomWall1.sprite.endPosition.x)-1, screenHeight-float64(bottomWall1.sprite.size.y)),
0,
newVec2b(true, false),
BottomWallBorder,
image,
)
return []Border{
corner1,
corner2,
sideWall1,
sideWall2,
bottomWall1,
bottomWall2,
}
}