examples/tetris: smaller screenshot

pull/315/head
Alexander Medvednikov 2019-04-15 13:35:49 +02:00
parent eaf7eca8ef
commit 758e444699
2 changed files with 6 additions and 7 deletions

View File

@ -1 +1 @@
<img src='https://raw.githubusercontent.com/vlang/v/master/examples/tetris/screenshot.png' width=540> <img src='https://raw.githubusercontent.com/vlang/v/master/examples/tetris/screenshot.png' width=200>

View File

@ -236,19 +236,19 @@ fn (g mut Game) drop_tetro() {
} }
} }
fn (g mut Game) draw_tetro() { fn (g &Game) draw_tetro() {
for i := 0; i < TETRO_SIZE; i++ { for i := 0; i < TETRO_SIZE; i++ {
tetro := g.tetro[i] tetro := g.tetro[i]
g.draw_block(g.posY + tetro.y, g.posX + tetro.x, g.tetroIdx + 1) g.draw_block(g.posY + tetro.y, g.posX + tetro.x, g.tetroIdx + 1)
} }
} }
fn (g mut Game) draw_block(i, j int, color_idx int) { fn (g &Game) draw_block(i, j int, color_idx int) {
g.gg.draw_rect((j - 1) * BLOCK_SIZE, (i - 1) * BLOCK_SIZE, g.gg.draw_rect((j - 1) * BLOCK_SIZE, (i - 1) * BLOCK_SIZE,
BLOCK_SIZE - 1, BLOCK_SIZE - 1, COLORS[color_idx]) BLOCK_SIZE - 1, BLOCK_SIZE - 1, COLORS[color_idx])
} }
fn (g mut Game) draw_field() { fn (g &Game) draw_field() {
for i := 1; i < FIELD_HEIGHT + 1; i++ { for i := 1; i < FIELD_HEIGHT + 1; i++ {
for j := 1; j < FIELD_WIDTH + 1; j++ { for j := 1; j < FIELD_WIDTH + 1; j++ {
f := g.field[i] f := g.field[i]
@ -259,14 +259,13 @@ fn (g mut Game) draw_field() {
} }
} }
fn (g mut Game) draw_scene() { fn (g &Game) draw_scene() {
g.draw_tetro() g.draw_tetro()
g.draw_field() g.draw_field()
} }
fn parse_binary_tetro(t int) []Block { fn parse_binary_tetro(t int) []Block {
res := [Block{} res := [Block{} ; 4]
; 4]
mut cnt := 0 mut cnt := 0
horizontal := t == 9// special case for the horizontal line horizontal := t == 9// special case for the horizontal line
for i := 0; i <= 3; i++ { for i := 0; i <= 3; i++ {