Esempio n. 1
0
static void start(void)
{
	setSingleClickHandler(PLAYER1_LEFT, move, LEFT_P1);
	setSingleClickHandler(PLAYER1_RIGHT, move, RIGHT_P1);
	setSingleClickHandler(PLAYER2_LEFT, move, LEFT_P2);
	setSingleClickHandler(PLAYER2_RIGHT, move, RIGHT_P2);
	setSingleClickHandler(MENU, menu, 0);

	byte s;
	for (s = 0; s < 2; s++) {
		byte i;
		for (i = 0; i < snake[s].length; i++)
			matrix.setLed(0, snake[s].body.y[i], snake[s].body.x[i], true);
	}

	matrix.setLed(0, apple.y, apple.x, apple.on);

	printLcd(3, 0, "Scores :");
	printLcd(2, 1, snake[0].score);
	printLcd(7, 1, "--");
	printLcd(13, 1, snake[1].score);

	delay(500);

	updateSnakesTimer = registerTimerEvent(options[SNAKE_MOVE_DELAY_O], updateSnakes, 0);
	blinkApple(0);
	blinkSecondSnake(0);
}
Esempio n. 2
0
void printSeven(int position) {
    clearLcd();
    drawFirstLine();
    drawFirstRightColumn();
    drawLastRightColumn();
    printLcd(position);
}
Esempio n. 3
0
void printFour(int position) {
    clearLcd();
    drawFirstLeftColumn();
    drawFirstRightColumn();
    drawMiddleLine();
    drawLastRightColumn();
    printLcd(position);
}
Esempio n. 4
0
static void gameOver(void)
{
	endRound();
	matrix.setLed(0, apple.y, apple.x, true); // In case the apple is off at that time
	strcpy_P(buffer, (char *) pgm_read_word(&(strings[GAME_OVER])));
	printLcd(3, 1, buffer);
	wipeMatrix();
	delay(500);
	newRound();
}
Esempio n. 5
0
static void updateValue(void)
{
	switch (selectedOption) {
		case MATRIX_BRIGHTNESS_O:
			matrix.setIntensity(0, options[MATRIX_BRIGHTNESS_O]);
			break;
	}

	clearLcdLine(1);
	printLcd(7, 1, options[selectedOption]);
}
Esempio n. 6
0
static void start(void)
{
	setSingleClickHandler(PLAYER1_LEFT, move, LEFT);
	setSingleClickHandler(PLAYER1_RIGHT, move, RIGHT);
	setSingleClickHandler(PLAYER2_LEFT, move, LEFT);
	setSingleClickHandler(PLAYER2_RIGHT, move, RIGHT);
	setSingleClickHandler(MENU, menu, 0);

	byte i;
	for (i = 0; i < snake.length; i++)
		matrix.setLed(0, snake.body.y[i], snake.body.x[i], true);
	matrix.setLed(0, apple.y, apple.x, apple.on);

	printLcd(3, 0, "Score :");
	printLcd(11, 0, snake.length - 3);

	delay(500);

	updateSnakeTimer = registerTimerEvent(options[SNAKE_MOVE_DELAY_O], updateSnake, 0);
	blinkAppleTimer = registerTimerEvent(100, blinkApple, 0);
}
Esempio n. 7
0
static void gameOver(byte s)
{
	endRound();
	matrix.setLed(0, apple.y, apple.x, true); // In case the apple is off at that time
	strcpy_P(buffer, (char *) pgm_read_word(&(strings[GAME_OVER])));
	printLcd(3, 0, buffer);
	switch (s) {
		case 0:
			strcpy_P(buffer2, (char *) pgm_read_word(&(strings[PLAYER_WIN])));
			printLcd(0, 1, buffer2);
			printLcd(7, 1, "2");
			snake[1].score++;
			break;

		case 1:
			strcpy_P(buffer2, (char *) pgm_read_word(&(strings[PLAYER_WIN])));
			printLcd(0, 1, buffer2);
			printLcd(7, 1, "1");
			snake[0].score++;
			break;

		case 2:
			strcpy_P(buffer2, (char *) pgm_read_word(&(strings[TIE])));
			printLcd(4, 1, buffer2);
	}
	wipeMatrix();
	delay(500);
	newRound();
}
Esempio n. 8
0
static void print(void)
{
	stopLcdScroll(0);
	clearLcdLine(0);

	strcpy_P(buffer, (char *) pgm_read_word(&(strings[OPTION_1 + selectedOption])));

	if (stringsSizes[OPTION_1 + selectedOption] > 16)
		newLcdScroll(buffer, 0, 200);
	else
		printLcd(8 - stringsSizes[OPTION_1 + selectedOption], 0, buffer);

	updateValue();
}
Esempio n. 9
0
static void updateSnakes(byte data)
{
	byte s;
	for (s = 0; s < 2; s++) {
		matrix.setLed(0, snake[s].body.y[snake[s].length - 1], snake[s].body.x[snake[s].length - 1], false);

		byte i;
		for (i = snake[s].length - 1; i > 0; i--) {
			snake[s].body.x[i] = snake[s].body.x[i - 1];
			snake[s].body.y[i] = snake[s].body.y[i - 1];
		}

		snake[s].body.x[0] += snake[s].xDir;
		snake[s].body.y[0] += snake[s].yDir; 

		if (snake[s].body.x[0] == 8 || snake[s].body.y[0] == 8 || snake[s].body.x[0] == 0xFF || snake[s].body.y[0] == 0xFF) {
			gameOver(s);
			return;
		}

		// Colisions check
		byte s2;
		for (s2 = 0; s2 < 2; s2++) {
			for (i = (s2 == s) ? 4 : 1; i < snake[s2].length; i++) {
				if (snake[s].body.x[0] == snake[s2].body.x[i] && snake[s].body.y[0] == snake[s2].body.y[i]) {
					gameOver(s);
					return;
				}

			}
		}

		matrix.setLed(0, snake[s].body.y[0], snake[s].body.x[0], true);

		if (snake[s].body.x[0] == apple.x && snake[s].body.y[0] == apple.y) {
			printLcd((s == 0) ? 2 : 13, 1, ++snake[s].length - 3);
			generateApple();
		}

		snake[s].hasTurned = false;
	}

	if (snake[0].body.x[0] == snake[1].body.x[0] && snake[0].body.y[0] == snake[1].body.y[0]) // Collision head to head
		gameOver(2);

	updateSnakesTimer = registerTimerEvent(options[SNAKE_MOVE_DELAY_O], updateSnakes, 0);
}
Esempio n. 10
0
static void updateSnake(byte data)
{
	matrix.setLed(0, snake.body.y[snake.length - 1], snake.body.x[snake.length - 1], false);

	byte i;
	for (i = snake.length - 1; i > 0; i--) {
		snake.body.x[i] = snake.body.x[i - 1];
		snake.body.y[i] = snake.body.y[i - 1];
	}

	snake.body.x[0] += snake.xDir;
	snake.body.y[0] += snake.yDir; 

	if (snake.body.x[0] == 8 || snake.body.y[0] == 8 || snake.body.x[0] == 0xFF || snake.body.y[0] == 0xFF) {
		gameOver();
		return;
	}

	for (i = 4; i < snake.length; i++) {
		if (snake.body.x[0] == snake.body.x[i] && snake.body.y[0] == snake.body.y[i]) {
			gameOver();
			return;
		}

	}

	matrix.setLed(0, snake.body.y[0], snake.body.x[0], true);

	if (snake.body.x[0] == apple.x && snake.body.y[0] == apple.y) {
		printLcd(11, 0, ++snake.length - 3);
		generateApple();
	}

	snake.hasTurned = false;

	updateSnakeTimer = registerTimerEvent(options[SNAKE_MOVE_DELAY_O], updateSnake, 0);
}