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:
2026-01-24 19:12:36 -06:00
parent a698c0eb41
commit 3aaf5021cc
468 changed files with 262023 additions and 59 deletions

103
battle.c
View File

@@ -6,6 +6,8 @@
#include <game.h>
#include <input.h>
#include <deck.h>
#include <main.h>
#include <battle.h>
#define BOARDER_THICKNESS 10
//do not let dx or dy be anything less than 2
@@ -17,13 +19,15 @@ SDL_Rect mouse_rect;
SDL_Rect bot_rect, hand_rect;
SDL_Point mouse_pos;
int check_col(int i);
int selected_card;
int dragging;
void start_battle(){
int cardoff_x, cardoff_y;
int i, cardoff_x, cardoff_y;
int mx, my;
state = BATTLE;
selected_card = -1;
dragging = 0;
PRINT_M(STARTING GAME LOOP);
@@ -32,6 +36,11 @@ void start_battle(){
SDL_Texture *grid = IMG_LoadTexture(renderer, "assets/battle_grid.png");
SDL_Texture *card = IMG_LoadTexture(renderer, "assets/default_card.png");
SDL_Texture *selected = IMG_LoadTexture(renderer, "assets/selected_card.png");
SDL_Texture *enemy_grid = IMG_LoadTexture(renderer, "assets/enemy_grid.png");
SDL_Texture *friendly_grid = IMG_LoadTexture(renderer, "assets/friendly_grid.png");
SDL_Texture *friendly_far = IMG_LoadTexture(renderer, "assets/friendly_far.png");
SDL_Texture *selected_grid = IMG_LoadTexture(renderer, "assets/selected_grid.png");
mouse_rect.x = 0;
mouse_rect.y = 0;
@@ -61,12 +70,55 @@ void start_battle(){
HAND hand;
hand.handsize = 7;
for(int i=0; i<7; i++){
for(i=0; i<7; i++){
hand.cards[i] = card;
hand.card_rects[i].w = CARD_SIZE;
hand.card_rects[i].h = CARD_SIZE;
}
}
battle_rows[0] = enemy_backrow;
battle_rows[1] = enemy_frontrow;
battle_rows[2] = friendly_frontrow;
battle_rows[3] = friendly_midrow;
battle_rows[4] = friendly_backrow;
battle_rows[5] = friendly_farrow;
//battle grid setup
//enemy setup
int grid_w, grid_h;
int side_buffer = DEF_WINDOW_WIDTH / (BATTLE_COLS + 2);
enemy_frontrow[0].x = enemy_backrow[0].x = side_buffer;
enemy_frontrow[0].w = grid_w = enemy_backrow[0].w = side_buffer;
enemy_backrow[0].y = GRID_SPACING;
enemy_frontrow[0].h = grid_h = enemy_backrow[0].h = side_buffer - (side_buffer >> 2 );
enemy_frontrow[0].y = (GRID_SPACING * 2) + grid_h;
for(i = 1; i < BATTLE_COLS; i++)
{
enemy_frontrow[i].x = enemy_backrow[i].x = enemy_backrow[i-1].x + grid_w + GRID_SPACING;
enemy_frontrow[i].w = enemy_backrow[i].w = grid_w;
enemy_backrow[i].y = GRID_SPACING;
enemy_frontrow[i].h = enemy_backrow[i].h = grid_h;
enemy_frontrow[i].y = enemy_frontrow[0].y;
}
//friendly side setup
for(i=0; i < BATTLE_COLS; i++)
{
friendly_farrow[i].x = friendly_backrow[i].x = friendly_midrow[i].x =
friendly_frontrow[i].x = enemy_frontrow[i].x;
friendly_farrow[i].w = friendly_backrow[i].w = friendly_midrow[i].w =
friendly_frontrow[i].w = grid_w;
friendly_backrow[i].h = friendly_midrow[i].h =
friendly_frontrow[i].h = grid_h;
friendly_farrow[i].h = grid_h >> 1;
friendly_frontrow[i].y = enemy_frontrow[i].y + grid_h + (GRID_SPACING * 3);
friendly_midrow[i].y = friendly_frontrow[i].y + grid_h + GRID_SPACING;
friendly_backrow[i].y = friendly_midrow[i].y + grid_h + GRID_SPACING;
friendly_farrow[i].y = friendly_backrow[i].y + grid_h + GRID_SPACING;
}
int check = 1;
int inside = 0;
while(running)
{
handle_event(&event);
@@ -74,7 +126,6 @@ void start_battle(){
SDL_GetMouseState(&mx, &my);
mouse_pos.x = mouse_rect.x = mx;
mouse_pos.y = mouse_rect.y = my;
int inside = 0;
//handle resizing hand box
inside = SDL_PointInRect(&mouse_pos, &hand_rect);
if(SDL_GetTicks64() > lastdraw)
@@ -107,11 +158,11 @@ void start_battle(){
{
spacing = useable_hand_space / (hand.handsize - 1);
}
int check = 1;
check = 1;
if(selected_card == -1) { check = 1;}
else if(SDL_PointInRect(&mouse_pos, &(hand.card_rects[selected_card]))){ check = 0;}
else { selected_card = -1; }
for(int 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)
- ((CARD_SIZE - CARD_W)>>1) ;
@@ -147,7 +198,7 @@ void start_battle(){
if(!inside)
{
hand.handsize--;
for(int i = selected_card; i < hand.handsize; i++)
for(i = selected_card; i < hand.handsize; i++)
{
hand.cards[i] = hand.cards[i+1];
}
@@ -156,10 +207,31 @@ void start_battle(){
}
}
}
SDL_RenderClear(renderer);
//background
SDL_RenderCopy(renderer, grid, NULL, NULL);
SDL_RenderClear(renderer);
//background this isnt a grid anymore
SDL_RenderCopy(renderer, grid, NULL, NULL);
//render battle grid
check = 1;
int sel_row = 0;
for(i = 0; i < BATTLE_COLS; i++)
{
SDL_RenderCopy(renderer, enemy_grid, NULL, &(enemy_backrow[i]));
SDL_RenderCopy(renderer, enemy_grid, NULL, &(enemy_frontrow[i]));
SDL_RenderCopy(renderer, friendly_grid, NULL, &(friendly_frontrow[i]));
SDL_RenderCopy(renderer, friendly_grid, NULL, &(friendly_midrow[i]));
SDL_RenderCopy(renderer, friendly_grid, NULL, &(friendly_backrow[i]));
SDL_RenderCopy(renderer, friendly_far, NULL, &(friendly_farrow[i]));
if(check && (sel_row = check_col(i)))
{
check = 0;
SDL_RenderCopy(renderer, selected_grid, NULL, &(battle_rows[sel_row-1][i]));
}
}
//bottom box for ui shit
SDL_SetRenderDrawColor(renderer, 0,0,0,255);
SDL_RenderFillRect(renderer, &bot_rect);
@@ -196,6 +268,15 @@ void start_battle(){
return;
}
//bad but im lazy lol fix in future
int check_col(int i){
int ret = SDL_PointInRect(&mouse_pos, &(enemy_backrow[i])) * 1;
ret |= SDL_PointInRect(&mouse_pos, &(enemy_frontrow[i])) * 2;
ret |= SDL_PointInRect(&mouse_pos, &(friendly_frontrow[i])) * 3;
ret |= SDL_PointInRect(&mouse_pos, &(friendly_midrow[i])) * 4;
ret |= SDL_PointInRect(&mouse_pos, &(friendly_backrow[i])) * 5;
ret |= SDL_PointInRect(&mouse_pos, &(friendly_farrow[i])) * 6;
return ret;
}