From 553678b169248410165858dae9495fb6d56a20b1 Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Sun, 2 Oct 2022 12:24:14 +0300 Subject: [PATCH] best game of 2022 --- assets/fish/angryfish.png | Bin 0 -> 9507 bytes assets/fish/fish.png | Bin 0 -> 9837 bytes meson.build | 9 +- src/main.c | 252 ++++++++++++++++++++++++++++++++++++++ src/main.cpp | 47 ------- 5 files changed, 257 insertions(+), 51 deletions(-) create mode 100644 assets/fish/angryfish.png create mode 100644 assets/fish/fish.png create mode 100644 src/main.c delete mode 100644 src/main.cpp diff --git a/assets/fish/angryfish.png b/assets/fish/angryfish.png new file mode 100644 index 0000000000000000000000000000000000000000..e8fe4e6687f22326ce1f9b6e879790153c19c957 GIT binary patch literal 9507 zcmeHMc|4Ts+aLQ*5+O85)-fAnX6)HR_H2>aFm`4zWS2yxknBV{BwKb`ED6PlLUvga zA(8CVJ9N(Zo%4C$Ki>0xe!usx^UUX&d7k^euJ3hyuj{&>d#;%{({p+ptb(in0D!|l zU)!Ae8F6qjGg9B5t6{pRa$03-+b5P$><(HQ`sjC@YF4>;Ap zq5Y$Q6&wjZ^1*LQr9*k;YiLVJlHG#HrQoHW#74&la;KT;#b}4Uek|s8>__Jcoh92= z-#H&YCs{X!oikqV>8bB&ncEEsp9r5`OPyJs;Y!qs8~hgHvFaZ}%G#V-Z+QCb$i!UJ z@!%$w?7*+vu@e_NItFKEYMe^m9}m{K)k-2XIbNiIZcoeR?}g-)Up@P9hv4r1tSswd z?82P5wv7|ZFFMHbQOWfvj zifcj^{#pFXu~~vW(lMD76KR%6{n5oUtgi&U1x*@2+*UsfTP8jdYB>Us+vU zKA}?Glu$UgHFsuqX5G;CeMfYNa*mojPm{K#dbv>ebyp+c_Dm0#m8#1CX+w2*Hizw! ze7W({I=}b6(-j`$<-B1ju`7;Wyl3immL+>_Uz?!aR`O!>Z>*BkZsFb#;EpEg5LC;M;xTQ}MtxJ0|Hqtv}ukob% z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JX&8Z5x^Fz?NC;bP8(X?4ho|3;_>f}~x`q=*p g68m2su;!){U=EE`V}>2-(;Hx*b56VLj8oKq0p*;V^8f$< literal 0 HcmV?d00001 diff --git a/assets/fish/fish.png b/assets/fish/fish.png new file mode 100644 index 0000000000000000000000000000000000000000..e917cdfe28c78d2a22384140e0f8f4d13fb2f09c GIT binary patch literal 9837 zcmeHMXIPWlvJSl$K@gA?>Xz`m#+2n8)dU?hy~Wzqy#1f42@Bo%>Dk&a;E)YKr?$t)ndIa zAlUn*9HTtq`?u#uyg_Z7`^yV@LEkr80>ATn3wi0he9LRQ%(VQK+h+FYQ`DB%ai1a| zU)OuXuiv^kDtC5{c6P+=Ty3cWDuA~f9olUrTPU@*>k7XG*;cZRzFTarSl`Q*YQI+Z z(l(sK<)IR6Qz{^N^6PZrOJ&)5u#xGSU%_Yc-JA0ZM|~y9;=QTLpIiFw<{Mu+V!(Mm zZ|Qr(eJ<+gV(CdvQ`o-Z0E-zeL>KW*CUf@L5?n3h^A3C};6s;ggrxIkRr_M!(d&%e zq;2W^yq$cq(fw^1Glk*k&mV#U^jO<1uOH<|1veMwwFK8Md*~a_=Se*pUPnG_ zP@EYSf3o6LLWQ>xbvhe5`;g=qWXe*y5D1_HGYptlL{&`!^@ia88;O}jxZgUm_;O?-(g@>$me&U$!|=f zcl_m~OZcd?DPrv{ATp+rE}n*lJc!|8Bv(t%Wq#&9O8JO1!%#2EdgaR(-Ay?0T5O(W zq)SV@H2afg^LVZ=2rxA?)Y8v z8)?QF{^BSCH&$q@de4`~xi6$;pVr$k z(aB8K8Kf-2^=|woXg|84ar#7Xdfs#~M`{1N;xH${HtFb0y@I0KJ&yAD@d{yG%Y6w?ghMa zQr5-iJutuYp~k1wup|Q=R77Q*-m;|Dkoauz?xt?{nr4u**$a^d33l^1`WNRPg3O~6E;uY+IvnHnF;MWnN`K(Inmq$` zbt!wTTY6iw;jCXobySWSsuE%Py3XRcrCU2cp$3MkBYSb{SHJZlHUX6vH`XUP_H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>$KFX^*VS(-WaaEsUHhfpyp;$E0qn19&~k% zIJc?o-B5Jv4j69|+LSfn%&y&`h8?YUJ027h*^;LVbvq0Wt)>$c%ee93d~|Aas%*Pl z@2z&8VJoi#EWNz{(>vrNDVcsRs@$k!VE_|j&EQ9yHpRef5cLD=hTX*O?);38O+)jg z*As^;*f-^8Oxz|UpSA*?`I4M`tH;NhBvE|c<8V@&;gM~S8u*Z5(NIE>Ae&XVxt&fS z+_JPwCH3(-#h6| zCP|->R!MHpe!-;MY6{tCQ%Ls#w9}bgb7lmEh)V`l2UFrqZX({lQy&cNZ=Yv6Flk;h z-;F2$kvF2gg{2QQhGXJ#3=2+QzQ;vMH;sokor z+%t(v07{){onOm>+vltmZ|8>$9b%GsLn=|PBCiz9uI|?yD8HS24q!+)r1#`P@?zDf zedOqF4)Y)M9|9;{{bR)eIvO|l8w1G0Y$rx}WvfPV-jzk`m_chBCYbOCMKhu*w7_M( z*7O;$QSDmWh!1_HMdzin-oqi%W(ir26xo;jowJrhD!;JF=h0RAAZn2An*QIuBhzx` zJ|vr?b5Sp11pwh=a5ehC>7Evxos6f<6V+a~JR~oBYcEqctC0Ku^0Is;S?Gl9x{^d5 U7Pc@zJZk`&s@JYQR<;ZOFKXB(Z2$lO literal 0 HcmV?d00001 diff --git a/meson.build b/meson.build index efef5a0..3981489 100644 --- a/meson.build +++ b/meson.build @@ -1,9 +1,10 @@ -project('rotcpu', 'cpp') +project('fish-simulator', 'c') sdl2_dep = dependency('sdl2') +sdl2_image_dep = dependency('sdl2_image') executable( - 'rotcpuemu', - './src/main.cpp', - dependencies : [sdl2_dep] + 'fish-simulator', + './src/main.c', + dependencies : [sdl2_dep, sdl2_image_dep] ) diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..710ab7e --- /dev/null +++ b/src/main.c @@ -0,0 +1,252 @@ +#include "SDL.h" +#include "SDL_events.h" +#include "SDL_rect.h" +#include "SDL_render.h" +#include "SDL_image.h" +#include "SDL_timer.h" +#include "SDL_video.h" + +#define FISHES_MAX 1024 +#define SIMULATION_DELTA_TIME (1.0f / 60.0f) + +enum fish_type { + FISH_TYPE_NORMAL, + FISH_TYPE_ANGRY +}; + +enum fish_state { + FISH_STATE_NONE, + FISH_STATE_INIT, + FISH_STATE_WANDER_PICK_POINT, + FISH_STATE_WANDER_TRANSITION, + FISH_STATE_WANDER_DONE +}; + +struct fish { + int x, y, w, h; + enum fish_type type; + enum fish_state state; + + /* state arguments */ + float wander_start_x, wander_start_y, wander_target_x, wander_target_y, wander_step; /* FISH_STATE_WANDER_* */ +}; + +struct app { + struct fish *fishes[FISHES_MAX]; + int fishes_count; + SDL_Window *window; + SDL_Renderer *renderer; + + SDL_Texture *fish_texture; + SDL_Texture *angry_fish_texture; +}; + +float lerp(float a, float b, float t) +{ + return a + (b - a) * t; +} + +void scc(int code) +{ + if (code < 0) { + fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError()); + exit(1); + } +} + +void *scp(void *ptr) +{ + if (ptr == NULL) { + fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError()); + exit(1); + } + + return ptr; +} + +int fishes_add(struct app *app, int x, int y, int w, int h, enum fish_type type) +{ + struct fish *new_fish = malloc(sizeof(struct fish)); + new_fish->x = x; + new_fish->y = y; + new_fish->w = w; + new_fish->h = h; + new_fish->type = type; + new_fish->state = FISH_STATE_INIT; + + for (int i = 0; i < FISHES_MAX; i++) { + if (app->fishes[i] == NULL) { + app->fishes[i] = new_fish; + app->fishes_count++; + return i; + } + } + + return -1; +} + +void fish_update(const struct app *app, struct fish *fish, float delta_time) +{ + switch (fish->state) + { + case FISH_STATE_INIT: { + fish->state = FISH_STATE_WANDER_PICK_POINT; + } break; + + case FISH_STATE_WANDER_PICK_POINT: { + int width, height; + SDL_GetWindowSize(app->window, &width, &height); + + fish->wander_target_x = rand() % width; + fish->wander_target_y = rand() % height; + fish->wander_start_x = fish->x; + fish->wander_start_y = fish->y; + fish->wander_step = 0.1; + fish->state = FISH_STATE_WANDER_TRANSITION; + } break; + + case FISH_STATE_WANDER_TRANSITION: { + if (fish->x != fish->wander_target_x) { + fish->x = lerp(fish->wander_start_x, fish->wander_target_x, fish->wander_step); + } + if (fish->y != fish->wander_target_y) { + fish->y = lerp(fish->wander_start_y, fish->wander_target_y, fish->wander_step); + } + if (fish->wander_step >= 1.0) { + fish->state = FISH_STATE_WANDER_DONE; + } + fish->wander_step += 0.05 * delta_time; + } break; + + case FISH_STATE_WANDER_DONE: { + fish->state = FISH_STATE_INIT; + } break; + + case FISH_STATE_NONE: /* through */ + default: + break; + } + +} + +void fish_draw(const struct app *app, const struct fish *fish) +{ + SDL_Rect rect = { + .x = fish->x, + .y = fish->y, + .w = fish->w, + .h = fish->h + }; + SDL_Texture *texture = fish->type == FISH_TYPE_ANGRY ? app->angry_fish_texture : app->fish_texture; + SDL_RenderCopy(app->renderer, texture, NULL, &rect); +} + +struct app *app_new() +{ + struct app *app = malloc(sizeof(struct app)); + + scc(SDL_Init(SDL_INIT_VIDEO)); + scc(SDL_CreateWindowAndRenderer(320, 240, SDL_WINDOW_RESIZABLE, &app->window, &app->renderer)); + app->fish_texture = scp(IMG_LoadTexture(app->renderer, "./assets/fish/fish.png")); + app->angry_fish_texture = scp(IMG_LoadTexture(app->renderer, "./assets/fish/angryfish.png")); + fishes_add(app, 20, 20, 128, 128, FISH_TYPE_NORMAL); + fishes_add(app, 20, 150, 128, 128, FISH_TYPE_NORMAL); + fishes_add(app, 150, 150, 128, 128, FISH_TYPE_ANGRY); + + return app; +} + +void app_update(struct app *app, float delta_time) +{ + /* fishes */ + { + int found_fishes = 0; + for (int i = 0; i < FISHES_MAX; i++) { + if (app->fishes[i] != NULL) { + found_fishes++; + fish_update(app, app->fishes[i], delta_time); + } + if (found_fishes >= app->fishes_count) { + break; + } + } + } +} + +void app_draw(struct app *app) +{ + /* background */ + { + SDL_SetRenderDrawColor(app->renderer, 0x11, 0x65, 0xBA, 0xff); + SDL_RenderClear(app->renderer); + } + + /* fishes */ + { + int found_fishes = 0; + for (int i = 0; i < FISHES_MAX; i++) { + if (app->fishes[i] != NULL) { + found_fishes++; + fish_draw(app, app->fishes[i]); + } + if (found_fishes >= app->fishes_count) { + break; + } + } + } +} + +void app_loop(struct app *app) { + SDL_Event event; + Uint32 prev_ticks = SDL_GetTicks(); + float lag_sec = 0; + while (1) { + Uint32 current_ticks = SDL_GetTicks(); + lag_sec += (float) (current_ticks - prev_ticks) / 1000.0f; + SDL_PollEvent(&event); + if (event.type == SDL_QUIT) { + break; + } + + { + SDL_Delay(1); + while (lag_sec >= SIMULATION_DELTA_TIME) { + app_update(app, SIMULATION_DELTA_TIME); + lag_sec -= SIMULATION_DELTA_TIME; + } + } + + app_draw(app); + + SDL_RenderPresent(app->renderer); + } +} + +void app_free(struct app *app) +{ + int found_fishes = 0; + for (int i = 0; i < FISHES_MAX; i++) { + if (app->fishes[i] != NULL) { + free(app->fishes[i]); + found_fishes++; + } + if (found_fishes >= app->fishes_count) { + break; + } + } + SDL_DestroyRenderer(app->renderer); + SDL_DestroyWindow(app->window); + SDL_DestroyTexture(app->fish_texture); + free(app); +} + +int main(int argc, char *argv[]) +{ + struct app *app = app_new(); + app_loop(app); + app_free(app); + + SDL_Quit(); + + return 0; +} diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index 312a071..0000000 --- a/src/main.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "SDL.h" - -void scc(int code) -{ - if (code < 0) { - fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError()); - exit(1); - } -} - -void *scp(void *ptr) -{ - if (ptr == NULL) { - fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError()); - exit(1); - } - - return ptr; -} - -int main(int argc, char *argv[]) -{ - SDL_Window *window; - SDL_Renderer *renderer; - SDL_Surface *surface; - SDL_Event event; - - scc(SDL_Init(SDL_INIT_VIDEO)); - scc(SDL_CreateWindowAndRenderer(320, 240, SDL_WINDOW_RESIZABLE, &window, &renderer)); - - while (1) { - SDL_PollEvent(&event); - if (event.type == SDL_QUIT) { - break; - } - SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00); - SDL_RenderClear(renderer); - SDL_RenderPresent(renderer); - } - - SDL_DestroyRenderer(renderer); - SDL_DestroyWindow(window); - - SDL_Quit(); - - return 0; -}