|
@@ -5,9 +5,10 @@
|
|
|
#include <string.h>
|
|
|
#include <time.h>
|
|
|
|
|
|
-#include <SDL.h>
|
|
|
+#include <SDL2/SDL.h>
|
|
|
|
|
|
#include "./digits.h"
|
|
|
+#include "./penger_walk_sheet.h"
|
|
|
|
|
|
#define FPS 60
|
|
|
//#define DELTA_TIME (1.0f / FPS)
|
|
@@ -31,6 +32,7 @@
|
|
|
#define BACKGROUND_COLOR_G 24
|
|
|
#define BACKGROUND_COLOR_B 24
|
|
|
#define SCALE_FACTOR 0.15f
|
|
|
+#define PENGER_SCALE 4
|
|
|
|
|
|
void secc(int code)
|
|
|
{
|
|
@@ -50,15 +52,15 @@ void *secp(void *ptr)
|
|
|
return ptr;
|
|
|
}
|
|
|
|
|
|
-SDL_Surface *load_png_file_as_surface()
|
|
|
+SDL_Surface *load_png_file_as_surface(uint32_t *data, size_t width, size_t height)
|
|
|
{
|
|
|
SDL_Surface* image_surface =
|
|
|
secp(SDL_CreateRGBSurfaceFrom(
|
|
|
- png,
|
|
|
- (int) png_width,
|
|
|
- (int) png_height,
|
|
|
+ data,
|
|
|
+ (int) width,
|
|
|
+ (int) height,
|
|
|
32,
|
|
|
- (int) png_width * 4,
|
|
|
+ (int) width * 4,
|
|
|
0x000000FF,
|
|
|
0x0000FF00,
|
|
|
0x00FF0000,
|
|
@@ -66,12 +68,19 @@ SDL_Surface *load_png_file_as_surface()
|
|
|
return image_surface;
|
|
|
}
|
|
|
|
|
|
-SDL_Texture *load_png_file_as_texture(SDL_Renderer *renderer)
|
|
|
+SDL_Texture *load_digits_png_file_as_texture(SDL_Renderer *renderer)
|
|
|
{
|
|
|
- SDL_Surface *image_surface = load_png_file_as_surface();
|
|
|
+ SDL_Surface *image_surface = load_png_file_as_surface(digits_data, digits_width, digits_height);
|
|
|
return secp(SDL_CreateTextureFromSurface(renderer, image_surface));
|
|
|
}
|
|
|
|
|
|
+SDL_Texture *load_penger_png_file_as_texture(SDL_Renderer *renderer)
|
|
|
+{
|
|
|
+ SDL_Surface *image_surface = load_png_file_as_surface(penger_data, penger_width, penger_height);
|
|
|
+ return secp(SDL_CreateTextureFromSurface(renderer, image_surface));
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
void render_digit_at(SDL_Renderer *renderer, SDL_Texture *digits, size_t digit_index,
|
|
|
size_t wiggle_index, int *pen_x, int *pen_y, float user_scale, float fit_scale)
|
|
|
{
|
|
@@ -94,6 +103,38 @@ void render_digit_at(SDL_Renderer *renderer, SDL_Texture *digits, size_t digit_i
|
|
|
*pen_x += effective_digit_width;
|
|
|
}
|
|
|
|
|
|
+void render_penger_at(SDL_Renderer *renderer, SDL_Texture *penger, size_t time, SDL_Window *window)
|
|
|
+{
|
|
|
+ int frame_index = (time%60)%2;
|
|
|
+
|
|
|
+ const SDL_Rect src_rect = {
|
|
|
+ (int) (penger_width / 2) * frame_index,
|
|
|
+ 0,
|
|
|
+ (int) penger_width / 2,
|
|
|
+ (int) penger_height
|
|
|
+ };
|
|
|
+
|
|
|
+ int window_width, window_height;
|
|
|
+ SDL_GetWindowSize(window, &window_width, &window_height);
|
|
|
+
|
|
|
+ float step = time%60;
|
|
|
+
|
|
|
+ float progress = step / 60.0f;
|
|
|
+
|
|
|
+ float penger_drawn_width = ((float)penger_width / 2) / PENGER_SCALE;
|
|
|
+
|
|
|
+ float penger_walk_width = window_width + penger_drawn_width;
|
|
|
+
|
|
|
+ SDL_Rect dst_rect = {
|
|
|
+ floorf((float)penger_walk_width * progress - penger_drawn_width),
|
|
|
+ window_height - (penger_height / PENGER_SCALE),
|
|
|
+ (int) (penger_width / 2) / PENGER_SCALE,
|
|
|
+ (int) penger_height / PENGER_SCALE
|
|
|
+ };
|
|
|
+
|
|
|
+ SDL_RenderCopy(renderer, penger, &src_rect, &dst_rect);
|
|
|
+}
|
|
|
+
|
|
|
void initial_pen(SDL_Window *window, int *pen_x, int *pen_y, float user_scale, float *fit_scale)
|
|
|
{
|
|
|
int w, h;
|
|
@@ -221,7 +262,8 @@ int main(int argc, char **argv)
|
|
|
|
|
|
secc(SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"));
|
|
|
|
|
|
- SDL_Texture *digits = load_png_file_as_texture(renderer);
|
|
|
+ SDL_Texture *digits = load_digits_png_file_as_texture(renderer);
|
|
|
+ SDL_Texture *penger = load_penger_png_file_as_texture(renderer);
|
|
|
secc(SDL_SetTextureColorMod(digits, MAIN_COLOR_R, MAIN_COLOR_G, MAIN_COLOR_B));
|
|
|
|
|
|
if (paused) {
|
|
@@ -320,11 +362,18 @@ int main(int argc, char **argv)
|
|
|
SDL_SetRenderDrawColor(renderer, BACKGROUND_COLOR_R, BACKGROUND_COLOR_G, BACKGROUND_COLOR_B, 255);
|
|
|
SDL_RenderClear(renderer);
|
|
|
{
|
|
|
+ const size_t t = (size_t) ceilf(fmaxf(displayed_time, 0.0f));
|
|
|
+ // PENGER BEGIN //////////////////////////////
|
|
|
+
|
|
|
+ render_penger_at(renderer, penger, t, window);
|
|
|
+
|
|
|
+ // PENGER END //////////////////////////////
|
|
|
+
|
|
|
+ // DIGITS BEGIN //////////////////////////////
|
|
|
int pen_x, pen_y;
|
|
|
float fit_scale = 1.0;
|
|
|
initial_pen(window, &pen_x, &pen_y, user_scale, &fit_scale);
|
|
|
|
|
|
- const size_t t = (size_t) ceilf(fmaxf(displayed_time, 0.0f));
|
|
|
|
|
|
// TODO: support amount of hours >99
|
|
|
const size_t hours = t / 60 / 60;
|
|
@@ -347,6 +396,7 @@ int main(int argc, char **argv)
|
|
|
SDL_SetWindowTitle(window, title);
|
|
|
}
|
|
|
memcpy(title, prev_title, TITLE_CAP);
|
|
|
+ // DIGITS END //////////////////////////////
|
|
|
}
|
|
|
SDL_RenderPresent(renderer);
|
|
|
// RENDER END //////////////////////////////
|