-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcanvas.go
More file actions
59 lines (45 loc) · 1.18 KB
/
Copy pathcanvas.go
File metadata and controls
59 lines (45 loc) · 1.18 KB
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
package vimman
import "os"
//import tb "github.com/nsf/termbox-go"
type Canvas [][]*TermBoxCell
func NewCanvas(width, height int) Canvas {
canvas := make(Canvas, height)
for i := range canvas {
canvas[i] = make([]*TermBoxCell, width)
}
return canvas
}
func (c Canvas) GetCellAt(x, y int) *TermBoxCell {
return c[y][x]
}
func (c Canvas) CheckCollision(x, y int) bool {
// check if out of boundaries
if x < 0 || y < 0 || y >= len(c) || x >= len(c[0]) {
return true
}
if c[y][x] == nil {
return true
}
if c[y][x].cellData.CollisionCallback != nil {
c[y][x].cellData.CollisionCallback()
}
if os.Getenv("DEBUG") == "1" {
return false
}
return c[y][x].collidesPhysically
}
func (c *Canvas) OverWriteCanvasCell(x, y int, termboxCell *TermBoxCell) {
if x >= 0 && x < len((*c)[0]) && y >= 0 && y < len((*c)) {
// intentionally use x,y in reverse order
(*c)[y][x] = termboxCell
}
}
func (c *Canvas) SetCellAt(row, column int, cell *TermBoxCell) {
(*c)[row][column] = cell
}
func (c *Canvas) IsInsideOfBoundaries(x, y int) bool {
return x >= 0 && x < len((*c)[0])-1 && y >= 0 && y < len(*c)-1
}
func (c *Canvas) IsInLastColumn(x int) bool {
return len((*c)[0])-1 == x
}