This repository was archived by the owner on Nov 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
126 lines (102 loc) · 2.39 KB
/
main.go
File metadata and controls
126 lines (102 loc) · 2.39 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
package main
import (
"log"
"time"
"github.com/bcvery1/Deadication/hud"
"github.com/bcvery1/Deadication/player"
"github.com/bcvery1/Deadication/util"
"github.com/faiface/pixel"
"github.com/faiface/pixel/pixelgl"
"golang.org/x/image/colornames"
)
const (
winWidth float64 = 1280
winHeight float64 = 720
)
var (
backgroundColour = colornames.Forestgreen
x1 = 0
x2 = 0
y1 = 0
y2 = 0
)
func run() {
cfg := pixelgl.WindowConfig{
Title: "DEADication",
Bounds: pixel.R(0, 0, winWidth, winHeight),
VSync: true,
}
win, err := pixelgl.NewWindow(cfg)
if err != nil {
log.Fatal(err)
}
win.SetSmooth(true)
win.Clear(backgroundColour)
sprites, pic := util.GetSprites()
playerObj := player.NewPlayer(sprites)
gamehud := hud.NewHUD()
batch, collisions := util.CreateBatch(sprites, pic)
interactives, zones := util.AllInteractives()
// Assign to global var
util.AllSprites = sprites
// Add two initial humans
util.Pens["Bottom pen"].AddHuman()
util.Pens["Bottom pen"].AddHuman()
// Add initial corn to top field
util.Fields["Top field"].Plant(util.NewCrop("corn"))
util.Fields["Mid field"].Plant(util.NewCrop("apple"))
// Start listening for popups
util.InitPopups()
// Start listening for eatings
util.InitPens()
// Start listening for harvests
util.InitFields()
last := time.Now()
inZone := ""
for !win.Closed() {
win.Clear(backgroundColour)
if win.JustPressed(pixelgl.MouseButtonLeft) {
log.Println(win.MousePosition())
}
dt := time.Since(last).Seconds()
last = time.Now()
batch.Draw(win)
// Update crop growth via fields
for _, f := range util.Fields {
f.UpdateCrop(win, sprites)
}
newZone := playerObj.Update(win, dt, collisions, zones)
if newZone != "" {
// Player is in a named interactive zone
// Only activate if changed zones
if newZone != inZone {
interactives[newZone].Activate(playerObj.Carrying())
// Set inZone
inZone = newZone
}
interactives[newZone].Update(win, playerObj.Carrying())
} else {
// Reset inZone
inZone = ""
// Deactivate all zones
for _, zone := range interactives {
zone.Deactivate()
}
}
// Update human movements
for _, p := range util.Pens {
p.UpdateHumans(win, dt)
}
// Update the HUD
gamehud.Update(win, playerObj)
// Display any popups
popup, show := util.GetMessage()
if show {
popup.Draw(win)
}
win.Update()
}
}
func main() {
pixelgl.Run(run)
}