mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
examples/tetris: better font initialization
This commit is contained in:
parent
7879bde8bb
commit
11c2f634f3
@ -21,6 +21,14 @@ const (
|
|||||||
TimerPeriod = 250 // ms
|
TimerPeriod = 250 // ms
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
text_cfg = gx.TextCfg{
|
||||||
|
align:gx.ALIGN_LEFT
|
||||||
|
size:12
|
||||||
|
color:gx.rgb(0, 0, 170)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Tetros' 4 possible states are encoded in binaries
|
// Tetros' 4 possible states are encoded in binaries
|
||||||
BTetros = [
|
BTetros = [
|
||||||
@ -105,8 +113,7 @@ struct Game {
|
|||||||
gg *gg.GG
|
gg *gg.GG
|
||||||
// ft context for font drawing
|
// ft context for font drawing
|
||||||
ft *freetype.Context
|
ft *freetype.Context
|
||||||
// gx text config for font drawing
|
font_loaded bool
|
||||||
tcfg *gx.TextCfg
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -121,7 +128,6 @@ fn main() {
|
|||||||
window_user_ptr: game
|
window_user_ptr: game
|
||||||
})
|
})
|
||||||
ft: 0
|
ft: 0
|
||||||
tcfg: 0
|
|
||||||
}
|
}
|
||||||
game.gg.window.set_user_ptr(game) // TODO remove this when `window_user_ptr:` works
|
game.gg.window.set_user_ptr(game) // TODO remove this when `window_user_ptr:` works
|
||||||
game.init_game()
|
game.init_game()
|
||||||
@ -135,14 +141,7 @@ fn main() {
|
|||||||
use_ortho: true
|
use_ortho: true
|
||||||
font_size: 18
|
font_size: 18
|
||||||
}, 1)
|
}, 1)
|
||||||
if game.ft != 0 {
|
game.font_loaded = (game.ft != 0 )
|
||||||
// if font loaded, define default font color etc..
|
|
||||||
game.tcfg = &gx.TextCfg{
|
|
||||||
align:gx.ALIGN_LEFT
|
|
||||||
size:12
|
|
||||||
color:gx.rgb(0, 0, 170)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for {
|
for {
|
||||||
gg.clear(gx.White)
|
gg.clear(gx.White)
|
||||||
game.draw_scene()
|
game.draw_scene()
|
||||||
@ -309,8 +308,8 @@ fn (g &Game) draw_field() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn (g &Game) draw_score() {
|
fn (g &Game) draw_score() {
|
||||||
if g.tcfg != 0 {
|
if g.font_loaded {
|
||||||
g.ft.draw_text(1, 2, 'score: ' + g.score.str(), g.tcfg)
|
g.ft.draw_text(1, 2, 'score: ' + g.score.str(), text_cfg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user