made the join game screen to get ready for attaching to host and also made a protocol doc
This commit is contained in:
5
battle.c
5
battle.c
@@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
SDL_Rect mouse_rect;
|
SDL_Rect mouse_rect;
|
||||||
SDL_Rect bot_rect, hand_rect;
|
SDL_Rect bot_rect, hand_rect;
|
||||||
SDL_Point mouse_pos;
|
|
||||||
|
|
||||||
int check_col(int i);
|
int check_col(int i);
|
||||||
int selected_card;
|
int selected_card;
|
||||||
@@ -32,7 +31,6 @@ void start_battle(){
|
|||||||
dragging = 0;
|
dragging = 0;
|
||||||
PRINT_M(STARTING GAME LOOP);
|
PRINT_M(STARTING GAME LOOP);
|
||||||
|
|
||||||
//SDL_Texture *maroon = IMG_LoadTexture(renderer, "assets/maroon.png");
|
|
||||||
SDL_Texture *grid = IMG_LoadTexture(renderer, "assets/battle_grid.png");
|
SDL_Texture *grid = IMG_LoadTexture(renderer, "assets/battle_grid.png");
|
||||||
SDL_Texture *card = IMG_LoadTexture(renderer, "assets/default_card.png");
|
SDL_Texture *card = IMG_LoadTexture(renderer, "assets/default_card.png");
|
||||||
SDL_Texture *selected = IMG_LoadTexture(renderer, "assets/selected_card.png");
|
SDL_Texture *selected = IMG_LoadTexture(renderer, "assets/selected_card.png");
|
||||||
@@ -164,8 +162,7 @@ void start_battle(){
|
|||||||
else { selected_card = -1; }
|
else { selected_card = -1; }
|
||||||
for(i = 0; i < hand.handsize; i++)
|
for(i = 0; i < hand.handsize; i++)
|
||||||
{
|
{
|
||||||
hand.card_rects[i].x = hand_rect.x + BOARDER_THICKNESS + ( spacing * i)
|
hand.card_rects[i].x = hand_rect.x + BOARDER_THICKNESS + ( spacing * i);
|
||||||
- ((CARD_SIZE - CARD_W)>>1) ;
|
|
||||||
hand.card_rects[i].y = hand_rect.y + BOARDER_THICKNESS;
|
hand.card_rects[i].y = hand_rect.y + BOARDER_THICKNESS;
|
||||||
if(check && SDL_PointInRect(&mouse_pos, &(hand.card_rects[i])))
|
if(check && SDL_PointInRect(&mouse_pos, &(hand.card_rects[i])))
|
||||||
{
|
{
|
||||||
|
|||||||
16
game.c
16
game.c
@@ -9,16 +9,20 @@
|
|||||||
#include <mydebug.h>
|
#include <mydebug.h>
|
||||||
|
|
||||||
|
|
||||||
|
void init_start_game()
|
||||||
|
|
||||||
void start_game()
|
|
||||||
{
|
{
|
||||||
|
PRINT_M(INIT START GAME)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void render_start_game()
|
||||||
|
{
|
||||||
|
|
||||||
state = OVERWORLD;
|
state = OVERWORLD;
|
||||||
start_overworld();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
218
host.c
218
host.c
@@ -15,14 +15,16 @@
|
|||||||
#define BOARDER_THICKNESS 20
|
#define BOARDER_THICKNESS 20
|
||||||
|
|
||||||
int over_object;
|
int over_object;
|
||||||
|
int num_players = 1;
|
||||||
|
int lobby_has_name = 0;
|
||||||
|
|
||||||
|
struct host_ctx
|
||||||
|
{
|
||||||
|
|
||||||
char player_names[MAX_PLAYERS][MAX_NAMESZ];
|
char player_names[MAX_PLAYERS][MAX_NAMESZ];
|
||||||
char temp_name[MAX_NAMESZ];
|
char temp_name[MAX_NAMESZ];
|
||||||
char lobby_name[MAX_NAMESZ];
|
char lobby_name[MAX_NAMESZ];
|
||||||
char lobby_name_perm[MAX_NAMESZ];
|
char lobby_name_perm[MAX_NAMESZ];
|
||||||
int num_players = 1;
|
|
||||||
int lobby_has_name = 0;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SDL_Rect set_name_rect, name_rect, player_name_rect;
|
SDL_Rect set_name_rect, name_rect, player_name_rect;
|
||||||
@@ -31,7 +33,6 @@ SDL_Rect player_name_rects[MAX_PLAYERS];
|
|||||||
SDL_Rect start_rect;
|
SDL_Rect start_rect;
|
||||||
|
|
||||||
TTF_Font* font;
|
TTF_Font* font;
|
||||||
SDL_Color white = {255, 255, 255, 0};
|
|
||||||
SDL_Surface *set_name_surf;
|
SDL_Surface *set_name_surf;
|
||||||
SDL_Surface *start_surf;
|
SDL_Surface *start_surf;
|
||||||
SDL_Surface *lobby_name_surf;
|
SDL_Surface *lobby_name_surf;
|
||||||
@@ -44,20 +45,86 @@ SDL_Surface *player_name_surfs[MAX_PLAYERS];
|
|||||||
SDL_Surface *player_tempname_surf;
|
SDL_Surface *player_tempname_surf;
|
||||||
SDL_Texture *player_name_texs[MAX_PLAYERS];
|
SDL_Texture *player_name_texs[MAX_PLAYERS];
|
||||||
SDL_Texture *player_tempname_tex;
|
SDL_Texture *player_tempname_tex;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct host_ctx host;
|
||||||
|
|
||||||
|
void init_host()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
over_object = NO_OBJECT;
|
||||||
|
|
||||||
|
strcpy(host.player_names[0], "player_1");
|
||||||
|
strcpy(host.player_names[1], "no_player_2");
|
||||||
|
strcpy(host.player_names[2], "no_player_3");
|
||||||
|
strcpy(host.player_names[3], "no_player_4");
|
||||||
|
|
||||||
|
host.font = TTF_OpenFont("assets/font.ttf", 24);
|
||||||
|
host.set_name_surf = TTF_RenderText_Solid(host.font, "set name", white);
|
||||||
|
host.start_surf = TTF_RenderText_Solid(host.font, "start game", white);
|
||||||
|
host.lobby_name_surf = TTF_RenderText_Solid(host.font, host.lobby_name, white);
|
||||||
|
|
||||||
|
host.set_name_tex = SDL_CreateTextureFromSurface(renderer, host.set_name_surf);
|
||||||
|
host.start_tex = SDL_CreateTextureFromSurface(renderer, host.start_surf);
|
||||||
|
|
||||||
|
|
||||||
|
host.set_name_rect.w = DEF_WINDOW_WIDTH >> 3;
|
||||||
|
host.set_name_rect.h = DEF_WINDOW_HEIGHT >> 4;
|
||||||
|
host.set_name_rect.x = DEF_WINDOW_WIDTH - (host.set_name_rect.w << 1);
|
||||||
|
host.set_name_rect.y = DEF_WINDOW_HEIGHT - (host.set_name_rect.h << 2);
|
||||||
|
|
||||||
|
host.name_rect.w = DEF_WINDOW_WIDTH - (host.set_name_rect.w << 2) - (BOARDER_THICKNESS << 1);
|
||||||
|
host.name_rect.h = host.set_name_rect.h;
|
||||||
|
host.name_rect.x = (host.set_name_rect.w << 1) + BOARDER_THICKNESS;
|
||||||
|
host.name_rect.y = host.set_name_rect.y;
|
||||||
|
|
||||||
|
host.start_rect.w = host.set_name_rect.w;
|
||||||
|
host.start_rect.h = host.set_name_rect.h;
|
||||||
|
host.start_rect.x = (DEF_WINDOW_WIDTH >> 1) - (host.start_rect.w >> 1);
|
||||||
|
host.start_rect.y = host.set_name_rect.y + host.set_name_rect.h + BOARDER_THICKNESS;
|
||||||
|
|
||||||
|
host.player_name_rect.w = DEF_WINDOW_WIDTH - (host.set_name_rect.w << 2) - (BOARDER_THICKNESS << 1);
|
||||||
|
host.player_name_rect.h = host.set_name_rect.h;
|
||||||
|
host.player_name_rect.x = (host.set_name_rect.w << 1) + BOARDER_THICKNESS;
|
||||||
|
host.player_name_rect.y = host.set_name_rect.y;
|
||||||
|
|
||||||
|
host.player_rects[0].w = host.player_rects[1].w = host.player_rects[2].w = host.player_rects[3].w
|
||||||
|
= DEF_WINDOW_WIDTH - (host.set_name_rect.w << 1);
|
||||||
|
host.player_rects[0].h = host.player_rects[1].h = host.player_rects[2].h = host.player_rects[3].h
|
||||||
|
= ((DEF_WINDOW_HEIGHT - (DEF_WINDOW_HEIGHT - host.set_name_rect.y))
|
||||||
|
- (BOARDER_THICKNESS << 2) - BOARDER_THICKNESS) >> 2;
|
||||||
|
host.player_rects[0].x = host.player_rects[1].x = host.player_rects[2].x = host.player_rects[3].x
|
||||||
|
= host.set_name_rect.w;
|
||||||
|
|
||||||
|
host.player_rects[0].y = BOARDER_THICKNESS;
|
||||||
|
host.player_rects[1].y = host.player_rects[0].y + host.player_rects[0].h + BOARDER_THICKNESS;
|
||||||
|
host.player_rects[2].y = host.player_rects[1].y + host.player_rects[1].h + BOARDER_THICKNESS;
|
||||||
|
host.player_rects[3].y = host.player_rects[2].y + host.player_rects[2].h + BOARDER_THICKNESS;
|
||||||
|
|
||||||
|
for(i = 0; i < MAX_PLAYERS; i++)
|
||||||
|
{
|
||||||
|
host.player_name_rects[i].w = host.player_rects[i].w;
|
||||||
|
host.player_name_rects[i].h = host.player_rects[i].h - (BOARDER_THICKNESS << 1);
|
||||||
|
host.player_name_rects[i].x = host.player_rects[i].x + BOARDER_THICKNESS;
|
||||||
|
host.player_name_rects[i].y = host.player_rects[i].y + BOARDER_THICKNESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
char *get_this_name(int i)
|
char *get_this_name(int i)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(!lobby_has_name) {
|
if(!lobby_has_name) {
|
||||||
if(i == -1){return lobby_name; }
|
if(i == -1){return host.lobby_name; }
|
||||||
if(i == 0) { return lobby_name_perm; }
|
if(i == 0) { return host.lobby_name_perm; }
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if(i == -1) { return temp_name; }
|
if(i == -1) { return host.temp_name; }
|
||||||
if(i >= 0 && i < MAX_PLAYERS){
|
if(i >= 0 && i < MAX_PLAYERS){
|
||||||
return player_names[i];
|
return host.player_names[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -67,72 +134,72 @@ void render_lobby()
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
player_tempname_surf= TTF_RenderText_Solid(font, temp_name, white);
|
host.player_tempname_surf= TTF_RenderText_Solid(host.font, host.temp_name, white);
|
||||||
player_tempname_tex = SDL_CreateTextureFromSurface(renderer, player_tempname_surf);
|
host.player_tempname_tex = SDL_CreateTextureFromSurface(renderer, host.player_tempname_surf);
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
//set name button
|
//set name button
|
||||||
SDL_SetRenderDrawColor(renderer, 64, 64, 64,255);
|
SDL_SetRenderDrawColor(renderer, 64, 64, 64,255);
|
||||||
SDL_RenderFillRect(renderer, &set_name_rect);
|
SDL_RenderFillRect(renderer, &host.set_name_rect);
|
||||||
SDL_RenderCopy(renderer, set_name_tex, NULL, &(set_name_rect));
|
SDL_RenderCopy(renderer, host.set_name_tex, NULL, &(host.set_name_rect));
|
||||||
|
|
||||||
//player fields
|
//player fields
|
||||||
for(i = 0; i < MAX_PLAYERS; i++)
|
for(i = 0; i < MAX_PLAYERS; i++)
|
||||||
{
|
{
|
||||||
player_name_rects[i].w = (player_rects[0].w / MAX_NAMESZ) * strlen(player_names[i]);
|
host.player_name_rects[i].w = (host.player_rects[0].w / MAX_NAMESZ) * strlen(host.player_names[i]);
|
||||||
player_name_surfs[i] = TTF_RenderText_Solid(font, player_names[i], white);
|
host.player_name_surfs[i] = TTF_RenderText_Solid(host.font, host.player_names[i], white);
|
||||||
player_name_texs[i] = SDL_CreateTextureFromSurface(renderer, player_name_surfs[i]);
|
host.player_name_texs[i] = SDL_CreateTextureFromSurface(renderer, host.player_name_surfs[i]);
|
||||||
SDL_RenderFillRect(renderer, &(player_rects[i]));
|
SDL_RenderFillRect(renderer, &(host.player_rects[i]));
|
||||||
SDL_RenderCopy(renderer, player_name_texs[i], NULL, &(player_name_rects[i]));
|
SDL_RenderCopy(renderer, host.player_name_texs[i], NULL, &(host.player_name_rects[i]));
|
||||||
}
|
}
|
||||||
//name field
|
//name field
|
||||||
player_name_rect.w = (name_rect.w / MAX_NAMESZ) * strlen(temp_name);
|
host.player_name_rect.w = (host.name_rect.w / MAX_NAMESZ) * strlen(host.temp_name);
|
||||||
SDL_RenderFillRect(renderer, &name_rect);
|
SDL_RenderFillRect(renderer, &host.name_rect);
|
||||||
SDL_RenderCopy(renderer, player_tempname_tex, NULL, &player_name_rect);
|
SDL_RenderCopy(renderer, host.player_tempname_tex, NULL, &host.player_name_rect);
|
||||||
|
|
||||||
//start game button
|
//start game button
|
||||||
SDL_RenderFillRect(renderer, &start_rect);
|
SDL_RenderFillRect(renderer, &host.start_rect);
|
||||||
SDL_RenderCopy(renderer, start_tex, NULL, &(start_rect));
|
SDL_RenderCopy(renderer, host.start_tex, NULL, &(host.start_rect));
|
||||||
|
|
||||||
|
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
|
|
||||||
player_tempname_surf= TTF_RenderText_Solid(font, temp_name, white);
|
host.player_tempname_surf= TTF_RenderText_Solid(host.font, host.temp_name, white);
|
||||||
player_tempname_tex = SDL_CreateTextureFromSurface(renderer, player_tempname_surf);
|
host.player_tempname_tex = SDL_CreateTextureFromSurface(renderer, host.player_tempname_surf);
|
||||||
|
|
||||||
SDL_FreeSurface(player_tempname_surf);
|
SDL_FreeSurface(host.player_tempname_surf);
|
||||||
SDL_DestroyTexture(player_tempname_tex);
|
SDL_DestroyTexture(host.player_tempname_tex);
|
||||||
for(i = 0; i < MAX_PLAYERS; i++)
|
for(i = 0; i < MAX_PLAYERS; i++)
|
||||||
{
|
{
|
||||||
SDL_FreeSurface(player_name_surfs[i]);
|
SDL_FreeSurface(host.player_name_surfs[i]);
|
||||||
SDL_DestroyTexture(player_name_texs[i]);
|
SDL_DestroyTexture(host.player_name_texs[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_lobby_name()
|
void render_lobby_name()
|
||||||
{
|
{
|
||||||
|
|
||||||
lobby_name_surf = TTF_RenderText_Solid(font, lobby_name, white);
|
host.lobby_name_surf = TTF_RenderText_Solid(host.font, host.lobby_name, white);
|
||||||
lobby_name_tex = SDL_CreateTextureFromSurface(renderer, lobby_name_surf);
|
host.lobby_name_tex = SDL_CreateTextureFromSurface(renderer, host.lobby_name_surf);
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
//set lobby name button
|
//set lobby name button
|
||||||
SDL_SetRenderDrawColor(renderer, 64, 64, 64,255);
|
SDL_SetRenderDrawColor(renderer, 64, 64, 64,255);
|
||||||
SDL_RenderFillRect(renderer, &set_name_rect);
|
SDL_RenderFillRect(renderer, &host.set_name_rect);
|
||||||
SDL_RenderCopy(renderer, set_name_tex, NULL, &(set_name_rect));
|
SDL_RenderCopy(renderer, host.set_name_tex, NULL, &(host.set_name_rect));
|
||||||
|
|
||||||
//name field
|
//name field
|
||||||
player_name_rect.w = (name_rect.w / MAX_NAMESZ) * strlen(lobby_name);
|
host.player_name_rect.w = (host.name_rect.w / MAX_NAMESZ) * strlen(host.lobby_name);
|
||||||
SDL_RenderFillRect(renderer, &name_rect);
|
SDL_RenderFillRect(renderer, &host.name_rect);
|
||||||
SDL_RenderCopy(renderer, lobby_name_tex, NULL, &player_name_rect);
|
SDL_RenderCopy(renderer, host.lobby_name_tex, NULL, &host.player_name_rect);
|
||||||
|
|
||||||
//start game button
|
//start game button
|
||||||
SDL_RenderFillRect(renderer, &start_rect);
|
SDL_RenderFillRect(renderer, &host.start_rect);
|
||||||
SDL_RenderCopy(renderer, start_tex, NULL, &(start_rect));
|
SDL_RenderCopy(renderer, host.start_tex, NULL, &(host.start_rect));
|
||||||
|
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
|
|
||||||
@@ -140,90 +207,25 @@ void render_lobby_name()
|
|||||||
|
|
||||||
void render_main()
|
void render_main()
|
||||||
{
|
{
|
||||||
|
SDL_SetTextInputRect(&host.name_rect);
|
||||||
|
|
||||||
SDL_GetMouseState(&(mouse_pos.x), &(mouse_pos.y));
|
SDL_GetMouseState(&(mouse_pos.x), &(mouse_pos.y));
|
||||||
|
|
||||||
if(SDL_PointInRect(&mouse_pos, &start_rect)){
|
if(SDL_PointInRect(&mouse_pos, &host.start_rect)){
|
||||||
over_object = START_GAME_BUTTON;
|
over_object = START_GAME_BUTTON;
|
||||||
}
|
}
|
||||||
else if(SDL_PointInRect(&mouse_pos, &set_name_rect)){
|
else if(SDL_PointInRect(&mouse_pos, &host.set_name_rect)){
|
||||||
over_object = SET_NAME_BUTTON;
|
over_object = SET_NAME_BUTTON;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle_event(&event);
|
|
||||||
|
|
||||||
if(lobby_has_name){ render_lobby(); }
|
if(lobby_has_name){ render_lobby(); }
|
||||||
else{ render_lobby_name(); }
|
else{ render_lobby_name(); }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void host_game(){
|
void render_host_game(){
|
||||||
int i;
|
|
||||||
PRINT_M(HOST state)
|
|
||||||
|
|
||||||
over_object = NO_OBJECT;
|
|
||||||
|
|
||||||
strcpy(player_names[0], "player_1");
|
|
||||||
strcpy(player_names[1], "no_player_2");
|
|
||||||
strcpy(player_names[2], "no_player_3");
|
|
||||||
strcpy(player_names[3], "no_player_4");
|
|
||||||
|
|
||||||
font = TTF_OpenFont("assets/font.ttf", 24);
|
|
||||||
set_name_surf = TTF_RenderText_Solid(font, "set name", white);
|
|
||||||
start_surf = TTF_RenderText_Solid(font, "start game", white);
|
|
||||||
lobby_name_surf = TTF_RenderText_Solid(font, lobby_name, white);
|
|
||||||
|
|
||||||
set_name_tex = SDL_CreateTextureFromSurface(renderer, set_name_surf);
|
|
||||||
start_tex = SDL_CreateTextureFromSurface(renderer, start_surf);
|
|
||||||
|
|
||||||
|
|
||||||
set_name_rect.w = DEF_WINDOW_WIDTH >> 3;
|
|
||||||
set_name_rect.h = DEF_WINDOW_HEIGHT >> 4;
|
|
||||||
set_name_rect.x = DEF_WINDOW_WIDTH - (set_name_rect.w << 1);
|
|
||||||
set_name_rect.y = DEF_WINDOW_HEIGHT - (set_name_rect.h << 2);
|
|
||||||
|
|
||||||
name_rect.w = DEF_WINDOW_WIDTH - (set_name_rect.w << 2) - (BOARDER_THICKNESS << 1);
|
|
||||||
name_rect.h = set_name_rect.h;
|
|
||||||
name_rect.x = (set_name_rect.w << 1) + BOARDER_THICKNESS;
|
|
||||||
name_rect.y = set_name_rect.y;
|
|
||||||
|
|
||||||
start_rect.w = set_name_rect.w;
|
|
||||||
start_rect.h = set_name_rect.h;
|
|
||||||
start_rect.x = (DEF_WINDOW_WIDTH >> 1) - (start_rect.w >> 1);
|
|
||||||
start_rect.y = set_name_rect.y + set_name_rect.h + BOARDER_THICKNESS;
|
|
||||||
|
|
||||||
player_name_rect.w = DEF_WINDOW_WIDTH - (set_name_rect.w << 2) - (BOARDER_THICKNESS << 1);
|
|
||||||
player_name_rect.h = set_name_rect.h;
|
|
||||||
player_name_rect.x = (set_name_rect.w << 1) + BOARDER_THICKNESS;
|
|
||||||
player_name_rect.y = set_name_rect.y;
|
|
||||||
|
|
||||||
player_rects[0].w = player_rects[1].w = player_rects[2].w = player_rects[3].w
|
|
||||||
= DEF_WINDOW_WIDTH - (set_name_rect.w << 1);
|
|
||||||
player_rects[0].h = player_rects[1].h = player_rects[2].h = player_rects[3].h
|
|
||||||
= ((DEF_WINDOW_HEIGHT - (DEF_WINDOW_HEIGHT - set_name_rect.y))
|
|
||||||
- (BOARDER_THICKNESS << 2) - BOARDER_THICKNESS) >> 2;
|
|
||||||
player_rects[0].x = player_rects[1].x = player_rects[2].x = player_rects[3].x
|
|
||||||
= set_name_rect.w;
|
|
||||||
|
|
||||||
player_rects[0].y = BOARDER_THICKNESS;
|
|
||||||
player_rects[1].y = player_rects[0].y + player_rects[0].h + BOARDER_THICKNESS;
|
|
||||||
player_rects[2].y = player_rects[1].y + player_rects[1].h + BOARDER_THICKNESS;
|
|
||||||
player_rects[3].y = player_rects[2].y + player_rects[2].h + BOARDER_THICKNESS;
|
|
||||||
|
|
||||||
for(i = 0; i < MAX_PLAYERS; i++){
|
|
||||||
player_name_rects[i].w = player_rects[i].w;
|
|
||||||
player_name_rects[i].h = player_rects[i].h - (BOARDER_THICKNESS << 1);
|
|
||||||
player_name_rects[i].x = player_rects[i].x + BOARDER_THICKNESS;
|
|
||||||
player_name_rects[i].y = player_rects[i].y + BOARDER_THICKNESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SDL_StartTextInput();
|
|
||||||
SDL_SetTextInputRect(&name_rect);
|
|
||||||
|
|
||||||
while(running)
|
|
||||||
{
|
|
||||||
render_main();
|
render_main();
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
#ifndef __game_h__
|
#ifndef __game_h__
|
||||||
#define __game_h__
|
#define __game_h__
|
||||||
|
|
||||||
|
void init_start_game();
|
||||||
|
void render_start_game();
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
extern SDL_Point mouse_pos;
|
extern SDL_Point mouse_pos;
|
||||||
@@ -17,10 +20,7 @@ extern SDL_Point mouse_pos;
|
|||||||
extern int state;
|
extern int state;
|
||||||
|
|
||||||
void start_battle();
|
void start_battle();
|
||||||
void start_game();
|
|
||||||
void show_options();
|
void show_options();
|
||||||
void host_game();
|
|
||||||
void join_game();
|
|
||||||
|
|
||||||
#define GRAB_NEW 2
|
#define GRAB_NEW 2
|
||||||
#define GRAB_OLD 1
|
#define GRAB_OLD 1
|
||||||
|
|||||||
@@ -3,17 +3,31 @@
|
|||||||
#define __host_h__
|
#define __host_h__
|
||||||
|
|
||||||
#define NO_OBJECT 0
|
#define NO_OBJECT 0
|
||||||
|
//host view
|
||||||
#define SET_NAME_BUTTON 1
|
#define SET_NAME_BUTTON 1
|
||||||
#define START_GAME_BUTTON 2
|
#define START_GAME_BUTTON 2
|
||||||
|
//join view
|
||||||
|
#define JOIN_GAME_BUTTON 1
|
||||||
|
#define PLAYER_NAME_BOX 2
|
||||||
|
#define LOBBY_NAME_BOX 3
|
||||||
|
#define PLAYER_NAME_SEL 0
|
||||||
|
#define LOBBY_NAME_SEL 1
|
||||||
|
|
||||||
|
//host
|
||||||
|
void render_host_game();
|
||||||
|
void init_host();
|
||||||
extern int over_object;
|
extern int over_object;
|
||||||
extern int lobby_has_name;
|
extern int lobby_has_name;
|
||||||
|
|
||||||
|
|
||||||
char *get_this_name(int i);
|
char *get_this_name(int i);
|
||||||
|
|
||||||
|
//join
|
||||||
|
|
||||||
|
char *join_get_name_ptr();
|
||||||
|
void render_join_game();
|
||||||
|
void init_join();
|
||||||
|
int join_over_object();
|
||||||
|
void join_set_selected(int);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
#define DEF_WINDOW_WIDTH 1920
|
#define DEF_WINDOW_WIDTH 1024
|
||||||
#define DEF_WINDOW_HEIGHT 1080
|
#define DEF_WINDOW_HEIGHT 768
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -25,5 +25,7 @@ extern int selected_index;
|
|||||||
extern SDL_Window* window;
|
extern SDL_Window* window;
|
||||||
extern SDL_Renderer* renderer;
|
extern SDL_Renderer* renderer;
|
||||||
extern SDL_Event event;
|
extern SDL_Event event;
|
||||||
|
extern SDL_Color white;
|
||||||
|
extern SDL_Point mouse_pos;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
void start_overworld();
|
void init_overworld();
|
||||||
|
void render_overworld();
|
||||||
|
|
||||||
#define OW_GRIDSZ 128
|
#define OW_GRIDSZ 128
|
||||||
|
|
||||||
|
|||||||
60
input.c
60
input.c
@@ -12,6 +12,7 @@ void handle_input_mainmenu(SDL_Event *e);
|
|||||||
void handle_input_battle(SDL_Event *e);
|
void handle_input_battle(SDL_Event *e);
|
||||||
void handle_input_overworld(SDL_Event *e);
|
void handle_input_overworld(SDL_Event *e);
|
||||||
void handle_input_host(SDL_Event *e);
|
void handle_input_host(SDL_Event *e);
|
||||||
|
void handle_input_join(SDL_Event *e);
|
||||||
|
|
||||||
void mainmenu_selection_state()
|
void mainmenu_selection_state()
|
||||||
{
|
{
|
||||||
@@ -74,11 +75,15 @@ void handle_event(SDL_Event *e){
|
|||||||
case HOST:
|
case HOST:
|
||||||
handle_input_host(e);
|
handle_input_host(e);
|
||||||
break;
|
break;
|
||||||
|
case JOIN:
|
||||||
|
handle_input_join(e);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
if(e->type == SDL_KEYDOWN && e->key.keysym.sym == SDLK_ESCAPE)
|
if(e->type == SDL_KEYDOWN && e->key.keysym.sym == SDLK_ESCAPE)
|
||||||
{
|
{
|
||||||
running = 0;
|
running = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -199,3 +204,58 @@ void handle_input_host(SDL_Event *e)
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handle_input_join(SDL_Event *e)
|
||||||
|
{
|
||||||
|
int oldlen, inputlen;
|
||||||
|
char tempname[MAX_NAMESZ], *nameptr;
|
||||||
|
nameptr = join_get_name_ptr();
|
||||||
|
strcpy(tempname, nameptr);
|
||||||
|
oldlen = strlen(tempname);
|
||||||
|
|
||||||
|
switch(e->type)
|
||||||
|
{
|
||||||
|
case SDL_KEYUP:
|
||||||
|
break;
|
||||||
|
case SDL_KEYDOWN:
|
||||||
|
switch(e->key.keysym.sym)
|
||||||
|
{
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
running = 0;
|
||||||
|
break;
|
||||||
|
case SDLK_BACKSPACE:
|
||||||
|
PRINT_M(got backspace)
|
||||||
|
if(oldlen == 0){ break; }
|
||||||
|
tempname[oldlen - 1] = '\0';
|
||||||
|
strcpy(nameptr, tempname);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SDL_TEXTINPUT:
|
||||||
|
inputlen = strlen(e->text.text);
|
||||||
|
PRINT_M(got text input event)
|
||||||
|
if(oldlen + inputlen > MAX_NAMESZ -1){ break; }
|
||||||
|
strcat(tempname, e->text.text);
|
||||||
|
strcpy(nameptr, tempname);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
|
switch(join_over_object())
|
||||||
|
{
|
||||||
|
case NO_OBJECT:
|
||||||
|
break;
|
||||||
|
case JOIN_GAME_BUTTON:
|
||||||
|
PRINT_M(JOIN_GAME BUTTON)
|
||||||
|
//check name field and send it off bb
|
||||||
|
break;
|
||||||
|
case LOBBY_NAME_BOX:
|
||||||
|
join_set_selected(LOBBY_NAME_SEL);
|
||||||
|
break;
|
||||||
|
case PLAYER_NAME_BOX:
|
||||||
|
join_set_selected(PLAYER_NAME_SEL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|||||||
158
join.c
158
join.c
@@ -2,19 +2,169 @@
|
|||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
|
#include <SDL_ttf.h>
|
||||||
#include <mydebug.h>
|
#include <mydebug.h>
|
||||||
#include <game.h>
|
#include <game.h>
|
||||||
|
#include <host.h>
|
||||||
#include <input.h>
|
#include <input.h>
|
||||||
#include <deck.h>
|
#include <deck.h>
|
||||||
#include <main.h>
|
#include <main.h>
|
||||||
|
|
||||||
void join_game(){
|
#define BOARDER_THICKNESS 20
|
||||||
running = 0;
|
|
||||||
|
struct join_ctx
|
||||||
|
{
|
||||||
|
int selected;
|
||||||
|
|
||||||
|
int over_object;
|
||||||
|
|
||||||
|
char player_name[MAX_NAMESZ];
|
||||||
|
char lobby_name[MAX_NAMESZ];
|
||||||
|
|
||||||
|
TTF_Font *font;
|
||||||
|
|
||||||
|
SDL_Rect lobby_name_rect, player_name_rect, join_game_rect;
|
||||||
|
SDL_Rect lobby_name_box, player_name_box, join_game_box;
|
||||||
|
|
||||||
|
SDL_Surface *player_name_surf, *lobby_prompt_surf, *name_promt_surf,
|
||||||
|
*join_surf, *lobby_name_surf;
|
||||||
|
SDL_Texture *player_name_tex, *lobby_prompt_tex, *name_prompt_tex,
|
||||||
|
*lobby_name_tex, *join_tex;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
struct join_ctx join;
|
||||||
|
|
||||||
|
void join_set_selected(int obj)
|
||||||
|
{
|
||||||
|
join.selected = obj;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int join_over_object()
|
||||||
|
{
|
||||||
|
return join.over_object;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *join_get_name_ptr()
|
||||||
|
{
|
||||||
|
if(join.selected == PLAYER_NAME_SEL){
|
||||||
|
return join.player_name;
|
||||||
|
}
|
||||||
|
else if(join.selected == LOBBY_NAME_SEL){
|
||||||
|
return join.lobby_name;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void init_join()
|
||||||
|
{
|
||||||
|
|
||||||
|
join.over_object = NO_OBJECT;
|
||||||
|
join.font = TTF_OpenFont("assets/font.ttf", 24);
|
||||||
|
|
||||||
|
strcpy(join.player_name, "PLAYER");
|
||||||
|
strcpy(join.lobby_name, "lobby_name");
|
||||||
|
|
||||||
|
join.player_name_box.x = DEF_WINDOW_WIDTH >> 3;
|
||||||
|
join.player_name_box.y = DEF_WINDOW_HEIGHT >> 3;
|
||||||
|
join.player_name_box.w = (DEF_WINDOW_WIDTH >> 1) + (DEF_WINDOW_WIDTH >> 2);
|
||||||
|
join.player_name_box.h = DEF_WINDOW_HEIGHT >> 3;
|
||||||
|
|
||||||
|
join.player_name_rect.x = join.player_name_box.x + BOARDER_THICKNESS;
|
||||||
|
join.player_name_rect.y = join.player_name_box.y + BOARDER_THICKNESS;
|
||||||
|
join.player_name_rect.w = join.player_name_box.w - (BOARDER_THICKNESS<<1);
|
||||||
|
join.player_name_rect.h = join.player_name_box.h - (BOARDER_THICKNESS<<1);
|
||||||
|
|
||||||
|
join.lobby_name_box.x = join.player_name_box.x;
|
||||||
|
join.lobby_name_box.y = join.player_name_box.y + join.player_name_box.h + BOARDER_THICKNESS;
|
||||||
|
join.lobby_name_box.w = join.player_name_box.w;
|
||||||
|
join.lobby_name_box.h = join.player_name_box.h;
|
||||||
|
|
||||||
|
join.lobby_name_rect.x = join.player_name_rect.x;
|
||||||
|
join.lobby_name_rect.y = join.lobby_name_box.y + BOARDER_THICKNESS;
|
||||||
|
join.lobby_name_rect.w = join.player_name_rect.w;
|
||||||
|
join.lobby_name_rect.h = join.player_name_rect.h;
|
||||||
|
|
||||||
|
join.join_game_box.w = join.lobby_name_box.w >> 1;
|
||||||
|
join.join_game_box.x = (DEF_WINDOW_WIDTH >> 1) - (join.join_game_box.w >> 1);
|
||||||
|
join.join_game_box.y = join.lobby_name_box.y + join.lobby_name_box.h + BOARDER_THICKNESS;
|
||||||
|
join.join_game_box.h = join.lobby_name_box.h;
|
||||||
|
|
||||||
|
join.join_game_rect.x = join.join_game_box.x + BOARDER_THICKNESS;
|
||||||
|
join.join_game_rect.y = join.join_game_box.y + BOARDER_THICKNESS;
|
||||||
|
join.join_game_rect.w = join.join_game_box.w - (BOARDER_THICKNESS << 1);
|
||||||
|
join.join_game_rect.h = join.join_game_box.h - (BOARDER_THICKNESS << 1);
|
||||||
|
|
||||||
|
join.join_surf = TTF_RenderText_Solid(join.font, "JOIN GAME", white);
|
||||||
|
join.join_tex = SDL_CreateTextureFromSurface(renderer, join.join_surf);
|
||||||
|
|
||||||
|
|
||||||
|
PRINT_M(INIT JOIN)
|
||||||
|
}
|
||||||
|
|
||||||
|
void join_update_hover()
|
||||||
|
{
|
||||||
|
if(SDL_PointInRect(&mouse_pos, &join.join_game_box)){ join.over_object = JOIN_GAME_BUTTON; }
|
||||||
|
else if(SDL_PointInRect(&mouse_pos, &join.lobby_name_box)){ join.over_object = LOBBY_NAME_BOX; }
|
||||||
|
else if(SDL_PointInRect(&mouse_pos, &join.player_name_box)){ join.over_object = PLAYER_NAME_BOX; }
|
||||||
|
else { join.over_object = NO_OBJECT; }
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void render_join_game()
|
||||||
|
{
|
||||||
|
join_update_hover();
|
||||||
|
|
||||||
|
join.player_name_surf = TTF_RenderText_Solid(join.font, join.player_name, white);
|
||||||
|
join.player_name_tex = SDL_CreateTextureFromSurface(renderer, join.player_name_surf);
|
||||||
|
join.lobby_name_surf = TTF_RenderText_Solid(join.font, join.lobby_name, white);
|
||||||
|
join.lobby_name_tex = SDL_CreateTextureFromSurface(renderer, join.lobby_name_surf);
|
||||||
|
|
||||||
|
SDL_SetRenderDrawColor(renderer, 0,0,0,255);
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
|
if(join.selected == PLAYER_NAME_SEL ){
|
||||||
|
//player name rect
|
||||||
|
SDL_SetRenderDrawColor(renderer, 32, 64, 32, 255);
|
||||||
|
SDL_RenderFillRect(renderer, &join.player_name_box);
|
||||||
|
//lobby name rect
|
||||||
|
SDL_SetRenderDrawColor(renderer, 64,64,64,255);
|
||||||
|
SDL_RenderFillRect(renderer, &join.lobby_name_box);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
//lobby name rect
|
||||||
|
SDL_SetRenderDrawColor(renderer, 32, 64, 32, 255);
|
||||||
|
SDL_RenderFillRect(renderer, &join.lobby_name_box);
|
||||||
|
//player name rect
|
||||||
|
SDL_SetRenderDrawColor(renderer, 64,64,64,255);
|
||||||
|
SDL_RenderFillRect(renderer, &join.player_name_box);
|
||||||
|
}
|
||||||
|
|
||||||
|
//player name text
|
||||||
|
join.player_name_rect.w = (join.player_name_box.w / MAX_NAMESZ) * strlen(join.player_name);
|
||||||
|
SDL_RenderCopy(renderer, join.player_name_tex, NULL, &join.player_name_rect);
|
||||||
|
|
||||||
|
//lobby name text
|
||||||
|
join.lobby_name_rect.w = (join.lobby_name_box.w / MAX_NAMESZ) * strlen(join.lobby_name);
|
||||||
|
SDL_RenderCopy(renderer, join.lobby_name_tex, NULL, &join.lobby_name_rect);
|
||||||
|
|
||||||
|
|
||||||
|
SDL_RenderFillRect(renderer, &join.join_game_box);
|
||||||
|
SDL_RenderCopy(renderer, join.join_tex, NULL, &join.join_game_rect);
|
||||||
|
|
||||||
|
|
||||||
|
SDL_RenderPresent(renderer);
|
||||||
|
|
||||||
|
SDL_FreeSurface(join.player_name_surf);
|
||||||
|
SDL_DestroyTexture(join.player_name_tex);
|
||||||
|
SDL_FreeSurface(join.lobby_name_surf);
|
||||||
|
SDL_DestroyTexture(join.lobby_name_tex);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
282
main.c
282
main.c
@@ -4,6 +4,7 @@
|
|||||||
#include <game.h>
|
#include <game.h>
|
||||||
#include <input.h>
|
#include <input.h>
|
||||||
#include <overworld.h>
|
#include <overworld.h>
|
||||||
|
#include <host.h>
|
||||||
|
|
||||||
#include <mydebug.h>
|
#include <mydebug.h>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
@@ -12,170 +13,73 @@
|
|||||||
|
|
||||||
#define SPACING 20
|
#define SPACING 20
|
||||||
|
|
||||||
|
void render_mainmenu();
|
||||||
|
void init_mainmenu();
|
||||||
|
|
||||||
|
SDL_Point mouse_pos;
|
||||||
SDL_Window* window;
|
SDL_Window* window;
|
||||||
SDL_Renderer* renderer;
|
SDL_Renderer* renderer;
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
SDL_Color white = {255,255,255,0};
|
||||||
|
|
||||||
|
struct mainmenu_ctx {
|
||||||
|
TTF_Font* font;
|
||||||
|
SDL_Texture* background;
|
||||||
|
SDL_Surface *start_surface, *host_surface, *join_surface, *exit_surface, *options_surface;
|
||||||
|
SDL_Texture *start_text, *host_text, *join_text, *exit_text, *options_text;
|
||||||
|
SDL_Rect start_rect, host_rect, join_rect, exit_rect, options_rect;
|
||||||
|
SDL_Rect mainmenu_rects[MAIN_SELECTIONS];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct mainmenu_ctx mainmenu;
|
||||||
int state = TITLE;
|
int state = TITLE;
|
||||||
int running;
|
int running;
|
||||||
|
|
||||||
|
|
||||||
int selected_index = START_GAME;
|
int selected_index = START_GAME;
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
int x1, x2, y1, y2;
|
int main(void)
|
||||||
SDL_Point mouse_pos;
|
{
|
||||||
SDL_Init(SDL_INIT_VIDEO);
|
SDL_Init(SDL_INIT_VIDEO);
|
||||||
TTF_Init();
|
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);
|
init_mainmenu();
|
||||||
|
init_start_game();
|
||||||
SDL_Texture* background = IMG_LoadTexture(renderer, "assets/mainscreen.png");
|
init_join();
|
||||||
|
init_host();
|
||||||
if (!background) {
|
init_overworld();
|
||||||
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;
|
running = 1;
|
||||||
|
|
||||||
|
//main game loop
|
||||||
while (running)
|
while (running)
|
||||||
{
|
{
|
||||||
handle_event(&event);
|
handle_event(&event);
|
||||||
|
|
||||||
SDL_RenderClear(renderer);
|
SDL_GetMouseState(&mouse_pos.x, &mouse_pos.y);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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<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)
|
switch(state)
|
||||||
{
|
{
|
||||||
case START:
|
case START:
|
||||||
start_game();
|
render_start_game();
|
||||||
|
break;
|
||||||
|
case OVERWORLD:
|
||||||
|
render_overworld();
|
||||||
break;
|
break;
|
||||||
case HOST:
|
case HOST:
|
||||||
PRINT_M(hosting state)
|
render_host_game();
|
||||||
host_game();
|
|
||||||
break;
|
break;
|
||||||
case JOIN:
|
case JOIN:
|
||||||
PRINT_M(joining state)
|
render_join_game();
|
||||||
join_game();
|
|
||||||
break;
|
break;
|
||||||
case OPTIONS:
|
case OPTIONS:
|
||||||
PRINT_M(options menu state)
|
|
||||||
show_options();
|
show_options();
|
||||||
break;
|
break;
|
||||||
|
case TITLE:
|
||||||
|
render_mainmenu();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_DestroyRenderer(renderer);
|
SDL_DestroyRenderer(renderer);
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
IMG_Quit();
|
IMG_Quit();
|
||||||
@@ -183,3 +87,119 @@ int main(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void render_mainmenu_selected()
|
||||||
|
{
|
||||||
|
int x1, x2, y1, y2;
|
||||||
|
switch(selected_index)
|
||||||
|
{
|
||||||
|
case START_GAME:
|
||||||
|
x1 = mainmenu.start_rect.x;
|
||||||
|
x2 = x1 + mainmenu.start_rect.w;
|
||||||
|
y1 = y2 = mainmenu.start_rect.y + mainmenu.start_rect.h;
|
||||||
|
break;
|
||||||
|
case HOST_GAME:
|
||||||
|
x1 = mainmenu.host_rect.x;
|
||||||
|
x2 = x1 + mainmenu.host_rect.w;
|
||||||
|
y1 = y2 = mainmenu.host_rect.y + mainmenu.host_rect.h;
|
||||||
|
break;
|
||||||
|
case JOIN_GAME:
|
||||||
|
x1 = mainmenu.join_rect.x;
|
||||||
|
x2 = x1 + mainmenu.join_rect.w;
|
||||||
|
y1 = y2 = mainmenu.join_rect.y + mainmenu.join_rect.h;
|
||||||
|
break;
|
||||||
|
case OPTIONS_MENU:
|
||||||
|
x1 = mainmenu.options_rect.x;
|
||||||
|
x2 = x1 + mainmenu.options_rect.w;
|
||||||
|
y1 = y2 = mainmenu.options_rect.y + mainmenu.options_rect.h;
|
||||||
|
break;
|
||||||
|
case EXIT_GAME:
|
||||||
|
x1 = mainmenu.exit_rect.x;
|
||||||
|
x2 = x1 + mainmenu.exit_rect.w;
|
||||||
|
y1 = y2 = mainmenu.exit_rect.y + mainmenu.exit_rect.h;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
SDL_RenderDrawLine(renderer, x1, y1, x2, y2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_mainmenu()
|
||||||
|
{
|
||||||
|
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_StartTextInput();
|
||||||
|
|
||||||
|
mainmenu.background = IMG_LoadTexture(renderer, "assets/mainscreen.png");
|
||||||
|
|
||||||
|
mainmenu.font = TTF_OpenFont("assets/font.ttf", 24);
|
||||||
|
|
||||||
|
mainmenu.start_surface = TTF_RenderText_Solid(mainmenu.font, "START", white);
|
||||||
|
mainmenu.start_text = SDL_CreateTextureFromSurface(renderer, mainmenu.start_surface);
|
||||||
|
mainmenu.host_surface = TTF_RenderText_Solid(mainmenu.font, "HOST", white);
|
||||||
|
mainmenu.host_text = SDL_CreateTextureFromSurface(renderer, mainmenu.host_surface);
|
||||||
|
mainmenu.join_surface = TTF_RenderText_Solid(mainmenu.font, "JOIN", white);
|
||||||
|
mainmenu.join_text = SDL_CreateTextureFromSurface(renderer, mainmenu.join_surface);
|
||||||
|
mainmenu.exit_surface = TTF_RenderText_Solid(mainmenu.font, "EXIT", white);
|
||||||
|
mainmenu.exit_text = SDL_CreateTextureFromSurface(renderer, mainmenu.exit_surface);
|
||||||
|
mainmenu.options_surface = TTF_RenderText_Solid(mainmenu.font, "OPTIONS", white);
|
||||||
|
mainmenu.options_text = SDL_CreateTextureFromSurface(renderer, mainmenu.options_surface);
|
||||||
|
|
||||||
|
mainmenu.start_rect.w = (DEF_WINDOW_WIDTH >> 2) - (DEF_WINDOW_WIDTH >> 3);
|
||||||
|
mainmenu.start_rect.h = (DEF_WINDOW_HEIGHT >> 3) - (DEF_WINDOW_HEIGHT >> 4);
|
||||||
|
mainmenu.start_rect.x = (DEF_WINDOW_WIDTH - mainmenu.start_rect.w) >> 1;
|
||||||
|
mainmenu.start_rect.y = (DEF_WINDOW_HEIGHT - mainmenu.start_rect.h) >> 1;
|
||||||
|
|
||||||
|
mainmenu.host_rect.w = mainmenu.join_rect.w = mainmenu.exit_rect.w =
|
||||||
|
mainmenu.options_rect.w = mainmenu.start_rect.w;
|
||||||
|
mainmenu.options_rect.w <<= 1;
|
||||||
|
mainmenu.host_rect.h = mainmenu.join_rect.h = mainmenu.exit_rect.h =
|
||||||
|
mainmenu.options_rect.h = mainmenu.start_rect.h;
|
||||||
|
mainmenu.host_rect.x = mainmenu.join_rect.x = mainmenu.exit_rect.x =
|
||||||
|
mainmenu.options_rect.x = mainmenu.start_rect.x;
|
||||||
|
mainmenu.options_rect.x -= mainmenu.join_rect.w >> 1;
|
||||||
|
|
||||||
|
mainmenu.host_rect.y = mainmenu.start_rect.y + mainmenu.start_rect.h + SPACING;
|
||||||
|
mainmenu.join_rect.y = mainmenu.host_rect.y + mainmenu.host_rect.h + SPACING;
|
||||||
|
mainmenu.options_rect.y = mainmenu.join_rect.y + mainmenu.join_rect.h + SPACING;
|
||||||
|
mainmenu.exit_rect.y = mainmenu.options_rect.y + mainmenu.options_rect.h + SPACING;
|
||||||
|
|
||||||
|
mainmenu.mainmenu_rects[START_GAME] = mainmenu.start_rect;
|
||||||
|
mainmenu.mainmenu_rects[HOST_GAME] = mainmenu.host_rect;
|
||||||
|
mainmenu.mainmenu_rects[JOIN_GAME] = mainmenu.join_rect;
|
||||||
|
mainmenu.mainmenu_rects[OPTIONS_MENU] = mainmenu.options_rect;
|
||||||
|
mainmenu.mainmenu_rects[EXIT_GAME] = mainmenu.exit_rect;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void render_mainmenu()
|
||||||
|
{
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
|
SDL_SetRenderDrawColor(renderer, 0,196,0,255);
|
||||||
|
SDL_RenderCopy(renderer, mainmenu.background, NULL, NULL);
|
||||||
|
|
||||||
|
SDL_RenderCopy(renderer, mainmenu.start_text, NULL, &(mainmenu.start_rect));
|
||||||
|
SDL_RenderCopy(renderer, mainmenu.host_text, NULL, &mainmenu.host_rect);
|
||||||
|
SDL_RenderCopy(renderer, mainmenu.join_text, NULL, &mainmenu.join_rect);
|
||||||
|
SDL_RenderCopy(renderer, mainmenu.options_text, NULL, &mainmenu.options_rect);
|
||||||
|
SDL_RenderCopy(renderer, mainmenu.exit_text, NULL, &mainmenu.exit_rect);
|
||||||
|
|
||||||
|
for(int i = 0; i<MAIN_SELECTIONS; i++)
|
||||||
|
{
|
||||||
|
if(SDL_PointInRect(&mouse_pos, &mainmenu.mainmenu_rects[i]))
|
||||||
|
{
|
||||||
|
selected_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render_mainmenu_selected();
|
||||||
|
SDL_RenderPresent(renderer);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
68
net_proto.txt
Normal file
68
net_proto.txt
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
|
||||||
|
we will use this port in net.h
|
||||||
|
#define PORT 36911
|
||||||
|
|
||||||
|
here packet size is also defined, subject to change but makes it
|
||||||
|
easy to no block on send
|
||||||
|
#define PACKSZ 1024
|
||||||
|
|
||||||
|
|
||||||
|
pack type will be at the front of the packet to ensure we handle packets right
|
||||||
|
|
||||||
|
enum pack_type{
|
||||||
|
G_STATE, S_STATE, HOSTS_REQ, NEW_HOST, JOIN_REQ, U_NAME
|
||||||
|
};
|
||||||
|
|
||||||
|
packets are defined so that they keep the exact size of PACKSZ
|
||||||
|
typedef struct packet{
|
||||||
|
enum pack_type type;
|
||||||
|
char payload[PACKSZ - sizeof(enum pack_type)];
|
||||||
|
} packet;
|
||||||
|
|
||||||
|
|
||||||
|
JOIN GAME:
|
||||||
|
|
||||||
|
CLIENT | SERVER
|
||||||
|
|
||||||
|
HOSTS_REQ ----------->
|
||||||
|
<---------- HOSTS_REQ [ list of names that are open lobbies]
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
JOIN_REQ ----------->
|
||||||
|
[name of lobby, name of player]
|
||||||
|
<----------- JOIN_REQ [IP info of host with that name]
|
||||||
|
|
||||||
|
|
||||||
|
HOST GAME:
|
||||||
|
|
||||||
|
CLIENT | SERVER
|
||||||
|
|
||||||
|
NEW_HOST ------------>
|
||||||
|
[name of lobby]
|
||||||
|
<----------- NEW_HOST [ack]
|
||||||
|
|
||||||
|
(ON PLAYER JOIN REQUEST)
|
||||||
|
<------------ JOIN_REQ [player ip info]
|
||||||
|
|
||||||
|
JOIN_REQ ------------>
|
||||||
|
[lobby count]
|
||||||
|
|
||||||
|
(ON HOST START GAME)
|
||||||
|
|
||||||
|
S_STATE ----------->
|
||||||
|
[starting game]
|
||||||
|
<---------- S_STATE [ack]
|
||||||
|
|
||||||
|
(on timeout for lobbies ie games not started)
|
||||||
|
|
||||||
|
<--------- G_STATE [you alive?]
|
||||||
|
|
||||||
|
G_STATE --------->
|
||||||
|
[yup]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
49
overworld.c
49
overworld.c
@@ -10,24 +10,26 @@
|
|||||||
#include <overworld.h>
|
#include <overworld.h>
|
||||||
#include <err_check.h>
|
#include <err_check.h>
|
||||||
|
|
||||||
|
#define OW_ROWS ((DEF_WINDOW_WIDTH / OW_GRIDSZ) + 1)
|
||||||
|
#define OW_COLS ((DEF_WINDOW_HEIGHT / OW_GRIDSZ) + 1)
|
||||||
|
|
||||||
|
|
||||||
PLAYER *myplayer, me;
|
PLAYER *myplayer, me;
|
||||||
|
SDL_Texture *selected_grid, *player_sprite, *grass;
|
||||||
|
|
||||||
|
|
||||||
PLAYER *get_this_player()
|
PLAYER *get_this_player()
|
||||||
{
|
{
|
||||||
return &me;
|
return &me;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ow_rows ((DEF_WINDOW_WIDTH / OW_GRIDSZ) + 1)
|
SDL_Rect ow_rects[OW_ROWS][OW_COLS];
|
||||||
#define ow_cols ((DEF_WINDOW_HEIGHT / OW_GRIDSZ) + 1)
|
|
||||||
|
|
||||||
SDL_Rect ow_rects[ow_rows][ow_cols];
|
void init_overworld()
|
||||||
|
|
||||||
|
|
||||||
void start_overworld()
|
|
||||||
{
|
{
|
||||||
SDL_Texture *selected_grid, *player_sprite, *grass;
|
int row, col;
|
||||||
|
|
||||||
PRINT_M(STARTING GAME)
|
PRINT_M(INIT OVERWORLD)
|
||||||
|
|
||||||
IMG_GETANDCHECK(grass, renderer, "assets/ow_grid_grass.png")
|
IMG_GETANDCHECK(grass, renderer, "assets/ow_grid_grass.png")
|
||||||
IMG_GETANDCHECK(selected_grid, renderer, "assets/ow_selected_grid.png");
|
IMG_GETANDCHECK(selected_grid, renderer, "assets/ow_selected_grid.png");
|
||||||
@@ -35,12 +37,10 @@ void start_overworld()
|
|||||||
|
|
||||||
myplayer = get_this_player();
|
myplayer = get_this_player();
|
||||||
|
|
||||||
int row, col;
|
|
||||||
|
|
||||||
//set up rects to render textures into
|
//set up rects to render textures into
|
||||||
for(row = 0; row <= ow_rows; row++)
|
for(row = 0; row <= OW_ROWS; row++)
|
||||||
{
|
{
|
||||||
for(col = 0; col <= ow_cols; col++)
|
for(col = 0; col <= OW_COLS; col++)
|
||||||
{
|
{
|
||||||
ow_rects[row][col].x = row * OW_GRIDSZ;
|
ow_rects[row][col].x = row * OW_GRIDSZ;
|
||||||
ow_rects[row][col].y = col * OW_GRIDSZ;
|
ow_rects[row][col].y = col * OW_GRIDSZ;
|
||||||
@@ -50,40 +50,31 @@ void start_overworld()
|
|||||||
}
|
}
|
||||||
|
|
||||||
myplayer->texture = player_sprite;
|
myplayer->texture = player_sprite;
|
||||||
myplayer->pos.x = ow_rows >> 1;
|
myplayer->pos.x = OW_ROWS >> 1;
|
||||||
myplayer->pos.y = ow_cols >> 1;
|
myplayer->pos.y = OW_COLS >> 1;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while(running)
|
void render_overworld()
|
||||||
{
|
{
|
||||||
handle_event(&event);
|
int row, col;
|
||||||
|
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
//render the ow grid
|
//render the ow grid
|
||||||
for(row = 0; row < ow_rows; row++)
|
for(row = 0; row < OW_ROWS; row++)
|
||||||
{
|
{
|
||||||
for(col = 0; col < ow_cols; col++)
|
for(col = 0; col < OW_COLS; col++)
|
||||||
{
|
{
|
||||||
SDL_RenderCopy(renderer, grass, NULL, &(ow_rects[row][col]));
|
SDL_RenderCopy(renderer, grass, NULL, &(ow_rects[row][col]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SDL_RenderCopy(renderer, myplayer->texture, NULL, &(ow_rects[myplayer->pos.x][myplayer->pos.y]));
|
SDL_RenderCopy(renderer, myplayer->texture, NULL, &(ow_rects[myplayer->pos.x][myplayer->pos.y]));
|
||||||
|
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
start_battle();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user