-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
131 lines (121 loc) · 3.46 KB
/
main.go
File metadata and controls
131 lines (121 loc) · 3.46 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
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
package main
import (
"image"
"log"
"math/rand"
"time"
"ColorHit/dep"
"github.com/hajimehoshi/ebiten/v2"
)
const (
screenWidth = 512
screenHeight = 384
resolWidth = 512
resolHeight = 384
)
var (
cursorGame = dep.LoadImg("data/img/icons.png").SubImage(image.Rect(112, 80, 127, 95)).(*ebiten.Image)
cursorMenu = dep.LoadImg("data/img/icons.png").SubImage(image.Rect(128, 80, 144, 96)).(*ebiten.Image)
game *Game
temp int
start bool = true
)
type Game struct {
gamebody *dep.GameBody
count int
start bool
Acc *dep.Acc
Sco *dep.Sco
}
func (g *Game) Update() error {
if g.start {
g.start = g.gamebody.Update()
if ebiten.IsKeyPressed(ebiten.KeyEscape) {
g.start = false
start = true
}
if !g.start {
dep.Chen = dep.Pal[rand.Intn(len(dep.Pal))]
g.Sco.SetScore(g.gamebody.M.Point)
t := &dep.Map{ebiten.NewImage(resolWidth, resolHeight), 0, nil, dep.AllMap[rand.Intn(len(dep.AllMap))], []*dep.Coin{}, []dep.Add{}, 1, 0}
img := dep.LoadImg("data/img/tank.png")
g.gamebody = &dep.GameBody{
&dep.Player{&dep.RigidBody{resolWidth/2 - 4, resolHeight/2 - 4, 16, 16}, resolWidth, resolHeight, t, img.SubImage(image.Rect(0, 0, 16, 16)).(*ebiten.Image), img.SubImage(image.Rect(16, 0, 32, 16)).(*ebiten.Image), 0, 0, 3, 0, 0},
t,
0,
[]int{},
[]int{},
}
g.gamebody.Player.RigidBody.X, g.gamebody.Player.RigidBody.Y = game.gamebody.CreateSpawn()
}
} else if start {
g.start = g.Acc.Update(&temp, &g.count)
start = !g.start
} else {
g.start = g.Sco.Update(&temp, &g.count)
}
return nil
}
func (g *Game) Draw(screen *ebiten.Image) {
if g.start {
g.gamebody.Draw(screen)
} else if start {
g.Acc.Draw(screen)
} else {
g.Sco.Draw(screen)
}
t, x := ebiten.CursorPosition()
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(t), float64(x))
if g.start {
op.GeoM.Translate(-7, -7)
screen.DrawImage(cursorGame, op)
} else {
screen.DrawImage(cursorMenu, op)
}
}
func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
return resolWidth, resolHeight
}
func init() {
rand.Seed(time.Now().Unix())
t := &dep.Map{ebiten.NewImage(resolWidth, resolHeight), 0, nil, dep.AllMap[rand.Intn(len(dep.AllMap))], []*dep.Coin{}, []dep.Add{}, 1, 0}
img := dep.LoadImg("data/img/tank.png")
game = &Game{
&dep.GameBody{
&dep.Player{&dep.RigidBody{resolWidth/2 - 4, resolHeight/2 - 4, 16, 16}, resolWidth, resolHeight, t, img.SubImage(image.Rect(0, 0, 16, 16)).(*ebiten.Image), img.SubImage(image.Rect(16, 0, 32, 16)).(*ebiten.Image), 0, 0, 3, 0, 0},
t,
0,
[]int{},
[]int{},
},
0,
false,
&dep.Acc{
dep.LoadImg("data/ui/menu.png"),
dep.RigidBody{224, 192, 64, 32},
dep.RigidBody{224, 240, 64, 32},
},
&dep.Sco{
dep.LoadImg("data/ui/score_menu.png"),
dep.RigidBody{192, 240, 128, 32},
dep.RigidBody{224, 288, 64, 32},
dep.LoadScore(),
0,
},
}
game.gamebody.Player.RigidBody.X, game.gamebody.Player.RigidBody.Y = game.gamebody.CreateSpawn()
dep.Chen = dep.Pal[rand.Intn(len(dep.Pal))]
}
func main() {
ebiten.SetCursorMode(ebiten.CursorModeHidden)
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
ebiten.SetWindowTitle("Color Hit")
ebiten.SetMaxTPS(60)
ebiten.SetWindowResizable(true)
ebiten.SetFullscreen(true)
ebiten.SetWindowIcon([]image.Image{dep.LoadImgImage("data/logo16.png"), dep.LoadImgImage("data/logo32.png"), dep.LoadImgImage("data/logo48.png")})
if err := ebiten.RunGame(game); err != nil {
log.Fatal(err)
}
}