draw function added
This commit is contained in:
parent
6b2517604e
commit
808fd83e6e
2 changed files with 88 additions and 38 deletions
|
@ -1,7 +1,11 @@
|
||||||
<<<<<<< HEAD
|
<<<<<<< HEAD
|
||||||
|
<<<<<<< HEAD
|
||||||
#pragma once
|
#pragma once
|
||||||
=======
|
=======
|
||||||
>>>>>>> 8e3d2ca (add game structure)
|
>>>>>>> 8e3d2ca (add game structure)
|
||||||
|
=======
|
||||||
|
#pragma once
|
||||||
|
>>>>>>> 08f4a9f (draw function added)
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define MAX_UNITS 100
|
#define MAX_UNITS 100
|
||||||
|
@ -76,6 +80,7 @@ typedef struct Map {
|
||||||
int mapWidth;
|
int mapWidth;
|
||||||
int mapHeight;
|
int mapHeight;
|
||||||
<<<<<<< HEAD
|
<<<<<<< HEAD
|
||||||
|
<<<<<<< HEAD
|
||||||
<<<<<<< HEAD
|
<<<<<<< HEAD
|
||||||
int tileData[MAP_SIZE][MAP_SIZE]; // 2D array for map tile indices
|
int tileData[MAP_SIZE][MAP_SIZE]; // 2D array for map tile indices
|
||||||
=======
|
=======
|
||||||
|
@ -84,6 +89,9 @@ typedef struct Map {
|
||||||
=======
|
=======
|
||||||
int tileData[MAP_SIZE][MAP_SIZE]; // Assuming 2D array for resource coordinates
|
int tileData[MAP_SIZE][MAP_SIZE]; // Assuming 2D array for resource coordinates
|
||||||
>>>>>>> 0125c62 (update gamestructure)
|
>>>>>>> 0125c62 (update gamestructure)
|
||||||
|
=======
|
||||||
|
int tileData[MAP_SIZE][MAP_SIZE]; // 2D array for map tile indices
|
||||||
|
>>>>>>> 08f4a9f (draw function added)
|
||||||
int playerStartingPositions[MAX_PLAYERS][2]; // [x, y] coordinates for each player
|
int playerStartingPositions[MAX_PLAYERS][2]; // [x, y] coordinates for each player
|
||||||
int resourceLocations[MAX_RESOURCES][2]; // [x, y] coordinates for each resource
|
int resourceLocations[MAX_RESOURCES][2]; // [x, y] coordinates for each resource
|
||||||
} Map;
|
} Map;
|
||||||
|
|
56
src/main.c
56
src/main.c
|
@ -1,18 +1,61 @@
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include "data.h"
|
||||||
|
|
||||||
const int SCREEN_WIDTH = 800;
|
const int SCREEN_WIDTH = 800;
|
||||||
const int SCREEN_HEIGHT = 600;
|
const int SCREEN_HEIGHT = 600;
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
// Function to draw the game data onto the screen
|
||||||
// Initialize SDL
|
void drawGameData(SDL_Renderer *renderer, const GameData *gameData, SDL_Texture *tileTexture, SDL_Texture *unitTexture, SDL_Texture *buildingTexture) {
|
||||||
SDL_Init(SDL_INIT_VIDEO);
|
// Clear the screen
|
||||||
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
// Create a window
|
// 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);
|
||||||
SDL_Window* window = SDL_CreateWindow("RTS Game", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
SDL_Window* window = SDL_CreateWindow("RTS Game", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||||
SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
|
SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
|
||||||
|
|
||||||
// Create a renderer
|
|
||||||
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
|
|
||||||
// Main loop flag
|
// Main loop flag
|
||||||
|
@ -50,7 +93,6 @@ SDL_DestroyRenderer(renderer);
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
|
|
||||||
// Destroy window and renderer
|
// Destroy window and renderer
|
||||||
SDL_DestroyRenderer(renderer);
|
SDL_DestroyRenderer(renderer);
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
|
|
Loading…
Reference in a new issue