Compare commits
3 commits
53ac3840ba
...
9b11f3b220
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b11f3b220 | |||
| dc83316886 | |||
| 4319ec55e5 |
3 changed files with 70 additions and 6 deletions
14
assets/logo.go
Normal file
14
assets/logo.go
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
package assets
|
||||||
|
|
||||||
|
const (
|
||||||
|
LOGO_STRIDE = 20
|
||||||
|
LOGO_HEIGHT = 5
|
||||||
|
)
|
||||||
|
|
||||||
|
var Logo = [LOGO_HEIGHT * LOGO_STRIDE]byte{
|
||||||
|
1, 1, 1, 0, 2, 2, 0, 3, 3, 3, 0, 4, 4, 0, 0, 5, 0, 6, 6, 6,
|
||||||
|
0, 1, 0, 0, 2, 0, 0, 0, 3, 0, 0, 4, 0, 4, 0, 5, 0, 6, 0, 0,
|
||||||
|
0, 1, 0, 0, 2, 2, 0, 0, 3, 0, 0, 4, 4, 0, 0, 5, 0, 0, 6, 0,
|
||||||
|
0, 1, 0, 0, 2, 0, 0, 0, 3, 0, 0, 4, 0, 4, 0, 5, 0, 0, 0, 6,
|
||||||
|
0, 1, 0, 0, 2, 2, 0, 0, 3, 0, 0, 4, 0, 4, 0, 5, 0, 6, 6, 6,
|
||||||
|
}
|
||||||
|
|
@ -1,25 +1,45 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"image/color"
|
||||||
|
|
||||||
"tetris/assets"
|
"tetris/assets"
|
||||||
"tetris/engine/audio"
|
"tetris/engine/audio"
|
||||||
|
"tetris/engine/core"
|
||||||
"tetris/engine/render"
|
"tetris/engine/render"
|
||||||
"tetris/game/state"
|
"tetris/game/state"
|
||||||
|
|
||||||
rl "github.com/gen2brain/raylib-go/raylib"
|
rl "github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GameOver struct{}
|
type GameOver struct {
|
||||||
|
blinkTimer core.IntervalTimer
|
||||||
|
textColor color.RGBA
|
||||||
|
}
|
||||||
|
|
||||||
func (GameOver) Enter() {
|
func (GameOver *GameOver) Enter() {
|
||||||
audio.Play(assets.SFX_GAME_OVER)
|
audio.Play(assets.SFX_GAME_OVER)
|
||||||
|
GameOver.blinkTimer = core.NewIntervalTimer(0.2)
|
||||||
|
GameOver.textColor = rl.White
|
||||||
}
|
}
|
||||||
|
|
||||||
func (GameOver) Exit() {
|
func (GameOver) Exit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (GameOver GameOver) Update(fsm state.Transitioner, delta float32) {
|
func (GameOver) soundDone() bool {
|
||||||
if !audio.IsPlaying(assets.SFX_GAME_OVER) {
|
return !audio.IsPlaying(assets.SFX_GAME_OVER)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (GameOver *GameOver) Update(fsm state.Transitioner, delta float32) {
|
||||||
|
if GameOver.blinkTimer.UpdateReset(delta) {
|
||||||
|
if GameOver.textColor == rl.Red {
|
||||||
|
GameOver.textColor = rl.White
|
||||||
|
} else {
|
||||||
|
GameOver.textColor = rl.Red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if GameOver.soundDone() {
|
||||||
if rl.IsKeyPressed(rl.KeyEnter) {
|
if rl.IsKeyPressed(rl.KeyEnter) {
|
||||||
fsm.Switch("gameplay")
|
fsm.Switch("gameplay")
|
||||||
} else if rl.IsKeyPressed(rl.KeyQ) {
|
} else if rl.IsKeyPressed(rl.KeyQ) {
|
||||||
|
|
@ -28,8 +48,12 @@ func (GameOver GameOver) Update(fsm state.Transitioner, delta float32) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (GameOver *GameOver) Render() {
|
func (GameOver GameOver) Render() {
|
||||||
render.Begin(rl.Black)
|
render.Begin(rl.Black)
|
||||||
render.DrawTextCenter(340, 200, 32, "Game Over", rl.White)
|
render.DrawTextCenter(340, 200, 32, "Game Over", GameOver.textColor)
|
||||||
|
if GameOver.soundDone() {
|
||||||
|
render.DrawTextCenter(340, 290, 16, "Press ENTER to restart", rl.White)
|
||||||
|
render.DrawTextCenter(340, 316, 16, "Press Q to return to menu", rl.White)
|
||||||
|
}
|
||||||
render.End()
|
render.End()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"tetris/assets"
|
"tetris/assets"
|
||||||
"tetris/engine/audio"
|
"tetris/engine/audio"
|
||||||
"tetris/engine/render"
|
"tetris/engine/render"
|
||||||
|
"tetris/game"
|
||||||
"tetris/game/state"
|
"tetris/game/state"
|
||||||
|
|
||||||
rl "github.com/gen2brain/raylib-go/raylib"
|
rl "github.com/gen2brain/raylib-go/raylib"
|
||||||
|
|
@ -53,8 +54,33 @@ func (menu *Menu) Update(fsm state.Transitioner, delta float32) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (Menu) renderLogo(offset_x, offset_y int32) {
|
||||||
|
for y := range assets.LOGO_HEIGHT {
|
||||||
|
for x := range assets.LOGO_STRIDE {
|
||||||
|
index := assets.Logo[x+(y*assets.LOGO_STRIDE)]
|
||||||
|
block := game.Block(index)
|
||||||
|
|
||||||
|
if block == game.BLOCK_EMPTY {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
src := block.Tile().GetTexRect()
|
||||||
|
|
||||||
|
render.DrawTextureRec(src, rl.Rectangle{
|
||||||
|
X: float32(offset_x) + (float32(x) * src.Width * 2),
|
||||||
|
Y: float32(offset_y) + (float32(y) * src.Height * 2),
|
||||||
|
Width: src.Width * 2,
|
||||||
|
Height: src.Height * 2,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (menu Menu) Render() {
|
func (menu Menu) Render() {
|
||||||
render.Begin(rl.Black)
|
render.Begin(rl.Black)
|
||||||
|
|
||||||
|
menu.renderLogo(20, 150)
|
||||||
|
|
||||||
y := int32(400)
|
y := int32(400)
|
||||||
for i, entry := range menu.entries {
|
for i, entry := range menu.entries {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue