examples/tetris: remove old array hacks
parent
98034e5504
commit
23c9563600
|
@ -179,11 +179,9 @@ fn (mut g Game) init_game() {
|
|||
row[field_width + 1] = -1
|
||||
g.field << row
|
||||
}
|
||||
mut first_row := g.field[0]
|
||||
mut last_row := g.field[field_height + 1]
|
||||
for j in 0 .. field_width + 2 {
|
||||
first_row[j] = -1
|
||||
last_row[j] = -1
|
||||
g.field[0][j] = -1
|
||||
g.field[field_height + 1][j] = -1
|
||||
}
|
||||
g.score = 0
|
||||
g.lines = 0
|
||||
|
@ -284,8 +282,7 @@ fn (mut g Game) delete_completed_lines() {
|
|||
|
||||
fn (mut g Game) delete_completed_line(y int) {
|
||||
for x := 1; x <= field_width; x++ {
|
||||
f := g.field[y]
|
||||
if f[x] == 0 {
|
||||
if g.field[y][x] == 0 {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -294,9 +291,7 @@ fn (mut g Game) delete_completed_line(y int) {
|
|||
// Move everything down by 1 position
|
||||
for yy := y - 1; yy >= 1; yy-- {
|
||||
for x := 1; x <= field_width; x++ {
|
||||
mut a := g.field[yy + 1]
|
||||
b := g.field[yy]
|
||||
a[x] = b[x]
|
||||
g.field[yy + 1][x] = g.field[yy][x]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -361,9 +356,8 @@ fn (g &Game) draw_block(i int, j int, color_idx int) {
|
|||
fn (g &Game) draw_field() {
|
||||
for i := 1; i < field_height + 1; i++ {
|
||||
for j := 1; j < field_width + 1; j++ {
|
||||
f := g.field[i]
|
||||
if f[j] > 0 {
|
||||
g.draw_block(i, j, f[j])
|
||||
if g.field[i][j] > 0 {
|
||||
g.draw_block(i, j, g.field[i][j])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue