draw function
This commit is contained in:
parent
808fd83e6e
commit
17fdac54f4
3 changed files with 18 additions and 59 deletions
|
@ -46,6 +46,7 @@ void drawGameData(SDL_Renderer *renderer, const GameData *gameData, SDL_Texture
|
|||
|
||||
// Present the rendered frame
|
||||
SDL_RenderPresent(renderer);
|
||||
<<<<<<< HEAD
|
||||
}
|
||||
|
||||
void drawMinimap(SDL_Renderer *renderer, const Map *map, int minimapX, int minimapY, int minimapSize) {
|
||||
|
@ -70,4 +71,6 @@ void drawMinimap(SDL_Renderer *renderer, const Map *map, int minimapX, int minim
|
|||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
SDL_Rect minimapBorderRect = {minimapX, minimapY, minimapSize, minimapSize};
|
||||
SDL_RenderDrawRect(renderer, &minimapBorderRect);
|
||||
=======
|
||||
>>>>>>> 6abc1cd (draw function)
|
||||
}
|
28
src/draw.h
28
src/draw.h
|
@ -1,4 +1,5 @@
|
|||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
#ifndef DRAW_H
|
||||
#define DRAW_H
|
||||
|
||||
|
@ -14,21 +15,22 @@ void drawGameData(SDL_Renderer *renderer, const GameData *gameData, SDL_Texture
|
|||
#endif /* DRAW_H */
|
||||
=======
|
||||
#define MAP_SIZE 96
|
||||
=======
|
||||
#ifndef DRAW_H
|
||||
#define DRAW_H
|
||||
>>>>>>> 6abc1cd (draw function)
|
||||
|
||||
#define TILE_HEIGHT 30
|
||||
#define TILE_WIDTH 60
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#define MAP_RENDER_SIZE 24
|
||||
// Define the size of your tiles in pixels
|
||||
#define TILE_SIZE 32
|
||||
#include "data.h"
|
||||
|
||||
#define MAP_RENDER_OFFSET_X ((SCREEN_WIDTH - (TILE_WIDTH * MAP_RENDER_SIZE)) / 2)
|
||||
#define MAP_RENDER_OFFSET_Y 425
|
||||
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
int sx;
|
||||
int sy;
|
||||
AtlasImage *texture;
|
||||
} ISOObject;
|
||||
// Function prototype for drawing game data
|
||||
void drawGameData(SDL_Renderer *renderer, const GameData *gameData, SDL_Texture *tileTexture, SDL_Texture *unitTexture, SDL_Texture *buildingTexture);
|
||||
|
||||
<<<<<<< HEAD
|
||||
>>>>>>> 8e3d2ca (add game structure)
|
||||
=======
|
||||
#endif /* DRAW_H */
|
||||
>>>>>>> 6abc1cd (draw function)
|
||||
|
|
46
src/main.c
46
src/main.c
|
@ -5,52 +5,6 @@
|
|||
const int SCREEN_WIDTH = 800;
|
||||
const int SCREEN_HEIGHT = 600;
|
||||
|
||||
// Function to draw the game data onto the screen
|
||||
void drawGameData(SDL_Renderer *renderer, const GameData *gameData, SDL_Texture *tileTexture, SDL_Texture *unitTexture, SDL_Texture *buildingTexture) {
|
||||
// Clear the screen
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
// Draw the map tiles
|
||||
for (int i = 0; i < gameData->currentMap.mapWidth; i++) {
|
||||
for (int j = 0; j < gameData->currentMap.mapHeight; j++) {
|
||||
int tileIndex = gameData->currentMap.tileData[i][j];
|
||||
|
||||
// Calculate destination rectangle for the tile
|
||||
SDL_Rect destRect = {i * TILE_SIZE, j * TILE_SIZE, TILE_SIZE, TILE_SIZE};
|
||||
|
||||
// Render the tile texture
|
||||
SDL_RenderCopy(renderer, tileTexture, NULL, &destRect);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw units
|
||||
for (int i = 0; i < MAX_UNITS; i++) {
|
||||
// Check if the unit exists (you may have a different condition)
|
||||
if (gameData->units[i].unitID != -1) {
|
||||
// Calculate destination rectangle for the unit
|
||||
SDL_Rect destRect = {gameData->units[i].x, gameData->units[i].y, TILE_SIZE, TILE_SIZE};
|
||||
|
||||
// Render the unit texture
|
||||
SDL_RenderCopy(renderer, unitTexture, NULL, &destRect);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw buildings
|
||||
for (int i = 0; i < MAX_BUILDINGS; i++) {
|
||||
// Check if the building exists (you may have a different condition)
|
||||
if (gameData->buildings[i].buildingID != -1) {
|
||||
// Calculate destination rectangle for the building
|
||||
SDL_Rect destRect = {gameData->buildings[i].x, gameData->buildings[i].y, TILE_SIZE, TILE_SIZE};
|
||||
|
||||
// Render the building texture
|
||||
SDL_RenderCopy(renderer, buildingTexture, NULL, &destRect);
|
||||
}
|
||||
}
|
||||
|
||||
// Present the rendered frame
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
|
|
Loading…
Reference in a new issue