include SDL SDL include SDL SDL_draw include SDL SDL_ttf include stdli

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
#include <SDL/SDL.h>
#include <SDL/SDL_draw.h>
#include <SDL/SDL_ttf.h>
#include <stdlib.h>
#include <math.h>
const int scrwidth = 1024, scrheight = 720 , scrdepth = 32;
struct car
{Sint16 x0, y0;};
int draw_garbage(SDL_Surface * screen, Sint16 x, Sint16 y,int run)
{int x1=x;
if(run == 0)
{
Draw_FillEllipse(screen, x+125, y, 100, 50, SDL_MapRGB(screen->format,150,150,150));
return 0;
}
else
{
//while(x1>=x-250)
Draw_FillEllipse(screen, x1+125, y, 100, 50, SDL_MapRGB(screen->format,150,150,150));
return x1;
}
}
void draw_car (SDL_Surface * screen, Sint16 x, int run)
{struct car CAR;
CAR.x0=x;
CAR.y0=500;
Draw_FillCircle(screen, CAR.x0+50, CAR.y0+120, 35, SDL_MapRGB(screen->format,0,0,0));
Draw_FillCircle(screen, CAR.x0+220, CAR.y0+120, 35, SDL_MapRGB(screen->format,0,0,0));
Draw_FillRect(screen, CAR.x0, CAR.y0, 250, 100, SDL_MapRGB(screen->format,255,0, 0));
Draw_FillRect(screen, CAR.x0+250, CAR.y0-20, 80, 120, SDL_MapRGB(screen->format,50,50,50));
}
int main(int argc, char** argv){
SDL_Surface *screen, *image;
SDL_Event event;
int run=1;
Sint16 x=50, x1=600, y=500;
/* Начальная инициализация */
if(SDL_Init(SDL_INIT_VIDEO)<0){
printf("Unable to init SDL: %s\n", SDL_GetError());
return 1;
}
screen = SDL_SetVideoMode(scrwidth, scrheight, scrdepth, SDL_ANYFORMAT);
if(!screen){
printf("Unable to set 1024x720 video: %s\n", SDL_GetError());
return 1;
}
image=SDL_LoadBMP("image.bmp"); // Грузим картинку
while(run) {
/* Проверяем действия пользователя */
while(SDL_PollEvent(&event)) {
switch (event.type){
case SDL_QUIT:
run = 0;break;
case SDL_KEYDOWN:{
if (event.key.keysym.sym == SDLK_ESCAPE)
run = 0;
break;
}
}
}
/* Рисуем фон */
SDL_BlitSurface(image, NULL, screen, NULL);
if(x==600)
{x=600;
if (draw_garbage(screen,x1, 500, 1)>=350)
x1--;
else
if (y<600)
{draw_garbage(screen,x1, y, 1);
y++;
}
draw_car(screen, x, 1);
}
else
{x++;
draw_garbage(screen, x, 500, 0);
draw_car(screen, x, 0) ;
}
/* Тут Рисует */
SDL_Delay(1);
SDL_Flip(screen);
}
/* Удаляем поверхности перед выходом */
SDL_FreeSurface(image);
SDL_FreeSurface(screen);
SDL_Quit();
return 0;
}