2013-12-18 10:05:28 +01:00
|
|
|
package blocks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hajimehoshi/go-ebiten/graphics"
|
|
|
|
"github.com/hajimehoshi/go-ebiten/graphics/matrix"
|
2013-12-18 19:21:25 +01:00
|
|
|
"github.com/hajimehoshi/go-ebiten/ui"
|
2013-12-18 10:05:28 +01:00
|
|
|
"image/color"
|
|
|
|
)
|
|
|
|
|
2013-12-18 19:21:25 +01:00
|
|
|
func init() {
|
|
|
|
texturePaths["background"] = "images/blocks/background.png"
|
|
|
|
}
|
|
|
|
|
2013-12-18 10:05:28 +01:00
|
|
|
type TitleScene struct {
|
|
|
|
count int
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTitleScene() *TitleScene {
|
|
|
|
return &TitleScene{}
|
|
|
|
}
|
|
|
|
|
2013-12-18 19:21:25 +01:00
|
|
|
func (s *TitleScene) Update(state *GameState) {
|
2013-12-18 10:05:28 +01:00
|
|
|
s.count++
|
2013-12-18 19:21:25 +01:00
|
|
|
if state.Input.StateForKey(ui.KeySpace) == 1 {
|
|
|
|
state.SceneManager.GoTo(NewGameScene())
|
|
|
|
}
|
2013-12-18 10:05:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *TitleScene) Draw(context graphics.Context) {
|
|
|
|
drawTitleBackground(context, s.count)
|
|
|
|
drawLogo(context, "BLOCKS")
|
2013-12-18 19:21:25 +01:00
|
|
|
|
|
|
|
message := "PRESS SPACE TO START"
|
2014-01-07 15:29:12 +01:00
|
|
|
x := (ScreenWidth - textWidth(message)) / 2
|
|
|
|
y := ScreenHeight - 48
|
2013-12-18 19:21:25 +01:00
|
|
|
drawTextWithShadow(context, message, x, y, 1, color.RGBA{0x80, 0, 0, 0xff})
|
2013-12-18 10:05:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func drawTitleBackground(context graphics.Context, c int) {
|
|
|
|
const textureWidth = 32
|
|
|
|
const textureHeight = 32
|
|
|
|
|
|
|
|
backgroundTextureId := drawInfo.textures["background"]
|
|
|
|
parts := []graphics.TexturePart{}
|
|
|
|
for j := -1; j < ScreenHeight/textureHeight+1; j++ {
|
|
|
|
for i := 0; i < ScreenWidth/textureWidth+1; i++ {
|
|
|
|
parts = append(parts, graphics.TexturePart{
|
2013-12-18 19:21:25 +01:00
|
|
|
LocationX: i * textureWidth,
|
|
|
|
LocationY: j * textureHeight,
|
2013-12-18 10:05:28 +01:00
|
|
|
Source: graphics.Rect{0, 0, textureWidth, textureHeight},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-07 15:29:12 +01:00
|
|
|
dx := (-c / 4) % textureWidth
|
|
|
|
dy := (c / 4) % textureHeight
|
2013-12-18 10:05:28 +01:00
|
|
|
geo := matrix.IdentityGeometry()
|
|
|
|
geo.Translate(float64(dx), float64(dy))
|
2013-12-18 19:21:25 +01:00
|
|
|
clr := matrix.IdentityColor()
|
|
|
|
context.DrawTextureParts(backgroundTextureId, parts, geo, clr)
|
2013-12-18 10:05:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func drawLogo(context graphics.Context, str string) {
|
2013-12-18 19:21:25 +01:00
|
|
|
scale := 4
|
|
|
|
textWidth := textWidth(str) * scale
|
|
|
|
x := (ScreenWidth - textWidth) / 2
|
|
|
|
y := 32
|
|
|
|
drawTextWithShadow(context, str, x, y, scale, color.RGBA{0x00, 0x00, 0x80, 0xff})
|
2013-12-18 10:05:28 +01:00
|
|
|
}
|