-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.go
45 lines (39 loc) · 1.31 KB
/
background.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
package main
import (
_ "image/png"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil"
)
type Background struct {
background *ebiten.Image
base *ebiten.Image
latitude float64
}
func new_background() *Background {
background := Background{}
background.background, _, _ = ebitenutil.NewImageFromFile("images/background-night.png", ebiten.FilterDefault)
background.base, _, _ = ebitenutil.NewImageFromFile("images/base.png", ebiten.FilterDefault)
background.latitude = 0
return &background
}
func (background *Background) move() {
background.latitude -= VELOCITY
if background.latitude <= -BG_WIDTH {
background.latitude += BG_WIDTH
}
}
func (background *Background) draw(screen *ebiten.Image) {
op_bg := &ebiten.DrawImageOptions{}
op_base := &ebiten.DrawImageOptions{}
op_base.GeoM.Translate(background.latitude, BG_HEIGHT)
screen.DrawImage(background.background, op_bg)
screen.DrawImage(background.base, op_base)
for i := 1; i < BG_NUM; i++ {
op_bg.GeoM.Translate(BG_WIDTH, 0)
screen.DrawImage(background.background, op_bg)
op_base.GeoM.Translate(BG_WIDTH, 0)
screen.DrawImage(background.base, op_base)
}
op_base.GeoM.Translate(BG_WIDTH, 0)
screen.DrawImage(background.base, op_base)
}