-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.go
More file actions
71 lines (57 loc) · 1.89 KB
/
Copy pathgame.go
File metadata and controls
71 lines (57 loc) · 1.89 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
package main
import (
_ "image/png"
"github.com/ForgeLeaf/Forge"
"github.com/ForgeLeaf/Forge/Graphics"
"github.com/ForgeLeaf/Forge/Graphics/Viewports"
"github.com/ForgeLeaf/Forge/Input"
"github.com/go-gl/gl/v3.3-core/gl"
)
type Game struct {
batch *Graphics.Batch
viewport *Viewports.FitViewport
goblin *Player
werewolf *Player
}
func (game *Game) Create(driver *Forge.Driver) {
game.batch = Graphics.NewBatch(driver)
game.viewport = Viewports.NewFitViewport(8, 5, driver.Width, driver.Height)
goblinTexture, _ := Graphics.NewTexture("assets/Goblin.png")
goblinTexture.SetFilter(gl.NEAREST, gl.NEAREST)
game.goblin = NewPlayer(1, 1, goblinTexture, Input.KeyW, Input.KeyS, Input.KeyA, Input.KeyD)
werewolfTexture, _ := Graphics.NewTexture("assets/Werewolf.png")
werewolfTexture.SetFilter(gl.NEAREST, gl.NEAREST)
game.werewolf = NewPlayer(5, 1, werewolfTexture, Input.KeyUp, Input.KeyDown, Input.KeyLeft, Input.KeyRight)
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
driver.Input.SetKeyCallback(func(key Input.Key, action Input.Action, modifiers Input.ModifierKey) {
if key == Input.KeyEscape && action == Input.ActionPress {
driver.Stop()
}
})
}
func (game *Game) Render(driver *Forge.Driver, delta float32) {
// input
game.goblin.input(driver)
game.werewolf.input(driver)
// logic
game.viewport.Apply(true)
game.goblin.logic(delta)
game.werewolf.logic(delta)
// draw
gl.ClearColor(0.52, 0.72, 0.83, 1)
gl.Clear(gl.COLOR_BUFFER_BIT)
game.batch.SetProjection(game.viewport.GetCamera().Matrix)
game.batch.Begin()
game.goblin.draw(game.batch)
game.werewolf.draw(game.batch)
game.batch.End()
}
func (game *Game) Resize(driver *Forge.Driver, width, height float32) {
game.viewport.Update(width, height, true)
}
func (game *Game) Destroy(driver *Forge.Driver) {
game.batch.Dispose()
game.goblin.texture.Dispose()
game.werewolf.texture.Dispose()
}