add game structure
This commit is contained in:
parent
563504af1b
commit
73ca24c36b
3 changed files with 89 additions and 20 deletions
38
src/data.h
38
src/data.h
|
@ -1,28 +1,44 @@
|
||||||
|
<<<<<<< HEAD
|
||||||
#pragma once
|
#pragma once
|
||||||
|
=======
|
||||||
|
>>>>>>> 8e3d2ca (add game structure)
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define MAX_UNITS 100
|
#define MAX_UNITS 100
|
||||||
#define MAX_BUILDINGS 50
|
#define MAX_BUILDINGS 50
|
||||||
#define MAX_PLAYERS 2
|
#define MAX_PLAYERS 2
|
||||||
|
<<<<<<< HEAD
|
||||||
#define MAX_MISSIONS 10
|
#define MAX_MISSIONS 10
|
||||||
#define MAX_RESOURCES 50
|
#define MAX_RESOURCES 50
|
||||||
#define MAP_SIZE 100
|
#define MAP_SIZE 100
|
||||||
|
|
||||||
typedef struct Player {
|
typedef struct Player {
|
||||||
|
=======
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
>>>>>>> 8e3d2ca (add game structure)
|
||||||
int playerID;
|
int playerID;
|
||||||
char playerName[50];
|
char playerName[50];
|
||||||
int gold;
|
int gold;
|
||||||
int xp;
|
int xp;
|
||||||
} Player;
|
} Player;
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
typedef struct Unit {
|
typedef struct Unit {
|
||||||
|
=======
|
||||||
|
typedef struct {
|
||||||
|
>>>>>>> 8e3d2ca (add game structure)
|
||||||
int unitID;
|
int unitID;
|
||||||
int playerID;
|
int playerID;
|
||||||
int x, y; // Position
|
int x, y; // Position
|
||||||
int health;
|
int health;
|
||||||
} Unit;
|
} Unit;
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
typedef struct Building {
|
typedef struct Building {
|
||||||
|
=======
|
||||||
|
typedef struct {
|
||||||
|
>>>>>>> 8e3d2ca (add game structure)
|
||||||
int buildingID;
|
int buildingID;
|
||||||
int playerID;
|
int playerID;
|
||||||
int x, y; // Position
|
int x, y; // Position
|
||||||
|
@ -30,17 +46,29 @@ typedef struct Building {
|
||||||
int health;
|
int health;
|
||||||
} Building;
|
} Building;
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
typedef struct Map {
|
typedef struct Map {
|
||||||
|
=======
|
||||||
|
typedef struct {
|
||||||
|
>>>>>>> 8e3d2ca (add game structure)
|
||||||
int mapID;
|
int mapID;
|
||||||
char mapName[50];
|
char mapName[50];
|
||||||
int mapWidth;
|
int mapWidth;
|
||||||
int mapHeight;
|
int mapHeight;
|
||||||
|
<<<<<<< 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
|
||||||
|
=======
|
||||||
|
int tileData[MAX_MAP_WIDTH][MAX_MAP_HEIGHT];
|
||||||
|
>>>>>>> 8e3d2ca (add game structure)
|
||||||
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;
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
typedef struct Mission {
|
typedef struct Mission {
|
||||||
|
=======
|
||||||
|
typedef struct {
|
||||||
|
>>>>>>> 8e3d2ca (add game structure)
|
||||||
int missionID;
|
int missionID;
|
||||||
char missionName[50];
|
char missionName[50];
|
||||||
char missionDescription[100];
|
char missionDescription[100];
|
||||||
|
@ -55,12 +83,17 @@ typedef struct Mission {
|
||||||
bool hasSpecialConditions; // Flag indicating whether the mission has special conditions
|
bool hasSpecialConditions; // Flag indicating whether the mission has special conditions
|
||||||
} Mission;
|
} Mission;
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
typedef struct GameData {
|
typedef struct GameData {
|
||||||
|
=======
|
||||||
|
typedef struct {
|
||||||
|
>>>>>>> 8e3d2ca (add game structure)
|
||||||
Player players[MAX_PLAYERS];
|
Player players[MAX_PLAYERS];
|
||||||
Unit units[MAX_UNITS];
|
Unit units[MAX_UNITS];
|
||||||
Building buildings[MAX_BUILDINGS];
|
Building buildings[MAX_BUILDINGS];
|
||||||
Map currentMap;
|
Map currentMap;
|
||||||
Mission missions[MAX_MISSIONS];
|
Mission missions[MAX_MISSIONS];
|
||||||
|
<<<<<<< HEAD
|
||||||
int mapx, mapy;
|
int mapx, mapy;
|
||||||
} GameData;
|
} GameData;
|
||||||
|
|
||||||
|
@ -89,4 +122,7 @@ typedef struct {
|
||||||
GameData data;
|
GameData data;
|
||||||
BuildingData buildings[100];
|
BuildingData buildings[100];
|
||||||
UnitData units[100];
|
UnitData units[100];
|
||||||
} Game;
|
} Game;
|
||||||
|
=======
|
||||||
|
} GameData;
|
||||||
|
>>>>>>> 8e3d2ca (add game structure)
|
||||||
|
|
21
src/draw.h
21
src/draw.h
|
@ -1,3 +1,4 @@
|
||||||
|
<<<<<<< HEAD
|
||||||
#ifndef DRAW_H
|
#ifndef DRAW_H
|
||||||
#define DRAW_H
|
#define DRAW_H
|
||||||
|
|
||||||
|
@ -11,3 +12,23 @@
|
||||||
void drawGameData(SDL_Renderer *renderer, const GameData *gameData, SDL_Texture *tileTexture, SDL_Texture *unitTexture, SDL_Texture *buildingTexture);
|
void drawGameData(SDL_Renderer *renderer, const GameData *gameData, SDL_Texture *tileTexture, SDL_Texture *unitTexture, SDL_Texture *buildingTexture);
|
||||||
|
|
||||||
#endif /* DRAW_H */
|
#endif /* DRAW_H */
|
||||||
|
=======
|
||||||
|
#define MAP_SIZE 96
|
||||||
|
|
||||||
|
#define TILE_HEIGHT 30
|
||||||
|
#define TILE_WIDTH 60
|
||||||
|
|
||||||
|
#define MAP_RENDER_SIZE 24
|
||||||
|
|
||||||
|
#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;
|
||||||
|
|
||||||
|
>>>>>>> 8e3d2ca (add game structure)
|
||||||
|
|
50
src/main.c
50
src/main.c
|
@ -16,29 +16,41 @@ int main(int argc, char* argv[]) {
|
||||||
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
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
|
SDL_Event event;
|
||||||
|
|
||||||
// Event handler
|
while (!quit) {
|
||||||
SDL_Event e;
|
// Event handling
|
||||||
|
while (SDL_PollEvent(&event) != 0) {
|
||||||
// Main loop
|
if (event.type == SDL_QUIT) {
|
||||||
while (!quit) {
|
quit = true;
|
||||||
// Handle events on queue
|
|
||||||
while (SDL_PollEvent(&e) != 0) {
|
|
||||||
// User requests quit
|
|
||||||
if (e.type == SDL_QUIT) {
|
|
||||||
quit = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// Handle other events such as key presses, mouse input, etc.
|
||||||
// Clear screen
|
|
||||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
|
|
||||||
// Update screen
|
|
||||||
SDL_RenderPresent(renderer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update game state
|
||||||
|
updateGameState(); // You need to define this function to update the game state
|
||||||
|
|
||||||
|
// Clear the screen
|
||||||
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
|
// Render game objects
|
||||||
|
renderGame(renderer); // You need to define this function to render the game
|
||||||
|
|
||||||
|
// Update the screen
|
||||||
|
SDL_RenderPresent(renderer);
|
||||||
|
|
||||||
|
// Cap the frame rate
|
||||||
|
SDL_Delay(16); // Cap to approximately 60 frames per second
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up and exit
|
||||||
|
SDL_DestroyRenderer(renderer);
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
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