1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

glfw and tetris fixes; temporary ci fixes

This commit is contained in:
Alexander Medvednikov
2020-04-01 23:49:11 +02:00
parent 24fc4a4c04
commit c6cf8ace22
3 changed files with 57 additions and 57 deletions

View File

@ -16,7 +16,7 @@ const (
BlockSize = 20 // pixels
FieldHeight = 20 // # of blocks
FieldWidth = 10
TetroSize = 4
tetro_size = 4
WinWidth = BlockSize * FieldWidth
WinHeight = BlockSize * FieldHeight
TimerPeriod = 250 // ms
@ -39,7 +39,7 @@ const (
const (
// Tetros' 4 possible states are encoded in binaries
BTetros = [
b_tetros = [
// 0000 0
// 0000 0
// 0110 6
@ -91,7 +91,7 @@ const (
UIColor = gx.Red
)
// TODO: type Tetro [TetroSize]struct{ x, y int }
// TODO: type Tetro [tetro_size]struct{ x, y int }
struct Block {
mut:
x int
@ -193,8 +193,8 @@ fn (g mut Game) init_game() {
}
fn (g mut Game) parse_tetros() {
for b_tetros in BTetros {
for b_tetro in b_tetros {
for b_tetros0 in b_tetros {
for b_tetro in b_tetros0 {
for t in parse_binary_tetro(b_tetro) {
g.tetros_cache << t
}
@ -239,7 +239,7 @@ fn (g mut Game) move_tetro() {
fn (g mut Game) move_right(dx int) bool {
// Reached left/right edge or another tetro?
for i in 0..TetroSize {
for i in 0..tetro_size {
tetro := g.tetro[i]
y := tetro.y + g.pos_y
x := tetro.x + g.pos_x + dx
@ -280,21 +280,21 @@ fn (g mut Game) delete_completed_line(y int) {
// Place a new tetro on top
fn (g mut Game) generate_tetro() {
g.pos_y = 0
g.pos_x = FieldWidth / 2 - TetroSize / 2
g.tetro_idx = rand.next(BTetros.len)
g.pos_x = FieldWidth / 2 - tetro_size / 2
g.tetro_idx = rand.next(b_tetros.len)
g.rotation_idx = 0
g.get_tetro()
}
// Get the right tetro from cache
fn (g mut Game) get_tetro() {
idx := g.tetro_idx * TetroSize * TetroSize + g.rotation_idx * TetroSize
g.tetro = g.tetros_cache[idx..idx+TetroSize]
idx := g.tetro_idx * tetro_size * tetro_size + g.rotation_idx * tetro_size
g.tetro = g.tetros_cache[idx..idx+tetro_size]
}
// TODO mut
fn (g &Game) drop_tetro() {
for i in 0..TetroSize {
for i in 0..tetro_size{
tetro := g.tetro[i]
x := tetro.x + g.pos_x
y := tetro.y + g.pos_y
@ -306,7 +306,7 @@ fn (g &Game) drop_tetro() {
}
fn (g &Game) draw_tetro() {
for i in 0..TetroSize {
for i in 0..tetro_size {
tetro := g.tetro[i]
g.draw_block(g.pos_y + tetro.y, g.pos_x + tetro.x, g.tetro_idx + 1)
}
@ -367,7 +367,7 @@ fn parse_binary_tetro(t_ int) []Block {
for j := 3; j >= 0; j-- {
bin := digit % 2
digit /= 2
if bin == 1 || (horizontal && i == TetroSize - 1) {
if bin == 1 || (horizontal && i == tetro_size - 1) {
// TODO: res[cnt].x = j
// res[cnt].y = i
mut point := &res[cnt]
@ -414,7 +414,7 @@ fn key_down(wnd voidptr, key, code, action, mods int) {
// Rotate the tetro
old_rotation_idx := game.rotation_idx
game.rotation_idx++
if game.rotation_idx == TetroSize {
if game.rotation_idx == tetro_size {
game.rotation_idx = 0
}
game.get_tetro()