From 31abc9905852e5b41d6c7517996d743bd1ac4d57 Mon Sep 17 00:00:00 2001 From: nemo Date: Mon, 18 Nov 2024 11:22:02 +0100 Subject: [PATCH] poopenger + fix bugs --- app.c | 50 ++++++++++++++++++++++++++++++------------- museum/Poopenger.png | Bin 0 -> 3741 bytes 2 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 museum/Poopenger.png diff --git a/app.c b/app.c index 251c5d1..29da7f5 100644 --- a/app.c +++ b/app.c @@ -114,7 +114,7 @@ Collision collision_union(Collision rec1, Collision rec2) return overlap; } -void collision_rec(Collision fix, int i, int scale) +Collision collision_rec(Collision fix, int i, int scale) { Collision col = collision_union(fix, (Collision) { .x = penger_pos.x - pengers_width[id]*scale/2, @@ -122,23 +122,24 @@ void collision_rec(Collision fix, int i, int scale) .width = pengers_width[id]*scale, .height = pengers_height[id]*scale, }); - if (col.width == 0 && col.height == 0) return; - if (col.width == 1 && col.height == 1) return; + if (col.width == 0 && col.height == 0) return col; + if (col.width == 1 && col.height == 1) return col; float div = -1.8; if (col.width <= col.height) { if (fix.x + fix.width == col.x + col.width) - penger_pos.x = fix.x + fix.width + pengers_width[id]*scale/2 + 1; + penger_pos.x = fix.x + fix.width + pengers_width[id]*scale/2; else if (fix.x == col.x) penger_pos.x = col.x - pengers_width[id]*scale/2 + 1; velocity.x /= div; } else { if (fix.y + fix.height == col.y + col.height) - penger_pos.y = fix.y + fix.height + pengers_height[id]*scale/2 + 1; + penger_pos.y = fix.y + fix.height + pengers_height[id]*scale/2; else if (fix.y == col.y) penger_pos.y = col.y - pengers_height[id]*scale/2 + 1; velocity.y /= div; } + return col; } void set_velocity(float x, float y) @@ -189,31 +190,31 @@ void init() int col_id = 0; collisions[col_id++] = (Collision) { .x = 100, - .y = 450, + .y = 400, .width = 50, .height = 100, }; collisions[col_id++] = (Collision) { .x = 150, - .y = 500, + .y = 450, .width = 500, .height = 50, }; collisions[col_id++] = (Collision) { .x = 650, - .y = 450, + .y = 400, .width = 50, .height = 100, }; collisions[col_id++] = (Collision) { .x = 280, - .y = 250, + .y = 200, .width = 75, .height = 75, }; collisions[col_id++] = (Collision) { .x = 445, - .y = 250, + .y = 200, .width = 75, .height = 75, }; @@ -250,6 +251,8 @@ void draw(float dt) if ((!keys[ARROW_LEFT] || !keys[Q]) && (!keys[ARROW_RIGHT] || !keys[D])) { penger_pos.x += velocity.x; } + if (id == 28) // fatger id + velocity.y += GRAVITY * dt; velocity.y += GRAVITY * dt; penger_pos.y += velocity.y; if (velocity.x <= -0.1) @@ -260,18 +263,25 @@ void draw(float dt) penger_pos.x += velocity.x; // movement + int x_collide = 0; float speed = 100.0f * dt; if (keys[SHIFT]) speed /= 2.0f; if (keys[ARROW_RIGHT] || keys[D]) { penger_pos.x += speed; - if (velocity.x < 0) velocity.x *= -1; + if (velocity.x < 0) { + velocity.x *= -1; + x_collide = 1; + } else if (velocity.x >= -EPSILON) velocity.x = speed; } if (keys[ARROW_LEFT] || keys[Q]) { penger_pos.x -= speed; - if (velocity.x > 0) velocity.x *= -1; + if (velocity.x > 0) { + velocity.x *= -1; + x_collide = 1; + } else if (velocity.x <= EPSILON) velocity.x = -speed; } @@ -282,17 +292,27 @@ void draw(float dt) rebondi(&penger_pos, scale); for (int i = 0; i < NB_COLLISIONS; i++) { - collision_rec(collisions[i], i, scale); + Collision col = collision_rec(collisions[i], i, scale); + x_collide = x_collide || (col.height > 1); } // dessine le penger sur le canva for (int y = 0; y < pengers_height[id]; y++) { for (int i = 0; i < pengers_width[id]; i++) { - int i_for_reverse_pixel_rendering_it_s_craazy = i; - if (velocity.x < EPSILON) + int i_for_reverse_pixel_rendering_it_s_craazy = 0; + static int last_dir = 1; + if ((velocity.x < -EPSILON && !x_collide) || last_dir == -1) { i_for_reverse_pixel_rendering_it_s_craazy = pengers_width[id]-i-1; + last_dir = -1; + } + if ((velocity.x > EPSILON && !x_collide) || last_dir == 1) { + i_for_reverse_pixel_rendering_it_s_craazy = i; + last_dir = 1; + } + if (pengers_img[id][y*pengers_width[id] + i_for_reverse_pixel_rendering_it_s_craazy] <= 0x00FFFFFF) // pixel transparant continue; + for (int s1 = 0; s1 < scale; s1++) { for (int s2 = 0; s2 < scale; s2++) { int idx_x = penger_origin.x + i*scale+s1; diff --git a/museum/Poopenger.png b/museum/Poopenger.png new file mode 100644 index 0000000000000000000000000000000000000000..0ce18b6a3c006a418851daec447510be4afab765 GIT binary patch literal 3741 zcmV;O4r1|%P)uJ@VVD_UC<6{N zG_fI~0ue<-1QkJoA_k0xBC#Thg@9ne9*`iQ#9$OrQF$}6R&?d%y_c8YA7_1QpS|}z zXYYO1x&V;8{kgn!SPFnNo`4_X6{c}T z{8k*B#$jdxfFg<9uYy1K45IaYvHg`_dOZM)Sy63ve6hvv1)yUy0P^?0*fb9UASvow`@mQC zp^4`uNg&9uGcn1|&Nk+9SjOUl{-OWr@Hh0;_l(8q{wNRKos+;6rV8ldy0Owz(}jF` zW(JeRp&R{qi2rfmU!TJ;gp(Kmm5I1s5m_f-n#TRsj}B0%?E`vOzxB z2#P=n*a3EfYETOrKoe*ICqM@{4K9Go;5xVgZi5G41dM~{UdP6d+Yd z3o?MrAqM0Kc|iV92owdyL5UC#5<>aVCa44|hpM4Es0sQWIt5*Tu0n&*J!lk~f_{hI z!w5`*sjxDv4V%CW*ah~3!{C*0BD@;TgA3v9a1~q+AA{TB3-ERLHar49hi4Ih5D^-p zh8Q6X#0?2VqLBoIkE}zAkxHZUgRb+f=natP#6>iMMoK->`~sRLq)(kHo*Vn{;LcG6+edD1=7 zD>9j^O?D{Qg|tCDK{ym)H7&wDr6*;uGTJg8GHjVbnL{!c zWyUB7MT6o-VNo_w8Yq`2<5Ub)hw4L3rj}5@qxMs0WMyP6Wy582WNT#4$d1qunl{ac zmP#w5ouJ*Jy_Zv#bCKi7ZIf$}8dZdVy& z)LYdbX%I9R8VMQ|8r>Q*nyQ)sn)#Z|n)kKvS`4iutvy=3T65Yu+7a4Yv^%sXb>ww? zbn(=Yu(!=O6^iuTp>)p_Y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