diff -r 000000000000 -r b2e3aa63e96c src/draw.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/draw.c Thu Jul 17 22:03:19 2025 -0400 @@ -0,0 +1,113 @@ +/* +Copyright (c) 2023 MCL Software + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), +to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "draw.h" +#include "common.h" +#include "missions.h" +#include "localztn.h" +#include "SDL2/SDL_ttf.h" + +SDL_Rect clip; +SDL_Rect destRect; +SDL_Renderer* renderer = 0; +SDL_Texture* tilemap = 0; + +FC_Font* font = 0; + + +void initGraphics() +{ + IMG_Init(IMG_INIT_PNG); + SDL_Surface* tilemapSurface = IMG_Load("./img/tilemap.png"); + SDL_Surface* logoSurface = IMG_Load("./img/logo.png"); + + tilemap = SDL_CreateTextureFromSurface(renderer, tilemapSurface); + logo = SDL_CreateTextureFromSurface(renderer, logoSurface); + + + SDL_FreeSurface(tilemapSurface); + SDL_FreeSurface(logoSurface); + + initTitleScreenGraphics(); + + // Create font cache + font = FC_CreateFont(); + FC_LoadFont(font, renderer, "./Montserrat-ExtraBold.ttf", 24, FC_MakeColor(255, 255, 255, 255), TTF_STYLE_NORMAL); + +} + + +void freeGraphics() +{ + SDL_DestroyTexture(tilemap); + SDL_DestroyTexture(logo); + FC_FreeFont(font); +} + +void drawLeaveSchool() +{ + SDL_SetRenderDrawColor(renderer, 10, 69, 127, 199); + SDL_RenderFillRect(renderer, &(SDL_Rect){SCREEN_WIDTH / 3, SCREEN_HEIGHT / 3, SCREEN_WIDTH / 3, SCREEN_HEIGHT / 3}); + FC_DrawAlign(font, renderer, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, FC_ALIGN_CENTER, checkForMissionComplete(currentMission) ? "Do you want to leave \nthe campus? (Y/N)" : "You can't leave right now."); +} + +void drawHUD() +{ + SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); + + // Progress bar background + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 127); + SDL_RenderFillRect(renderer, &(SDL_Rect){50, 50, 128 * 1.5, 40}); + + FC_SetDefaultColor(font, (SDL_Color){255, 255, 255, 255}); + + // Selected object indicator + SDL_RenderFillRect(renderer, &(SDL_Rect){250, 50, FC_GetBounds(font, 250, 50, FC_ALIGN_LEFT, (FC_Scale){1, 1}, "Selected object: %s", getTranslationForObject(levelTiles[player.x * LEVEL_WIDTH + player.y])).w, 40}); + FC_Draw(font, renderer, 250, 55, "Selected object: %s", getTranslationForObject(levelTiles[player.x * LEVEL_WIDTH + player.y])); + + // Camera offset + SDL_Rect bounds = FC_GetBounds(font, 50, 200, FC_ALIGN_LEFT, (FC_Scale){1, 1}, "Cam offset: %i, %i", offset.x, offset.y); + bounds.h += 5; + SDL_RenderFillRect(renderer, &bounds); + FC_Draw(font, renderer, 50, 205, "Cam offset: %i, %i", offset.x, offset.y); + + // Player pos + SDL_RenderFillRect(renderer, &(SDL_Rect){50, 100, FC_GetBounds(font, 50, 50, FC_ALIGN_LEFT, (FC_Scale){1, 1}, "Player pos: %i, %i\nObjects stolen: %s", player.x, player.y, player.objectsStolen).w, 75}); + FC_Draw(font, renderer, 50, 105, "Player pos: %i, %i\nObjects stolen: %s", player.x, player.y, player.objectsStolen); + + // Fill progress bar + SDL_SetRenderDrawColor(renderer, 200, 0, 0, 200); + SDL_RenderFillRect(renderer, &(SDL_Rect){50, 50, stealProgress * 1.5, 40}); + FC_DrawAlign(font, renderer, 50 + 64 * 1.5, 55, FC_ALIGN_CENTER, "Stealing (%i)", stealProgress); + + if(fireAlarmSystemActivated) + { + SDL_SetRenderDrawColor(renderer, 255, 255, 255, 220); + SDL_RenderFillRect(renderer, &(SDL_Rect){0, 0, SCREEN_WIDTH, SCREEN_HEIGHT}); + } +} + +void drawGoToExit() +{ + SDL_SetRenderDrawColor(renderer, 0, 0, 255, 200); + SDL_RenderFillRect(renderer, &(SDL_Rect){300, 400, 128, 40}); + FC_Draw(font, renderer, 300, 400, "Go to exit"); +} + +void drawTitleMenuText() +{ + FC_DrawAlign(font, renderer, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 1.1, FC_ALIGN_CENTER, "Version 0.9 (2025-01-28)\nDevious Licks is currently in beta. Bugs may occur."); + FC_Draw(font, renderer, 0, SCREEN_HEIGHT - 30, "Copyright (c) 2023 - 2025 MCL Software"); + FC_DrawAlign(font, renderer, SCREEN_WIDTH, SCREEN_HEIGHT - 30, FC_ALIGN_RIGHT, "Free-as-in-freedom, please copy and share!"); +}