void ScanBC(Car car, Road road) { if (((car.GetDirection()==false)&&(car.GetX()>MainWindowWidth/2+10))|| ((car.GetDirection()==true)&&(car.GetX()<MainWindowWidth/2-10))) BFlag=true; else BFlag=false; if (((car.GetX()>MainWindowWidth/2)||(car.GetX()<MainWindowWidth/2))&&(!BFlag)) CFlag=true; }
int main(int argc, char *argv[]) { SDL_Init(SDL_INIT_EVERYTHING); SDL_Window *window; window = SDL_CreateWindow("SDLwindow", 600, 300, MainWindowWidth, MainWindowHigh, SDL_WINDOW_SHOWN); SDL_Renderer* renderer = NULL; renderer = SDL_CreateRenderer( window, 0, SDL_RENDER_TARGETS_RESET); SDL_SetRenderDrawColor(renderer,255,255,255,255); SDL_RenderClear( renderer ); SDL_SetRenderDrawColor(renderer,0,0,0,0); SDL_RenderDrawLine(renderer,MainWindowWidth/12,MainWindowHigh-30,MainWindowWidth/12,MainWindowHigh-70); SDL_RenderDrawLine(renderer,MainWindowWidth/12,MainWindowHigh-30,MainWindowWidth/12-10,MainWindowHigh-50); SDL_RenderDrawLine(renderer,MainWindowWidth/12,MainWindowHigh-30,MainWindowWidth/12+10,MainWindowHigh-50); SDL_RenderDrawLine(renderer,MainWindowWidth/12*11,MainWindowHigh-30,MainWindowWidth/12*11,MainWindowHigh-70); SDL_RenderDrawLine(renderer,MainWindowWidth/12*11,MainWindowHigh-70,MainWindowWidth/12*11-10,MainWindowHigh-50); SDL_RenderDrawLine(renderer,MainWindowWidth/12*11,MainWindowHigh-70,MainWindowWidth/12*11+10,MainWindowHigh-50); Road road; road.Draw(renderer); Car object; object.SetX(MainWindowWidth/5*3); object.SetY(MainWindowHigh/5*3); object.SetAngle(0); object.Draw(renderer); Actions actions; SDL_Event event; int rl=0,rp=0; while (1) { while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: { if (SDL_GetScancodeFromKey(event.key.keysym.sym)==SDL_SCANCODE_LEFT) { if (((object.GetX()>=MainWindowWidth/2-10)&&(object.GetDirection()==true))|| ((object.GetX()<=MainWindowWidth/2+10)&&(object.GetDirection()==false))) { bool AChecked=false; if ((object.GetX()<MainWindowWidth/2+10)&&(object.GetX()>MainWindowWidth/2-10)) { actions.ScanA(object,road); AChecked=true; } if (rp==1) { rl=0; rp=0; } if (rl==0) { object.RotateLeft(); rl++; } object.Rotate90(renderer); road.Draw(renderer); if (!AChecked) actions.ScanA(object,road); actions.ScanBC(object,road); actions.ActionOutput(); } } if (SDL_GetScancodeFromKey(event.key.keysym.sym)==SDL_SCANCODE_RIGHT) { if (((object.GetX()>=MainWindowWidth/2-10)&&(object.GetDirection()==false))|| ((object.GetX()<=MainWindowWidth/2+10)&&(object.GetDirection()==true))) { bool AChecked=false; if ((object.GetX()<MainWindowWidth/2+10)&&(object.GetX()>MainWindowWidth/2-10)) { actions.ScanA(object,road); AChecked=true; } actions.ScanA(object,road); if (rl==1) { rl=0; rp=0; } if (rp==0) { object.RotateRight(); rp++; } object.Rotate90(renderer); road.Draw(renderer); if (!AChecked) actions.ScanA(object,road); actions.ScanBC(object,road); actions.ActionOutput(); } } if (SDL_GetScancodeFromKey(event.key.keysym.sym)==SDL_SCANCODE_UP) { if ((object.GetX()<MainWindowWidth/2-10)||(object.GetX()>MainWindowWidth/2+10)) { road.Draw(renderer); road.Move(object.GetDirection()); Sleep(50); } } if (SDL_GetScancodeFromKey(event.key.keysym.sym)==SDL_SCANCODE_ESCAPE) return 0; } break; case SDL_QUIT: exit(0); } } } SDL_DestroyWindow(window); SDL_Quit(); return 0; }