battleloom-engine/src/main.c

77 lines
2.1 KiB
C
Raw Normal View History

2024-02-15 13:53:51 +00:00
#include <SDL2/SDL.h>
2024-02-21 03:16:04 +00:00
#include <stdbool.h>
#include "data.h"
2024-02-21 07:30:49 +00:00
#include "draw.h"
#include "input.h"
#include "ui.h"
2024-03-14 10:56:44 +00:00
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_image.h>
2024-02-15 13:53:51 +00:00
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 600;
2024-03-14 10:56:44 +00:00
void updateGameState() {
}
2024-02-15 13:53:51 +00:00
int main(int argc, char* argv[]) {
SDL_Init(SDL_INIT_VIDEO);
2024-03-14 10:56:44 +00:00
TTF_Init();
2024-02-15 13:53:51 +00:00
SDL_Window* window = SDL_CreateWindow("RTS Game", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
// Main loop flag
2024-02-21 03:16:04 +00:00
bool quit = false;
SDL_Event event;
2024-03-14 10:56:44 +00:00
// Load textures for tiles, units, and buildings
SDL_Texture* unitTexture = IMG_LoadTexture(renderer, "path/to/unit_texture.png");
SDL_Texture* buildingTexture = IMG_LoadTexture(renderer, "path/to/building_texture.png");
SDL_Texture* tileTexture = IMG_LoadTexture(renderer, "path/to/tile_texture.png");
// Assuming you have a GameData instance named gameData
GameData gameData;
// Initialize gameData here...
2024-02-21 03:16:04 +00:00
while (!quit) {
// Event handling
while (SDL_PollEvent(&event) != 0) {
if (event.type == SDL_QUIT) {
quit = true;
}
// Handle other events such as key presses, mouse input, etc.
2024-02-15 13:53:51 +00:00
}
2024-02-21 03:16:04 +00:00
// Update game state
updateGameState(); // You need to define this function to update the game state
2024-02-15 15:28:36 +00:00
2024-02-21 03:16:04 +00:00
// Clear the screen
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
2024-02-15 15:28:36 +00:00
2024-02-21 03:16:04 +00:00
// Render game objects
2024-03-14 10:56:44 +00:00
drawGameData(renderer, &gameData, tileTexture, unitTexture, buildingTexture);
2024-02-15 15:28:36 +00:00
2024-02-21 03:16:04 +00:00
// Update the screen
SDL_RenderPresent(renderer);
2024-02-15 15:28:36 +00:00
2024-02-21 03:16:04 +00:00
// Cap the frame rate
SDL_Delay(16); // Cap to approximately 60 frames per second
}
2024-02-15 13:53:51 +00:00
2024-02-21 03:16:04 +00:00
// Clean up and exit
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
2024-02-15 13:53:51 +00:00
// Destroy window and renderer
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
// Quit SDL subsystems
SDL_Quit();
return 0;
2024-02-21 07:30:49 +00:00
}