minor fixes
							parent
							
								
									91749d81f5
								
							
						
					
					
						commit
						c291336d61
					
				| 
						 | 
					@ -4,6 +4,7 @@ import gx
 | 
				
			||||||
import gl
 | 
					import gl
 | 
				
			||||||
import gg
 | 
					import gg
 | 
				
			||||||
import glfw
 | 
					import glfw
 | 
				
			||||||
 | 
					import math
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	BLOCK_SIZE = 20 // pixels
 | 
						BLOCK_SIZE = 20 // pixels
 | 
				
			||||||
| 
						 | 
					@ -15,12 +16,6 @@ const (
 | 
				
			||||||
	TIMER_PERIOD = 250 // ms
 | 
						TIMER_PERIOD = 250 // ms
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TODO: type Tetro [TETRO_SIZE]struct{ x, y int }
 | 
					 | 
				
			||||||
struct Block {
 | 
					 | 
				
			||||||
	x int
 | 
					 | 
				
			||||||
	y int
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	// Tetros and their 4 possible states are encoded in binaries
 | 
						// Tetros and their 4 possible states are encoded in binaries
 | 
				
			||||||
	B_TETROS = [
 | 
						B_TETROS = [
 | 
				
			||||||
| 
						 | 
					@ -72,8 +67,14 @@ const (
 | 
				
			||||||
	]
 | 
						]
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TODO: type Tetro [TETRO_SIZE]struct{ x, y int }
 | 
				
			||||||
 | 
					struct Block {
 | 
				
			||||||
 | 
						x int
 | 
				
			||||||
 | 
						y int
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct Game {
 | 
					struct Game {
 | 
				
			||||||
	// Position of the dropping tetromino
 | 
						// Position of the current tetro
 | 
				
			||||||
	pos_x        int
 | 
						pos_x        int
 | 
				
			||||||
	pos_y        int
 | 
						pos_y        int
 | 
				
			||||||
	// field[y][x] contains the color of the block with (x,y) coordinates
 | 
						// field[y][x] contains the color of the block with (x,y) coordinates
 | 
				
			||||||
| 
						 | 
					@ -88,7 +89,7 @@ struct Game {
 | 
				
			||||||
	tetro       []Block
 | 
						tetro       []Block
 | 
				
			||||||
	// TODO: tetros_cache []Tetro 
 | 
						// TODO: tetros_cache []Tetro 
 | 
				
			||||||
	tetros_cache []Block 
 | 
						tetros_cache []Block 
 | 
				
			||||||
	// Index of the dropping tetromino. Refers to its color.
 | 
						// Index of the current tetro. Refers to its color.
 | 
				
			||||||
	tetro_idx    int
 | 
						tetro_idx    int
 | 
				
			||||||
	// Index of the rotation (0-3)
 | 
						// Index of the rotation (0-3)
 | 
				
			||||||
	rotation_idx int
 | 
						rotation_idx int
 | 
				
			||||||
| 
						 | 
					@ -166,11 +167,12 @@ fn (g mut Game) run() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn (g mut Game) move_tetro() {
 | 
					fn (g mut Game) move_tetro() {
 | 
				
			||||||
	// Check each block in the dropping tetro
 | 
						// Check each block in current tetro
 | 
				
			||||||
	for i := 0; i < TETRO_SIZE; i++ {
 | 
						//for i := 0; i < TETRO_SIZE; i++ {
 | 
				
			||||||
		tetro := g.tetro[i]
 | 
							//tetro := g.tetro[i]
 | 
				
			||||||
		y := tetro.y + g.pos_y + 1
 | 
						for block in g.tetro {
 | 
				
			||||||
		x := tetro.x + g.pos_x
 | 
							y := block.y + g.pos_y + 1
 | 
				
			||||||
 | 
							x := block.x + g.pos_x
 | 
				
			||||||
		// Reached the bottom of the screen or another block?
 | 
							// Reached the bottom of the screen or another block?
 | 
				
			||||||
		// TODO: if g.field[y][x] != 0
 | 
							// TODO: if g.field[y][x] != 0
 | 
				
			||||||
		row := g.field[y]
 | 
							row := g.field[y]
 | 
				
			||||||
| 
						 | 
					@ -331,7 +333,7 @@ fn key_down(wnd voidptr, key int, code int, action, mods int) {
 | 
				
			||||||
	case GLFW_KEY_RIGHT:
 | 
						case GLFW_KEY_RIGHT:
 | 
				
			||||||
		game.move_right(1)
 | 
							game.move_right(1)
 | 
				
			||||||
	case GLFW_KEY_DOWN:
 | 
						case GLFW_KEY_DOWN:
 | 
				
			||||||
		game.move_tetro() // drop faster when the player preses <down>
 | 
							game.move_tetro() // drop faster when the player presses <down>
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue