Files
shitgame/overworld.c

81 lines
1.6 KiB
C

/*Troy Rosin*/
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <mydebug.h>
#include <game.h>
#include <input.h>
#include <deck.h>
#include <main.h>
#include <overworld.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;
SDL_Texture *selected_grid, *player_sprite, *grass;
PLAYER *get_this_player()
{
return &me;
}
SDL_Rect ow_rects[OW_ROWS][OW_COLS];
void init_overworld()
{
int row, col;
PRINT_M(INIT OVERWORLD)
IMG_GETANDCHECK(grass, renderer, "assets/ow_grid_grass.png")
IMG_GETANDCHECK(selected_grid, renderer, "assets/ow_selected_grid.png");
IMG_GETANDCHECK(player_sprite, renderer, "assets/player.png");
myplayer = get_this_player();
//set up rects to render textures into
for(row = 0; row <= OW_ROWS; row++)
{
for(col = 0; col <= OW_COLS; col++)
{
ow_rects[row][col].x = row * OW_GRIDSZ;
ow_rects[row][col].y = col * OW_GRIDSZ;
ow_rects[row][col].h = OW_GRIDSZ;
ow_rects[row][col].w = OW_GRIDSZ;
}
}
myplayer->texture = player_sprite;
myplayer->pos.x = OW_ROWS >> 1;
myplayer->pos.y = OW_COLS >> 1;
return;
}
void render_overworld()
{
int row, col;
SDL_RenderClear(renderer);
//render the ow grid
for(row = 0; row < OW_ROWS; row++)
{
for(col = 0; col < OW_COLS; 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_RenderPresent(renderer);
return;
}