mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
examples: fix bounce.v; clean up tetris.v
This commit is contained in:
@ -195,7 +195,7 @@ fn (mut g Game) init_game() {
|
||||
g.parse_tetros()
|
||||
rand.seed(int(time.now().unix))
|
||||
g.generate_tetro()
|
||||
g.field = [] // TODO: g.field = [][]int
|
||||
g.field = []
|
||||
// Generate the field, fill it with 0's, add -1's on each edge
|
||||
for _ in 0..field_height + 2 {
|
||||
mut row := [0].repeat(field_width + 2)
|
||||
@ -240,10 +240,7 @@ fn (mut g Game) move_tetro() bool {
|
||||
y := block.y + g.pos_y + 1
|
||||
x := block.x + g.pos_x
|
||||
// Reached the bottom of the screen or another block?
|
||||
// TODO: if g.field[y][x] != 0
|
||||
//if g.field[y][x] != 0 {
|
||||
row := g.field[y]
|
||||
if row[x] != 0 {
|
||||
if g.field[y][x] != 0 {
|
||||
// The new tetro has no space to drop => end of the game
|
||||
if g.pos_y < 2 {
|
||||
g.state = .gameover
|
||||
@ -321,9 +318,7 @@ fn (g &Game) drop_tetro() {
|
||||
x := tetro.x + g.pos_x
|
||||
y := tetro.y + g.pos_y
|
||||
// Remember the color of each block
|
||||
// TODO: g.field[y][x] = g.tetro_idx + 1
|
||||
mut row := g.field[y]
|
||||
row[x] = g.tetro_idx + 1
|
||||
g.field[y][x] = g.tetro_idx + 1
|
||||
}
|
||||
}
|
||||
|
||||
@ -377,7 +372,7 @@ fn (mut g Game) draw_scene() {
|
||||
|
||||
fn parse_binary_tetro(t_ int) []Block {
|
||||
mut t := t_
|
||||
res := [Block{}].repeat(4)
|
||||
mut res := [Block{}].repeat(4)
|
||||
mut cnt := 0
|
||||
horizontal := t == 9// special case for the horizontal line
|
||||
ten_powers := [1000,100,10,1]
|
||||
@ -391,11 +386,8 @@ fn parse_binary_tetro(t_ int) []Block {
|
||||
bin := digit % 2
|
||||
digit /= 2
|
||||
if bin == 1 || (horizontal && i == tetro_size - 1) {
|
||||
// TODO: res[cnt].x = j
|
||||
// res[cnt].y = i
|
||||
mut point := &res[cnt]
|
||||
point.x = j
|
||||
point.y = i
|
||||
res[cnt].x = j
|
||||
res[cnt].y = i
|
||||
cnt++
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user