added new screens and getting ready for networking, looking at SDL_net for cross platfrom networking so i dont have to touch windows
This commit is contained in:
137
main.c
137
main.c
@@ -1,13 +1,17 @@
|
||||
/*Troy Rosin*/
|
||||
|
||||
#include <main.h>
|
||||
#include <game.h>
|
||||
#include <input.h>
|
||||
#include <overworld.h>
|
||||
|
||||
#include <mydebug.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL_ttf.h>
|
||||
|
||||
#define SPACING 20
|
||||
|
||||
SDL_Window* window;
|
||||
SDL_Renderer* renderer;
|
||||
SDL_Event event;
|
||||
@@ -19,8 +23,8 @@ int running;
|
||||
int selected_index = START_GAME;
|
||||
|
||||
int main(void) {
|
||||
int ret = 0;
|
||||
|
||||
int x1, x2, y1, y2;
|
||||
SDL_Point mouse_pos;
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
TTF_Init();
|
||||
window = SDL_CreateWindow("Shufflers", SDL_WINDOWPOS_UNDEFINED,
|
||||
@@ -32,51 +36,140 @@ int main(void) {
|
||||
SDL_CaptureMouse(SDL_TRUE);
|
||||
|
||||
SDL_Texture* background = IMG_LoadTexture(renderer, "assets/mainscreen.png");
|
||||
//remove from here
|
||||
SDL_Texture* start_img = IMG_LoadTexture(renderer, "assets/mainscreen_start.png");
|
||||
SDL_Texture* exit_img = IMG_LoadTexture(renderer, "assets/mainscreen_exit.png");
|
||||
SDL_Texture* selection_img = start_img;
|
||||
//keep this tho
|
||||
if (!background || !start_img || !exit_img ) {
|
||||
|
||||
if (!background) {
|
||||
printf("IMG_LoadTexture error: %s\n", IMG_GetError());
|
||||
}
|
||||
|
||||
ret = SDL_SetTextureColorMod(start_img, 255, 0, 0);
|
||||
ret |= SDL_SetTextureColorMod(exit_img, 255, 0, 0);
|
||||
|
||||
if(ret){
|
||||
puts("SetTextureColorMod error");
|
||||
}
|
||||
//end remove
|
||||
|
||||
TTF_Font* sans = TTF_OpenFont("Sans.ttf", 24);
|
||||
TTF_Font* font = TTF_OpenFont("assets/font.ttf", 24);
|
||||
|
||||
SDL_Color white = {255, 255, 255, 0};
|
||||
SDL_Surface* start_surface = TTF_RenderText_Solid(sans, "START", white);
|
||||
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);
|
||||
|
||||
if(selected_index == START_GAME){ selection_img = start_img;}
|
||||
else if(selected_index == EXIT_GAME) {selection_img = exit_img;}
|
||||
|
||||
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 0,196,0,255);
|
||||
|
||||
SDL_RenderCopy(renderer, background, NULL, NULL);
|
||||
SDL_RenderCopy(renderer, selection_img, 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<MAIN_SELECTIONS; i++)
|
||||
{
|
||||
if(SDL_PointInRect(&mouse_pos, &mainmenu_rects[i]))
|
||||
{
|
||||
selected_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch(selected_index)
|
||||
{
|
||||
case START_GAME:
|
||||
x1 = start_rect.x;
|
||||
x2 = x1 + start_rect.w;
|
||||
y1 = y2 = start_rect.y + start_rect.h;
|
||||
break;
|
||||
case HOST_GAME:
|
||||
x1 = host_rect.x;
|
||||
x2 = x1 + host_rect.w;
|
||||
y1 = y2 = host_rect.y + host_rect.h;
|
||||
break;
|
||||
case JOIN_GAME:
|
||||
x1 = join_rect.x;
|
||||
x2 = x1 + join_rect.w;
|
||||
y1 = y2 = join_rect.y + join_rect.h;
|
||||
break;
|
||||
case OPTIONS_MENU:
|
||||
x1 = options_rect.x;
|
||||
x2 = x1 + options_rect.w;
|
||||
y1 = y2 = options_rect.y + options_rect.h;
|
||||
break;
|
||||
case EXIT_GAME:
|
||||
x1 = exit_rect.x;
|
||||
x2 = x1 + exit_rect.w;
|
||||
y1 = y2 = exit_rect.y + exit_rect.h;
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_RenderDrawLine(renderer, x1, y1, x2, y2);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
if(state)
|
||||
{
|
||||
switch(state)
|
||||
{
|
||||
case BATTLE:
|
||||
start_battle();
|
||||
case START:
|
||||
start_game();
|
||||
break;
|
||||
case HOST:
|
||||
PRINT_M(hosting state)
|
||||
host_game();
|
||||
break;
|
||||
case JOIN:
|
||||
PRINT_M(joining state)
|
||||
join_game();
|
||||
break;
|
||||
case OPTIONS:
|
||||
PRINT_M(options menu state)
|
||||
show_options();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user