Beispiel #1
0
void init_grid(Grid* grid) {
	grid->ticks_per_drop = 20;
	grid->level_progress = 0;
	grid->lines = 0;
	grid->animation = 0;
	grid->state = STATE_NORMAL;
	memset(grid->matrix, 0, sizeof(grid->matrix));
	memset(grid->highlight, 0, sizeof(grid->highlight));
	new_stone(grid);
	new_stone(grid);


//	print_5x3_at(0,0,"Text Test",15);
}
Beispiel #2
0
static void update_grid_normal(Grid* grid) {
	int i, j, x, y;

	// rotation
	j = button_down(BUTTON_A) - button_down(BUTTON_B);
	if(j) {
		i = grid->rot;
		grid->rot = (j > 0)
			? grid->rot * 2 % 15
			: (grid->rot / 2 | grid->rot * 8) & 15;
		if(collision(grid, 0)) grid->rot = i;
	}


	// horizontal movement
	i = grid->x;
	grid->x += button_down(BUTTON_RIGHT) - button_down(BUTTON_LEFT);
	if(i != grid->x && collision(grid, 0)) grid->x = i;


	// vertical movement
	grid->tick++;
	if(button_down(BUTTON_DOWN) || grid->tick >= grid->ticks_per_drop) {
		grid->tick = 0;
		grid->y++;
		if(collision(grid, 0)) {
			grid->y--;

			// check for game over
			if(collision(grid, 1)) {
				grid->state = STATE_GAMEOVER;
				return;
			}

			// copy stone to grid
			for(y = 0; y < 4; y++)
				for(x = 0; x < 4; x++)
					if(STONES[grid->stone][x * 4 + y] & grid->rot)
						grid->matrix[y + grid->y][x + grid->x] = grid->stone + 1;

			// get a new stone
			new_stone(grid);

			// check for complete lines
			int lines = 0;
			for(y = 0; y < GRID_HEIGHT; y++) {

				for(x = 0; x < GRID_WIDTH; x++)
					if(!grid->matrix[y][x]) break;

				lines += (x == GRID_WIDTH);
				grid->highlight[y] = (x == GRID_WIDTH);
			}
			grid->state = lines ? STATE_CLEARLINES : STATE_WAIT;
			grid->state_delay = 0;
		}
	}
}
Beispiel #3
0
void init_grid(Grid* grid, int nr) {
	grid->nr = nr;
	grid->ticks_per_drop = 20;
	grid->level_progress = 0;
	grid->lines = 0;
	grid->animation = 0;
//	grid->state = STATE_FREE;
	grid->state = STATE_NORMAL;
	memset(grid->matrix, 0, sizeof(grid->matrix));
	memset(grid->highlight, 0, sizeof(grid->highlight));
	grid->stone_count = -1;
	new_stone(grid);
	new_stone(grid);
	int x, y;
	for(x = 0; x < 12; x++) {
		for(y = 0; y < 32; y++) {
//			pixel(grid->nr * 12 + x, y, 0);
			set_frame_buffer(grid->nr * 12 + x, y, 0);
		}
	}
}
bool			set_player_addstone(t_player *player, e_stone type,
					   uint nb)
{
  t_stone 		*stone;

  if ((stone = get_data_as_arg(player->stones, match_stone, &type)))
    stone->nb += nb;
  else if (!(stone = new_stone(type, nb)) ||
	   !put_in_list(&(player->stones), stone))
    return (false);
  return (true);
}
Beispiel #5
0
void play( void )
{
	ende=0;
	display_field();
	new_stone();
	display_stone();
	while (!ende)
	{
		move_stone();
		display_stone();
		fall_stone();
		clear_line();
		display_score();
		check_ende();
		delay(zeit);
	}
}
Beispiel #6
0
static void update_grid_normal(Grid* grid) {
	int i, x, y;

	int mov, rot, drop;
	get_grid_input(grid, &mov, &rot, &drop);

	// rotation
	if(rot) {
		i = grid->rot;
		grid->rot = (rot > 0)
			? grid->rot * 2 % 15
			: (grid->rot / 2 | grid->rot * 8) & 15;
		if(grid_collision(grid, 0)) grid->rot = i;
	}


	// horizontal movement
	i = grid->x;
	grid->x += mov;
	if(i != grid->x && grid_collision(grid, 0)) grid->x = i;


	// vertical movement
	grid->tick++;
	if(drop || grid->tick >= grid->ticks_per_drop) {
		grid->tick = 0;
		grid->y++;
		if(grid_collision(grid, 0)) {
			grid->y--;

			int over = 0;
			// check for game over
			if(grid_collision(grid, 1)) {
				grid->state_delay = 0;
				grid->state = STATE_GAMEOVER;
				over = 1;
			}

			stone_to_grid(grid, grid->stone + 1);

			if(over) return;


			// get a new stone
			new_stone(grid);

			// check for complete lines
			int lines = 0;
			for(y = 0; y < GRID_HEIGHT; y++) {

				for(x = 0; x < GRID_WIDTH; x++)
					if(!grid->matrix[y][x]) break;

				lines += (x == GRID_WIDTH);
				grid->highlight[y] = (x == GRID_WIDTH);
			}
			grid->state = lines ? STATE_CLEARLINES : STATE_WAIT;
			grid->state_delay = 0;
		}
	}
}
Beispiel #7
0
void replace_stone( void )
{
	displayed=0;
	new_stone();
}
Beispiel #8
0
void ram() {

	int raw_key, key;
	int i, j;

	new_stone();
	new_stone();

	// epmty grid
	for(i = 0; i < GRID_HEIGHT; i++)
		for(j = 0; j < GRID_WIDTH; j++)
			grid[i][j] = 0;


	// prepare screen
	lcdClear();
	for(i = 0; i < 96; i++) {
		lcdSetPixel(i, 2, 1);
		lcdSetPixel(i, 65, 1);
	}
	for(i = 3; i < 65; i++) {
		lcdSetPixel(2, i, 1);
		lcdSetPixel(35, i, 1);
		lcdSetPixel(93, i, 1);
	}

	for(;;) {

		// handle input
		raw_key = getInputRaw();
		key = 0;
		for(i = 0; i < 5; i++) {
			if(raw_key & (1 << i)) {
				if(!key_rep[i] || key_rep[i] == KEY_REPEAT_DELEAY) key |= 1 << i;
				key_rep[i] += key_rep[i] < KEY_REPEAT_DELEAY;
			}
			else key_rep[i] = 0;
		}


		// rotate
		if(key & BTN_UP) {
			i = rot;
			rot = (rot << 1) % 15;
			if(collision(0)) rot = i;
		}

		// horizontal movement
		i = x_pos;
		x_pos += !!(key & BTN_RIGHT) - !!(key & BTN_LEFT);
		if(i != x_pos && collision(0)) x_pos = i;

		// vertical movement
		ticks++;
		if(key & BTN_DOWN || ticks >= ticks_per_drop) {
			ticks = 0;
			y_pos++;
			if(collision(0)) {
				y_pos--;

				// check for game over
				if(collision(1)) return;

				// copy stone to grid
				int x, y;
				for(y = 0; y < 4; y++) {
					for(x = 0; x < 4; x++) {
						if(stones[stone][(x << 2) + y] & rot)
							grid[y + y_pos][x + x_pos] = 1;
					}
				}

				// check for complete lines
				for(y = 0; y < GRID_HEIGHT; y++) {
					for(x = 0; x < GRID_WIDTH; x++)
						if(!grid[y][x]) break;

					if(x == GRID_WIDTH) {

						lines++;
						ticks_per_drop = STARTING_SPEED - lines / 10;
						if(ticks_per_drop < 1) ticks_per_drop = 1;

						for(i = y; i > 0; i--)
							for(x = 0; x < GRID_WIDTH; x++)
								grid[i][x] = grid[i - 1][x];
					}
				}

				// get a new stone
				new_stone();
			}
		}

		draw_grid();
        lcdDisplay();
		delayms(TICK_LENGTH);
	}
	return;
}
Beispiel #9
0
void ram() {

	int raw_key, key;
	int i, j;
	int score, lastlvl, linec;

	new_stone();
	new_stone();

	// epmty grid
	for(i = 0; i < GRID_HEIGHT; i++)
		for(j = 0; j < GRID_WIDTH; j++)
			grid[i][j] = 0;
	
	// prepare screen
	lcdClear();
	for(i = 0; i < 96; i++) {
		lcdSetPixel(i, 2, 1);
		lcdSetPixel(i, 65, 1);
	}
	for(i = 3; i < 65; i++) {
		lcdSetPixel(2, i, 1);
		lcdSetPixel(35, i, 1);
		lcdSetPixel(93, i, 1);
	}

	score = 0;
	lastlvl=0;
	linec = 0;

	lcdSetCrsr(37,25);
	lcdPrint("level: 0");

	lcdSetCrsr(37,40);
	lcdPrint("score:");
	lcdSetCrsr(37,50);
	lcdPrintInt(0);
	
	for(;;) {

		// handle input
		raw_key = getInputRaw();
		key = 0;
		for(i = 0; i < 5; i++) {
			if(raw_key & (1 << i)) {
				if(!key_rep[i] || key_rep[i] == KEY_REPEAT_DELEAY) key |= 1 << i;
				key_rep[i] += key_rep[i] < KEY_REPEAT_DELEAY;
			}
			else key_rep[i] = 0;
		}


		// rotate
		if(key & BTN_UP) {
			i = rot;
			rot = (rot << 1) % 15;
			if(collision(0)) rot = i;
		}

		// horizontal movement
		i = x_pos;
		x_pos += !!(key & BTN_RIGHT) - !!(key & BTN_LEFT);
		if(i != x_pos && collision(0)) x_pos = i;

		// vertical movement
		ticks++;
		if(key & BTN_DOWN || ticks >= ticks_per_drop) {
			ticks = 0;
			y_pos++;
			if(collision(0)) {
				y_pos--;

				// check for game over
				if(collision(1)) return;

				// copy stone to grid
				int x, y;
				for(y = 0; y < 4; y++) {
					for(x = 0; x < 4; x++) {
						if(stones[stone][(x << 2) + y] & rot)
							grid[y + y_pos][x + x_pos] = 1;
					}
				}

				// check for complete lines
				for(y = 0; y < GRID_HEIGHT; y++) {
					for(x = 0; x < GRID_WIDTH; x++)
						if(!grid[y][x]) break;

					if(x == GRID_WIDTH) {

						lines++;
						linec++;	// temporary line counter
						ticks_per_drop = STARTING_SPEED - lines / 10;
						if(ticks_per_drop < 1) ticks_per_drop = 1;

						for(i = y; i > 0; i--)
							for(x = 0; x < GRID_WIDTH; x++)
								grid[i][x] = grid[i - 1][x];

						switch(linec){
							case 1:
								score += 40*(lines/10+1);
								break;
							case 2:
								score += 100*(lines/10+1);
								break;
							case 3:
								score += 300*(lines/10+1);
								break;
							case 4:
								score += 1200*(lines/10+1);
								break;
						} 
					}
				}

				if (lines/10>lastlvl){
					lcdSetCrsr(37,25);
					lcdPrint("level: ");
					lcdPrintInt(lines/10);
				}
				if (linec > 0){
					lcdSetCrsr(37,40);
					lcdPrint("score:");
					lcdSetCrsr(37,50);
					lcdPrintInt(score);
				}
				
				lastlvl=lines/10;
				linec = 0;
				
				// get a new stone
				new_stone();
			}
		}

		draw_grid();
        lcdDisplay();
		delayms(TICK_LENGTH);
	}
	return;
}