/*Troy Rosin*/ #include #include #include #include #include #include #include #include #define SPACING 20 SDL_Window* window; SDL_Renderer* renderer; SDL_Event event; int state = TITLE; int running; int selected_index = START_GAME; int main(void) { int x1, x2, y1, y2; SDL_Point mouse_pos; SDL_Init(SDL_INIT_VIDEO); TTF_Init(); window = SDL_CreateWindow("Shufflers", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, DEF_WINDOW_WIDTH,DEF_WINDOW_HEIGHT, 0); renderer = SDL_CreateRenderer(window, -1, 0); IMG_Init(IMG_INIT_PNG); SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); SDL_CaptureMouse(SDL_TRUE); SDL_Texture* background = IMG_LoadTexture(renderer, "assets/mainscreen.png"); if (!background) { printf("IMG_LoadTexture error: %s\n", IMG_GetError()); } TTF_Font* font = TTF_OpenFont("assets/font.ttf", 24); SDL_Color white = {255, 255, 255, 0}; SDL_Surface* start_surface = TTF_RenderText_Solid(font, "START", white); SDL_Texture* start_text = SDL_CreateTextureFromSurface(renderer, start_surface); SDL_Surface* host_surface = TTF_RenderText_Solid(font, "HOST", white); SDL_Texture* host_text = SDL_CreateTextureFromSurface(renderer, host_surface); SDL_Surface* join_surface = TTF_RenderText_Solid(font, "JOIN", white); SDL_Texture* join_text = SDL_CreateTextureFromSurface(renderer, join_surface); SDL_Surface* exit_surface = TTF_RenderText_Solid(font, "EXIT", white); SDL_Texture* exit_text = SDL_CreateTextureFromSurface(renderer, exit_surface); SDL_Surface* options_surface = TTF_RenderText_Solid(font, "OPTIONS", white); SDL_Texture* options_text = SDL_CreateTextureFromSurface(renderer, options_surface); SDL_Rect start_rect, host_rect, join_rect, exit_rect, options_rect; start_rect.w = (DEF_WINDOW_WIDTH >> 2) - (DEF_WINDOW_WIDTH >> 3); start_rect.h = (DEF_WINDOW_HEIGHT >> 3) - (DEF_WINDOW_HEIGHT >> 4); start_rect.x = (DEF_WINDOW_WIDTH - start_rect.w) >> 1; start_rect.y = (DEF_WINDOW_HEIGHT - start_rect.h) >> 1; host_rect.w = join_rect.w = exit_rect.w = options_rect.w = start_rect.w; options_rect.w <<= 1; host_rect.h = join_rect.h = exit_rect.h = options_rect.h = start_rect.h; host_rect.x = join_rect.x = exit_rect.x = options_rect.x = start_rect.x; options_rect.x -= join_rect.w >> 1; host_rect.y = start_rect.y + start_rect.h + SPACING; join_rect.y = host_rect.y + host_rect.h + SPACING; options_rect.y = join_rect.y + join_rect.h + SPACING; exit_rect.y = options_rect.y + options_rect.h + SPACING; SDL_Rect mainmenu_rects[MAIN_SELECTIONS]; mainmenu_rects[START_GAME] = start_rect; mainmenu_rects[HOST_GAME] = host_rect; mainmenu_rects[JOIN_GAME] = join_rect; mainmenu_rects[OPTIONS_MENU] = options_rect; mainmenu_rects[EXIT_GAME] = exit_rect; running = 1; while (running) { handle_event(&event); SDL_RenderClear(renderer); SDL_SetRenderDrawColor(renderer, 0,196,0,255); SDL_RenderCopy(renderer, background, NULL, NULL); SDL_RenderCopy(renderer, start_text, NULL, &start_rect); SDL_RenderCopy(renderer, host_text, NULL, &host_rect); SDL_RenderCopy(renderer, join_text, NULL, &join_rect); SDL_RenderCopy(renderer, options_text, NULL, &options_rect); SDL_RenderCopy(renderer, exit_text, NULL, &exit_rect); SDL_GetMouseState(&(mouse_pos.x), &(mouse_pos.y)); for(int i = 0; i