|
0
|
1 |
/*
|
|
|
2 |
Copyright (c) 2023 MCL Software
|
|
|
3 |
|
|
|
4 |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”),
|
|
|
5 |
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
6 |
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:
|
|
|
7 |
|
|
|
8 |
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
|
9 |
|
|
|
10 |
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
11 |
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,
|
|
|
12 |
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.
|
|
|
13 |
*/
|
|
|
14 |
|
|
|
15 |
#include "draw.h"
|
|
|
16 |
#include "common.h"
|
|
|
17 |
#include "missions.h"
|
|
|
18 |
#include "localztn.h"
|
|
|
19 |
#include "SDL2/SDL_ttf.h"
|
|
|
20 |
|
|
|
21 |
SDL_Rect clip;
|
|
|
22 |
SDL_Rect destRect;
|
|
|
23 |
SDL_Renderer* renderer = 0;
|
|
|
24 |
SDL_Texture* tilemap = 0;
|
|
|
25 |
|
|
|
26 |
FC_Font* font = 0;
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
void initGraphics()
|
|
|
30 |
{
|
|
|
31 |
IMG_Init(IMG_INIT_PNG);
|
|
|
32 |
SDL_Surface* tilemapSurface = IMG_Load("./img/tilemap.png");
|
|
|
33 |
SDL_Surface* logoSurface = IMG_Load("./img/logo.png");
|
|
|
34 |
|
|
|
35 |
tilemap = SDL_CreateTextureFromSurface(renderer, tilemapSurface);
|
|
|
36 |
logo = SDL_CreateTextureFromSurface(renderer, logoSurface);
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
SDL_FreeSurface(tilemapSurface);
|
|
|
40 |
SDL_FreeSurface(logoSurface);
|
|
|
41 |
|
|
|
42 |
initTitleScreenGraphics();
|
|
|
43 |
|
|
|
44 |
// Create font cache
|
|
|
45 |
font = FC_CreateFont();
|
|
|
46 |
FC_LoadFont(font, renderer, "./Montserrat-ExtraBold.ttf", 24, FC_MakeColor(255, 255, 255, 255), TTF_STYLE_NORMAL);
|
|
|
47 |
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
void freeGraphics()
|
|
|
52 |
{
|
|
|
53 |
SDL_DestroyTexture(tilemap);
|
|
|
54 |
SDL_DestroyTexture(logo);
|
|
|
55 |
FC_FreeFont(font);
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
void drawLeaveSchool()
|
|
|
59 |
{
|
|
|
60 |
SDL_SetRenderDrawColor(renderer, 10, 69, 127, 199);
|
|
|
61 |
SDL_RenderFillRect(renderer, &(SDL_Rect){SCREEN_WIDTH / 3, SCREEN_HEIGHT / 3, SCREEN_WIDTH / 3, SCREEN_HEIGHT / 3});
|
|
|
62 |
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.");
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
void drawHUD()
|
|
|
66 |
{
|
|
|
67 |
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
|
|
68 |
|
|
|
69 |
// Progress bar background
|
|
|
70 |
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 127);
|
|
|
71 |
SDL_RenderFillRect(renderer, &(SDL_Rect){50, 50, 128 * 1.5, 40});
|
|
|
72 |
|
|
|
73 |
FC_SetDefaultColor(font, (SDL_Color){255, 255, 255, 255});
|
|
|
74 |
|
|
|
75 |
// Selected object indicator
|
|
|
76 |
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});
|
|
|
77 |
FC_Draw(font, renderer, 250, 55, "Selected object: %s", getTranslationForObject(levelTiles[player.x * LEVEL_WIDTH + player.y]));
|
|
|
78 |
|
|
|
79 |
// Camera offset
|
|
|
80 |
SDL_Rect bounds = FC_GetBounds(font, 50, 200, FC_ALIGN_LEFT, (FC_Scale){1, 1}, "Cam offset: %i, %i", offset.x, offset.y);
|
|
|
81 |
bounds.h += 5;
|
|
|
82 |
SDL_RenderFillRect(renderer, &bounds);
|
|
|
83 |
FC_Draw(font, renderer, 50, 205, "Cam offset: %i, %i", offset.x, offset.y);
|
|
|
84 |
|
|
|
85 |
// Player pos
|
|
|
86 |
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});
|
|
|
87 |
FC_Draw(font, renderer, 50, 105, "Player pos: %i, %i\nObjects stolen: %s", player.x, player.y, player.objectsStolen);
|
|
|
88 |
|
|
|
89 |
// Fill progress bar
|
|
|
90 |
SDL_SetRenderDrawColor(renderer, 200, 0, 0, 200);
|
|
|
91 |
SDL_RenderFillRect(renderer, &(SDL_Rect){50, 50, stealProgress * 1.5, 40});
|
|
|
92 |
FC_DrawAlign(font, renderer, 50 + 64 * 1.5, 55, FC_ALIGN_CENTER, "Stealing (%i)", stealProgress);
|
|
|
93 |
|
|
|
94 |
if(fireAlarmSystemActivated)
|
|
|
95 |
{
|
|
|
96 |
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 220);
|
|
|
97 |
SDL_RenderFillRect(renderer, &(SDL_Rect){0, 0, SCREEN_WIDTH, SCREEN_HEIGHT});
|
|
|
98 |
}
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
void drawGoToExit()
|
|
|
102 |
{
|
|
|
103 |
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 200);
|
|
|
104 |
SDL_RenderFillRect(renderer, &(SDL_Rect){300, 400, 128, 40});
|
|
|
105 |
FC_Draw(font, renderer, 300, 400, "Go to exit");
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
void drawTitleMenuText()
|
|
|
109 |
{
|
|
|
110 |
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.");
|
|
|
111 |
FC_Draw(font, renderer, 0, SCREEN_HEIGHT - 30, "Copyright (c) 2023 - 2025 MCL Software");
|
|
|
112 |
FC_DrawAlign(font, renderer, SCREEN_WIDTH, SCREEN_HEIGHT - 30, FC_ALIGN_RIGHT, "Free-as-in-freedom, please copy and share!");
|
|
|
113 |
}
|