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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#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 lcar
{Sint16 x0, y0;};
struct car
{Sint16 x0, y0;};
void draw_garbage(SDL_Surface * screen, Sint16 x, Sint16 y)
{int x1=x;
Draw_FillRect(screen, x+60, y-30, 120, 40, SDL_MapRGB(screen->format,101, 67, 33));
return ;
}
void draw_car (SDL_Surface * screen, Sint16 x)
{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));
}
void draw_little_car (SDL_Surface * screen, Sint16 x, Sint16 yp)
{struct lcar LCAR;
LCAR.x0=x;
LCAR.y0=550;
Draw_FillCircle(screen, LCAR.x0+30, LCAR.y0+50, 20, SDL_MapRGB(screen->format,0,0,0));
Draw_FillCircle(screen, LCAR.x0+120, LCAR.y0+50, 20, SDL_MapRGB(screen->format,0,0,0));
Draw_FillRect(screen, LCAR.x0+150, LCAR.y0-50, 10, 100, SDL_MapRGB(screen->format,0,0, 255));
Draw_FillRect(screen, LCAR.x0+150, LCAR.y0-50+yp, 200, 10, SDL_MapRGB(screen->format,0,0, 255));
Draw_FillRect(screen, LCAR.x0, LCAR.y0, 150, 50, SDL_MapRGB(screen->format,0,0, 255));
}
int main(int argc, char** argv){
SDL_Surface *screen, *image;
SDL_Event event;
int run=1,flag=1;
Sint16 xcar=50, xpaz=50, xgar=50, xost=600, xostp=430;
/* Начальная инициализация */
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;
}
}
}
/* Проверяем действия пользователя */
/* while(SDL_PollEvent(&event)) {
switch (event.type){
case SDL_QUIT:
break;
case SDL_KEYDOWN:{
if (event.key.keysym.sym == SDLK_ESCAPE)
break;
}
}
}*/
/* Рисуем фон */
SDL_BlitSurface(image, NULL, screen, NULL);
//первый этап
if(xcar<xost)
{
draw_garbage(screen, xgar, 500);
draw_car(screen, xcar);
xcar++;
xgar++;
}
//второй этап
if((xcar==xost) && (xpaz<xostp)&&flag)
{ draw_garbage(screen, xgar, 500);
draw_little_car(screen, xpaz, 0);
xpaz++;
//draw_garbage(screen, xgar, 500);
draw_car(screen, xcar);
if(xpaz==xostp)
flag=0;
}
if((flag==0) &&(xpaz>50))
{ draw_car(screen, xcar);
draw_garbage(screen, xgar, 500);
xgar--;
draw_little_car(screen, xpaz, 0);
xpaz--;
//draw_garbage(screen, xgar, 500);
//xgar--;
}
if((flag==0) &&(xpaz==50))
{ draw_car(screen, xcar);
draw_garbage(screen, xgar, 500);
draw_little_car(screen, xpaz, 0);
//draw_garbage(screen, xgar, 500);
}
SDL_Delay(1);
SDL_Flip(screen);
}
SDL_FreeSurface(image);
SDL_FreeSurface(screen);
SDL_Quit();
return 0;
}