Witam czy mógł by mi ktoś wytłumaczyć ten kod bo z AVRC++ jestem zielony?:
źródło
#define F_CPU 20000000UL
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include <stdlib.h>
#include <util/delay.h>
#include "interrupts.h"
#include "graphic.h"
#include "sound.h"
#include "controller.h"
#include "collision.h"
#include "data.h"
extern unsigned char JOY1_UP,JOY1_DOWN,JOY1_LEFT,JOY1_RIGHT,JOY1_BTN1,JOY1_BTN2,JOY2_UP,JOY2_DOWN,JOY2_LEFT,JOY2_RIGHT,JOY2_BTN1,JOY2_BTN2;
unsigned char ball_x = 100;
unsigned char ball_y = 100;
unsigned char ball_horizontal_dir;
unsigned char ball_vertical_dir;
unsigned char p1_y = 100;
unsigned char p2_y = 100;
unsigned char p1_score=0;
unsigned char p2_score=0;
unsigned char p1_miss=0;
unsigned char p2_miss=0;
unsigned char winner;
unsigned char ball_speed = 5;
char mode=0;
char result_str[3];
int main(void)
{
//konfiguracja portow
DDRA = 0xFF;
DDRB = 0xFF;
DDRC = 0xFF;
DDRD = 0xFF;
//inicjalizuj USART
UBRRL = 129; // 9600bps @ 20.00MHz
UCSRC = 0x86; // No Parity | 1 Stop Bit | 8 Data Bit
UCSRB = (1<<TXEN)|(1<<RXEN);
//inicjalizuj przerwania
InitInterrupts();
while(1)
{
NextFrame();
InputUpdate();
/***********************************************/
FillScreen(G);
DrawRectangle(98,0,99,255,W);
DrawBitmap(10,p1_y,4,32,desk);
DrawBitmap(178,p2_y,4,32,desk);
DrawBitmap(ball_x,ball_y,2,4,ball);
DrawText(82,10,itoa(p1_score,result_str,10),0);
DrawText(105,10,itoa(p2_score,result_str,10),0);
if (p1_miss) DrawText(20,10,"PUDLO",R);
if (p2_miss) DrawText(140,10,"PUDLO",R);
/***********************************************/
if( JOY1_UP && p1_y > 0){
p1_y=p1_y-10;
} else if( JOY1_DOWN && p1_y < 220){
p1_y=p1_y+10;
}
/***********************************************/
if( JOY2_UP && p2_y > 0){
p2_y=p2_y-10;
} else if( JOY2_DOWN && p2_y < 220){
p2_y=p2_y+10;
}
/***********************************************/
if(mode==1)
{
//////////////////////////
if (CheckRectangleCollision(ball_x,ball_y,ball_x+2,ball_y+4,10,p1_y,20,p1_y+32))
{
ball_horizontal_dir=1;
//PlaySound(pong_sound);
}
else if (CheckRectangleCollision(ball_x,ball_y,ball_x+2,ball_y+4,172,p2_y,182,p2_y+32))
{
ball_horizontal_dir=0;
//PlaySound(pong_sound);
}
if (ball_y<6) ball_vertical_dir=1;
if (ball_y>245) ball_vertical_dir=0;
if (ball_horizontal_dir) ball_x=ball_x+ball_speed; else ball_x=ball_x-ball_speed;
if (ball_vertical_dir) ball_y=ball_y+ball_speed; else ball_y=ball_y-ball_speed;
if ((!p1_miss)&&(!p2_miss))
{
if (ball_x<10)
{
p1_miss=1;
p2_score++;
} else
if (ball_x>182)
{
p2_miss=1;
p1_score++;
}
} else
{
if ((ball_x>14)&&(ball_x<24))
{
p2_miss=0;
} else
if ((ball_x<178)&&(ball_x>168))
{
p1_miss=0;
}
}
if ((p1_score >= 10)&&((p1_score-p2_score)>1))
{
winner=1;
mode++;
}
if ((p2_score >= 10)&&((p2_score-p1_score)>1))
{
winner=2;
mode++;
}
//////////////////////////
} else
if (mode==0)
{
//////////////////////////
DrawRectangle(40,60,162,180,0);
DrawText(60,120,"NACISNIJ PRZYCISK",R);
DrawText(75,150,"K RACHWAL",W);
DrawText(75,80,"PONG 2008",B);
if (JOY1_BTN1||JOY1_BTN2||JOY2_BTN1||JOY2_BTN2) mode++;
//////////////////////////
} else
if (mode==2)
{
//////////////////////////
if (winner==1) DrawText(73,80,"GRACZ 1 WYGRAL",0);
if (winner==2) DrawText(73,80,"GRACZ 2 WYGRAL",0);
DrawRectangle(40,115,162,135,0);
DrawText(60,120,"NACISNIJ PRZYCISK",R);
if (JOY1_BTN1||JOY1_BTN2||JOY2_BTN1||JOY2_BTN2)
{
ball_x = 100;
ball_y = 100;
p1_score=0;
p2_score=0;
p1_miss=0;
p2_miss=0;
mode=1;
}
//////////////////////////
}
/***********************************************/
}
}
źródło