-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock.go
82 lines (65 loc) · 1.43 KB
/
block.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
package main
import (
"github.com/gdamore/tcell/v2"
"strings"
)
type Block struct {
Width int
Height int
X int
Y int
Style tcell.Style
Active bool
ScoreComputed bool
}
func (block Block) GetX() int{
return block.X
}
func (block Block) GetY() int{
return block.Y
}
func (block Block) GetHeight() int{
return block.Height
}
func (block Block) GetWidth() int{
return block.Width
}
func (block Block) GetActiveState() bool{
return block.Active
}
func (block Block) Display(engine *Engine) {
shape := strings.Repeat(" ", block.Width)
// Style := tcell.StyleDefault.Background(tcell.ColorPapayaWhip).Foreground(tcell.ColorAntiqueWhite)
renderGameObject(
engine.Screen,
block.GetX(),
block.GetY(),
block.GetX() + block.Width,
block.GetY() + block.Height,
block.Style,
shape,
)
}
func (block *Block) Update(engine Engine){
if (!block.Active && !block.ScoreComputed){
block.ScoreComputed = true
engine.Player.Score+=1
}
}
func (block *Block) CheckEdges(screenWidth int, screenHeight int){
}
func (block *Block) CheckCollision(g GameObject){
_, ok := g.(*Ball)
if !ok {
return
}
hasCollision :=
g.GetX() >= block.GetX() &&
g.GetX() <= block.GetX() + block.GetWidth() &&
g.GetY() >= block.GetY() &&
g.GetY() <= block.GetY() + block.GetHeight()
if (hasCollision){
block.Style = tcell.StyleDefault.Background(tcell.ColorDefault).Foreground(tcell.ColorDefault)
block.Active = false
}
}