/*
 * ekrany.c
 *
 *  Created on: 18-12-2012
 *      Author: Mirosław Kardaś
 */
#include <avr/io.h>
#include <avr/interrupt.h>
#include <string.h>
#include <stdlib.h>
#include <util/delay.h>

#include "LCD/lcd44780.h"
#include "ekrany.h"
#include "SNAKE/snake.h"

uint8_t lg[] = {32,32,32,32,1,4,32,4};
uint8_t pg[] = {32,32,32,32,16,4,32,4};
uint8_t ld[] = {4,32,4,32,1,32,32,32};
uint8_t pd[] = {4,32,4,32,16,32,32,32};

uint8_t poziom[] = {32,32,32,32,21,32,32,32};
uint8_t pion[] = {4,32,4,32,4,32,4,32};


void display_init( uint8_t usr_cnt ) {
	lcd_locate(0,0);
	lcd_str("\x80\x80            \x81\x81");
	lcd_locate(1,0);
	lcd_str(" \x80 SNAKE WAR! \x81");
	lcd_locate(2,1);
	lcd_str("\x80            \x81");
	lcd_locate(3,1);
	lcd_str("\x80\x80\x80\x80  \x82    \x81\x81\x81");
	_delay_ms(1000);
	lcd_cls();
}


void ekran_koncowy( uint8_t usr_cnt ) {

	lcd_defchar(0x82, lg);
	lcd_defchar(0x83, pg);
	lcd_defchar(0x84, ld);
	lcd_defchar(0x85, pd);

	lcd_defchar(0x86, poziom);
	lcd_defchar(0x87, pion);

	lcd_cls();

	uint8_t i;
	lcd_locate(0,0);
	for(i=0; i<16; i++) lcd_char(0x86);
	lcd_locate(3,0);
	for(i=0; i<16; i++) lcd_char(0x86);

	for(i=0; i<4; i++) {
		lcd_locate( i, 0 );
		lcd_char(0x87);
		lcd_locate( i, 15 );
		lcd_char(0x87);
	}

	lcd_locate(0,0);
	lcd_char(0x82);
	lcd_locate(0,15);
	lcd_char(0x83);
	lcd_locate(3,0);
	lcd_char(0x84);
	lcd_locate(3,15);
	lcd_char(0x85);

	lcd_locate(0,4);
	lcd_str(" KONIEC ");
	lcd_locate(1,5);
	lcd_str("max: ");
	lcd_int( ram_cfg.max_score );
	lcd_locate(2,2);
	lcd_char(snakes(0)->face);
	if( usr_cnt == 1 ) {
		lcd_char(snakes(0)->face);
		lcd_char(snakes(0)->face);
		lcd_char(snakes(0)->face);
		lcd_char(snakes(0)->face);
		lcd_locate(2,10);
	} else lcd_locate(2,5);
	lcd_int( snakes(0)->punkty );

	if( usr_cnt == 2 ) {
		lcd_locate(2,13);
		lcd_char(snakes(1)->face);
		lcd_locate(2,10);
		lcd_int( snakes(1)->punkty );
	}
}
