From 9cef5e64ddd1ef20369b25cc19b1980084ebaefe Mon Sep 17 00:00:00 2001 From: Andy Belle-Isle Date: Mon, 7 Oct 2019 15:06:24 -0400 Subject: [PATCH] Added image based hitbox detection --- Assets/world/world1/layers/0/hitbox.png | Bin 3972 -> 4795 bytes Assets/world/world1/layers/0/texture.png | Bin 4573 -> 6142 bytes Scripts/init.lua | 2 +- src/world.cpp | 5 +++-- src/world.hpp | 14 +++++++------- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Assets/world/world1/layers/0/hitbox.png b/Assets/world/world1/layers/0/hitbox.png index 0a9a37e8d2ccd31f3428e47d63d8a1cf45e35e46..881b13ea81b9e4239995238f3a6c402bb327ba98 100644 GIT binary patch literal 4795 zcmeH~_g7O}7ROHrgwPB~FOM!rkurc3A(ViCJetTDiV%?+TId~ubfgFZx`{ExbRAhD&7S@O&rH>nR2x0E zl$w7=*0FXoyuRghx>sh{)`^(B6pw)dhB}}3ZH>iORj!2(zEQJDa&%_B9;B-=BQoxr z8gr^iVlpdHfw9&f6C!wYrsVnO!`CH20Z}?#GrY!8n&i>)izY5bYI(;p(#q`=u&4T5 z`yF1@=L}9&_W3S#j|fa@WE&$p_B`BD};Wfh!WW_9$rZ zqsW`=Td3+eUEFNIbB`vGxW7W1WL#%tKgFMoU9^06yRi&~*m9HxpIdgn9(wJ$Z714SGUUYBYi&V`JYRT_p!QV zaUD_Y?KjTuGN0F(bJGE5XTX@zWv*HH_bW%lbXV%gscte4m9=I3_aIxub$bQ)@>ND)w4QZ_y^;IkH{No zn3WInxeWHDI>JFgP;h9uAMbMV)3h~*s7<1VX{MC%dHHA|RSi1QN& zDRY8R8Tqnu&Ms}N#~7>!TyP2ZnXoc4t9`lU$@kKwY=`ly_K)2MwvylZM0D8RPdjEa z=)TyQZp&*~RWd!*9)7}+-v7dhrtDrbnfflTq<87l+|2dD(fv6`bUs~75jiGQUlwhT zpA4*9eE4{>*{n}zquF8CDN<*}P^NfgT!j?6XE&l{g~yy0(E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l831AVRQ?M8Qsk>3m=a$d^2HDTKrAy= diff --git a/Assets/world/world1/layers/0/texture.png b/Assets/world/world1/layers/0/texture.png index 149273f21cadd69083c0a5dd759a708da706f465..429107e7d50f7d8afd65776fd855d020b7d96e75 100644 GIT binary patch delta 4025 zcmXX|2{=^m7yf3kBx{JGOsOFfvXrt6*|jK=WeUljeP8d0ES043OA?KgB@D#~Sw<3t zvW&3~ic*Fw8Dky)q5tJ)`6ECLr}i{J}&Mz zol${dzRoD;PIwG~B4~^;MnaW-`j{8C7f$`5ok+JlEO%tr z6(qPuXO1p0q_CED)f7#SBGOoQUb3*_#cNkaF35%Jj9$?!AN^VSRo+SD-a;|)Yvt{* zj|ZcFws^jPKGa4DQK)}&pv?yoSkMQr!MfC;0oM(MUu(1Ux->^&#REr}czY`z>;rVz z&-tUBp)QNjGMYB)&NCdX4)Bp7VY_3S%vF1;y?w_f1lIO>uZj*!MF|Y{N!E4>&O#Qz1UqeKa?4ICifxYUqXP5%->&7F`5dPLcC|yXLV+5yyey_yI*< zzaAH^ImiMoC}6Iq)Fx&3%WB9wDE4`K(b@Nx(A=9nXc$qMLbw=N)0i zvdHDHIA=`UlCb4F#Cknc%TI(OXZQoijYl`alYSXO56rv?96R~O<&!>5N`nKpJYtm( zVF;GHa(V7P9Y_*v1(+Q@Hfg5?Q7YL=4==xfLy{9pfletsb!o}=J+kr7(;r*7d=KTx#t#4F;V@WP+6t*Nc(leFZRO z!8He~Tb3)R5GDEKRMC%0-TWu<{MRw&Vz0ec9hj()19vugywh8fB{nT4hzQy<{Xee5 z(YFURXTpXP>$>NVBnGRQCGOG%0_XKUZsLslHU9ZJ&wVolHML2xX~XTK6Y-@+%KSQHhlR z5-B-8_GTe_P10=1a_obKS+QDR-l+vimp!~G+C9vE(mutwrGw2r^~+j8kW`Bo#IWgF zi13Uf;LjnSJ3t0ZPpA1GUF8$x5a;axd z3}ly|>D2W~_C}Oo8XIU+oj27XSDZqs_S1?SVu!JA`Y1tz9{1_tOZ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Scripts/init.lua b/Scripts/init.lua index ec9e350..1693d0c 100644 --- a/Scripts/init.lua +++ b/Scripts/init.lua @@ -86,7 +86,7 @@ ball = { dofile("Scripts/world.lua") playerSpawn = game.spawn(player); -game.spawn(ball); +--game.spawn(ball); ------------------- -- SERIALIZING -- diff --git a/src/world.cpp b/src/world.cpp index 8c15ccc..a3923fa 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -128,11 +128,12 @@ double World::getHeight(double x, double y, double z) int h = 0.0; for (auto b : l.hitbox[wx]) { - if (b) + if (b == true) Y = h; h++; } - return Y; + std::cout << l.drawLayer << "," << wx << "," << Y << std::endl; + return (Y/unitSize); } } return 0; diff --git a/src/world.hpp b/src/world.hpp index fe4e400..6776e2c 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -88,22 +88,22 @@ private: public: SolidLayer(float z, sol::table tab) : Layer(z, tab) { if (tab["hitbox"] != nullptr) { - int width, height; + int width, height, channels; unsigned char* box = SOIL_load_image(std::string(tab["hitbox"]).c_str(), - &width, &height, 0, + &width, &height, &channels, SOIL_LOAD_RGBA); - for (int w = 0; w < width; w++) { + for (int w = 0; w < width*4; w+=4) { hitbox.push_back(std::vector(height)); for (int h = 0; h < height; h++) { - unsigned char* c = &box[(h) + (height*w*4)]; - // we want to read the red channel + unsigned char* c = &box[(w) + (width*h*4)]; + // we want to read the alpha if (c[3]) { - hitbox[w][h] = true; + hitbox[w/4][height-h] = true; } else - hitbox[w][h] = false; + hitbox[w/4][height-h] = false; } } -- 2.39.5