From cce7209221f3da1d4a17d99587bcfa29dff53116 Mon Sep 17 00:00:00 2001 From: mibi88 <76903855+mibi88@users.noreply.github.com> Date: Thu, 1 Aug 2024 19:08:47 +0200 Subject: [PATCH 01/10] Starting to add the inventory. --- assets-fx/1b/inventory.png | Bin 0 -> 608 bytes src/config.h | 2 ++ src/events.c | 2 +- src/game.h | 20 +++++++++++++++++++- src/inventory.c | 1 + src/inventory.h | 9 +++++++++ src/main.c | 11 +++++++++++ 7 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 assets-fx/1b/inventory.png create mode 100644 src/inventory.c create mode 100644 src/inventory.h diff --git a/assets-fx/1b/inventory.png b/assets-fx/1b/inventory.png new file mode 100644 index 0000000000000000000000000000000000000000..53d66aa231613a89d9ed36523940b082a6e53836 GIT binary patch literal 608 zcmV-m0-ybfP)3{Lk0GK~ur2{@U!(=_EWb|$j+t5&di*m81#s_vNe?~?Pl^Eam)x9B zb66Opc4nSAbZ4mLbIE|wL3{w$@^Qq<2gvdQ!po2rAR$Vo-tKy-4oS`}&?o?hAkYYV zb+_>4WJ)x}tK3>y^C~b9VGurEx?aTf9r|UVHQ)S?>)d*>QhdoU$a^w-uCDyl;oD-6 z337VwrbD{9tG?cU^m<-K&mt0 zMgda3+KmEkZvj%+m>oC3;LOwa7wf_HX2gIxi$XBCQX@$^luYb0O+ zGlJH)1i59ZabIBW2!xP#Tj#n&KmlA=8BQ&Lr;Y8}0yr>gqi~ELvtIfEQc>W^1i1;W z=K;Dfmpc5Qjj+(Cp)?Wp=t_9Z5a=#Xkg2^L5SpYW-hQX8t%D+%ZFsOh8t*~e? z4~PMdD{_~`5Jw)+zclavc78m;oD&?W51YR_o?$Kz(1yW0Ko@4CfELX8fPYX6tf78C zdiE#gYXPo)K>I#X3MTV_;5!joMSef-wky0Ucus|NU@#BppMEKSVDJcxo=-ma0<5@w uCg?^1&m$=zx^5J3dkc`lqk!E4?8Y1Fd5+CPx%%G#0000 Date: Thu, 1 Aug 2024 19:11:11 +0200 Subject: [PATCH 02/10] Ran clang-format. --- src/game.c | 2 +- src/inventory.h | 2 -- src/main.c | 7 ++++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/game.c b/src/game.c index 36e86b3..25b94eb 100644 --- a/src/game.c +++ b/src/game.c @@ -2,8 +2,8 @@ #include "config.h" #include "map.h" -#include "npc.h" #include "mapdata.h" +#include "npc.h" #include #include diff --git a/src/inventory.h b/src/inventory.h index 44c8613..2c41b82 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -4,6 +4,4 @@ /* The structs related to the inventory are defined in game.h */ #include "game.h" - - #endif diff --git a/src/main.c b/src/main.c index 9f25dbc..986e4ea 100644 --- a/src/main.c +++ b/src/main.c @@ -120,9 +120,10 @@ int main(void) { extern char *_message_buffer; _message_buffer = NULL; _message_buffer = malloc(MESSAGE_BUFFER_SZ); - if(!_message_buffer){ - dtext(64, 64, C_BLACK, "Failed to allocate the message buffer: not " - "enough RAM available. Press any key to quit."); + if(!_message_buffer) { + dtext(64, 64, C_BLACK, + "Failed to allocate the message buffer: not " + "enough RAM available. Press any key to quit."); dupdate(); getkey(); return 0; From 04d4c9e31eb4392b1e9cae91581661345c5ab7b3 Mon Sep 17 00:00:00 2001 From: mibi88 <76903855+mibi88@users.noreply.github.com> Date: Thu, 1 Aug 2024 19:14:29 +0200 Subject: [PATCH 03/10] Cleaner enums with clang-format. --- .clang-format | 1 + src/events.h | 6 +++++- src/game.h | 13 +++++++++++-- src/npc.h | 1 - 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.clang-format b/.clang-format index 196c51c..e35924c 100644 --- a/.clang-format +++ b/.clang-format @@ -10,3 +10,4 @@ IndentCaseBlocks: true IncludeBlocks: Regroup AllowShortBlocksOnASingleLine: Empty ColumnLimit: 80 +AllowShortEnumsOnASingleLine: false diff --git a/src/events.h b/src/events.h index f4a19bf..a095283 100644 --- a/src/events.h +++ b/src/events.h @@ -15,7 +15,11 @@ typedef struct { unsigned int vars; } EventHandler; -typedef enum { T_NULL, T_VAR_EDIT, T_AMOUNT } Token; +typedef enum { + T_NULL, + T_VAR_EDIT, + T_AMOUNT +} Token; typedef enum { OP_NULL, diff --git a/src/game.h b/src/game.h index 0728ac5..f82c51b 100644 --- a/src/game.h +++ b/src/game.h @@ -8,9 +8,18 @@ #include /* The direction where the player is going to. */ -typedef enum { D_UP, D_DOWN, D_LEFT, D_RIGHT } Direction; +typedef enum { + D_UP, + D_DOWN, + D_LEFT, + D_RIGHT +} Direction; -typedef enum { P_LEFTUP = -1, P_CENTER = 0, P_RIGHTDOWN = 1 } Checkpos; +typedef enum { + P_LEFTUP = -1, + P_CENTER = 0, + P_RIGHTDOWN = 1 +} Checkpos; typedef enum { I_NONE, diff --git a/src/npc.h b/src/npc.h index 8c7f83e..2726e20 100644 --- a/src/npc.h +++ b/src/npc.h @@ -13,7 +13,6 @@ enum { NPC_FRIENDLY = 1, // The player's team NPC_HOSTILE = 2, // to the player NPC_ALL = 3 - }; /* /!\ Warning /!\ From 4d2eb2e8de82cc702a47509d85fe918a698d14a9 Mon Sep 17 00:00:00 2001 From: mibi88 <76903855+mibi88@users.noreply.github.com> Date: Thu, 1 Aug 2024 20:05:28 +0200 Subject: [PATCH 04/10] Graphics for the inventory. --- assets-cg/inventory.ase | Bin 0 -> 5780 bytes assets-cg/inventory.png | Bin 0 -> 2892 bytes assets-cg/player_female_inv.png | Bin 0 -> 536 bytes assets-cg/player_male_inv.png | Bin 0 -> 421 bytes assets-fx/1b/fxconv-metadata.txt | 4 ++++ assets-fx/2b/fxconv-metadata.txt | 4 ++++ assets-fx/2b/inventory.png | Bin 0 -> 608 bytes 7 files changed, 8 insertions(+) create mode 100644 assets-cg/inventory.ase create mode 100644 assets-cg/inventory.png create mode 100644 assets-cg/player_female_inv.png create mode 100644 assets-cg/player_male_inv.png create mode 100644 assets-fx/2b/inventory.png diff --git a/assets-cg/inventory.ase b/assets-cg/inventory.ase new file mode 100644 index 0000000000000000000000000000000000000000..4e9487ad183f942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=CedDOt8~7?1c}uc_F^}1q=elrfFAYie?d?8aK%9L^dY#tgl~y$5;`K`-#h^ z_3`3%{C;oEk=$_54s^3xN09_~I5{TXT%zb3OO4(@9^^K=;Pm=bJf;9@h zDo>IVW1o1Y5TDXH^@&_>3|J+T9xmnO6qd7T2po<|hfakDUWxQ4T&T?Le7;S(y zQ5-Y-Pd@MPt>T>m@^UAq)wY-nrjl~UtWKGA&fw31hYyy5~#lsp(NFlk9k-eypI z!ozEAs4>|%oHu^-Jiv{NdY=~LUctsraRBx8;1&+jIjD3xt6`95Nul0($>Ot@bFZ)i zF}|c-z|Bm(4yg`=S ztObpA;c|Is09g1GOjcGd^4$4QOa`%hGnA&HU@lXbCh;1k?S~ zRiVWKu`I8p+E1;@_|YS8d||g_6u4(BzVxHw%ja{RD>Fx@6*|idwsA#X1lJ8_f8hwv zr7US7HA<4i!ElFOH>Y?p?Bc@aXwhhT?OT)R@C|mP0XzU+}c- zN#!ff_v7F_5xg*C+yqjqw3xiO!6rb)E2~~3v?kxzy6?=Xbk8E#eDwpWw_%7rq=`d-m8Km6Q*Ku6 zi6}>S1|^@y&FrA44oE0qMmUnX4tz!s!Wt)bpq|?0c*6>B+-Om~`b?Q*^@+wvL2$;2 zorZaElhBUp1{z2atcD9GF z4eK5?i2Y7ZBlhN9Ox;`D>(rE4$#U3ulo$T5d~hWBVA&z0j+wUwEf3(i|1ls`iShWB z5^S3BlFNrVYrM2sz1JM_PPTMs$R(J`m;KnhHtdbQY64|!d-Cc!{B|2QU!e7e#Xd4X zF}82FR=0@2+?J6^rwYJb{ZSFn0qEb~7yrw3^8eSpC2%fcW6MU7d>6PSgB*T#wXHoK GaOIzA1zywu literal 0 HcmV?d00001 diff --git a/assets-cg/player_female_inv.png b/assets-cg/player_female_inv.png new file mode 100644 index 0000000000000000000000000000000000000000..49e2bae8e726890aba65a0a65df0f3e5bf0d86e7 GIT binary patch literal 536 zcmV+z0_XjSP)6hYshwWQC>&t;MQsk4p z>z$h$J4*<_wjId;$vi`X^J62fMj!(!)jF4wx*#A!U<87fA!+@rlsgp(&AvGze?=m@ ze@T&lg+xTJhPCZ)9HKho6=|&eJQC@tDXUQ`n65b^#|`U|M5La;p&T6{#it2K5E)Q< z+hx$lDqrHHPtEjDs8S{}!D-M!XI2kpJ+Yct;DkJqDnh8aS&bXcSw&9}*8^}!5#=3l z5Q=@IW@V_zF{aIvAmFz#k`xgemq{^O3~EecRwsC+f&`G7b>WS6an;Ip`vPXm&NrnE zDhhTS8}4(74Dr_2m@j>V5r_onNK{uYfY~yUA^#k$#YC1ZTOyMs;gXiU>CEUHTw-cT z!H`UdDvzWj0QALE61n&sCNZl-q82J5hUlmxt;vr)vR;cpuix)j)gPEBA9#x=lUnLe zbNBc$N)>HhtjJ~~NA36RSoMGA@#%9flli39iM9bD%i!96FbOZ!nVO~Hv<4%6A>30rtm;XHX?ww&rbk=`TR@VL-a^0V~KgxXh literal 0 HcmV?d00001 diff --git a/assets-cg/player_male_inv.png b/assets-cg/player_male_inv.png new file mode 100644 index 0000000000000000000000000000000000000000..0361d95fc8f02f129e25e2e15220780b5b26c7aa GIT binary patch literal 421 zcmV;W0b2fvP)X!Z*B5w@V?1YCk@w+$=~Og&DIY zy)hIaLB)8)J|ja2F+U^c6NKatV6SZns=P)45b2+l8W%chYY8gmjQk488IBk_-eNow zzcm(8&c%9RT3#dez@-A@9fIBE^qO(B-gmg|uzEO7-Pk*G57gs?}P6UQ999 zm&A$5Ll`>-1Pc}`HHSKqs95i9y&L4jM_vDQd P00000NkvXXu0mjf4JozV literal 0 HcmV?d00001 diff --git a/assets-fx/1b/fxconv-metadata.txt b/assets-fx/1b/fxconv-metadata.txt index 9f0baf7..400e93b 100644 --- a/assets-fx/1b/fxconv-metadata.txt +++ b/assets-fx/1b/fxconv-metadata.txt @@ -1,3 +1,7 @@ INFO_Icon.png: type: bopti-image name: INFO_Icon_img + +inventory.png: + type: bopti-image + name: inventory_img diff --git a/assets-fx/2b/fxconv-metadata.txt b/assets-fx/2b/fxconv-metadata.txt index 9f0baf7..400e93b 100644 --- a/assets-fx/2b/fxconv-metadata.txt +++ b/assets-fx/2b/fxconv-metadata.txt @@ -1,3 +1,7 @@ INFO_Icon.png: type: bopti-image name: INFO_Icon_img + +inventory.png: + type: bopti-image + name: inventory_img diff --git a/assets-fx/2b/inventory.png b/assets-fx/2b/inventory.png new file mode 100644 index 0000000000000000000000000000000000000000..53d66aa231613a89d9ed36523940b082a6e53836 GIT binary patch literal 608 zcmV-m0-ybfP)3{Lk0GK~ur2{@U!(=_EWb|$j+t5&di*m81#s_vNe?~?Pl^Eam)x9B zb66Opc4nSAbZ4mLbIE|wL3{w$@^Qq<2gvdQ!po2rAR$Vo-tKy-4oS`}&?o?hAkYYV zb+_>4WJ)x}tK3>y^C~b9VGurEx?aTf9r|UVHQ)S?>)d*>QhdoU$a^w-uCDyl;oD-6 z337VwrbD{9tG?cU^m<-K&mt0 zMgda3+KmEkZvj%+m>oC3;LOwa7wf_HX2gIxi$XBCQX@$^luYb0O+ zGlJH)1i59ZabIBW2!xP#Tj#n&KmlA=8BQ&Lr;Y8}0yr>gqi~ELvtIfEQc>W^1i1;W z=K;Dfmpc5Qjj+(Cp)?Wp=t_9Z5a=#Xkg2^L5SpYW-hQX8t%D+%ZFsOh8t*~e? z4~PMdD{_~`5Jw)+zclavc78m;oD&?W51YR_o?$Kz(1yW0Ko@4CfELX8fPYX6tf78C zdiE#gYXPo)K>I#X3MTV_;5!joMSef-wky0Ucus|NU@#BppMEKSVDJcxo=-ma0<5@w uCg?^1&m$=zx^5J3dkc`lqk!E4?8Y1Fd5+CPx%%G#0000 Date: Thu, 1 Aug 2024 23:09:04 +0200 Subject: [PATCH 05/10] Started inventory rendering. --- CMakeLists.txt | 11 ++- assets-cg/base_slot.png | Bin 0 -> 223 bytes assets-cg/inventory.png | Bin 2892 -> 2878 bytes assets-cg/items.png | Bin 0 -> 666 bytes assets-cg/selected.png | Bin 0 -> 206 bytes assets-cg/selection.png | Bin 0 -> 211 bytes assets-fx/1b/fxconv-metadata.txt | 4 + assets-fx/1b/items.png | Bin 0 -> 181 bytes assets-fx/2b/fxconv-metadata.txt | 4 + assets-fx/2b/items.png | Bin 0 -> 181 bytes assets-fx/selected.png | Bin 0 -> 93 bytes assets-fx/selection.png | Bin 0 -> 90 bytes src/config.h | 1 + src/game.c | 141 +++++++++++++++++-------------- src/game.h | 6 ++ src/inventory.c | 50 +++++++++++ src/inventory.h | 2 + src/main.c | 51 +++++------ 18 files changed, 182 insertions(+), 88 deletions(-) create mode 100644 assets-cg/base_slot.png create mode 100644 assets-cg/items.png create mode 100644 assets-cg/selected.png create mode 100644 assets-cg/selection.png create mode 100644 assets-fx/1b/items.png create mode 100644 assets-fx/2b/items.png create mode 100644 assets-fx/selected.png create mode 100644 assets-fx/selection.png diff --git a/CMakeLists.txt b/CMakeLists.txt index e646b91..ae1e57a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ set(SOURCES src/npc.c src/events.c src/animation.c + src/inventory.c # ... ) # Shared assets, fx-9860G-only assets and fx-CG-50-only assets @@ -56,6 +57,8 @@ set(ASSETS set(ASSETS_cg assets-cg/player_male.png assets-cg/player_female.png + assets-cg/player_male_inv.png + assets-cg/player_female_inv.png assets-cg/npc/char/npc_male.png assets-cg/npc/char/npc_female.png assets-cg/npc/char/npc_milkman.png @@ -69,6 +72,8 @@ set(ASSETS_cg assets-cg/INFO_Icon.png assets-cg/player_face.png assets-cg/font.png + assets-cg/inventory.png + assets-cg/items.png ) set(ASSETS_cg_EGA64 @@ -98,6 +103,8 @@ set(ASSETS_fx_1b assets-fx/1b/npc/face/npc_milkman.png assets-fx/1b/npc/face/npc_police.png assets-fx/1b/INFO_Icon.png + assets-fx/1b/inventory.png + assets-fx/1b/items.png # ... ) @@ -112,7 +119,9 @@ set(ASSETS_fx_2b assets-fx/2b/npc/face/npc_female.png assets-fx/2b/npc/face/npc_milkman.png assets-fx/2b/npc/face/npc_police.png - assets-fx/1b/INFO_Icon.png + assets-fx/2b/INFO_Icon.png + assets-fx/2b/inventory.png + assets-fx/2b/items.png # ... ) diff --git a/assets-cg/base_slot.png b/assets-cg/base_slot.png new file mode 100644 index 0000000000000000000000000000000000000000..8a45491edb2abd227ce4927331af6a2b276d6a71 GIT binary patch literal 223 zcmV<503iQ~P)Y+GE)aG@{k$aoS4NtR2^K! z5c(QGSZn&Y2#-E)G|WP*X!sqyE+Q}n&C!^L7H#n=hH8|kHbwtcxTf{D{8vk^QNR;k}2=(ykj?bVYq0Tf>=+LQc6`eYlj^gb1 Zd;+A>Nhl%vb^HJT002ovPDHLkV1nX4T%Q*8=l&7VvyiB2m`u`9D$ArO+(V~Nip=93)4!G z8u?*Y7N=x={Q9wDV?@rk3!5*bCb$rF6?6;)3xW? z8#j2Tx;8e6?7% zmSm;zjex;7)qWkc2;Ki_P_tZ|#3YKQ#WmqU#nxJ86H z7WL&6u%qFNjtj#ZC6q_4b{RI~JgPKLtKQxj1L@ zKiaZ_A?hK&AOIn4SZ4&tSgDv;s97*Yu|_-uWU>bHZichoFr`qHpgPqgezV+-M0>iN z%}*Dk>0BHebt2kTj@-ss(bDG=z0wPz!JeL|rhD{4iX1J^nTTr{xTd|07uJXFwrn2% zBvx+JfNE*#O7quVPyFz8due|%{CHi^H3m74JvqUB0s!-^uQ^k5quB$~gZeNNlRd-J zo3xF&aE@h5&Ec%~L>=y+Ax!_OuL98AXtoJDG#^S8TdS(MeLQA5JF`UePYh2P9&)G( z!q~s#B*KqZ2Hj%ddyx*MfXHlCGp$edwhxykV0X%WU$<Q6Wk-w9>^oxLm#04+jb{uV8>Tps194&C{AfA=+s{4l1Q7C@tESeJeA;X+UrM zdyLnZO?y`y8-5p^*I<*TpxUNuy+!$HRech*<}imK{?aw>#yd1&4{ zZ7DYATY32>OE4_~&rM64ky6eo@S7}GZF_LHH)`x<6>-wj^w{TaVDXg=s0WFG_a@qn zl@kr^jN{KddF-Ztd&p&K!@}Dmrz%rD6qW46Mt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(bke@was*vBzUxm}a?>4rL_Xg^$lS@N zZ#fd7YQ^fAWzT!$ih($4u8DzhQJnMzJ}Wo|h^gMrPROHBf~fsRL3nh`JFSq{O6C?F z0X4f(L_xOp7#_%}>ybC*qRmmw(nF_6r^Vs9Aq*w(-BBs~t~yTSg)tn6wzcZi;Odb# zP@W{DoA+(Y4(XMHE#%@F!6&cAO9ErNlXh}Q?A3DB)N-DsomoWP<1#x^TcV~4dV>!{bphpBB*}@SWJ5?TyMX2n<=<34b4j+xSl+QQa zjwer>?}Io@?-FJIHBq!xISL5mQ9h*WMfM+kZm%w=WG8Icf$B}z@KnCo3L><$I8;LQ z$H}J-zYrWRw@R7gb7C5Du=4IpoE7(D^?rs05o&mCOQh@cXTsaMUS4nL?*=IpAm88v zW?Ws?2R5?pGfIU076>flouVm>2yNf8G$$8#li2|bXI|J7F8BO#Nd3?vdc#Uy7u=|h^;_;uKQ>~xedF)}oMe#RY9LBo z93Vb6Ey9b`#|aq?sVistoa-BmswjjsP)~E4`A0ny=FaEqdMyL#VG+Mq_VEmu>07tS zF7bD|_2j}Uxj@Zp%1a_JqFIg^j1Q##>#-Ljm@JNBw0wD8(s(0)^nXP*r6*Gx%gC9I z6TY7X?o@4;+CTyRa-Mc;)JcrfkJaRYX7Yv3doBxyz$^8}{@+ DqlDG3 diff --git a/assets-cg/items.png b/assets-cg/items.png new file mode 100644 index 0000000000000000000000000000000000000000..3730ee2e93787d7efb8035e967a2d93d8c297061 GIT binary patch literal 666 zcmV;L0%iS)P)Q5a}paE>I@?M!#>`)f{zv@Gzzi^^jY zjUcmd@W6}4>waN{Nuc0?7nMg|oP~{`;DHyF_i}-QlxNWj9#v+^H_PM7me%DL`tOfQ zJPXs7VQI`Zt(Dg+m-~403Ujs$ZQ9zNRlJ;^KbA7Mw44pK+H^hM#cRbbk(OmyBx!h> z!Pn-a>Sk?As-q-z)9`Y(+iT$!%`i2*UY}^{a68leXrUh7K~ouuXK}d}-b~%3H?G7R zadne~J|kY6r>(m-bQmJ9|@+dM)hjX2hdeyi>4c|?iA4Tz%A470j(SC+qfFzl9ek-Ni2 zEhB8m)Z0Cf?kcR5wIkbnI|swN+ibPG!q2cCqLyW=b5^Tv*4DLi;gg4Uhe|D*(#rZ2 zrq%AS9%853h1k1d?NtMQ*CxR?=w(3c-r;PzwU_|11&DIo; zT3CC}j8WRtdJMutMg*D*Nl3Z6Spd(yzuKI>q3I_;{3a*`Ma9(YlC_{AJ};8ntJ zs=))V65hH29(a}TUMBFst0b<-r@n~|Jn%HU2c%N7FFW}h>i_@%07*qoM6N<$f?8@$ A*Z=?k literal 0 HcmV?d00001 diff --git a/assets-cg/selected.png b/assets-cg/selected.png new file mode 100644 index 0000000000000000000000000000000000000000..ae7cb57a1f3b92699b80d75535de7b83ee0338e3 GIT binary patch literal 206 zcmeAS@N?(olHy`uVBq!ia0vp^GC(ZN!3HGrIo|64si~eWjv*eMZ>L@4YB1n%-JAUX z|LL!j61eB~WwOj&-m%r#HP^+jkNbUfuia!9z9Z)u7Oc&-P7w@A6w7+iqaJ#%WS{qz zTVa_xr^W8JOv%E2t%d!zjItW@(DDKo3d*QdE(H5U8Dg(c5Y_I=%h{+WC9Nlrmza?ZtlV|=xZZ` zMPJ>Cc`Up@wis9qV;xmcQ^P9g@|<^JnZ{C8Bx3;Z%21JArse+9FYN#ia383=m!8&A z-n+`er%jP%r14L;P(tZ`m<3euamQx_I!4VjDrjqJ+l7wi(k`4Wt{dH+a45oD6XgH^ N002ovPDHLkV1j0WRf7Nk literal 0 HcmV?d00001 diff --git a/assets-fx/1b/fxconv-metadata.txt b/assets-fx/1b/fxconv-metadata.txt index 400e93b..881385f 100644 --- a/assets-fx/1b/fxconv-metadata.txt +++ b/assets-fx/1b/fxconv-metadata.txt @@ -5,3 +5,7 @@ INFO_Icon.png: inventory.png: type: bopti-image name: inventory_img + +items.png: + type: bopti-image + name: items_img diff --git a/assets-fx/1b/items.png b/assets-fx/1b/items.png new file mode 100644 index 0000000000000000000000000000000000000000..eeb6dbf22372575ae4cc6412e4c4b252ca0f4736 GIT binary patch literal 181 zcmeAS@N?(olHy`uVBq!ia0vp^7C_9w!2%@NzJ395YCK&WLo_Dt4RYjbFyP4U{r|tn zwujTgV3tJWrVG5c`gnd=a(FNbO~~-zwToUmzmvZ)Kf&@rSmgxWX*X6UEfcoBv_WX2*=FiKmX@9Hck|DT-5lV o$0uXa|Ct6N6IVX{4+M!S3=Ka-fBcqs^Z=y6)78&qol`;+09pGU`2YX_ literal 0 HcmV?d00001 diff --git a/assets-fx/selection.png b/assets-fx/selection.png new file mode 100644 index 0000000000000000000000000000000000000000..70920377b65f2f2bd75a2fb4a4cc6bb6e6fcaf8b GIT binary patch literal 90 zcmeAS@N?(olHy`uVBq!ia0vp^93afW0wnX;%77$;qNj^v2*=Fi1PA6G9v+_m7k_v# m{g;%Oabc@~SVH5=qnr%hJ}jKyYWA)JsrGdBb6Mw<&;$TErxy+Y literal 0 HcmV?d00001 diff --git a/src/config.h b/src/config.h index 87598ae..67e0b3a 100644 --- a/src/config.h +++ b/src/config.h @@ -13,6 +13,7 @@ #endif #define SLOT_NUM 9 +#define SLOT_COLUMNS 3 #if GINT_RENDER_RGB /* The tile size */ diff --git a/src/game.c b/src/game.c index 25b94eb..0b5306e 100644 --- a/src/game.c +++ b/src/game.c @@ -1,6 +1,7 @@ #include "game.h" #include "config.h" +#include "inventory.h" #include "map.h" #include "mapdata.h" #include "npc.h" @@ -135,6 +136,7 @@ void game_draw(Game *game) { dprint(8, 8, C_BLACK, "npc_count: %d", npc_count); dprint(8, 16, C_BLACK, "Mana: %d", game->mana); dprint(8, 24, C_BLACK, "X: %d Y: %d", game->player.x, game->player.y); + inventory_draw(game, &game->inventory); } /* Key management */ @@ -149,86 +151,99 @@ void game_get_inputs(Game *game) { if(keydown(KEY_EXIT)) game->exittoOS = true; - /* Player actions - Prototypes in player.h and implementation in player.c */ - if(keydown(KEY_LEFT)) - player_move(game, D_LEFT); - if(keydown(KEY_RIGHT)) - player_move(game, D_RIGHT); - if(keydown(KEY_UP)) - player_move(game, D_UP); - if(keydown(KEY_DOWN)) - player_move(game, D_DOWN); - if(keydown(KEY_SHIFT)) - player_action(game); - if(keydown(KEY_OPTN)) { - game->player.is_male = !game->player.is_male; + /* Inventory */ + if(keydown(KEY_ALPHA)) { + game->inventory.open = !game->inventory.open; /* TODO: Make something cleaner */ - while(keydown(KEY_OPTN)) { + while(keydown(KEY_ALPHA)) { clearevents(); sleep(); } - } - Player *player = &game->player; - if(keydown(KEY_SHIFT)) { - uint32_t i; - for(i = 0; i < game->map_level->nbPortal; i++) { - Portal *portal = &game->map_level->portals[i]; - if(player->x >= (int)portal->collider.x1 * PXSIZE && - player->x < (int)portal->collider.x2 * PXSIZE && - player->y >= (int)portal->collider.y1 * PXSIZE && - player->y < (int)portal->collider.y2 * PXSIZE) { - Portal *dest_portal = (Portal *)portal->portal; - Collider dest_collider = dest_portal->collider; - Map *dest_map = (Map *)portal->map; - player->x = (dest_collider.x1 + dest_collider.x2) / 2 * PXSIZE; - player->y = (dest_collider.y1 + dest_collider.y2) / 2 * PXSIZE; - game->map_level = dest_map; - /* TODO: Make something cleaner */ - while(keydown(KEY_SHIFT)) { - clearevents(); - sleep(); + } else { + /* Player actions - Prototypes in player.h and implementation in + * player.c */ + if(keydown(KEY_LEFT)) + player_move(game, D_LEFT); + if(keydown(KEY_RIGHT)) + player_move(game, D_RIGHT); + if(keydown(KEY_UP)) + player_move(game, D_UP); + if(keydown(KEY_DOWN)) + player_move(game, D_DOWN); + if(keydown(KEY_SHIFT)) + player_action(game); + if(keydown(KEY_OPTN)) { + game->player.is_male = !game->player.is_male; + /* TODO: Make something cleaner */ + while(keydown(KEY_OPTN)) { + clearevents(); + sleep(); + } + } + Player *player = &game->player; + if(keydown(KEY_SHIFT)) { + uint32_t i; + for(i = 0; i < game->map_level->nbPortal; i++) { + Portal *portal = &game->map_level->portals[i]; + if(player->x >= (int)portal->collider.x1 * PXSIZE && + player->x < (int)portal->collider.x2 * PXSIZE && + player->y >= (int)portal->collider.y1 * PXSIZE && + player->y < (int)portal->collider.y2 * PXSIZE) { + Portal *dest_portal = (Portal *)portal->portal; + Collider dest_collider = dest_portal->collider; + Map *dest_map = (Map *)portal->map; + player->x = + (dest_collider.x1 + dest_collider.x2) / 2 * PXSIZE; + player->y = + (dest_collider.y1 + dest_collider.y2) / 2 * PXSIZE; + game->map_level = dest_map; + /* TODO: Make something cleaner */ + while(keydown(KEY_SHIFT)) { + clearevents(); + sleep(); + } } } } - } - /*Temp debug*/ - if(keydown(KEY_F1)) { - NPC *mynpc = npc_create(); - if(mynpc) { - mynpc->curx = (player->x << PRECISION) / PXSIZE; - mynpc->cury = (player->y << PRECISION) / PXSIZE; - mynpc->x = player->x; - mynpc->y = player->x; - mynpc->hasPath = 0; - mynpc->face = 0; - mynpc->paused = 0; - mynpc->has_dialog = 0; + /*Temp debug*/ + if(keydown(KEY_F1)) { + NPC *mynpc = npc_create(); + if(mynpc) { + mynpc->curx = (player->x << PRECISION) / PXSIZE; + mynpc->cury = (player->y << PRECISION) / PXSIZE; + mynpc->x = player->x; + mynpc->y = player->x; + mynpc->hasPath = 0; + mynpc->face = 0; + mynpc->paused = 0; + mynpc->has_dialog = 0; + } } - } - /* Display Debug Information on screen */ + /* Display Debug Information on screen */ #if DEBUGMODE - if(keydown(KEY_F1)) { - game->debug_map = !game->debug_map; - } - if(keydown(KEY_F2)) { - game->debug_player = !game->debug_player; - } - if(keydown(KEY_F3)) { - game->debug_extra = !game->debug_extra; - } + if(keydown(KEY_F1)) { + game->debug_map = !game->debug_map; + } + if(keydown(KEY_F2)) { + game->debug_player = !game->debug_player; + } + if(keydown(KEY_F3)) { + game->debug_extra = !game->debug_extra; + } #endif - /* if USB is enabled - keybinding for screencapture */ + /* if USB is enabled - keybinding for screencapture */ #if USB_FEATURE - if(keydown(KEY_7)) - game->screenshot = true; - if(keydown(KEY_8)) - game->record = !game->record; + if(keydown(KEY_7)) + game->screenshot = true; + if(keydown(KEY_8)) + game->record = !game->record; #endif // USB_FEATURE + } } void game_update_animations(Game *game, unsigned char ms) { diff --git a/src/game.h b/src/game.h index f82c51b..a58a438 100644 --- a/src/game.h +++ b/src/game.h @@ -25,6 +25,7 @@ typedef enum { I_NONE, I_ARMOR, I_GLOVE, + I_SWORD, I_BEER, I_MILK, I_TALISMAN, @@ -38,6 +39,10 @@ typedef struct { typedef struct { Slot slots[SLOT_NUM]; + Slot talisman; + Slot armor; + Slot weapon; + char open : 1; } Inventory; typedef struct { @@ -204,6 +209,7 @@ typedef struct { bool debug_extra; Animation npc_animation; + Inventory inventory; int mana; /* Only for testing events TODO: Remove this! */ } Game; diff --git a/src/inventory.c b/src/inventory.c index 91f36e5..511bf51 100644 --- a/src/inventory.c +++ b/src/inventory.c @@ -1 +1,51 @@ #include "inventory.h" + +#include + +extern bopti_image_t inventory_img; +extern bopti_image_t items_img; +extern bopti_image_t player_male_inv_img; +extern bopti_image_t player_female_inv_img; + +void inventory_draw(Game *game, Inventory *inventory) { + size_t i; + /* TODO: Cleanup! */ + inventory->slots[5].i = I_GLOVE; + inventory->armor.i = I_ARMOR; + inventory->talisman.i = I_TALISMAN; + inventory->weapon.i = I_SWORD; + if(inventory->open) { + dimage(0, 0, &inventory_img); + for(i=0;islots[i].i*28, 0, 28, 27, + DIMAGE_NONE); +#else + dsubimage(88+(i%SLOT_COLUMNS)*12, 24+(i/SLOT_COLUMNS)*12, + &items_img, inventory->slots[i].i*8, 0, 8, 8, + DIMAGE_NONE); +#endif + } +#if GINT_RENDER_RGB + dsubimage(222, 87, &items_img, inventory->talisman.i*28, 0, 28, 27, + DIMAGE_NONE); + dsubimage(222, 87+32, &items_img, inventory->armor.i*28, 0, 28, 27, + DIMAGE_NONE); + dsubimage(222, 87+64, &items_img, inventory->weapon.i*28, 0, 28, 27, + DIMAGE_NONE); +#else + dsubimage(72, 24, &items_img, inventory->talisman.i*8, 0, 8, 8, + DIMAGE_NONE); + dsubimage(72, 24+12, &items_img, inventory->armor.i*8, 0, 8, 8, + DIMAGE_NONE); + dsubimage(72, 24+24, &items_img, inventory->weapon.i*8, 0, 8, 8, + DIMAGE_NONE); +#endif +#if GINT_RENDER_RGB + dimage(183, 20, + game->player.is_male ? &player_male_inv_img + : &player_female_inv_img); +#endif + } +} diff --git a/src/inventory.h b/src/inventory.h index 2c41b82..b8a0368 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -4,4 +4,6 @@ /* The structs related to the inventory are defined in game.h */ #include "game.h" +void inventory_draw(Game *game, Inventory *inventory); + #endif diff --git a/src/main.c b/src/main.c index 986e4ea..e9762af 100644 --- a/src/main.c +++ b/src/main.c @@ -32,31 +32,34 @@ extern Map *worldRPG[]; /* Game data (defined in "game.h")*/ -Game game = {NULL, - {12 * PXSIZE, - 36 * PXSIZE, - 0, - 0, - 100, - SPEED, - false, - 0, - false, - false, - true, - {}}, - {{}, {}, 0}, - false, - false, - false, - 0, +Game game = { + NULL, + {12 * PXSIZE, + 36 * PXSIZE, + 0, + 0, + 100, + SPEED, + false, + 0, + false, + false, + true, + {}}, + {{}, {}, 0}, + false, + false, + false, + 0, - /* debug variables*/ - false, - false, - false, - {}, - 100}; + /* debug variables*/ + false, + false, + false, + {}, + {}, + 100, +}; /* screen capture management code. TODO: Clean this up! */ From 311b7f27df05bdecf56ec07dec6abba93907205a Mon Sep 17 00:00:00 2001 From: mibi88 <76903855+mibi88@users.noreply.github.com> Date: Thu, 1 Aug 2024 23:09:43 +0200 Subject: [PATCH 06/10] Ran clang-format --- src/inventory.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/inventory.c b/src/inventory.c index 511bf51..1e135d7 100644 --- a/src/inventory.c +++ b/src/inventory.c @@ -16,30 +16,30 @@ void inventory_draw(Game *game, Inventory *inventory) { inventory->weapon.i = I_SWORD; if(inventory->open) { dimage(0, 0, &inventory_img); - for(i=0;islots[i].i*28, 0, 28, 27, - DIMAGE_NONE); + dsubimage(272 + (i % SLOT_COLUMNS) * 32, + 87 + (i / SLOT_COLUMNS) * 32, &items_img, + inventory->slots[i].i * 28, 0, 28, 27, DIMAGE_NONE); #else - dsubimage(88+(i%SLOT_COLUMNS)*12, 24+(i/SLOT_COLUMNS)*12, - &items_img, inventory->slots[i].i*8, 0, 8, 8, - DIMAGE_NONE); + dsubimage(88 + (i % SLOT_COLUMNS) * 12, + 24 + (i / SLOT_COLUMNS) * 12, &items_img, + inventory->slots[i].i * 8, 0, 8, 8, DIMAGE_NONE); #endif } #if GINT_RENDER_RGB - dsubimage(222, 87, &items_img, inventory->talisman.i*28, 0, 28, 27, + dsubimage(222, 87, &items_img, inventory->talisman.i * 28, 0, 28, 27, DIMAGE_NONE); - dsubimage(222, 87+32, &items_img, inventory->armor.i*28, 0, 28, 27, + dsubimage(222, 87 + 32, &items_img, inventory->armor.i * 28, 0, 28, 27, DIMAGE_NONE); - dsubimage(222, 87+64, &items_img, inventory->weapon.i*28, 0, 28, 27, + dsubimage(222, 87 + 64, &items_img, inventory->weapon.i * 28, 0, 28, 27, DIMAGE_NONE); #else - dsubimage(72, 24, &items_img, inventory->talisman.i*8, 0, 8, 8, + dsubimage(72, 24, &items_img, inventory->talisman.i * 8, 0, 8, 8, DIMAGE_NONE); - dsubimage(72, 24+12, &items_img, inventory->armor.i*8, 0, 8, 8, + dsubimage(72, 24 + 12, &items_img, inventory->armor.i * 8, 0, 8, 8, DIMAGE_NONE); - dsubimage(72, 24+24, &items_img, inventory->weapon.i*8, 0, 8, 8, + dsubimage(72, 24 + 24, &items_img, inventory->weapon.i * 8, 0, 8, 8, DIMAGE_NONE); #endif #if GINT_RENDER_RGB From 5dab7f9f1800b4cf7d612e6b539440158bbd81a3 Mon Sep 17 00:00:00 2001 From: mibi88 <76903855+mibi88@users.noreply.github.com> Date: Fri, 2 Aug 2024 12:59:10 +0200 Subject: [PATCH 07/10] Cleaner inventory rendering --- assets-cg/items.png | Bin 666 -> 684 bytes assets/converters.py | 2 +- src/config.h | 20 ++++++++++++++++---- src/game.h | 10 ++++++---- src/inventory.c | 39 ++++++++++----------------------------- 5 files changed, 33 insertions(+), 38 deletions(-) diff --git a/assets-cg/items.png b/assets-cg/items.png index 3730ee2e93787d7efb8035e967a2d93d8c297061..08ed2c27f0c219cff45abd95e639038b900c65fc 100644 GIT binary patch delta 660 zcmV;F0&D%61*`>-B!6>BL_t(|ob8-jj>8}fMd@g^m@aa%$j%oMLdN)oF{$ro3mj}> zFqGz1g6i)oAME@0U0%sco;A<3Q(Dc88cFKhh9BrzX#r zht0~Avb*ft5)fKvQtMPBEuFcN2en!2X?a-N)V@%8Cy(E+u2~yNoLS4(y7w&`h*7(< z`j$K@(~{RRq4HKdN?>Yum<7vtq2+(=Yg}} zRcV+U-e^oXeSi47%Evur>Wzeq(9BHQ+?Cos^}*$=MwFRP)91bnWpM%QmY=;erd;ai1WAw1P@#CGM{s{-EZkl+d0 z9uVFqDpXz#4C;{{m52Q>#cfMkhN^Gmxu;C;ySykj7NHXZ?re(v^pCZ{z2-pWLG5Wy z%s9MO(tn3a%9BdMgVInAFT@_g;>1CEEbzdK%3~9aAhU4rz>CJ~eqn`4px}WQl}BEjg^i%#fftqc za)E>8OkY1w9TYt9qVk^pplxNWj9#v+^H_PM7me%DL`tOfQJPXs7VQI`Zt(Dg+m-~403Ujs$ZQ9zNRlJ;^ zKbA7Mw44pK+H^hM#cRbbk(OmyBx!h>!Pn-a>Sk?As-q-z)9`Y(+iT$!%`i2*UY}^{ za68leXrUh7L4Q*jif3`T7T!$Vq&Kd_8*z1$ggzr)o2RY2Hgp>CcIV?}{*hN`d1T1+ zYpNSc;@-V98Vufyo$?Bgw5-}*OGth3sgj>0MwB$1n~bP>MwSc)Pun~~CXG1Oihir@ z>v=?p!VQR`(G0V?b61wXdob*lbdkHmMlB<3$kf|CkbmwftdzAQ+k86*!@JvTwYmt8UiTwR7Qo{6d*n0QXd|A+rF-zG@@96-G`w2Y zo65?w%6h`1!cYy5Ttj&50BDb3MB;hP))bFgSbNWmQQFgb49CLjZM$mMF*xlCo;y!_ z(!kR`>tJ{~?W%=xk{Aabcu{%y#Tz00000NkvXXu0mjf*3C`i diff --git a/assets/converters.py b/assets/converters.py index 2d267f9..c3ddc50 100644 --- a/assets/converters.py +++ b/assets/converters.py @@ -142,7 +142,7 @@ def convert_map(input: str, output: str, params: dict, target): indoor = int(input_map.get_property("indoor")) except Exception as e: # Show a warning - print(f"WARNING: Indoor property not found.\n") + print(f"WARNING: Indoor property not found.") if indoor: # Get the indoor tileset diff --git a/src/config.h b/src/config.h index 67e0b3a..2176fa1 100644 --- a/src/config.h +++ b/src/config.h @@ -25,9 +25,15 @@ /* The size of the player */ #define P_WIDTH 16 #define P_HEIGHT 16 -/*Max number of dynamic NPCs.*/ +/* Max number of dynamic NPCs. */ #define NPC_STACK_SIZE 256 - +/* The position of the slots in the inventory */ +#define SLOT_Y 87 +#define SLOT_X_EQUIPPED 222 +#define SLOT_X 272 +#define SLOT_W 28 +#define SLOT_H 27 +#define SLOT_SPACING 32 #else /* The tile size */ #define T_HEIGHT 8 @@ -38,9 +44,15 @@ /* The player size */ #define P_WIDTH 8 #define P_HEIGHT 8 -/*Max number of "dynamic" NPCs. We are starved for static ram on fx !*/ +/* Max number of "dynamic" NPCs. We are starved for static ram on fx ! */ #define NPC_STACK_SIZE 32 - +/* The position of the slots in the inventory */ +#define SLOT_Y 24 +#define SLOT_X_EQUIPPED 72 +#define SLOT_X 88 +#define SLOT_W 8 +#define SLOT_H 8 +#define SLOT_SPACING 12 #endif /* SPEED should NOT be 8 or bigger: it may cause bugs when handling diff --git a/src/game.h b/src/game.h index a58a438..be88cd4 100644 --- a/src/game.h +++ b/src/game.h @@ -33,15 +33,17 @@ typedef enum { } Item; typedef struct { - Item i; + Item i : 4; unsigned char durability; } Slot; typedef struct { + /* Backpack slots. */ Slot slots[SLOT_NUM]; - Slot talisman; - Slot armor; - Slot weapon; + /* Equipped items: first slot: talisman, second slot: armor, last slot: + weapon. */ + Slot equipped[3]; + /* 1 if the inventory is open. */ char open : 1; } Inventory; diff --git a/src/inventory.c b/src/inventory.c index 1e135d7..b2a1145 100644 --- a/src/inventory.c +++ b/src/inventory.c @@ -9,40 +9,21 @@ extern bopti_image_t player_female_inv_img; void inventory_draw(Game *game, Inventory *inventory) { size_t i; - /* TODO: Cleanup! */ - inventory->slots[5].i = I_GLOVE; - inventory->armor.i = I_ARMOR; - inventory->talisman.i = I_TALISMAN; - inventory->weapon.i = I_SWORD; if(inventory->open) { dimage(0, 0, &inventory_img); for(i = 0; i < SLOT_NUM; i++) { -#if GINT_RENDER_RGB - dsubimage(272 + (i % SLOT_COLUMNS) * 32, - 87 + (i / SLOT_COLUMNS) * 32, &items_img, - inventory->slots[i].i * 28, 0, 28, 27, DIMAGE_NONE); -#else - dsubimage(88 + (i % SLOT_COLUMNS) * 12, - 24 + (i / SLOT_COLUMNS) * 12, &items_img, - inventory->slots[i].i * 8, 0, 8, 8, DIMAGE_NONE); -#endif + dsubimage(SLOT_X + (i % SLOT_COLUMNS) * SLOT_SPACING, + SLOT_Y + (i / SLOT_COLUMNS) * SLOT_SPACING, &items_img, + inventory->slots[i].i * SLOT_W, 0, SLOT_W, SLOT_H, + DIMAGE_NONE); + } + for(i = 0; i < 3; i++) { + dsubimage(SLOT_X_EQUIPPED, SLOT_Y + i * SLOT_SPACING, &items_img, + inventory->equipped[i].i * SLOT_W, 0, SLOT_W, SLOT_H, + DIMAGE_NONE); } #if GINT_RENDER_RGB - dsubimage(222, 87, &items_img, inventory->talisman.i * 28, 0, 28, 27, - DIMAGE_NONE); - dsubimage(222, 87 + 32, &items_img, inventory->armor.i * 28, 0, 28, 27, - DIMAGE_NONE); - dsubimage(222, 87 + 64, &items_img, inventory->weapon.i * 28, 0, 28, 27, - DIMAGE_NONE); -#else - dsubimage(72, 24, &items_img, inventory->talisman.i * 8, 0, 8, 8, - DIMAGE_NONE); - dsubimage(72, 24 + 12, &items_img, inventory->armor.i * 8, 0, 8, 8, - DIMAGE_NONE); - dsubimage(72, 24 + 24, &items_img, inventory->weapon.i * 8, 0, 8, 8, - DIMAGE_NONE); -#endif -#if GINT_RENDER_RGB + /* Render the player between the two swords if we are on cg. */ dimage(183, 20, game->player.is_male ? &player_male_inv_img : &player_female_inv_img); From b26cf53e91460b69095ae7ae39400acc47d5fd5c Mon Sep 17 00:00:00 2001 From: mibi88 <76903855+mibi88@users.noreply.github.com> Date: Fri, 2 Aug 2024 16:14:04 +0200 Subject: [PATCH 08/10] Inventory item selection. --- CMakeLists.txt | 4 +++ assets-fx/fxconv-metadata.txt | 8 +++++ src/game.c | 46 ++++++++++++++++++++++-- src/game.h | 3 ++ src/inventory.c | 66 +++++++++++++++++++++++++++++++++-- src/inventory.h | 5 ++- 6 files changed, 126 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae1e57a..6d258ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,8 @@ set(ASSETS_cg assets-cg/font.png assets-cg/inventory.png assets-cg/items.png + assets-cg/selection.png + assets-cg/selected.png ) set(ASSETS_cg_EGA64 @@ -88,6 +90,8 @@ set(ASSETS_fx assets-fx/SGN_Icon.png assets-fx/player_face.png assets-fx/font.png + assets-fx/selection.png + assets-fx/selected.png # ... ) diff --git a/assets-fx/fxconv-metadata.txt b/assets-fx/fxconv-metadata.txt index 1d7d0f9..b3556bf 100644 --- a/assets-fx/fxconv-metadata.txt +++ b/assets-fx/fxconv-metadata.txt @@ -17,6 +17,14 @@ SGN_Icon.png: type: bopti-image name: SGN_Icon_img +selection.png: + type: bopti-image + name: selection_img + +selected.png: + type: bopti-image + name: selected_img + font.png: name: fontRPG type: font diff --git a/src/game.c b/src/game.c index 0b5306e..61f8987 100644 --- a/src/game.c +++ b/src/game.c @@ -36,6 +36,7 @@ void game_init(Game *game) { events_init_handler(&game->handler); events_bind_variable(&game->handler, (int *)&game->player.life, "life"); events_bind_variable(&game->handler, &game->mana, "mana"); + inventory_init(&game->inventory); // reload_npc(&game); } @@ -122,8 +123,10 @@ void game_render_indicator(Game *game) { /* Draw everything. */ void game_draw(Game *game) { - /*Only clear if we are inside, the screen is guaranteed to be filled + /* Only clear if we are inside, the screen is guaranteed to be filled * otherwise */ + /* (Mibi88) if we do so, we should only use opaque tiles in the background + layer (it's currently not the case), to artefacts when rendering dialogs. */ if(game->map_level->indoor) dclear(C_WHITE); map_render_by_layer(game, BACKGROUND); @@ -136,7 +139,7 @@ void game_draw(Game *game) { dprint(8, 8, C_BLACK, "npc_count: %d", npc_count); dprint(8, 16, C_BLACK, "Mana: %d", game->mana); dprint(8, 24, C_BLACK, "X: %d Y: %d", game->player.x, game->player.y); - inventory_draw(game, &game->inventory); + inventory_draw(&game->inventory, &game->player); } /* Key management */ @@ -159,6 +162,45 @@ void game_get_inputs(Game *game) { clearevents(); sleep(); } + } else if(game->inventory.open) { + if(keydown(KEY_LEFT)) + inventory_move_selection(&game->inventory, D_LEFT); + /* TODO: Make something cleaner */ + while(keydown(KEY_LEFT)) { + clearevents(); + sleep(); + } + if(keydown(KEY_RIGHT)) + inventory_move_selection(&game->inventory, D_RIGHT); + /* TODO: Make something cleaner */ + while(keydown(KEY_RIGHT)) { + clearevents(); + sleep(); + } + if(keydown(KEY_UP)) + inventory_move_selection(&game->inventory, D_UP); + /* TODO: Make something cleaner */ + while(keydown(KEY_UP)) { + clearevents(); + sleep(); + } + if(keydown(KEY_DOWN)) + inventory_move_selection(&game->inventory, D_DOWN); + /* TODO: Make something cleaner */ + while(keydown(KEY_DOWN)) { + clearevents(); + sleep(); + } + if(keydown(KEY_SHIFT)) + game->inventory.selected = game->inventory.selection; + if(keydown(KEY_OPTN)) { + game->player.is_male = !game->player.is_male; + /* TODO: Make something cleaner */ + while(keydown(KEY_OPTN)) { + clearevents(); + sleep(); + } + } } else { /* Player actions - Prototypes in player.h and implementation in * player.c */ diff --git a/src/game.h b/src/game.h index be88cd4..9670a4c 100644 --- a/src/game.h +++ b/src/game.h @@ -45,6 +45,8 @@ typedef struct { Slot equipped[3]; /* 1 if the inventory is open. */ char open : 1; + char selected; + char selection; } Inventory; typedef struct { @@ -142,6 +144,7 @@ typedef struct { uint8_t current_group; uint8_t hostile_to_group; + /* uint16_t to keep the struct aligned */ uint16_t __padding; } NPC; diff --git a/src/inventory.c b/src/inventory.c index b2a1145..5289fc1 100644 --- a/src/inventory.c +++ b/src/inventory.c @@ -1,13 +1,24 @@ #include "inventory.h" #include +#include extern bopti_image_t inventory_img; extern bopti_image_t items_img; +extern bopti_image_t selection_img; +extern bopti_image_t selected_img; extern bopti_image_t player_male_inv_img; extern bopti_image_t player_female_inv_img; -void inventory_draw(Game *game, Inventory *inventory) { +void inventory_init(Inventory *inventory) { + inventory->open = 0; + memset(inventory->slots, 0, sizeof(Slot)*SLOT_NUM); + memset(inventory->equipped, 0, sizeof(Slot)*3); + inventory->selected = -1; + inventory->selection = 0; +} + +void inventory_draw(Inventory *inventory, Player *player) { size_t i; if(inventory->open) { dimage(0, 0, &inventory_img); @@ -16,6 +27,16 @@ void inventory_draw(Game *game, Inventory *inventory) { SLOT_Y + (i / SLOT_COLUMNS) * SLOT_SPACING, &items_img, inventory->slots[i].i * SLOT_W, 0, SLOT_W, SLOT_H, DIMAGE_NONE); + if(i == inventory->selection){ + dimage(SLOT_X + (i % SLOT_COLUMNS) * SLOT_SPACING, + SLOT_Y + (i / SLOT_COLUMNS) * SLOT_SPACING, + &selection_img); + } + if(i == inventory->selected){ + dimage(SLOT_X + (i % SLOT_COLUMNS) * SLOT_SPACING, + SLOT_Y + (i / SLOT_COLUMNS) * SLOT_SPACING, + &selected_img); + } } for(i = 0; i < 3; i++) { dsubimage(SLOT_X_EQUIPPED, SLOT_Y + i * SLOT_SPACING, &items_img, @@ -25,8 +46,47 @@ void inventory_draw(Game *game, Inventory *inventory) { #if GINT_RENDER_RGB /* Render the player between the two swords if we are on cg. */ dimage(183, 20, - game->player.is_male ? &player_male_inv_img - : &player_female_inv_img); + player->is_male ? &player_male_inv_img : &player_female_inv_img); #endif } } + +char inventory_add(Inventory *inventory, Item item) { + size_t i; + for(i = 0; i < SLOT_NUM; i++) { + if(!inventory->slots[i].i) { + inventory->slots[i].i = item; + inventory->slots[i].durability = 255; + return 0; + } + } + return 1; +} + +void inventory_move_selection(Inventory *inventory, Direction direction) { + switch(direction) { + case D_UP: + inventory->selection -= SLOT_COLUMNS; + if(inventory->selection < 0) + inventory->selection = 0; + break; + case D_DOWN: + inventory->selection += SLOT_COLUMNS; + if(inventory->selection >= SLOT_NUM) { + inventory->selection = SLOT_NUM - 1; + } + break; + case D_LEFT: + if(inventory->selection > 0) { + inventory->selection--; + } + break; + case D_RIGHT: + if(inventory->selection < SLOT_NUM - 1) { + inventory->selection++; + } + break; + default: + break; + } +} diff --git a/src/inventory.h b/src/inventory.h index b8a0368..4e547f6 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -4,6 +4,9 @@ /* The structs related to the inventory are defined in game.h */ #include "game.h" -void inventory_draw(Game *game, Inventory *inventory); +void inventory_init(Inventory *inventory); +void inventory_draw(Inventory *inventory, Player *player); +char inventory_add(Inventory *inventory, Item item); +void inventory_move_selection(Inventory *inventory, Direction direction); #endif From fe824d73405983bc048fe7a0cc9654f05ef1c3f5 Mon Sep 17 00:00:00 2001 From: mibi88 <76903855+mibi88@users.noreply.github.com> Date: Fri, 2 Aug 2024 18:29:27 +0200 Subject: [PATCH 09/10] Inventory management. --- src/game.c | 23 ++++++++++++++---- src/game.h | 9 +++++++ src/inventory.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ src/inventory.h | 3 +++ 4 files changed, 95 insertions(+), 4 deletions(-) diff --git a/src/game.c b/src/game.c index 61f8987..8aae513 100644 --- a/src/game.c +++ b/src/game.c @@ -37,6 +37,10 @@ void game_init(Game *game) { events_bind_variable(&game->handler, (int *)&game->player.life, "life"); events_bind_variable(&game->handler, &game->mana, "mana"); inventory_init(&game->inventory); + /* For debugging */ + game->inventory.slots[5].i = I_GLOVE; + game->inventory.slots[1].i = I_ARMOR; + game->inventory.slots[8].i = I_TALISMAN; // reload_npc(&game); } @@ -191,16 +195,27 @@ void game_get_inputs(Game *game) { clearevents(); sleep(); } - if(keydown(KEY_SHIFT)) - game->inventory.selected = game->inventory.selection; - if(keydown(KEY_OPTN)) { - game->player.is_male = !game->player.is_male; + if(keydown(KEY_OPTN)) + inventory_move_from_selected(&game->inventory); /* TODO: Make something cleaner */ while(keydown(KEY_OPTN)) { clearevents(); sleep(); } + if(keydown(KEY_SQUARE)) { + inventory_use(&game->inventory, &game->player); } + if(keydown(KEY_F1)) { + inventory_unequip(&game->inventory, IT_TALISMAN); + } + if(keydown(KEY_F2)) { + inventory_unequip(&game->inventory, IT_ARMOR); + } + if(keydown(KEY_F3)) { + inventory_unequip(&game->inventory, IT_WEAPON); + } + if(keydown(KEY_SHIFT)) + game->inventory.selected = game->inventory.selection; } else { /* Player actions - Prototypes in player.h and implementation in * player.c */ diff --git a/src/game.h b/src/game.h index 9670a4c..f42269a 100644 --- a/src/game.h +++ b/src/game.h @@ -32,6 +32,15 @@ typedef enum { I_AMOUNT } Item; +typedef enum { + IT_NONE, + IT_TALISMAN, + IT_ARMOR, + IT_WEAPON, + IT_FOOD, + IT_AMOUNT +} ItemType; + typedef struct { Item i : 4; unsigned char durability; diff --git a/src/inventory.c b/src/inventory.c index 5289fc1..ec1836a 100644 --- a/src/inventory.c +++ b/src/inventory.c @@ -10,6 +10,16 @@ extern bopti_image_t selected_img; extern bopti_image_t player_male_inv_img; extern bopti_image_t player_female_inv_img; +char item_types[I_AMOUNT] = { + IT_NONE, + IT_ARMOR, + IT_WEAPON, + IT_WEAPON, + IT_FOOD, + IT_FOOD, + IT_TALISMAN +}; + void inventory_init(Inventory *inventory) { inventory->open = 0; memset(inventory->slots, 0, sizeof(Slot)*SLOT_NUM); @@ -49,6 +59,7 @@ void inventory_draw(Inventory *inventory, Player *player) { player->is_male ? &player_male_inv_img : &player_female_inv_img); #endif } + /* TODO: Stats. */ } char inventory_add(Inventory *inventory, Item item) { @@ -63,6 +74,59 @@ char inventory_add(Inventory *inventory, Item item) { return 1; } +void inventory_move_from_selected(Inventory *inventory) { + if(inventory->selected < 0) return; + Slot current = inventory->slots[inventory->selection]; + Slot new = inventory->slots[inventory->selected]; + inventory->slots[inventory->selection] = new; + inventory->slots[inventory->selected] = current; +} + +void inventory_use(Inventory *inventory, Player *player) { + Item item = inventory->slots[inventory->selection].i; + switch(item_types[item]){ + case IT_TALISMAN: + inventory->equipped[0] = inventory->slots[inventory->selection]; + break; + case IT_ARMOR: + inventory->equipped[1] = inventory->slots[inventory->selection]; + break; + case IT_WEAPON: + inventory->equipped[2] = inventory->slots[inventory->selection]; + break; + case IT_FOOD: + /* TODO */ + break; + default: + break; + } + inventory->slots[inventory->selection].i = I_NONE; + inventory->slots[inventory->selection].durability = 255; +} + +void inventory_unequip(Inventory *inventory, ItemType type) { + if(inventory->slots[inventory->selection].i) return; + switch(type){ + case IT_TALISMAN: + inventory->slots[inventory->selection] = inventory->equipped[0]; + inventory->equipped[0].i = I_NONE; + inventory->equipped[0].durability = 255; + break; + case IT_ARMOR: + inventory->slots[inventory->selection] = inventory->equipped[1]; + inventory->equipped[1].i = I_NONE; + inventory->equipped[1].durability = 255; + break; + case IT_WEAPON: + inventory->slots[inventory->selection] = inventory->equipped[2]; + inventory->equipped[2].i = I_NONE; + inventory->equipped[2].durability = 255; + break; + default: + break; + } +} + void inventory_move_selection(Inventory *inventory, Direction direction) { switch(direction) { case D_UP: diff --git a/src/inventory.h b/src/inventory.h index 4e547f6..5bc3116 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -7,6 +7,9 @@ void inventory_init(Inventory *inventory); void inventory_draw(Inventory *inventory, Player *player); char inventory_add(Inventory *inventory, Item item); +void inventory_move_from_selected(Inventory *inventory); +void inventory_use(Inventory *inventory, Player *player); +void inventory_unequip(Inventory *inventory, ItemType type); void inventory_move_selection(Inventory *inventory, Direction direction); #endif From a27ad9a14f0294afd88415f893c10f09c6e7612e Mon Sep 17 00:00:00 2001 From: mibi88 <76903855+mibi88@users.noreply.github.com> Date: Fri, 2 Aug 2024 18:29:56 +0200 Subject: [PATCH 10/10] Ran clang-format --- src/game.c | 50 +++++++++++++-------------- src/inventory.c | 91 +++++++++++++++++++++++-------------------------- 2 files changed, 68 insertions(+), 73 deletions(-) diff --git a/src/game.c b/src/game.c index 8aae513..935994c 100644 --- a/src/game.c +++ b/src/game.c @@ -169,39 +169,39 @@ void game_get_inputs(Game *game) { } else if(game->inventory.open) { if(keydown(KEY_LEFT)) inventory_move_selection(&game->inventory, D_LEFT); - /* TODO: Make something cleaner */ - while(keydown(KEY_LEFT)) { - clearevents(); - sleep(); - } + /* TODO: Make something cleaner */ + while(keydown(KEY_LEFT)) { + clearevents(); + sleep(); + } if(keydown(KEY_RIGHT)) inventory_move_selection(&game->inventory, D_RIGHT); - /* TODO: Make something cleaner */ - while(keydown(KEY_RIGHT)) { - clearevents(); - sleep(); - } + /* TODO: Make something cleaner */ + while(keydown(KEY_RIGHT)) { + clearevents(); + sleep(); + } if(keydown(KEY_UP)) inventory_move_selection(&game->inventory, D_UP); - /* TODO: Make something cleaner */ - while(keydown(KEY_UP)) { - clearevents(); - sleep(); - } + /* TODO: Make something cleaner */ + while(keydown(KEY_UP)) { + clearevents(); + sleep(); + } if(keydown(KEY_DOWN)) inventory_move_selection(&game->inventory, D_DOWN); - /* TODO: Make something cleaner */ - while(keydown(KEY_DOWN)) { - clearevents(); - sleep(); - } + /* TODO: Make something cleaner */ + while(keydown(KEY_DOWN)) { + clearevents(); + sleep(); + } if(keydown(KEY_OPTN)) inventory_move_from_selected(&game->inventory); - /* TODO: Make something cleaner */ - while(keydown(KEY_OPTN)) { - clearevents(); - sleep(); - } + /* TODO: Make something cleaner */ + while(keydown(KEY_OPTN)) { + clearevents(); + sleep(); + } if(keydown(KEY_SQUARE)) { inventory_use(&game->inventory, &game->player); } diff --git a/src/inventory.c b/src/inventory.c index ec1836a..3533c5c 100644 --- a/src/inventory.c +++ b/src/inventory.c @@ -10,20 +10,13 @@ extern bopti_image_t selected_img; extern bopti_image_t player_male_inv_img; extern bopti_image_t player_female_inv_img; -char item_types[I_AMOUNT] = { - IT_NONE, - IT_ARMOR, - IT_WEAPON, - IT_WEAPON, - IT_FOOD, - IT_FOOD, - IT_TALISMAN -}; +char item_types[I_AMOUNT] = {IT_NONE, IT_ARMOR, IT_WEAPON, IT_WEAPON, + IT_FOOD, IT_FOOD, IT_TALISMAN}; void inventory_init(Inventory *inventory) { inventory->open = 0; - memset(inventory->slots, 0, sizeof(Slot)*SLOT_NUM); - memset(inventory->equipped, 0, sizeof(Slot)*3); + memset(inventory->slots, 0, sizeof(Slot) * SLOT_NUM); + memset(inventory->equipped, 0, sizeof(Slot) * 3); inventory->selected = -1; inventory->selection = 0; } @@ -37,12 +30,12 @@ void inventory_draw(Inventory *inventory, Player *player) { SLOT_Y + (i / SLOT_COLUMNS) * SLOT_SPACING, &items_img, inventory->slots[i].i * SLOT_W, 0, SLOT_W, SLOT_H, DIMAGE_NONE); - if(i == inventory->selection){ + if(i == inventory->selection) { dimage(SLOT_X + (i % SLOT_COLUMNS) * SLOT_SPACING, SLOT_Y + (i / SLOT_COLUMNS) * SLOT_SPACING, &selection_img); } - if(i == inventory->selected){ + if(i == inventory->selected) { dimage(SLOT_X + (i % SLOT_COLUMNS) * SLOT_SPACING, SLOT_Y + (i / SLOT_COLUMNS) * SLOT_SPACING, &selected_img); @@ -75,7 +68,8 @@ char inventory_add(Inventory *inventory, Item item) { } void inventory_move_from_selected(Inventory *inventory) { - if(inventory->selected < 0) return; + if(inventory->selected < 0) + return; Slot current = inventory->slots[inventory->selection]; Slot new = inventory->slots[inventory->selected]; inventory->slots[inventory->selection] = new; @@ -84,46 +78,47 @@ void inventory_move_from_selected(Inventory *inventory) { void inventory_use(Inventory *inventory, Player *player) { Item item = inventory->slots[inventory->selection].i; - switch(item_types[item]){ - case IT_TALISMAN: - inventory->equipped[0] = inventory->slots[inventory->selection]; - break; - case IT_ARMOR: - inventory->equipped[1] = inventory->slots[inventory->selection]; - break; - case IT_WEAPON: - inventory->equipped[2] = inventory->slots[inventory->selection]; - break; - case IT_FOOD: - /* TODO */ - break; - default: - break; + switch(item_types[item]) { + case IT_TALISMAN: + inventory->equipped[0] = inventory->slots[inventory->selection]; + break; + case IT_ARMOR: + inventory->equipped[1] = inventory->slots[inventory->selection]; + break; + case IT_WEAPON: + inventory->equipped[2] = inventory->slots[inventory->selection]; + break; + case IT_FOOD: + /* TODO */ + break; + default: + break; } inventory->slots[inventory->selection].i = I_NONE; inventory->slots[inventory->selection].durability = 255; } void inventory_unequip(Inventory *inventory, ItemType type) { - if(inventory->slots[inventory->selection].i) return; - switch(type){ - case IT_TALISMAN: - inventory->slots[inventory->selection] = inventory->equipped[0]; - inventory->equipped[0].i = I_NONE; - inventory->equipped[0].durability = 255; - break; - case IT_ARMOR: - inventory->slots[inventory->selection] = inventory->equipped[1]; - inventory->equipped[1].i = I_NONE; - inventory->equipped[1].durability = 255; - break; - case IT_WEAPON: - inventory->slots[inventory->selection] = inventory->equipped[2]; - inventory->equipped[2].i = I_NONE; - inventory->equipped[2].durability = 255; - break; - default: - break; + if(inventory->slots[inventory->selection].i) + return; + switch(type) { + case IT_TALISMAN: + inventory->slots[inventory->selection] = inventory->equipped[0]; + inventory->equipped[0].i = I_NONE; + inventory->equipped[0].durability = 255; + break; + case IT_ARMOR: + inventory->slots[inventory->selection] = inventory->equipped[1]; + inventory->equipped[1].i = I_NONE; + inventory->equipped[1].durability = 255; + break; + case IT_WEAPON: + inventory->slots[inventory->selection] = inventory->equipped[2]; + inventory->equipped[2].i = I_NONE; + inventory->equipped[2].durability = 255; + break; + default: + break; } }