/
intro.go
62 lines (52 loc) · 1.9 KB
/
intro.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
package main
import (
"fmt"
"github.com/syndr0m/mygameengine"
"github.com/syndr0m/mygameengine/image"
"math"
)
func drawIntroBackground(screen *image.Image, frame uint64, imageIntroRotatingBg *image.Image) {
var y int = int(math.Mod(float64(frame), 217))
screen.BlitAt(imageIntroRotatingBg, 0, y-217)
screen.BlitAt(imageIntroRotatingBg, 0, y)
screen.BlitAt(imageIntroRotatingBg, 0, y+217)
screen.BlitAt(imageIntroRotatingBg, 0, y+434)
}
const maskDuration = 2 // seconds
func drawIntroMask(screen *image.Image, frame uint64, fps uint) {
var maxFrame uint64 = uint64(maskDuration * fps)
if frame < maxFrame {
black := mygameengine.COLOR_BLACK
black.A = uint8(math.Max(0, 255-float64(frame)*(255/float64(maxFrame))))
screen.DrawRectangle(0, 0, 640, 480, black)
}
}
func drawIntroText(screen *image.Image, frame uint64, imageIntroText *image.Image) {
var v int = int(math.Mod(float64(frame), 50))
if v > 25 {
screen.BlitAt(imageIntroText, 210, 370)
}
}
func Intro(engine *mygameengine.MyGameEngine) *mygameengine.Board {
engine.Assets().Png(IMG_ROTATING_BG)
engine.Assets().Png(IMG_TITLE)
engine.Assets().Png(IMG_PRESS_SPACE)
intro := mygameengine.NewBoard()
intro.OnKeyDown(func(key int) {
fmt.Println("intro: KEY DOWN", key)
if key == mygameengine.KEY_SPACE {
engine.Boards().SetCurrent(engine.Boards().Get("game"))
}
})
intro.OnRepaint(func(screen *image.Image) {
frame := intro.GetFrame()
drawIntroBackground(screen, frame, engine.Assets().Get(IMG_ROTATING_BG))
screen.BlitAt(engine.Assets().Get(IMG_TITLE), 130, 140)
drawIntroText(screen, frame, engine.Assets().Get(IMG_PRESS_SPACE))
drawIntroMask(screen, frame, engine.GetFps())
})
return intro
}
const IMG_ROTATING_BG string = "assets/images/intro-rotating-bg.png" // 640x217
const IMG_TITLE string = "assets/images/intro-title.png" // 380x120
const IMG_PRESS_SPACE string = "assets/images/intro-press-space-to-start.png"