#include "SDL.h"
int main(){
unsigned short sw=800,sh=480,o=0,n=0,hx=sw/2,hy=sh/2,hxc=hx-30,hyc=hy-30;
SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER);
SDL_Surface* d=SDL_SetVideoMode(sw,sh,32,SDL_SWSURFACE);
SDL_Event go;SDL_Rect t,t2;Uint32 colorkey;bool quit=false;
Uint8* key,l=1,f=10,cf,a,w,n1,n2,j,jc=0,cs=4,l1s=3,xh;
int cx,cy,sx,sy,l1,pbird[40][7],ec=0;
int jump,jt;
/* (purple) BIRD
ew[][0] ACTIVE
ew[][1] X
ew[][2] Y
ew[][3] Animation COUNTER
ew[][4] Animatin FRAME
ew[][5] Attack Counter
ew[][6] DRAW IMAGE
*/
if(l==1){cx=50;cy=300;sx=0;sy=0;// START of LEVEL 1 **********
l1=0;
pbird[ec][0]=1;
pbird[ec][1]=900;
pbird[ec][2]=70;
pbird[ec][3]=0;
pbird[ec][4]=1;
pbird[ec][5]=0;
pbird[ec][6]=0;
SDL_Surface* pbirdn1=SDL_LoadBMP("pbirdn1.bmp");
SDL_Surface* pbirdn2=SDL_LoadBMP("pbirdn2.bmp");
SDL_Surface* pbirds1=SDL_LoadBMP("pbirds1.bmp");
SDL_Surface* pbirds2=SDL_LoadBMP("pbirds2.bmp");
SDL_Surface* pbirdn1r=SDL_LoadBMP("pbirdn1r.bmp");
SDL_Surface* pbirdn2r=SDL_LoadBMP("pbirdn2r.bmp");
SDL_Surface* pbirds1r=SDL_LoadBMP("pbirds1r.bmp");
SDL_Surface* pbirds2r=SDL_LoadBMP("pbirds2r.bmp");
SDL_Surface* section1=SDL_LoadBMP("section1.bmp");
SDL_Surface* bmoon=SDL_LoadBMP("bmoon.bmp");
SDL_Surface* l1bf=SDL_LoadBMP("l1bf.bmp");
colorkey=SDL_MapRGB(bmoon->format,0,0,0);
SDL_SetColorKey(l1bf,SDL_SRCCOLORKEY,colorkey);
SDL_SetColorKey(section1,SDL_SRCCOLORKEY,colorkey);
SDL_SetColorKey(pbirdn1,SDL_SRCCOLORKEY,colorkey);
SDL_SetColorKey(pbirdn1r,SDL_SRCCOLORKEY,colorkey);
SDL_SetColorKey(pbirdn2,SDL_SRCCOLORKEY,colorkey);
SDL_SetColorKey(pbirdn2r,SDL_SRCCOLORKEY,colorkey);
SDL_SetColorKey(pbirds1,SDL_SRCCOLORKEY,colorkey);
SDL_SetColorKey(pbirds1r,SDL_SRCCOLORKEY,colorkey);
SDL_SetColorKey(pbirds2,SDL_SRCCOLORKEY,colorkey);
SDL_SetColorKey(pbirds2r,SDL_SRCCOLORKEY,colorkey);
/*SDL_SetColorKey(twalk1,SDL_SRCCOLORKEY,colorkey);
SDL_SetColorKey(jump1,SDL_SRCCOLORKEY,colorkey);*/
while(quit==false&&l==1){while(SDL_PollEvent(&go)){
if(go.type==SDL_QUIT){quit=true;}}
key=SDL_GetKeyState(NULL);
if(key[sDLK_ESCAPE]){quit=true;}
if(key[sDLK_UP]){}
if(key[sDLK_DOWN]){}
if(key[sDLK_LEFT]){
if(cx>hxc){cx-=cs;sx+=cs;l1+=l1s;}sx-=cs;l1-=l1s;cf+=1;if(cf>15){cf=0;a+=1;if(a==5)
{a=1;}}if(a==1){w=1;}if(a==2){w=2;}if(a==3){w=3;}if(a==4){w=2;}n2=0;}else{n2=1;}
if(key[sDLK_RIGHT]){
if(cx<hxc){cx+=cs;sx-=cs;l1-=l1s;}sx+=cs;l1+=l1s;cf+=1;if(cf>15){cf=0;a+=1;if(a==5)
{a=1;}}if(a==1){w=1;}if(a==2){w=2;}if(a==3){w=3;}if(a==4){w=2;}n1=0;}else{n1=1;}
if(key[sDLK_a]){
if(jc<20){cy-=8;jump=1;j=1;jc+=1;}
else{jump=0;}}else{jump=0;}
if(n1==1&&n2==1){w=0;}
if(sx<0){sx=0;cx-=cs;l1+=l1s;}if(cx<0){cx=0;}
if(sx>1360){sx=1360;cx+=cs;l1-=l1s;}if(cx>2100){cx=2100;}
if(jump==0){cy+=8;}if(cy>300){cy=300;j=0;jc=0;jt=12;}
/* DRAW BACKGROUND */
t2.x=0;t2.y=135;t.x=0;t.y=0;t.w=sw;t.h=sh;
SDL_BlitSurface(bmoon,&t,d,&t2);
t2.x=0;t2.y=0;t.x=l1-580;t.y=0;t.w=sw;t.h=sh;
SDL_BlitSurface(l1bf,&t,d,&t2);
t2.x=0;t2.y=0;t.x=sx;t.y=0;t.w=sw;t.h=sh;
SDL_BlitSurface(section1,&t,d,&t2);
/*
pb1.counter+=1;
if(pb1.counter==10){pb1.frame+=1;pb1.counter=0;}
if(pb1.frame==3){pb1.frame=1;}
xh=0;if(cx<pb1.x&&pb1.x-cx<250){xh=2;}
if(cx>pb1.x&&cx-pb1.x<250){xh=1;}
if(xh==0){if(pb1.frame==1){ew[0]=1;}else{ew[0]=3;}}
if(xh==1){//pb1.x-=2;
if(pb1.frame==1){ew[0]=1;}else{ew[0]=3;}}
if(xh==2){//pb1.x+=2;
if(pb1.frame==1){ew[0]=2;}else{ew[0]=4;}}
if(pb1.ac==0&&cx<500){
if(pb1.frame==1){ew[0]=5;}else{ew[0]=7;}pb1.ac+=1;}
if(pb1.ac==0&&cx>=500){
if(pb1.frame==1){ew[0]=6;}else{ew[0]=8;}pb1.ac+=1;}
if(pb1.ac>0){pb1.ac+=1;}if(pb1.ac==2000){pb1.ac=0;}
*/
pbird[ec][3]+=1;if(pbird[ec][3]==10){pbird[ec][4]+=1;pbird[ec][3]=0;}
if(pbird[ec][4]==3){pbird[ec][4]=1;}
xh=0;if(sx+cx<pbird[ec][1]){xh=1;}
if(sx+cx>pbird[ec][1]){xh=2;}
if(xh==0){if(pbird[ec][4]==1){pbird[ec][6]=1;}else{pbird[ec][6]=3;}}
if(xh==1){if(pbird[ec][4]==1){pbird[ec][6]=1;}else{pbird[ec][6]=3;}
/*if(pbird[ec][1]<sx+cx){pbird[ec][1]-=3;} SEPERATE MOVE FROM XH (direction)*/
}
if(xh==2){if(pbird[ec][4]==1){pbird[ec][6]=2;}else{pbird[ec][6]=4;}
if(pbird[ec][1]<sx+1100){pbird[ec][1]+=3;}
}
if(pbird[ec][6]==1){t2.x=pbird[ec][1]-sx;t2.y=pbird[ec][2];
t.x=0;t.y=0;t.w=60;t.h=60;SDL_BlitSurface(pbirdn1,&t,d,&t2);}
if(pbird[ec][6]==2){t2.x=pbird[ec][1]-sx;t2.y=pbird[ec][2];
t.x=0;t.y=0;t.w=60;t.h=60;SDL_BlitSurface(pbirdn1r,&t,d,&t2);}
if(pbird[ec][6]==3){t2.x=pbird[ec][1]-sx;t2.y=pbird[ec][2];
t.x=0;t.y=0;t.w=60;t.h=60;SDL_BlitSurface(pbirdn2,&t,d,&t2);}
if(pbird[ec][6]==4){t2.x=pbird[ec][1]-sx;t2.y=pbird[ec][2];
t.x=0;t.y=0;t.w=60;t.h=60;SDL_BlitSurface(pbirdn2r,&t,d,&t2);}
if(pbird[ec][6]==5){t2.x=pbird[ec][1]-sx;t2.y=pbird[ec][2];
t.x=0;t.y=0;t.w=60;t.h=60;SDL_BlitSurface(pbirds1,&t,d,&t2);}
if(pbird[ec][6]==6){t2.x=pbird[ec][1]-sx;t2.y=pbird[ec][2];
t.x=0;t.y=0;t.w=60;t.h=60;SDL_BlitSurface(pbirds1r,&t,d,&t2);}
if(pbird[ec][6]==7){t2.x=pbird[ec][1]-sx;t2.y=pbird[ec][2];
t.x=0;t.y=0;t.w=60;t.h=60;SDL_BlitSurface(pbirds2,&t,d,&t2);}
if(pbird[ec][6]==8){t2.x=pbird[ec][1]-sx;t2.y=pbird[ec][2];
t.x=0;t.y=0;t.w=60;t.h=60;SDL_BlitSurface(pbirds2r,&t,d,&t2);}
t2.x=0;t2.y=150;t.x=0;t.y=0;t.w=60;t.h=60;
SDL_BlitSurface(pbirdn1,&t,d,&t2);
SDL_Flip(d);t.x=0;t.y=0;t.w=sw;t.h=sh;
SDL_FillRect(d,&t,SDL_MapRGB(d->format,0,0,0));
n=SDL_GetTicks();if(n-o<f){SDL_Delay(f-(n-o));}o=SDL_GetTicks();}
SDL_FreeSurface(l1bf);
SDL_FreeSurface(bmoon);
SDL_FreeSurface(section1);
SDL_FreeSurface(pbirdn1);
SDL_FreeSurface(pbirdn2);
SDL_FreeSurface(pbirds1);
SDL_FreeSurface(pbirds2);
SDL_FreeSurface(pbirdn1r);
SDL_FreeSurface(pbirdn2r);
SDL_FreeSurface(pbirds1r);
SDL_FreeSurface(pbirds2r);}/* END of LEVEL 1 **********/
SDL_Quit();
return 0;
}