#include <SDL.h>
#include <SDL_ttf.h>
class instructions
{
public:
void apply(int srcX,int srcY,int x,int y,int w,int h,SDL_Surface *source,SDL_Surface *destination)
{
SDL_Rect set;
set.x=x;
set.y=y;
set.w=w;
set.h=h;
SDL_Rect src;
src.x=srcX;
src.y=srcY;
src.w=w;
src.h=h;
SDL_BlitSurface(source,&src,destination,&set);
}
void give(int x,int y,int w,int h,SDL_Rect &fake)
{
fake.x=x;
fake.y=y;
fake.w=w;
fake.h=h;
}
bool CheckCollision(float Ax,float Ay,float Aw,float Ah,
float Bx,float By,float Bw,float Bh)
{
if(Ay+Ah<By)
return false;
else if(Ay>By+Bh)
return false;
else if(Ax+Aw<Bx)
return false;
else if(Ax>Bx+Bw)
return false;
return true;
}
int showmenu(SDL_Surface *screen,TTF_Font *font)
{
int x,y;
const int NUMMENU=2;
const char *labels[NUMMENU]={"Continue","Exit"};
SDL_Surface *menus[NUMMENU];
bool selected[NUMMENU]={0,0};
SDL_Color color[2]={{255,255,255},{255,0,0}};
menus[0]=TTF_RenderText_Solid(font,labels[0],color[0]);
menus[1]=TTF_RenderText_Solid(font,labels[1],color[0]);
SDL_Rect pos[NUMMENU];
pos[0].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w/2;
pos[0].y=screen->clip_rect.h/2 - menus[0]->clip_rect.h;
pos[1].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w/2;
pos[1].y=screen->clip_rect.h/2 + menus[0]->clip_rect.h;
SDL_FillRect(screen,&screen->clip_rect,SDL_MapRGB(screen->format,0x200,0x200,0x255));
SDL_Event event;
while(true)
{
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
for(int i=0;i<NUMMENU;i++)
{
SDL_FreeSurface(menus[i]);
}
return 1;
case SDL_MOUSEMOTION:
x=event.motion.x;
y=event.motion.y;
for(int i=0;i<NUMMENU;i++)
{
if(x>=pos[i].x && x<=pos[i].x+pos[i].w && y>=pos[i].y && y<=pos[i].y+pos[i].h)
{
if(!selected[i])
{
selected[i]=1;
SDL_FreeSurface(menus[i]);
menus[i]=TTF_RenderText_Solid(font,labels[i],color[1]);
}
}
else
{
if(selected[i])
{
selected[i]=0;
SDL_FreeSurface(menus[i]);
menus[i]=TTF_RenderText_Solid(font,labels[i],color[0]);
}
}
}
break;
case SDL_MOUSEBUTTONDOWN:
x=event.button.x;
y=event.button.y;
for(int i=0;i<NUMMENU;i++)
{
if(x>=pos[i].x && x<=pos[i].x+pos[i].w && y>=pos[i].y && y<=pos[i].y+pos[i].h)
{
for(int j=0;j<NUMMENU;j++)
SDL_FreeSurface(menus[j]);
return i;
}
}
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_ESCAPE:
for(int i=0;i<NUMMENU;i++)
SDL_FreeSurface(menus[i]);
return 0;
}
}
}
for(int i=0;i<NUMMENU;i++)
SDL_BlitSurface(menus[i],NULL,screen,&pos[i]);
SDL_Flip(screen);
}
}
int showmenu1(SDL_Surface *screen,TTF_Font *font)
{
int x,y;
const int NUMMENU=3;
const char *labels[NUMMENU]={"Start","Rules","Exit"};
SDL_Surface *menus[NUMMENU];
bool selected[NUMMENU]={0,0,0};
SDL_Color color[2]={{255,255,255},{255,0,0}};
menus[0]=TTF_RenderText_Solid(font,labels[0],color[0]);
menus[1]=TTF_RenderText_Solid(font,labels[1],color[0]);
menus[2]=TTF_RenderText_Solid(font,labels[2],color[0]);
SDL_Rect pos[NUMMENU];
pos[0].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w/2;
pos[0].y=screen->clip_rect.h/3 - menus[0]->clip_rect.h;
pos[1].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w/2;
pos[1].y=screen->clip_rect.h/3 + menus[0]->clip_rect.h;
pos[2].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w/2;
pos[2].y=screen->clip_rect.h/2 + menus[0]->clip_rect.h;
SDL_FillRect(screen,&screen->clip_rect,SDL_MapRGB(screen->format,0x200,0x200,0x255));
SDL_Event event;
while(true)
{
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
for(int i=0;i<NUMMENU;i++)
{
SDL_FreeSurface(menus[i]);
}
return 2;
case SDL_MOUSEMOTION:
x=event.motion.x;
y=event.motion.y;
for(int i=0;i<NUMMENU;i++)
{
if(x>=pos[i].x && x<=pos[i].x+pos[i].w && y>=pos[i].y && y<=pos[i].y+pos[i].h)
{
if(!selected[i])
{
selected[i]=1;
SDL_FreeSurface(menus[i]);
menus[i]=TTF_RenderText_Solid(font,labels[i],color[1]);
}
}
else
{
if(selected[i])
{
selected[i]=0;
SDL_FreeSurface(menus[i]);
menus[i]=TTF_RenderText_Solid(font,labels[i],color[0]);
}
}
}
break;
case SDL_MOUSEBUTTONDOWN:
x=event.button.x;
y=event.button.y;
for(int i=0;i<NUMMENU;i++)
{
if(x>=pos[i].x && x<=pos[i].x+pos[i].w && y>=pos[i].y && y<=pos[i].y+pos[i].h)
{
for(int j=0;j<NUMMENU;j++)
SDL_FreeSurface(menus[j]);
return i;
}
}
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_ESCAPE:
for(int i=0;i<NUMMENU;i++)
SDL_FreeSurface(menus[i]);
return 0;
}
}
}
for(int i=0;i<NUMMENU;i++)
SDL_BlitSurface(menus[i],NULL,screen,&pos[i]);
SDL_Flip(screen);
}
}
int rules(SDL_Surface *screen,TTF_Font *font)
{
int x,y;
const int NUMMENU=5;
const char *labels[NUMMENU]={"Start","1)If you fell down.You loose.","2)Putting the down button you change","some of the background",
"3)You try to go to the other side"};
SDL_Surface *menus[NUMMENU];
bool selected[NUMMENU]={0,0,0,0,0};
SDL_Color color[2]={{255,255,255},{255,0,0}};
menus[0]=TTF_RenderText_Solid(font,labels[0],color[0]);
menus[1]=TTF_RenderText_Solid(font,labels[1],color[0]);
menus[2]=TTF_RenderText_Solid(font,labels[2],color[0]);
menus[3]=TTF_RenderText_Solid(font,labels[3],color[0]);
menus[4]=TTF_RenderText_Solid(font,labels[4],color[0]);
SDL_Rect pos[NUMMENU];
pos[0].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w/2;
pos[0].y=screen->clip_rect.h/1.5 + menus[0]->clip_rect.h;
pos[1].x=screen->clip_rect.w/6 - menus[0]->clip_rect.w;
pos[1].y=screen->clip_rect.h/4 - menus[0]->clip_rect.h;
pos[2].x=screen->clip_rect.w/6 - menus[0]->clip_rect.w;
pos[2].y=screen->clip_rect.h/3 - menus[0]->clip_rect.h;
pos[3].x=screen->clip_rect.w/4 - menus[0]->clip_rect.w;
pos[3].y=screen->clip_rect.h/2.6 - menus[0]->clip_rect.h;
pos[4].x=screen->clip_rect.w/6 - menus[0]->clip_rect.w;
pos[4].y=screen->clip_rect.h/2 - menus[0]->clip_rect.h;
SDL_FillRect(screen,&screen->clip_rect,SDL_MapRGB(screen->format,0x200,0x200,0x255));
SDL_Event event;
while(true)
{
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
for(int i=0;i<NUMMENU;i++)
{
SDL_FreeSurface(menus[i]);
}
return 1;
case SDL_MOUSEMOTION:
x=event.motion.x;
y=event.motion.y;
if(x>=pos[0].x && x<=pos[0].x+pos[0].w && y>=pos[0].y && y<=pos[0].y+pos[0].h)
{
if(!selected[0])
{
selected[0]=1;
SDL_FreeSurface(menus[0]);
menus[0]=TTF_RenderText_Solid(font,labels[0],color[1]);
}
}
else
{
if(selected[0])
{
selected[0]=0;
SDL_FreeSurface(menus[0]);
menus[0]=TTF_RenderText_Solid(font,labels[0],color[0]);
}
}
break;
case SDL_MOUSEBUTTONDOWN:
x=event.button.x;
y=event.button.y;
if(x>=pos[0].x && x<=pos[0].x+pos[0].w && y>=pos[0].y && y<=pos[0].y+pos[0].h)
{
SDL_FreeSurface(menus[0]);
return 0;
}
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_ESCAPE:
SDL_FreeSurface(menus[0]);
return 0;
}
}
}
for(int i=0;i<NUMMENU;i++)
SDL_BlitSurface(menus[i],NULL,screen,&pos[i]);
SDL_Flip(screen);
}
}
int win(SDL_Surface *screen,TTF_Font *font)
{
int x,y;
const int NUMMENU=2;
const char *labels[NUMMENU]={"Exit","You Won!!!"};
SDL_Surface *menus[NUMMENU];
bool selected[NUMMENU]={0,0};
SDL_Color color[2]={{255,255,255},{255,0,0}};
menus[0]=TTF_RenderText_Solid(font,labels[0],color[0]);
menus[1]=TTF_RenderText_Solid(font,labels[1],color[0]);
SDL_Rect pos[NUMMENU];
pos[0].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w/2;
pos[0].y=screen->clip_rect.h/1.5 + menus[0]->clip_rect.h;
pos[1].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w;
pos[1].y=screen->clip_rect.h/4 - menus[0]->clip_rect.h;
SDL_FillRect(screen,&screen->clip_rect,SDL_MapRGB(screen->format,0x200,0x200,0x255));
SDL_Event event;
while(true)
{
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
for(int i=0;i<NUMMENU;i++)
{
SDL_FreeSurface(menus[i]);
}
return 0;
case SDL_MOUSEMOTION:
x=event.motion.x;
y=event.motion.y;
if(x>=pos[0].x && x<=pos[0].x+pos[0].w && y>=pos[0].y && y<=pos[0].y+pos[0].h)
{
if(!selected[0])
{
selected[0]=1;
SDL_FreeSurface(menus[0]);
menus[0]=TTF_RenderText_Solid(font,labels[0],color[1]);
}
}
else
{
if(selected[0])
{
selected[0]=0;
SDL_FreeSurface(menus[0]);
menus[0]=TTF_RenderText_Solid(font,labels[0],color[0]);
}
}
break;
case SDL_MOUSEBUTTONDOWN:
x=event.button.x;
y=event.button.y;
if(x>=pos[0].x && x<=pos[0].x+pos[0].w && y>=pos[0].y && y<=pos[0].y+pos[0].h)
{
SDL_FreeSurface(menus[0]);
return 0;
}
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_ESCAPE:
SDL_FreeSurface(menus[0]);
return 0;
}
}
}
for(int i=0;i<NUMMENU;i++)
SDL_BlitSurface(menus[i],NULL,screen,&pos[i]);
SDL_Flip(screen);
}
}
int loose(SDL_Surface *screen,TTF_Font *font)
{
int x,y;
const int NUMMENU=2;
const char *labels[NUMMENU]={"Exit","You Lost!!!"};
SDL_Surface *menus[NUMMENU];
bool selected[NUMMENU]={0,0};
SDL_Color color[2]={{255,255,255},{255,0,0}};
menus[0]=TTF_RenderText_Solid(font,labels[0],color[0]);
menus[1]=TTF_RenderText_Solid(font,labels[1],color[0]);
SDL_Rect pos[NUMMENU];
pos[0].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w/2;
pos[0].y=screen->clip_rect.h/1.5 + menus[0]->clip_rect.h;
pos[1].x=screen->clip_rect.w/2 - menus[0]->clip_rect.w;
pos[1].y=screen->clip_rect.h/4 - menus[0]->clip_rect.h;
SDL_FillRect(screen,&screen->clip_rect,SDL_MapRGB(screen->format,0x200,0x200,0x255));
SDL_Event event;
while(true)
{
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
for(int i=0;i<NUMMENU;i++)
{
SDL_FreeSurface(menus[i]);
}
return 0;
case SDL_MOUSEMOTION:
x=event.motion.x;
y=event.motion.y;
if(x>=pos[0].x && x<=pos[0].x+pos[0].w && y>=pos[0].y && y<=pos[0].y+pos[0].h)
{
if(!selected[0])
{
selected[0]=1;
SDL_FreeSurface(menus[0]);
menus[0]=TTF_RenderText_Solid(font,labels[0],color[1]);
}
}
else
{
if(selected[0])
{
selected[0]=0;
SDL_FreeSurface(menus[0]);
menus[0]=TTF_RenderText_Solid(font,labels[0],color[0]);
}
}
break;
case SDL_MOUSEBUTTONDOWN:
x=event.button.x;
y=event.button.y;
if(x>=pos[0].x && x<=pos[0].x+pos[0].w && y>=pos[0].y && y<=pos[0].y+pos[0].h)
{
SDL_FreeSurface(menus[0]);
return 0;
}
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_ESCAPE:
SDL_FreeSurface(menus[0]);
return 0;
}
}
}
for(int i=0;i<NUMMENU;i++)
SDL_BlitSurface(menus[i],NULL,screen,&pos[i]);
SDL_Flip(screen);
}
}
};
SDL_Surface *screen=NULL;
SDL_Surface *text=NULL;
SDL_Surface *pause=NULL;
SDL_Surface *heroe=NULL;
SDL_Surface *imagebackground=NULL;
SDL_Event event;
bool run=true;
int srcX1=0;
int srcY1=0;
int dstX1=5;
int dstY1=930;
int ScreenWidth=1000;
int ScreenHeight=1000;
int main(int argc, char** argv)
{
SDL_Init(SDL_INIT_EVERYTHING);
TTF_Init();
SDL_WM_SetCaption("Space game",NULL);
screen=SDL_SetVideoMode(1000,1000,32,SDL_SWSURFACE);
instructions instr;
TTF_Font *font=TTF_OpenFont("256BYTES.ttf",80);
TTF_Font *font1=TTF_OpenFont("256BYTES.ttf",60);
TTF_Font *font2=TTF_OpenFont("256BYTES.ttf",100);
SDL_Color col{80,10,10};
text=TTF_RenderText_Solid(font,"GOOD\n\n\nLUCK !!!",col);
heroe=SDL_LoadBMP("myheroe.bmp");
imagebackground=SDL_LoadBMP("bg.bmp");
pause=SDL_LoadBMP("pause.bmp");
SDL_SetColorKey(heroe,SDL_SRCCOLORKEY,SDL_MapRGB(heroe->format,0xff,0xff,0xff));
Uint32 backround=SDL_MapRGB(screen->format,0x00,0xff,0xff);
Uint32 color=SDL_MapRGB(screen->format,0x00,0x00,0xff);
Uint32 color1=SDL_MapRGB(screen->format,0x100,0x255,0x100);
SDL_Rect obstacle,obstacle1,obstacle2,obstacle3,obstacle4,obstacle5,obstacle6,obstacle7,bad;
instr.give(150,960,80,40,obstacle);
instr.give(370,960,130,40,obstacle1);
instr.give(530,960,130,40,obstacle2);
instr.give(460,920,110,40,obstacle3);
instr.give(800,960,190,40,obstacle4);
instr.give(865,920,60,40,obstacle5);
instr.give(1110,690,100,40,obstacle6);
instr.give(1140,400,360,40,obstacle7);
instr.give(250,960,40,40,bad);
const int speed=6;
SDL_Rect camera;
instr.give(0,0,1000,1000,camera);
bool up=false;
bool down=true;
bool right=false;
bool left=false;
bool changeColor=false;
bool makePause=false;
int k;
k=instr.showmenu1(screen,font);
if(k==1)
{
int r;
r=instr.rules(screen,font1);
if(r==1)
run=false;
}
else if(k==2)
run=false;
while(run)
{
if(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
run=false;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_DOWN:
changeColor=true;
break;
case SDLK_UP:
up=true;
down=false;
break;
case SDLK_RIGHT:
right=true;
break;
case SDLK_LEFT:
left=true;
break;
case SDLK_ESCAPE:
int i;
i=instr.showmenu(screen,font);
if(i==1)
run=false;
break;
}
break;
case SDL_KEYUP:
switch(event.key.keysym.sym)
{
case SDLK_DOWN:
changeColor=false;
break;
case SDLK_UP:
up=false;
down=true;
break;
case SDLK_RIGHT:
right=false;
break;
case SDLK_LEFT:
left=false;
break;
}
break;
case SDL_MOUSEBUTTONDOWN:
makePause=true;
break;
}
}
///////////////////////////////////
///////////////////////////////////
///////////////////////////////////
///////////////////////////////////
///////////////////////////////////
if(makePause==true)
{
int x,y;
x=event.motion.x;
y=event.motion.y;
if(x>900 && x<900+pause->w && y>2 && 2+2+pause->h)
{
int i;
i=instr.showmenu(screen,font);
if(i==1)
run=false;
}
}
makePause=false;
if(changeColor==true)
{
backround=SDL_MapRGB(screen->format,0x80,0x80,0x20);
}
if(up==true && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle.x,obstacle.y,obstacle.w,obstacle.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle1.x,obstacle1.y,obstacle1.w,obstacle1.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle2.x,obstacle2.y,obstacle2.w,obstacle2.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle3.x,obstacle3.y,obstacle3.w,obstacle3.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle4.x,obstacle4.y,obstacle4.w,obstacle4.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle5.x,obstacle5.y,obstacle5.w,obstacle5.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle6.x,obstacle6.y,obstacle6.w,obstacle6.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle7.x,obstacle7.y,obstacle7.w,obstacle7.h)==true))
{
dstY1-=2;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle.x,obstacle.y,obstacle.w,obstacle.h)==true)
dstY1+=2;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle1.x,obstacle1.y,obstacle1.w,obstacle1.h)==true)
dstY1+=2;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle2.x,obstacle2.y,obstacle2.w,obstacle2.h)==true)
dstY1+=2;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle3.x,obstacle3.y,obstacle3.w,obstacle3.h)==true)
dstY1+=2;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle4.x,obstacle4.y,obstacle4.w,obstacle4.h)==true)
dstY1+=2;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle5.x,obstacle5.y,obstacle5.w,obstacle5.h)==true)
dstY1+=2;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle6.x,obstacle6.y,obstacle6.w,obstacle6.h)==true)
dstY1+=2;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle7.x,obstacle7.y,obstacle7.w,obstacle7.h)==true)
dstY1+=2;
}
if(down==true && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle.x,obstacle.y,obstacle.w,obstacle.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle1.x,obstacle1.y,obstacle1.w,obstacle1.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle2.x,obstacle2.y,obstacle2.w,obstacle2.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle3.x,obstacle3.y,obstacle3.w,obstacle3.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle4.x,obstacle4.y,obstacle4.w,obstacle4.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle5.x,obstacle5.y,obstacle5.w,obstacle5.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle6.x,obstacle6.y,obstacle6.w,obstacle6.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle7.x,obstacle7.y,obstacle7.w,obstacle7.h)==true))
{
dstY1+=2;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle.x,obstacle.y,obstacle.w,obstacle.h)==true)
dstY1-=2;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle1.x,obstacle1.y,obstacle1.w,obstacle1.h)==true)
dstY1-=2;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle2.x,obstacle2.y,obstacle2.w,obstacle2.h)==true)
dstY1-=2;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle3.x,obstacle3.y,obstacle3.w,obstacle3.h)==true)
dstY1-=2;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle4.x,obstacle4.y,obstacle4.w,obstacle4.h)==true)
dstY1-=2;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle5.x,obstacle5.y,obstacle5.w,obstacle5.h)==true)
dstY1-=2;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle6.x,obstacle6.y,obstacle6.w,obstacle6.h)==true)
dstY1-=2;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle7.x,obstacle7.y,obstacle7.w,obstacle7.h)==true)
dstY1-=2;
}
if(right==true && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle.x,obstacle.y,obstacle.w,obstacle.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle1.x,obstacle1.y,obstacle1.w,obstacle1.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle2.x,obstacle2.y,obstacle2.w,obstacle2.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle3.x,obstacle3.y,obstacle3.w,obstacle3.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle4.x,obstacle4.y,obstacle4.w,obstacle4.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle5.x,obstacle5.y,obstacle5.w,obstacle5.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle6.x,obstacle6.y,obstacle6.w,obstacle6.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle7.x,obstacle7.y,obstacle7.w,obstacle7.h)==true))
{
dstX1++;
camera.x+=speed;
if(camera.x>=5550)
camera.x=0;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle.x,obstacle.y,obstacle.w,obstacle.h)==true)
dstX1-=1;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle1.x,obstacle1.y,obstacle1.w,obstacle1.h)==true)
dstX1-=1;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle2.x,obstacle2.y,obstacle2.w,obstacle2.h)==true)
dstX1-=1;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle3.x,obstacle3.y,obstacle3.w,obstacle3.h)==true)
dstX1-=1;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle4.x,obstacle4.y,obstacle4.w,obstacle4.h)==true)
dstX1-=1;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle5.x,obstacle5.y,obstacle5.w,obstacle5.h)==true)
dstX1-=1;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle6.x,obstacle6.y,obstacle6.w,obstacle6.h)==true)
dstX1-=1;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle7.x,obstacle7.y,obstacle7.w,obstacle7.h)==true)
dstX1-=1;
}
if(left==true && !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle.x,obstacle.y,obstacle.w,obstacle.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle1.x,obstacle1.y,obstacle1.w,obstacle1.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle2.x,obstacle2.y,obstacle2.w,obstacle2.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle3.x,obstacle3.y,obstacle3.w,obstacle3.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle4.x,obstacle4.y,obstacle4.w,obstacle4.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle5.x,obstacle5.y,obstacle5.w,obstacle5.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle6.x,obstacle6.y,obstacle6.w,obstacle6.h)==true)
&& !(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle7.x,obstacle7.y,obstacle7.w,obstacle7.h)==true))
{
dstX1--;
camera.x-=speed;
if(camera.x<=0)
camera.x=5550;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle.x,obstacle.y,obstacle.w,obstacle.h)==true)
dstX1+=1;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle1.x,obstacle1.y,obstacle1.w,obstacle1.h)==true)
dstX1+=1;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle2.x,obstacle2.y,obstacle2.w,obstacle2.h)==true)
dstX1+=1;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle3.x,obstacle3.y,obstacle3.w,obstacle3.h)==true)
dstX1+=1;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle4.x,obstacle4.y,obstacle4.w,obstacle4.h)==true)
dstX1+=1;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle5.x,obstacle5.y,obstacle5.w,obstacle5.h)==true)
dstX1+=1;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle6.x,obstacle6.y,obstacle6.w,obstacle6.h)==true)
dstX1+=1;
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle7.x,obstacle7.y,obstacle7.w,obstacle7.h)==true)
dstX1+=1;
}
/////////////////////////
/////////////////////////
if(dstX1<0)
{
dstX1=0;
}
if(dstY1<0)
{
dstY1=0;
}
/////////////////////////
/////////////////////////
if(dstX1+heroe->w > ScreenWidth)
{
dstX1=ScreenWidth-heroe->w;
}
if(dstY1+heroe->h > ScreenHeight)
{
dstY1=ScreenHeight-heroe->h;
}
if(up==true && (dstY1+heroe->h < 900) )
{
down=true;
up=false;
}
/////////////////////////////////
/////////////////////////////////
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,bad.x,bad.y,bad.w,bad.h)==true)
{
int l;
l=instr.loose(screen,font2);
if(l==0)
run=false;
}
/////////////////////////////////
/////////////////////////////////
if(instr.CheckCollision(dstX1,dstY1,heroe->w,heroe->h,obstacle7.x-5,obstacle7.y-5,obstacle7.w-5,obstacle7.h-5)==true)
{
int w;
w=instr.win(screen,font2);
if(w==0)
run=false;
}
//////////////
SDL_FillRect(screen,&screen->clip_rect,backround);
SDL_BlitSurface(imagebackground,&camera,screen,NULL);
SDL_FillRect(screen,&obstacle,color);
SDL_FillRect(screen,&obstacle1,color);
SDL_FillRect(screen,&obstacle2,color);
SDL_FillRect(screen,&obstacle3,color);
SDL_FillRect(screen,&obstacle4,color);
SDL_FillRect(screen,&obstacle5,color);
SDL_FillRect(screen,&obstacle6,color);
SDL_FillRect(screen,&obstacle7,color);
SDL_FillRect(screen,&bad,color1);
instr.apply(srcX1, srcY1, 900, 2, pause->w,pause->h, pause, screen);
instr.apply(srcX1, srcY1, dstX1, dstY1, heroe->w,heroe->h, heroe, screen);
SDL_BlitSurface(text,NULL,screen,NULL);
SDL_Flip(screen);
}
SDL_FreeSurface(text);
TTF_CloseFont(font);
TTF_Quit();
SDL_Quit();
return 0;
}