diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7934e1b --- /dev/null +++ b/Makefile @@ -0,0 +1,40 @@ +# Auhtor: Dusten Knull + +# Base commands, do not edit! +CC=gcc +RM=rm -rf +CP=cp + +# Add all C files with full relative paths here +SRC=src/*.c + +# Output EXE file, please only edit the name and no the extension +BINDIR=bin +BIN=$(BINDIR)/Game.exe + +# Change to 'x86_64' if compiling on a 64-bit OS +ARCH=i386 + +# Include dirs for both libs and headers +LIBINCLUDES=-L$(ARCH)/SDL2/lib +INCLUDES=-I$(ARCH)/SDL2/include + +# Library linker flags for SDL2 +LIBS=-lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf + +# Extra flags to specify how the CC command should compile our code (add -fPIC later) +FLAGS=-Wall -O2 -g3 + +.PHONY: all +all: clean build + +.PHONY: build +build: + $(CC) $(SRC) -o $(BIN) $(FLAGS) $(INCLUDES) $(LIBINCLUDES) $(LIBS) + $(CP) $(ARCH)/SDL2/bin/*.dll $(BINDIR) + +.PHONY: clean +clean: + $(RM) $(BIN) + $(RM) $(BINDIR)/*.dll + \ No newline at end of file diff --git a/README.md b/README.md index 0f7583c..a170a34 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,24 @@ Authors: Alex Kaariainen, Dusten Knull, and Ellis Archuleta _______________________________________________________________ +## About: + Darwin's Playground is an arcade-style RTS game, inspired by the mechanics of other games such as Sid Meier's Civilization, Plague Inc., Spore, and Settlers of Catan. In this game, you create and evolve a species over time to make them grow and survive in their environment. As the species' populatioon grows, it's population will spread throughout the surrounding regions as well. You must continue to balance the species' traits and evolutionary status so that it may survive and thrive as it spreads and becomes dominant over the land. +_______________________________________________________________ + +## Build instructions: + +For Windows: +- In a MinGW terminal, cd to the 'Windows' directory in the root folder of this project +- On a 32-bit OS, simply run 'make all' or just 'make' +- On a 64-bit OS, run 'make all_64' + +For Linux: +- In a unix terminal, cd to the 'Linux' directory +- Run the configure script provided via './configure.sh'. This script utilizes the 'apt-get' command, so if your system does not + support the apt package manager, you will have to manually install the packages specifed using your system's package manager +- After you have successfully installed the required packages, simply run 'make all' or just 'make' +_______________________________________________________________ diff --git a/bin/Game.exe b/bin/Game.exe new file mode 100644 index 0000000..5e0a82a Binary files /dev/null and b/bin/Game.exe differ diff --git a/bin/SDL2.dll b/bin/SDL2.dll new file mode 100644 index 0000000..c21f747 Binary files /dev/null and b/bin/SDL2.dll differ diff --git a/bin/SDL2_image.dll b/bin/SDL2_image.dll new file mode 100644 index 0000000..cadd2c5 Binary files /dev/null and b/bin/SDL2_image.dll differ diff --git a/bin/SDL2_ttf.dll b/bin/SDL2_ttf.dll new file mode 100644 index 0000000..2d8929e Binary files /dev/null and b/bin/SDL2_ttf.dll differ diff --git a/bin/libfreetype-6.dll b/bin/libfreetype-6.dll new file mode 100644 index 0000000..6b19b3c Binary files /dev/null and b/bin/libfreetype-6.dll differ diff --git a/bin/libjpeg-9.dll b/bin/libjpeg-9.dll new file mode 100644 index 0000000..d66bd4a Binary files /dev/null and b/bin/libjpeg-9.dll differ diff --git a/bin/libpng16-16.dll b/bin/libpng16-16.dll new file mode 100644 index 0000000..d59e67e Binary files /dev/null and b/bin/libpng16-16.dll differ diff --git a/bin/libtiff-5.dll b/bin/libtiff-5.dll new file mode 100644 index 0000000..015d069 Binary files /dev/null and b/bin/libtiff-5.dll differ diff --git a/bin/libwebp-7.dll b/bin/libwebp-7.dll new file mode 100644 index 0000000..31405fd Binary files /dev/null and b/bin/libwebp-7.dll differ diff --git a/bin/resources/Thumbs.db b/bin/resources/Thumbs.db new file mode 100644 index 0000000..84a6440 Binary files /dev/null and b/bin/resources/Thumbs.db differ diff --git a/bin/resources/bone_spikes.png b/bin/resources/bone_spikes.png new file mode 100644 index 0000000..3967eb7 Binary files /dev/null and b/bin/resources/bone_spikes.png differ diff --git a/bin/resources/dexbutton.png b/bin/resources/dexbutton.png new file mode 100644 index 0000000..20b1fa8 Binary files /dev/null and b/bin/resources/dexbutton.png differ diff --git a/bin/resources/dumb_muscle.png b/bin/resources/dumb_muscle.png new file mode 100644 index 0000000..80edac1 Binary files /dev/null and b/bin/resources/dumb_muscle.png differ diff --git a/bin/resources/exoskeleton.png b/bin/resources/exoskeleton.png new file mode 100644 index 0000000..d9542a8 Binary files /dev/null and b/bin/resources/exoskeleton.png differ diff --git a/bin/resources/extra_stomach.png b/bin/resources/extra_stomach.png new file mode 100644 index 0000000..abe09aa Binary files /dev/null and b/bin/resources/extra_stomach.png differ diff --git a/bin/resources/fertility.png b/bin/resources/fertility.png new file mode 100644 index 0000000..2553718 Binary files /dev/null and b/bin/resources/fertility.png differ diff --git a/bin/resources/greenarrow.png b/bin/resources/greenarrow.png new file mode 100644 index 0000000..55d5c4c Binary files /dev/null and b/bin/resources/greenarrow.png differ diff --git a/bin/resources/hard_shell.png b/bin/resources/hard_shell.png new file mode 100644 index 0000000..a8b4b12 Binary files /dev/null and b/bin/resources/hard_shell.png differ diff --git a/bin/resources/hills00.png b/bin/resources/hills00.png new file mode 100644 index 0000000..71de7ad Binary files /dev/null and b/bin/resources/hills00.png differ diff --git a/bin/resources/improved_foraging.png b/bin/resources/improved_foraging.png new file mode 100644 index 0000000..44226b1 Binary files /dev/null and b/bin/resources/improved_foraging.png differ diff --git a/bin/resources/increased_size.png b/bin/resources/increased_size.png new file mode 100644 index 0000000..87bac2e Binary files /dev/null and b/bin/resources/increased_size.png differ diff --git a/bin/resources/insomniac.png b/bin/resources/insomniac.png new file mode 100644 index 0000000..52f1a6e Binary files /dev/null and b/bin/resources/insomniac.png differ diff --git a/bin/resources/iron_grip.png b/bin/resources/iron_grip.png new file mode 100644 index 0000000..908e5ad Binary files /dev/null and b/bin/resources/iron_grip.png differ diff --git a/bin/resources/longevity.png b/bin/resources/longevity.png new file mode 100644 index 0000000..61b1d44 Binary files /dev/null and b/bin/resources/longevity.png differ diff --git a/bin/resources/natural_camoflauge.png b/bin/resources/natural_camoflauge.png new file mode 100644 index 0000000..47a6d6e Binary files /dev/null and b/bin/resources/natural_camoflauge.png differ diff --git a/bin/resources/night_vision.png b/bin/resources/night_vision.png new file mode 100644 index 0000000..1b8363f Binary files /dev/null and b/bin/resources/night_vision.png differ diff --git a/bin/resources/olfactory_acuity.png b/bin/resources/olfactory_acuity.png new file mode 100644 index 0000000..e8e1911 Binary files /dev/null and b/bin/resources/olfactory_acuity.png differ diff --git a/bin/resources/opposable_thumbs.png b/bin/resources/opposable_thumbs.png new file mode 100644 index 0000000..4c3cec8 Binary files /dev/null and b/bin/resources/opposable_thumbs.png differ diff --git a/bin/resources/powerful_hind_legs.png b/bin/resources/powerful_hind_legs.png new file mode 100644 index 0000000..b1c9e95 Binary files /dev/null and b/bin/resources/powerful_hind_legs.png differ diff --git a/bin/resources/prehensile_tail.png b/bin/resources/prehensile_tail.png new file mode 100644 index 0000000..5a58c30 Binary files /dev/null and b/bin/resources/prehensile_tail.png differ diff --git a/bin/resources/redarrow.png b/bin/resources/redarrow.png new file mode 100644 index 0000000..7e21f05 Binary files /dev/null and b/bin/resources/redarrow.png differ diff --git a/bin/resources/resbutton.png b/bin/resources/resbutton.png new file mode 100644 index 0000000..49b5d63 Binary files /dev/null and b/bin/resources/resbutton.png differ diff --git a/bin/resources/small_frame.png b/bin/resources/small_frame.png new file mode 100644 index 0000000..5f7fbeb Binary files /dev/null and b/bin/resources/small_frame.png differ diff --git a/bin/resources/strbutton.png b/bin/resources/strbutton.png new file mode 100644 index 0000000..13b7d11 Binary files /dev/null and b/bin/resources/strbutton.png differ diff --git a/bin/resources/strong_jaw.png b/bin/resources/strong_jaw.png new file mode 100644 index 0000000..96a352d Binary files /dev/null and b/bin/resources/strong_jaw.png differ diff --git a/bin/resources/tail.png b/bin/resources/tail.png new file mode 100644 index 0000000..904550d Binary files /dev/null and b/bin/resources/tail.png differ diff --git a/bin/resources/tenbutton.png b/bin/resources/tenbutton.png new file mode 100644 index 0000000..003ea9d Binary files /dev/null and b/bin/resources/tenbutton.png differ diff --git a/bin/resources/thick_fur.png b/bin/resources/thick_fur.png new file mode 100644 index 0000000..81e8948 Binary files /dev/null and b/bin/resources/thick_fur.png differ diff --git a/bin/resources/tough_claws.png b/bin/resources/tough_claws.png new file mode 100644 index 0000000..717fd04 Binary files /dev/null and b/bin/resources/tough_claws.png differ diff --git a/bin/resources/water_reserves.png b/bin/resources/water_reserves.png new file mode 100644 index 0000000..72c0c00 Binary files /dev/null and b/bin/resources/water_reserves.png differ diff --git a/bin/resources/wolf_pack_tactics.png b/bin/resources/wolf_pack_tactics.png new file mode 100644 index 0000000..a9e9916 Binary files /dev/null and b/bin/resources/wolf_pack_tactics.png differ diff --git a/bin/zlib1 (2).dll b/bin/zlib1 (2).dll new file mode 100644 index 0000000..a364c4c Binary files /dev/null and b/bin/zlib1 (2).dll differ diff --git a/bin/zlib1.dll b/bin/zlib1.dll new file mode 100644 index 0000000..1aa57ce Binary files /dev/null and b/bin/zlib1.dll differ diff --git a/src/Evolve.c b/src/Evolve.c index c00a9f2..ce319e8 100644 --- a/src/Evolve.c +++ b/src/Evolve.c @@ -1,25 +1,73 @@ #include "Evolve.h" -void Evolve_init(Evolve* evolve, SDL_Renderer* renderer, const char* texfile, int dstr, int ddex, int dten, int dres, int dhot, int dcold, int darid, int dmount, int dforest) + +//Evolution initilaztion function +void Evolve_init(Evolve* evolve, SDL_Renderer* renderer, const char* texfile, int dstr, int ddex, int dten, int dres, int dhot, int dcold, int darid, int dmount, int dforest, int dfertility, int dlifespan, int cost) { Square_create(&(evolve->square), renderer, texfile, 0, 0, EVOLVE_TILE_SIZE, EVOLVE_TILE_SIZE); + Textbox_init(&(evolve->textbox), "", EVOLVE_TILE_SIZE + 30, EVOLVE_TILE_SIZE / 2, EVOLVE_TILE_SIZE + 16, (EVOLVE_TILE_SIZE / 2) - 14); + evolve->textbox.boxcolor = EVOLVE_LABEL_COLOR; + evolve->d_str = dstr; evolve->d_dex = ddex; evolve->d_ten = dten; evolve->d_res = dres; evolve->d_hot = dhot; + evolve->d_cold = dcold; evolve->d_arid = darid; evolve->d_mount = dmount; evolve->d_forest = dforest; + evolve->d_fertility = dfertility; + evolve->d_lifespan = dlifespan; + + evolve->applied = 0; + evolve->evo_cost = cost; } -void Evolve_trait(Evolve* evolve, Species* species) + + +void Evolve_trait(Evolve* evolve, Species* species)//applies bonuses from traits to species { Species_growRelative(species, evolve->d_str, evolve->d_dex, evolve->d_ten, evolve->d_res); + species->d_hot += evolve->d_hot; species->d_cold += evolve->d_cold; species->d_arid += evolve->d_arid; species->d_mount += evolve->d_mount; species->d_forest += evolve->d_forest; + species->fertility += evolve->d_fertility; + species->lifespan+= evolve->d_lifespan; - + species->evo_points -= evolve->evo_cost; + + evolve->applied = 1; +} + +void Evolve_moveTo(Evolve* evolve, int x, int y)//moves physical evolution location +{ + evolve->square.bounds.x = x; + evolve->square.bounds.y = y; + + evolve->textbox.bounds.x = x - 15; + evolve->textbox.bounds.y = y - evolve->textbox.bounds.h; +} + +void Evolve_hideDescription(Evolve* evolve)//hides evolution popup +{ + evolve->textbox.visible = 0; +} + +void Evolve_setDescription(Evolve* evolve, const char* title)//sets evolution desc. +{ + Textbox_setText(&(evolve->textbox), (char*)title, 0); +} + +void Evolve_render(Evolve* evolve, SDL_Renderer* renderer, TTF_Font* font)//renders evolution text +{ + Textbox_render(&(evolve->textbox), renderer, font); + SDL_RenderCopy(renderer, evolve->square.texture, NULL, &(evolve->square.bounds)); +} + +void Evolve_destroy(Evolve* evolve)//removes evolve txt +{ + Square_destroy(&(evolve->square)); } diff --git a/src/Evolve.h b/src/Evolve.h index 7e73586..3aba03b 100644 --- a/src/Evolve.h +++ b/src/Evolve.h @@ -1,27 +1,56 @@ #ifndef GAME_EVOLVE_H_ #define GAME_EVOLVE_H_ -#define EVOLVE_TILE_SIZE 60 -#include "Square.h" -#include "Species.h" + +#include + +#if defined(__APPLE__) +#include +#else +#include +#endif + #include #include #include -typedef struct { + +#include "Square.h" +#include "Species.h" +#include "Textbox.h" + +#define EVOLVE_TILE_SIZE 75 +#define EVOLVE_LABEL_COLOR 0x73555555 + +typedef struct {//evolution structure + + Textbox textbox; Square square; - //attribute modifiers + + unsigned applied; + int d_str; int d_dex; int d_ten; int d_res; - - //independent modifiers + int d_cold; int d_hot; int d_arid; int d_mount; int d_forest; + int d_fertility; + int d_lifespan; + int evo_cost; +} Evolve; + +void Evolve_init(Evolve*, SDL_Renderer*, const char*, int, int, int, int, int, int, int, int, int, int, int, int); +void Evolve_trait(Evolve*, Species*); + +void Evolve_moveTo(Evolve*, int, int); + +void Evolve_hideDescription(Evolve*); +void Evolve_setDescription(Evolve*, const char*); + +void Evolve_render(Evolve*, SDL_Renderer*, TTF_Font*); +void Evolve_destroy(Evolve*); -}Evolve; -void Evolve_init(Evolve* evolve, SDL_Renderer* renderer, const char* texfile, int dstr, int ddex, int dten, int dres, int dhot, int dcold, int darid, int dmount, int dforest); -void Evolve_trait(Evolve *evolve, Species *species); -#endif /*GAME_EVOLVE_H_*/ \ No newline at end of file +#endif /*GAME_EVOLVE_H_*/ diff --git a/src/Game.c b/src/Game.c index 508429d..c138dfa 100644 --- a/src/Game.c +++ b/src/Game.c @@ -4,6 +4,7 @@ #include #include +#include "Menu.h" #include "Region.h" #include "Textbox.h" @@ -14,14 +15,21 @@ #define BOARD_SIZE 6 Region board[BOARD_SIZE * BOARD_SIZE]; + Species mainSpecies; -Textbox mainInfo; +Menu popupMenu; +Textbox mainInfo; Textbox regionInfo; +Textbox growthInfo; +Textbox decayInfo; -SDL_Texture* background; TTF_Font* fontArial; +SDL_Texture* background; +SDL_Texture* redarrow; +SDL_Texture* greenarrow; + SDL_Renderer* mainRenderer; SDL_Window* mainWindow; @@ -30,10 +38,12 @@ void renderAll(void); int initAll(void); void createBoard(Region _[], int); -void createBackground(void); +void loadGlobalTexture(SDL_Texture**, const char*); void cleanup(void); +unsigned gamePaused = 0; + int main(int argc, char* argv[]) { if(initAll() != 0) @@ -41,25 +51,34 @@ int main(int argc, char* argv[]) Species_init(&mainSpecies); - Textbox_init(&mainInfo, "Population: 0", WINDOW_WIDTH - 40, 60); - Textbox_setTextDims(&mainInfo, 150, 30); + Textbox_init(&mainInfo, "Population: 0", (WINDOW_WIDTH - 40) / 2, 46, 150, 32); + Textbox_init(&growthInfo, ": 0", (WINDOW_WIDTH - 40) / 4, 46, 30, 32); + Textbox_init(&decayInfo, ": 0", (WINDOW_WIDTH - 40) / 4, 46, 30, 32); + Textbox_displayAt(&mainInfo, 20, 5); + Textbox_displayAt(&growthInfo, 20 + ((WINDOW_WIDTH - 40) / 2), 5); + Textbox_displayAt(&decayInfo, 20 + ((WINDOW_WIDTH - 40) / 2) + ((WINDOW_WIDTH - 40) / 4), 5); - Textbox_init(®ionInfo, "Pop: 0", 90, 50); - Textbox_setTextDims(®ionInfo, 40, 16); + Textbox_init(®ionInfo, "Pop: 0", 90, 50, 40, 16); regionInfo.visible = 0; -#define NUM_REGIONS 5 + Menu_init(&popupMenu, mainRenderer, "resources/folder.png", 50, 150, WINDOW_WIDTH, WINDOW_HEIGHT); + +#define NUM_REGIONS 6 - Region baseRegions[NUM_REGIONS]; - Region_init(&(baseRegions[0]), mainRenderer, "resources/forestBroadleaf00.png", 65, 40, 50); - Region_init(&(baseRegions[1]), mainRenderer, "resources/mountain00.png", 20, 50, 90); - Region_init(&(baseRegions[2]), mainRenderer, "resources/plains00.png", 80, 70, 10); - Region_init(&(baseRegions[3]), mainRenderer, "resources/desertDunes00.png", 100, 10, 10); - Region_init(&(baseRegions[4]), mainRenderer, "resources/marsh00.png", 55, 75, 100); + Region baseRegions[NUM_REGIONS];//initializing regions stats + Region_init(&(baseRegions[0]), mainRenderer, "resources/forestBroadleaf00.png", 60, 40, 50); + Region_init(&(baseRegions[1]), mainRenderer, "resources/mountain00.png", 30, 40, 90); + Region_init(&(baseRegions[2]), mainRenderer, "resources/plains00.png", 65, 70, 10); + Region_init(&(baseRegions[3]), mainRenderer, "resources/desertDunes00.png", 85, 10, 35); + Region_init(&(baseRegions[4]), mainRenderer, "resources/marsh00.png", 55, 75, 75); + Region_init(&(baseRegions[5]), mainRenderer, "resources/hills00.png", 30, 80, 40); createBoard(baseRegions, NUM_REGIONS); - createBackground(); + + loadGlobalTexture(&background, "resources/background.png"); + loadGlobalTexture(&greenarrow, "resources/greenarrow.png"); + loadGlobalTexture(&redarrow, "resources/redarrow.png"); unsigned running; running = 1; @@ -80,7 +99,7 @@ int main(int argc, char* argv[]) return 0; } -int initAll() +int initAll()//creates game window { if(SDL_Init(SDL_INIT_VIDEO) != 0) { @@ -103,7 +122,6 @@ int initAll() return -1; } - mainWindow = SDL_CreateWindow(WINDOW_TITLE, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOW_WIDTH, WINDOW_HEIGHT, 0); @@ -126,7 +144,7 @@ int initAll() } SDL_SetRenderDrawBlendMode(mainRenderer, SDL_BLENDMODE_BLEND); - fontArial = TTF_OpenFont("resources/arial.ttf", 240); + fontArial = TTF_OpenFont("resources/arial.ttf", 270); if(fontArial == NULL) { @@ -142,7 +160,10 @@ void cleanup() { SDL_DestroyRenderer(mainRenderer); SDL_DestroyWindow(mainWindow); + SDL_DestroyTexture(background); + SDL_DestroyTexture(greenarrow); + SDL_DestroyTexture(redarrow); TTF_CloseFont(fontArial); @@ -151,17 +172,15 @@ void cleanup() SDL_Quit(); } -void createBackground() +void loadGlobalTexture(SDL_Texture** texture, const char* filename) { - SDL_Surface* image = IMG_Load("resources/background.png"); + SDL_Surface* image = IMG_Load(filename); if(image == NULL) { - fprintf(stderr, "Error: Failed to load image 'resources/background.png'!\n"); + fprintf(stderr, "Error: Failed to load image '%s'!\n", filename); exit(1); } - background = SDL_CreateTextureFromSurface(mainRenderer, image); - - SDL_SetTextureAlphaMod(background, 170); + *texture = SDL_CreateTextureFromSurface(mainRenderer, image); SDL_FreeSurface(image); } @@ -207,10 +226,17 @@ static void consolidateRegion(int index) if(adjacents[i] < 0 || adjacents[i] >= BOARD_SIZE * BOARD_SIZE) continue; + int dx, dy; + dx = (board[index].square.bounds.x - board[adjacents[i]].square.bounds.x) / REGION_TILE_SIZE; + dy = (board[index].square.bounds.y - board[adjacents[i]].square.bounds.y) / REGION_TILE_SIZE; + + if(dx < -1 || dy < -1 || dx > 1 || dy > 1) + continue; + if(board[adjacents[i]].population == 0) { long newPop; - newPop = (long)((double)board[index].population * 0.70); + newPop = (long)((double)board[index].population * 0.30); board[adjacents[i]].population = board[index].population - newPop; board[index].population = newPop; @@ -226,6 +252,8 @@ void updateAll(unsigned* running) static unsigned frames = 0; static int hoverIndex = -1; + unsigned state; + SDL_Event e; while(SDL_PollEvent(&e)) { @@ -234,12 +262,18 @@ void updateAll(unsigned* running) else if(e.type == SDL_MOUSEBUTTONDOWN) { - if(!(gameStarted && e.button.button == SDL_BUTTON_LEFT)) + if(e.button.button == SDL_BUTTON_LEFT) + { + state = Menu_checkMouse(&popupMenu, &mainSpecies, e.motion.x, e.motion.y, 1); + if((state != MENU_CLOSED) && popupMenu.animating) + gamePaused = 1; + } + + if(!gameStarted && !gamePaused) { int i; for(i = 0; i < BOARD_SIZE * BOARD_SIZE; i ++) { - unsigned state; state = Region_update(&(board[i]), e.motion.x, e.motion.y, e.button.button == SDL_BUTTON_LEFT); if(state == CLICK_ON_REGION) @@ -249,27 +283,36 @@ void updateAll(unsigned* running) } else if(e.type == SDL_MOUSEMOTION || e.type == SDL_MOUSEBUTTONUP) { - int newHoverIndex; - newHoverIndex = -1; + if(e.type == SDL_MOUSEBUTTONUP) + Menu_checkMouse(&popupMenu, &mainSpecies, e.motion.x, e.motion.y, 0); - int i; - for(i = 0; i < BOARD_SIZE * BOARD_SIZE; i ++) + if(!gamePaused) { - unsigned state; - state = Region_update(&(board[i]), e.motion.x, e.motion.y, 0); + int newHoverIndex; + newHoverIndex = -1; - if(state == HOVER_ON_REGION) + int i; + for(i = 0; i < BOARD_SIZE * BOARD_SIZE; i ++) { - if(hoverIndex != i) - Textbox_setTextFromLong(®ionInfo, "Pop: ", board[i].population); + state = Region_update(&(board[i]), e.motion.x, e.motion.y, 0); + + if(state == HOVER_ON_REGION) + { + if(hoverIndex != i) + Textbox_setTextFromLong(®ionInfo, "Pop: ", board[i].population); - newHoverIndex = i; + newHoverIndex = i; + } } + hoverIndex = newHoverIndex; } - hoverIndex = newHoverIndex; } } + state = Menu_update(&popupMenu); + if(state == MENU_CLOSED) + gamePaused = 0; + int i; for(i = 0; i < BOARD_SIZE * BOARD_SIZE; i ++) { @@ -278,41 +321,55 @@ void updateAll(unsigned* running) Region_update(&(board[i]), 0, 0, 0); } + regionInfo.visible = 0; - if(hoverIndex != -1) + if(!gamePaused) { - Textbox_displayAt(®ionInfo, board[hoverIndex].square.bounds.x, board[hoverIndex].square.bounds.y - regionInfo.bounds.h); - regionInfo.visible = 1; - } - else regionInfo.visible = 0; + if(hoverIndex != -1) + { + int xoffset; + xoffset = (regionInfo.bounds.w - board[hoverIndex].square.bounds.w) / 2; + Textbox_displayAt(®ionInfo, board[hoverIndex].square.bounds.x - xoffset, board[hoverIndex].square.bounds.y - regionInfo.bounds.h); + regionInfo.visible = 1; + } - unsigned long netPopulation; - netPopulation = 0L; + unsigned long netPopulation, netGrowth, netDecay; + netGrowth = netDecay = 0L; + netPopulation = 0L; - for(i = 0; i < BOARD_SIZE * BOARD_SIZE; i ++) - { - if(board[i].population >= (board[i].maxPopulation / 2)) - consolidateRegion(i); + for(i = 0; i < BOARD_SIZE * BOARD_SIZE; i ++) + { + if(board[i].population >= (board[i].maxPopulation / 2)) + consolidateRegion(i); - Region_growPop(&(board[i]), &mainSpecies); + Region_growPop(&(board[i]), &mainSpecies); - netPopulation += board[i].population; - } + if(board[i].growth == 1) + netGrowth ++; + else if(board[i].growth == -1) + netDecay ++; - if(frames == 60) - { - if(hoverIndex != -1) - Textbox_setTextFromLong(®ionInfo, "Pop: ", board[hoverIndex].population); + netPopulation += board[i].population; + } - Textbox_setTextFromLong(&mainInfo, "Population: ", netPopulation); - frames = 0; + if(frames == 60) + { + if(hoverIndex != -1) + Textbox_setTextFromLong(®ionInfo, "Pop: ", board[hoverIndex].population); + + Textbox_setTextFromLong(&mainInfo, "Population: ", netPopulation); + Textbox_setTextFromLong(&growthInfo, ": ", netGrowth); + Textbox_setTextFromLong(&decayInfo, ": ", netDecay); + Textbox_setTextFromLong(&(popupMenu.points), "", mainSpecies.evo_points); + + frames = 0; + } + else frames ++; } - else frames ++; } void renderAll() { - SDL_SetRenderDrawColor(mainRenderer, 0xff, 0xff, 0xff, 0xff); SDL_RenderClear(mainRenderer); SDL_Rect dest = {.x=0, .y=0, .w=WINDOW_WIDTH, .h=WINDOW_HEIGHT}; @@ -320,15 +377,24 @@ void renderAll() int i; for(i = 0; i < BOARD_SIZE * BOARD_SIZE; i ++) - { Region_render(&(board[i]), mainRenderer); - if(board[i].population) - printf("Tile %d: %ld\n", i, board[i].population); - } - Textbox_render(&mainInfo, mainRenderer, fontArial); + Textbox_render(&growthInfo, mainRenderer, fontArial); + Textbox_render(&decayInfo, mainRenderer, fontArial); + + dest.x = WINDOW_WIDTH / 2 + 35; + dest.y = 10; + dest.w = 28; + dest.h = 35; + SDL_RenderCopy(mainRenderer, greenarrow, NULL, &dest); + + dest.x = WINDOW_WIDTH / 2 + 225; + SDL_RenderCopy(mainRenderer, redarrow, NULL, &dest); + Textbox_render(®ionInfo, mainRenderer, fontArial); + Menu_render(&popupMenu, mainRenderer, fontArial); + SDL_RenderPresent(mainRenderer); } diff --git a/src/Menu.c b/src/Menu.c index 30b7fbd..4e8d24d 100644 --- a/src/Menu.c +++ b/src/Menu.c @@ -6,7 +6,9 @@ #define MENU_ANIMATE_DX 20 -void Menu_init(Menu* menu, SDL_Renderer* renderer, const char* texfile, int cw, int ch, int iw, int ih) +static const char* titles[4] = {"Strength", "Dexterity", "Tenacity", "Resourcefulness"}; + +void Menu_init(Menu* menu, SDL_Renderer* renderer, const char* texfile, int cw, int ch, int iw, int ih)//initialize evolve menu { SDL_Surface* image = IMG_Load(texfile); if(image == NULL) @@ -27,10 +29,102 @@ void Menu_init(Menu* menu, SDL_Renderer* renderer, const char* texfile, int cw, menu->bounds.x = iw - cw; menu->bounds.y = 0; + Evolve_init(&(menu->buttons[0][0]), renderer, "resources/strbutton.png", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + Evolve_init(&(menu->buttons[1][0]), renderer, "resources/dexbutton.png", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + Evolve_init(&(menu->buttons[2][0]), renderer, "resources/tenbutton.png", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + Evolve_init(&(menu->buttons[3][0]), renderer, "resources/resbutton.png", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); +//initialized values of evolve traits, in order of base attributes then regional modifiers/misc bonuses + Evolve_init(&(menu->buttons[0][1]), renderer, "resources/increased_size.png", 15, -5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10); + Evolve_init(&(menu->buttons[0][2]), renderer, "resources/tough_claws.png", 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10); + Evolve_init(&(menu->buttons[0][3]), renderer, "resources/iron_grip.png", 5, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 10); + Evolve_init(&(menu->buttons[0][4]), renderer, "resources/dumb_muscle.png", 25, -10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20); + Evolve_init(&(menu->buttons[0][5]), renderer, "resources/bone_spikes.png", 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20); + Evolve_init(&(menu->buttons[0][6]), renderer, "resources/strong_jaw.png", 10, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 20); + + Evolve_init(&(menu->buttons[1][1]), renderer, "resources/small_frame.png", -5, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10); + Evolve_init(&(menu->buttons[1][2]), renderer, "resources/tail.png", 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10); + Evolve_init(&(menu->buttons[1][3]), renderer, "resources/natural_camoflauge.png", 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 10); + Evolve_init(&(menu->buttons[1][4]), renderer, "resources/prehensile_tail.png", 0, 10, 0, 0, 0, 0, 0, 0, 5, 0, 0, 20); + Evolve_init(&(menu->buttons[1][5]), renderer, "resources/powerful_hind_legs.png", 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20); + Evolve_init(&(menu->buttons[1][6]), renderer, "resources/opposable_thumbs.png", 0, 10, 0, 5, 0, 0, 0, 0, 0, 0, 0, 20); + + Evolve_init(&(menu->buttons[2][1]), renderer, "resources/thick_fur.png", 0, 0, 10, 0, -5, 5, 0, 0, 0, 0, 0, 10); + Evolve_init(&(menu->buttons[2][2]), renderer, "resources/hard_shell.png", 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 10); + Evolve_init(&(menu->buttons[2][3]), renderer, "resources/water_reserves.png", 0, 0, 5, 0, 0, 0, 5, 0, 0, 0, 0, 10); + Evolve_init(&(menu->buttons[2][4]), renderer, "resources/fertility.png", 0, 0, 10, 0, 0, 0, 0, 0, 0, 2, 0, 20); + Evolve_init(&(menu->buttons[2][5]), renderer, "resources/exoskeleton.png", 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 20); + Evolve_init(&(menu->buttons[2][6]), renderer, "resources/longevity.png", 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 10, 20); + + Evolve_init(&(menu->buttons[3][1]), renderer, "resources/wolf_pack_tactics.png", 5, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 10); + Evolve_init(&(menu->buttons[3][2]), renderer, "resources/night_vision.png", 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 10); + Evolve_init(&(menu->buttons[3][3]), renderer, "resources/improved_foraging.png", 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 10); + Evolve_init(&(menu->buttons[3][4]), renderer, "resources/insomniac.png", -10, 0, 0, 25, 0, 0, 0, 0, 0, 0, 0, 20); + Evolve_init(&(menu->buttons[3][5]), renderer, "resources/olfactory_acuity.png", 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 20); + Evolve_init(&(menu->buttons[3][6]), renderer, "resources/extra_stomach.png", 0, -10, 0, 25, 0, 0, 0, 0, 0, 0, 0, 20); + + Evolve_setDescription(&(menu->buttons[0][1]), "Increased Size"); + Evolve_setDescription(&(menu->buttons[0][2]), " Tough Claws "); + Evolve_setDescription(&(menu->buttons[0][3]), " Iron Grip "); + Evolve_setDescription(&(menu->buttons[0][4]), " Dumb Muscle "); + Evolve_setDescription(&(menu->buttons[0][5]), " Bone Spikes "); + Evolve_setDescription(&(menu->buttons[0][6]), " Strong Jaw "); + + Evolve_setDescription(&(menu->buttons[1][1]), " Small Frame "); + Evolve_setDescription(&(menu->buttons[1][2]), " Tail "); + Evolve_setDescription(&(menu->buttons[1][3]), " Camouflage "); + Evolve_setDescription(&(menu->buttons[1][4]), " Prehensile Tail "); + Evolve_setDescription(&(menu->buttons[1][5]), "Powerful Hind Legs"); + Evolve_setDescription(&(menu->buttons[1][6]), "Opposable Thumbs"); + + Evolve_setDescription(&(menu->buttons[2][1]), " Thick Fur "); + Evolve_setDescription(&(menu->buttons[2][2]), " Hard Shell "); + Evolve_setDescription(&(menu->buttons[2][3]), "Water Reserves"); + Evolve_setDescription(&(menu->buttons[2][4]), " Fertility "); + Evolve_setDescription(&(menu->buttons[2][5]), " Exoskeleton "); + Evolve_setDescription(&(menu->buttons[2][6]), " Longevity "); + + Evolve_setDescription(&(menu->buttons[3][1]), "Pack Mentality"); + Evolve_setDescription(&(menu->buttons[3][2]), " Night Vision "); + Evolve_setDescription(&(menu->buttons[3][3]), " Foraging "); + Evolve_setDescription(&(menu->buttons[3][4]), " Nocturnal "); + Evolve_setDescription(&(menu->buttons[3][5]), "Olfactory Acuity"); + Evolve_setDescription(&(menu->buttons[3][6]), "Extra Stomach"); + + Evolve_moveTo(&(menu->buttons[0][0]), 150, 75); + Evolve_moveTo(&(menu->buttons[1][0]), 150, 200); + Evolve_moveTo(&(menu->buttons[2][0]), 150, 325); + Evolve_moveTo(&(menu->buttons[3][0]), 150, 450); + + int i; + for(i = 0; i < NUM_EVOLVE_TREES; i ++) + { + Evolve_hideDescription(&(menu->buttons[i][0])); + + Evolve_moveTo(&(menu->buttons[i][1]), 350, 137); + Evolve_moveTo(&(menu->buttons[i][2]), 350, 262); + Evolve_moveTo(&(menu->buttons[i][3]), 350, 387); + Evolve_moveTo(&(menu->buttons[i][4]), 525, 137); + Evolve_moveTo(&(menu->buttons[i][5]), 525, 262); + Evolve_moveTo(&(menu->buttons[i][6]), 525, 387); + } + + Textbox_init(&(menu->title), "Strength", 200, 44, 90, 30); + Textbox_displayAt(&(menu->title), 375, 20); + + Textbox_init(&(menu->points), "0", 150, 40, 30, 30); + Textbox_displayAt(&(menu->points), 710, 280); + + menu->title.boxcolor = EVOLVE_LABEL_COLOR; + menu->title.visible = 0; + + menu->points.boxcolor = 0x0; + + menu->state = MENU_CLOSED; menu->animating = 0; + menu->selected = -1; } -unsigned Menu_checkMouse(Menu* menu, int mx, int my, unsigned clicked) +unsigned Menu_checkMouse(Menu* menu, Species* species, int mx, int my, unsigned clicked)//checks where mouse is/if it is clicking { static unsigned canClick = 1; @@ -51,6 +145,34 @@ unsigned Menu_checkMouse(Menu* menu, int mx, int my, unsigned clicked) else if(!clicked) canClick = 1; + if(menu->state == MENU_OPEN) + { + int i; + for(i = 0; i < NUM_EVOLVE_TREES; i ++) + { + if(Square_intersectsPoint(&(menu->buttons[i][0].square), mx, my) && clicked) + { + Textbox_setText(&(menu->title), (char*)(titles[i]), 1); + menu->title.visible = 1; + menu->selected = i; + + break; + } + } + + if(menu->selected != -1) + { + for(i = 1; i <= NUM_EVOLVE_SUBS; i ++) + { + if(Square_intersectsPoint(&(menu->buttons[menu->selected][i].square), mx, my) && clicked) + { + if(!(menu->buttons[menu->selected][i].applied) && species->evo_points >= (menu->buttons[menu->selected][i]).evo_cost)//checks if you have enough points to evolve + Evolve_trait(&(menu->buttons[menu->selected][i]), species); + } + } + } + } + return 0; } @@ -59,34 +181,84 @@ unsigned Menu_update(Menu* menu) if(menu->animating && menu->bounds.x > 0) { menu->bounds.x -= MENU_ANIMATE_DX; + menu->points.bounds.x -= MENU_ANIMATE_DX; if(menu->bounds.x < 0) menu->bounds.x = 0; + + if(menu->points.bounds.x < (menu->points.bounds.w / 2)) + menu->points.bounds.x = (menu->points.bounds.w / 2); } else if(!(menu->animating) && menu->bounds.x < (menu->bounds.w - menu->clickable.w)) { menu->bounds.x += MENU_ANIMATE_DX; + menu->points.bounds.x += MENU_ANIMATE_DX; if(menu->bounds.x > (menu->bounds.w - menu->clickable.w)) menu->bounds.x = (menu->bounds.w - menu->clickable.w); + + if(menu->points.bounds.x > (menu->bounds.w - menu->clickable.w) + (menu->points.bounds.w / 2)) + menu->points.bounds.x = (menu->bounds.w - menu->clickable.w) + (menu->points.bounds.w / 2); } menu->clickable.x = menu->bounds.x; if(menu->bounds.x <= 0) - return MENU_CLOSED; + return (menu->state = MENU_OPEN); else if(menu->bounds.x >= (menu->bounds.w - menu->clickable.w)) - return MENU_OPEN; + { + menu->selected = -1; + menu->title.visible = 0; + + return (menu->state = MENU_CLOSED); + } - else return MENU_ANIMATING; + else return (menu->state = MENU_ANIMATING); } -void Menu_render(Menu* menu, SDL_Renderer* renderer) +void Menu_render(Menu* menu, SDL_Renderer* renderer, TTF_Font* font) { SDL_RenderCopy(renderer, menu->texture, NULL, &(menu->bounds)); + + if(menu->state == MENU_OPEN) + { + unsigned char alpha; + + int i; + for(i = 0; i < NUM_EVOLVE_TREES; i ++) + { + alpha = (menu->selected == i) ? 0x83 : 0x44; + + SDL_SetRenderDrawColor(renderer, 0x55, 0x55, 0x55, alpha); + SDL_RenderFillRect(renderer, &(menu->buttons[i][0].square.bounds)); + + Evolve_render(&(menu->buttons[i][0]), renderer, font); + } + + if(menu->selected != -1) + { + for(i = 1; i <= NUM_EVOLVE_SUBS; i ++) + { + Evolve_render(&(menu->buttons[menu->selected][i]), renderer, font); + + if(menu->buttons[menu->selected][i].applied) + { + SDL_SetRenderDrawColor(renderer, 0x55, 0x55, 0x55, 0xAA); + SDL_RenderFillRect(renderer, &(menu->buttons[menu->selected][i].square.bounds)); + } + } + } + Textbox_render(&(menu->title), renderer, font); + } + //Textbox_renderRotatedText(&(menu->points), renderer, font, 90.0); } void Menu_destroy(Menu* menu) { + int i, j; + for(i = 0; i < NUM_EVOLVE_TREES; i ++) + for(j = 0; j <= NUM_EVOLVE_SUBS; j ++) + Evolve_destroy(&(menu->buttons[i][j])); + SDL_DestroyTexture(menu->texture); } diff --git a/src/Menu.h b/src/Menu.h index 2f90e80..fe210a1 100644 --- a/src/Menu.h +++ b/src/Menu.h @@ -1,32 +1,47 @@ #ifndef GAME_MENU_H__ #define GAME_MENU_H__ +#include "Evolve.h" +#include "Species.h" + #if defined(__APPLE__) #include +#include #else #include +#include #endif #include -#define MENU_OPEN 0 -#define MENU_CLOSED 1 +#define MENU_OPEN 1 +#define MENU_CLOSED 0 #define MENU_ANIMATING 2 +#define NUM_EVOLVE_TREES 4 +#define NUM_EVOLVE_SUBS 6 + typedef struct { SDL_Texture* texture; SDL_Rect clickable; SDL_Rect bounds; + Evolve buttons[NUM_EVOLVE_TREES][NUM_EVOLVE_SUBS + 1]; + + Textbox points; + Textbox title; + unsigned animating; + unsigned selected; + unsigned state; } Menu; void Menu_init(Menu*, SDL_Renderer*, const char*, int, int, int, int); -unsigned Menu_checkMouse(Menu*, int, int, unsigned); +unsigned Menu_checkMouse(Menu*, Species*, int, int, unsigned); unsigned Menu_update(Menu*); -void Menu_render(Menu*, SDL_Renderer*); +void Menu_render(Menu*, SDL_Renderer*, TTF_Font*); void Menu_destroy(Menu*); #endif /* GAME_MENU_H__ */ diff --git a/src/Region.c b/src/Region.c index d4787b4..0a3f6ef 100644 --- a/src/Region.c +++ b/src/Region.c @@ -1,5 +1,4 @@ #include "Region.h" -#include "Species.h" #include #include @@ -7,31 +6,33 @@ #include #define TAU (double)(12 * REGION_MAX_STAT_LEVEL * REGION_MAX_STAT_LEVEL * REGION_MAX_STAT_LEVEL) -#define E 2.718281828459 -void Region_init(Region* region, SDL_Renderer* renderer, const char* texfile, int baseTemp, int baseTerr, int baseHumid) +void Region_init(Region* region, SDL_Renderer* renderer, const char* texfile, int baseTemp, int baseTerr, int baseHumid)//Initalizes a region { srand(time(NULL)); - Square_create(&(region->square), renderer, texfile, 0, 0, REGION_TILE_SIZE, REGION_TILE_SIZE); + Square_create(&(region->square), renderer, texfile, 0, 0, REGION_TILE_SIZE, REGION_TILE_SIZE); + region->maxPopulation = 10000L; - region->randDanger = rand()%1; region->population = 0L; + + region->randDanger = rand()%1; region->temperature = baseTemp; region->humidity = baseHumid; region->terrain = baseTerr; + region->growth = 0; } -void Region_displayAt(Region* region, int x, int y) +void Region_displayAt(Region* region, int x, int y)//determines where region is located on screen { (region->square).bounds.x = x; (region->square).bounds.y = y; } -unsigned Region_update(Region* region, int mx, int my, int clicked) +unsigned Region_update(Region* region, int mx, int my, int clicked)//updates region when clicked upon { int c; - + if(Square_intersectsPoint(&(region->square), mx, my)) { if(clicked) @@ -46,56 +47,65 @@ unsigned Region_update(Region* region, int mx, int my, int clicked) } else { - c = (int)(((double)(region->maxPopulation - region->population) / (double)(region->maxPopulation)) * 0x000000bb); (region->square).color = (c << 16) | c | 0x0000bb00; - return HOVER_ON_REGION; } } else { - - c = (int)(((double)(region->maxPopulation - region->population) / (double)(region->maxPopulation)) * 255.0); (region->square).color = (c << 16) | c | 0x0000ff00; return 0; } } -void Region_growPop(Region* region, Species* species) +void Region_growPop(Region* region, Species* species)//function to grow population in a specific region { - double resourcei,dangeri,safetyi, rateG, rateD, grow, decay, seconds; + double resourcei,dangeri,safetyi, rateG, rateD, grow/*, rate, decay, secondsG, secondsD*/; static long time = 0; - if(region->population > 0) - { + static int counter=0; - seconds = time/60; - resourcei = ((region->temperature)+(region->terrain)+(species->resourcefulness)+(region->humidity))/(double)400; - dangeri = ((region->terrain)/(double)100) + (abs(region->temperature - 50)/(double)50) + region->randDanger; - safetyi = ((species->strength)+(species->dexterity)+(species->tenacity))/(double)300; + if(region->population > 0)//if region has a positive population. It will exbit the below growth/decay behavour + { time ++; + resourcei = (0.5*(region->temperature)+2*(species->resourcefulness)+0.5*(region->humidity))/(double)200;//resource index + dangeri = ((region->terrain)/(double)100) + (abs(region->temperature - 50)/(double)50) + region->randDanger - species->lifespan/30;//danger index + safetyi = 12*(2*(species->strength)+2*(species->dexterity)+2*(species->tenacity))/(double)300;//safety index if(region->population >= region->maxPopulation || region->population < 0L) region->population = region->maxPopulation; else { - rateG = resourcei * dangeri *safetyi; - rateD = (region->maxPopulation - region->population)/(region->maxPopulation) + region->randDanger + (region->terrain)/100.0; - grow = 10 * pow(E,((rateG*seconds)/6)); - decay = -2 * pow(E,((rateD*seconds)/6)); - if((double)region->population+grow+decay<0){region->population=0;} - else{region->population += grow+decay;} + rateG = (region->maxPopulation - region->population)/(double)region->maxPopulation*(resourcei+safetyi)/2+(rand()%3);//growth rate + rateD = (2*dangeri-species->lifespan/30)*1.85*region->population/region->maxPopulation+(rand()%3);//decay rate + grow = (rateG-rateD);//change in population + if(counter==200){//loop to add evolution points + + species->evo_points += 1+rand()%3; + counter-=200; + } + if(grow>0){ + region->growth = 1; + } + else if(grow<0){ + region->growth = -1; + } + else{region->growth = 0;} + //region->population *= 0.985; + if((double)region->population+grow<0){region->population=0;} + else{region->population += grow;} } - } + counter++; +} } -void Region_render(Region* region, SDL_Renderer* renderer) +void Region_render(Region* region, SDL_Renderer* renderer)//SDL2 renders region { Square_render(&(region->square), renderer); } -void Region_destroy(Region* region) +void Region_destroy(Region* region)//region is now dead { region->population = 0L; Square_destroy(&(region->square)); diff --git a/src/Region.h b/src/Region.h index d00531e..da73dbf 100644 --- a/src/Region.h +++ b/src/Region.h @@ -13,14 +13,14 @@ typedef struct { Square square; - long maxPopulation; - unsigned long population; + long population; int temperature; int terrain; int humidity; int randDanger; + int growth; } Region; void Region_init(Region*, SDL_Renderer*, const char*, int, int, int); diff --git a/src/Species.c b/src/Species.c index cc34816..93843d7 100644 --- a/src/Species.c +++ b/src/Species.c @@ -1,20 +1,23 @@ #include "Species.h" -#define DEFAULT_STATS 25 -#define DEFAULT_LIFESPAN (int)((((float)DEFAULT_STATS) / 100.0f) * (((float)DEFAULT_STATS) / 100.0f) * 80.0f) - -#include -#include +#define DEFAULT_STATS 50 +#define DEFAULT_LIFESPAN 10 void Species_init(Species* species) { - srand(time(NULL)); species->strength = DEFAULT_STATS; species->dexterity = DEFAULT_STATS; species->resourcefulness = DEFAULT_STATS; species->tenacity = DEFAULT_STATS; species->lifespan = DEFAULT_LIFESPAN; species->fertility = 1; + + species->d_hot = 0; + species->d_cold = 0; + species->d_arid = 0; + species->d_mount = 0; + species->d_forest = 0; + species->evo_points = 0; } void Species_growRelative(Species* species, int d_str, int d_dex, int d_sus, int d_res) @@ -26,7 +29,7 @@ void Species_growRelative(Species* species, int d_str, int d_dex, int d_sus, int float _lifespan; _lifespan = (float)(species->strength) / 100.0f; - _lifespan *= ((float)(species->tenacity) / 100.0f) * 80.0f; + _lifespan *= ((float)(species->tenacity) / 100.0f) * 240.0f; species->lifespan = (unsigned)_lifespan; } diff --git a/src/Species.h b/src/Species.h index c8a91a0..7f46411 100644 --- a/src/Species.h +++ b/src/Species.h @@ -7,8 +7,15 @@ typedef struct { unsigned dexterity; unsigned resourcefulness; unsigned tenacity; - unsigned lifespan; // generations + unsigned lifespan; unsigned fertility; + + int d_hot; + int d_cold; + int d_arid; + int d_mount; + int d_forest; + int evo_points; } Species; void Species_init(Species*); diff --git a/src/Square.c b/src/Square.c index b60b96d..2b93ecb 100644 --- a/src/Square.c +++ b/src/Square.c @@ -3,6 +3,12 @@ #include #include +/* +Square objects dictate most of the things that are rendered to the screen that are: +a) clickable +b) have a single, solid image +c) have static rectangular boundaries +*/ void Square_create(Square* square, SDL_Renderer* renderer, const char* texfile, int x, int y, int w, int h) { SDL_Surface* image = IMG_Load(texfile); @@ -30,6 +36,9 @@ void Square_create(Square* square, SDL_Renderer* renderer, const char* texfile, square->tw = w; } +/* +Renders the image of a square object to the screen, based on it's displayable size +*/ void Square_render(Square* square, SDL_Renderer* renderer) { unsigned char r, g, b; @@ -40,17 +49,22 @@ void Square_render(Square* square, SDL_Renderer* renderer) SDL_Rect dest = {.x=(square->bounds).x, .y=(square->bounds).y - (square->th - (square->bounds).h), .w=square->tw, .h=square->th}; SDL_SetTextureColorMod(square->texture, r, g, b); + //SDL_RenderCopyEx(renderer, square->texture, NULL, &dest, 90.0, NULL, SDL_FLIP_NONE); SDL_RenderCopy(renderer, square->texture, NULL, &dest); } +/* +Checks if a point (usually the mous X and Y) is within the Square'sbrk +clickable boundaries (different than it's displayable size) +*/ unsigned Square_intersectsPoint(Square* square, int x, int y) { int tw, th, rw, rh; tw = square->bounds.w; th = square->bounds.h; - rw = x + 1; - rh = y + 1; + rw = 1 + x; + rh = 1 + y; if(tw <= 0 || th <= 0) return 0; @@ -59,11 +73,14 @@ unsigned Square_intersectsPoint(Square* square, int x, int y) th += (square->bounds.y); return ((rw > (square->bounds.x)) && - (rh > (square->bounds.y)) && - (tw < (square->bounds.x) || tw > x) && - (th < (square->bounds.y) || th > y)); + (rh > (square->bounds.y)) && + (tw < (square->bounds.x) || tw > x) && + (th < (square->bounds.y) || th > y)); } +/* +Frees the Square's image data from memory +*/ void Square_destroy(Square* square) { SDL_DestroyTexture(square->texture); diff --git a/src/Textbox.c b/src/Textbox.c index 40a00b8..acab906 100644 --- a/src/Textbox.c +++ b/src/Textbox.c @@ -3,39 +3,42 @@ #include #include -void Textbox_init(Textbox* textbox, char* text, int w, int h) +void Textbox_init(Textbox* textbox, char* text, int w, int h, int tw, int th) { textbox->bounds.x = 0; textbox->bounds.y = 0; textbox->bounds.w = w; textbox->bounds.h = h; + textbox->textWidth = tw; + textbox->textHeight = th; textbox->textcolor = 0x00ffffff; - textbox->boxcolor = 0x0; + textbox->boxcolor = 0x88000000; textbox->visible = 1; - Textbox_setText(textbox, text); -} + int len; + len = strlen(text) > MAX_TEXT_SIZE ? MAX_TEXT_SIZE : strlen(text); -void Textbox_setTextDims(Textbox* textbox, int tw, int th) -{ - textbox->textWidth = tw; - textbox->textHeight = th; + memcpy(textbox->text, text, len); + textbox->text[len] = 0; } -void Textbox_setTextFromLong(Textbox* textbox, char* msg, long value) +void Textbox_setTextFromLong(Textbox* textbox, const char* msg, long value) { char buffer[500]; - snprintf(buffer, 5000, "%s%ld", msg, value); + snprintf(buffer, 500, "%s%ld", msg, value); - Textbox_setText(textbox, buffer); + Textbox_setText(textbox, buffer, 1); } -void Textbox_setText(Textbox* textbox, char* text) +void Textbox_setText(Textbox* textbox, char* text, unsigned dynamic) { int len; len = strlen(text) > MAX_TEXT_SIZE ? MAX_TEXT_SIZE : strlen(text); + if(dynamic) + textbox->textWidth = (int)(((double)(textbox->textWidth) * (double)strlen(text)) / (double)strlen(textbox->text)); + memcpy(textbox->text, text, len); textbox->text[len] = 0; } @@ -46,8 +49,11 @@ void Textbox_displayAt(Textbox* textbox, int x, int y) textbox->bounds.y = y; } -static void getComponents(unsigned color, unsigned char* r, unsigned char* g, unsigned char* b) +static void getComponents(unsigned color, unsigned char* a, unsigned char* r, unsigned char* g, unsigned char* b) { + if(a != NULL) + (*a) = (color >> 24) & 0xff; + (*r) = (color >> 16) & 0xff; (*g) = (color >> 8) & 0xff; (*b) = color & 0xff; @@ -57,15 +63,15 @@ void Textbox_render(Textbox* textbox, SDL_Renderer* renderer, TTF_Font* font) { if(!(textbox->visible)) return; - - unsigned char _r, _g, _b; - getComponents(textbox->boxcolor, &_r, &_g, &_b); + unsigned char _r, _g, _b, _a; + + getComponents(textbox->boxcolor, &_a, &_r, &_g, &_b); - SDL_SetRenderDrawColor(renderer, _r, _g, _b, 0xff); + SDL_SetRenderDrawColor(renderer, _r, _g, _b, _a); SDL_RenderFillRect(renderer, &(textbox->bounds)); - getComponents(textbox->textcolor, &_r, &_g, &_b); + getComponents(textbox->textcolor, NULL, &_r, &_g, &_b); SDL_Color color = {.r=_r, .g=_g, .b=_b}; SDL_Surface* surface = TTF_RenderText_Blended(font, textbox->text, color); @@ -82,3 +88,33 @@ void Textbox_render(Textbox* textbox, SDL_Renderer* renderer, TTF_Font* font) SDL_DestroyTexture(texture); SDL_FreeSurface(surface); } + +void Textbox_renderRotatedText(Textbox* textbox, SDL_Renderer* renderer, TTF_Font* font, double angle) +{ + if(!(textbox->visible)) + return; + + unsigned char _r, _g, _b, _a; + + getComponents(textbox->boxcolor, &_a, &_r, &_g, &_b); + + SDL_SetRenderDrawColor(renderer, _r, _g, _b, _a); + SDL_RenderFillRect(renderer, &(textbox->bounds)); + + getComponents(textbox->textcolor, NULL, &_r, &_g, &_b); + + SDL_Color color = {.r=_r, .g=_g, .b=_b}; + SDL_Surface* surface = TTF_RenderText_Blended(font, textbox->text, color); + SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface); + + SDL_Rect textBounds; + textBounds.x = (textbox->bounds).x + ((textbox->bounds).w - textbox->textWidth) / 2; + textBounds.y = (textbox->bounds).y + ((textbox->bounds).h - textbox->textHeight) / 2; + textBounds.w = textbox->textWidth; + textBounds.h = textbox->textHeight; + + SDL_RenderCopyEx(renderer, texture, NULL, &textBounds, angle, NULL, SDL_FLIP_NONE); + + SDL_DestroyTexture(texture); + SDL_FreeSurface(surface); +} diff --git a/src/Textbox.h b/src/Textbox.h index 7f3cff5..e943ecb 100644 --- a/src/Textbox.h +++ b/src/Textbox.h @@ -13,7 +13,7 @@ typedef struct { SDL_Rect bounds; char text[MAX_TEXT_SIZE]; - + int textWidth; int textHeight; @@ -22,13 +22,13 @@ typedef struct { unsigned visible; } Textbox; -void Textbox_init(Textbox*, char*, int, int); +void Textbox_init(Textbox*, char*, int, int, int, int); void Textbox_displayAt(Textbox*, int, int); -void Textbox_setTextFromLong(Textbox*, char*, long); -void Textbox_setTextDims(Textbox*, int, int); -void Textbox_setText(Textbox*, char*); +void Textbox_setTextFromLong(Textbox*, const char*, long); +void Textbox_setText(Textbox*, char*, unsigned); void Textbox_render(Textbox*, SDL_Renderer*, TTF_Font*); +void Textbox_renderRotatedText(Textbox*, SDL_Renderer*, TTF_Font*, double); #endif /* GAME_TEXTBOX_H__ */