From 188a21798155b8d749d20fd133cd6369d5d20797 Mon Sep 17 00:00:00 2001 From: ayabusa Date: Sat, 14 Dec 2024 10:13:24 +0100 Subject: [PATCH] started working on the thing --- src/game.py | 31 ++++++++++++++++++ src/sprites/_converter.py | 59 +++++++++++++++++++++++++++++++++++ src/sprites/assiette.png | Bin 0 -> 268 bytes src/sprites/oignon.png | Bin 0 -> 330 bytes src/sprites/oignon_coupe.png | Bin 0 -> 285 bytes src/sprites/planche.png | Bin 0 -> 329 bytes src/sprites/player_down.png | Bin 0 -> 280 bytes src/sprites/player_left.png | Bin 0 -> 286 bytes src/sprites/player_right.png | Bin 0 -> 290 bytes src/sprites/player_up.png | Bin 0 -> 236 bytes src/sprites/poele.png | Bin 0 -> 368 bytes src/sprites/salade.png | Bin 0 -> 311 bytes src/sprites/salade_cuite.png | Bin 0 -> 284 bytes src/sprites/steak.png | Bin 0 -> 330 bytes src/sprites/steak_cuit.png | Bin 0 -> 196 bytes 15 files changed, 90 insertions(+) create mode 100644 src/game.py create mode 100644 src/sprites/_converter.py create mode 100644 src/sprites/assiette.png create mode 100644 src/sprites/oignon.png create mode 100644 src/sprites/oignon_coupe.png create mode 100644 src/sprites/planche.png create mode 100644 src/sprites/player_down.png create mode 100644 src/sprites/player_left.png create mode 100644 src/sprites/player_right.png create mode 100644 src/sprites/player_up.png create mode 100644 src/sprites/poele.png create mode 100644 src/sprites/salade.png create mode 100644 src/sprites/salade_cuite.png create mode 100644 src/sprites/steak.png create mode 100644 src/sprites/steak_cuit.png diff --git a/src/game.py b/src/game.py new file mode 100644 index 0000000..59bcc73 --- /dev/null +++ b/src/game.py @@ -0,0 +1,31 @@ +from kandinsky import * + +print("Game started") +colors = [color(i) for i in [(26,28,44),(93,39,93),(177,62,83),(239,125,87),(255,205,117),(167,240,112),(56,183,100),(37,113,121),(41,54,111),(59,93,201),(65,166,246),(115,239,247),(244,244,244),(148,176,194),(86,108,134),(51,60,87)]] +sprites = {} + +class Ingredient: + def __init__(self, i_nom): + self.i_nom = i_nom + self.i_sprite = sprites[i_nom] + +class Plat: + def __init__(self, p_type, p_ingredients): + self.p_type = p_type + self.p_ingredients = p_ingredients + +def draw_map(mapid: int): + if mapid==0: + fill_rect(0,40,320,182,colors[4]) # table + fill_rect(40,80,240,4,colors[3]) + fill_rect(40,84,240,2,colors[1]) + fill_rect(40,86,240,8,colors[2]) + fill_rect(40,94,240,12,colors[15]) + fill_rect(40,106,240,116,colors[14]) # sol + fill_rect(120,120,80,80,colors[4]) # table 2 + fill_rect(120,200,80,4,colors[3]) + fill_rect(122,204,76,2,colors[1]) + fill_rect(122,206,76,8,colors[2]) + fill_rect(122,214,76,8,colors[15]) + +draw_map(0) \ No newline at end of file diff --git a/src/sprites/_converter.py b/src/sprites/_converter.py new file mode 100644 index 0000000..27a5d76 --- /dev/null +++ b/src/sprites/_converter.py @@ -0,0 +1,59 @@ +from os import listdir +from os.path import isfile, join +from PIL import Image +import numpy as np + +path = "./src/sprites/" +files_list = [f for f in listdir(path) if isfile(join(path, f))] + +def get_offset_x(img, w, h)->int: + offsetx = 0 + for i in range(h): + for i in range(w): + if img.getpixel((offsetx, i))[3] == 0: + continue + else: + return offsetx + offsetx+=1 + return offsetx + +def get_offset_y(img, w, h)->int: + offsety = 0 + for i in range(w): + for i in range(h): + if img.getpixel((i, offsety))[3] == 0: + continue + else: + return offsety + offsety+=1 + return offsety + +def get_croped_image(img)-> tuple[Image.Image, int, int]: + w, h = img.size + offsetx, offsety = get_offset_x(image, w, h), get_offset_y(img, w, h) + img_reversed = image.rotate(180) + neg_offsetx, neg_offsety = get_offset_y(img_reversed, w, h), get_offset_x(img_reversed, w, h) + img_croped = img.crop((offsetx, offsety, h-neg_offsety, w-neg_offsetx)) + print("w;", w, "h",h,"x:",offsetx, "y:", offsety, "neg x:", neg_offsetx, "neg y:", neg_offsety) + print(h-offsetx-neg_offsetx, w-offsety-neg_offsety) + return (img_croped, offsetx, offsety) + +image = Image.open(join(path, "salade.png")) +image_croped, off_x, off_y = get_croped_image(image) +w, h = image_croped.size +result = "" +for i in range(w): + for i in range(h): + result. +image_croped.show() +exit() + + +for file in files_list: + if not file.endswith(".png"): + print("Skipping", file, ", because it's not a png image.") + break + image = Image.open(join(path, file)) + w, h = image.size + offsetx, offsety = 0,0 + diff --git a/src/sprites/assiette.png b/src/sprites/assiette.png new file mode 100644 index 0000000000000000000000000000000000000000..32c37d31382d49723e300294c6e0f786e9836671 GIT binary patch literal 268 zcmV+n0rUQeP)%%pQMzG&VOv;&z@YtsSm3J%%EF0PGHrfreT58U=#sD1`%U0oFOHn^PgCQuo(<9 zlo6j{3-+ADYCwXE5l%x{aM`+G&pE6b3CS^Ha~(bn_|&LrSTHb=VmmTOa4|v&5*Qo9 zKvDoUi|#;?N=~Vo zGL0ldU_sNClZBd7kPT&EU|=9*FtR}m3^?*KK7-K#HiPgQh;A@Cz*inp9RL9Hm!6h4 Si09z|0000o7IG^#um9zgTNrvHl5AM zN)Le8uK-BEM&kwFz}wdkujb_ns&2ue@uIHNV@mRz)OGAvWTnUca$>q$0&rd*C~~7l zx6JN=6}eI8^?}W5Qujw)F!{~&n6~We-fZ4ETyA7YK(+~;K-g`QKe5R#X*TgN^~igAI{G$G>xX)O!s_F+x< z{uJvhHjXtKtkF?FeMLtm_&D@gUe;)h234umxU>(o>Vk2Bx62ipdjkNAZ@y;)YUeH* z%I1Ke0N}u?Qqazwt4Z0C6a^p)iL#KZ0QLeo4E9rh20d*ti)bWOsn1jPp)Ch|E9E^= jXB1c}<(K7q`4v3??~I%7X%aq%00000NkvXXu0mjfG>g literal 0 HcmV?d00001 diff --git a/src/sprites/planche.png b/src/sprites/planche.png new file mode 100644 index 0000000000000000000000000000000000000000..3836d49923a93cf931dee5927778cb0d4ba65ae9 GIT binary patch literal 329 zcmV-P0k-~$P)f%K|Jip zqDrw-AqIW?gKdESdb@ITH-j)%Q?Rz0KH;@a#FTduEX9K|h|io>QZ)@7%R-x0m3BV@jdR zKh)h@mD6k{#<*a&%K7@qo*wR(;wL8+9Mb=CS8=7l_7}(hu9^~*Wi`8eYsgbW^GpjJ zRXw4gvwIixx_;qfWO%&{NC623hcA6!g?mw{?qH+mdKI;Vst0D$ap(EtDd literal 0 HcmV?d00001 diff --git a/src/sprites/player_left.png b/src/sprites/player_left.png new file mode 100644 index 0000000000000000000000000000000000000000..9f50057784bb9ae294dd4a28a1e14e9fea265135 GIT binary patch literal 286 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE%G&c-kO{_vq~41jF3-6VFU|kaT22 z!g0bc!FoUP7pUXO@geCxe5Ouu( literal 0 HcmV?d00001 diff --git a/src/sprites/player_right.png b/src/sprites/player_right.png new file mode 100644 index 0000000000000000000000000000000000000000..4c1d56272ba7abb8d17c884cdd58df7a46eb8015 GIT binary patch literal 290 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE!*26sn-Q`1AkM)Ab8{c;@FE?l7Iw8S!3_dqtiC*8(?*q$5I`7Db!;8Gyiw%!q_i zhHVjP2bT$?3Fz6`d2f*F@HV{Z;N|xG|NqTP|Noz_`}hCT)6@UYO8cpiQ}dEP+iUuy zi$DLDELQj9Uix?Y<1?xjoB8a*1FVdQ&MBb@0A&SnqW}N^ literal 0 HcmV?d00001 diff --git a/src/sprites/player_up.png b/src/sprites/player_up.png new file mode 100644 index 0000000000000000000000000000000000000000..a3d54ca53395aee59feda4491a451c549f76b058 GIT binary patch literal 236 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE6(o^%s>+)^o~lm?MRY}=UNaSr#6MJ@MN;@jSU5g>eC9Ji8$#UWc|>l gxJkQU<3&b>#j7tx{C}h833NV#r>mdKI;Vst0CP51s{jB1 literal 0 HcmV?d00001 diff --git a/src/sprites/poele.png b/src/sprites/poele.png new file mode 100644 index 0000000000000000000000000000000000000000..d0064d0a02dc1758d8b990ea390cc29dfe007fda GIT binary patch literal 368 zcmV-$0gwKPP)F~)6vn@j(|9f?NRS-aLb53YNCXKM)M57rpqBj!lUSyPB|%^i2pkE40AgYZf`CUa z=~T<>qb&#FQ@z*k{rcM1tAImc6ie3}037xkVT&6<3aK>PJ|1SnZ!266!YGy$^1EDl zfraNM1FoQg!xV@n*u;Gb8gSD!5U-HuWKw0{AOo1TI$w?k(yrYqnyb&SwVq>8dNGWy ztHT%1<%>A(wg5<%>7Y O0000ST5Jf)`4I*8X24#dSzyfrX%)thrcmvPjl8yzu03#q8LqBFYT>(0L*E6)i;EnI!Z!3>@D?z+T(`K$ZBKzbQLm`rhFTk*K-4Sw zQqP#$Geo^w>*^L^Q4KgW+ygL!ZtdW?TfAa8!>Z7d6YaS;4cym(p*we3i|0nVuVgp+BAkq6mE6Do(Ab*2BcU4b) z(D=%7XX}O!tFoV@BqTJnNc-@_XEk^$U0&5X_5ae8l7G=T{*9Mecn`5}h;*9fxVRyM afgw69FL!NQ#~z?}89ZJ6T-G@yGywo7EOfH~ literal 0 HcmV?d00001 diff --git a/src/sprites/steak.png b/src/sprites/steak.png new file mode 100644 index 0000000000000000000000000000000000000000..9fbfcbcbe0ef0653b627b7df716d181316508c45 GIT binary patch literal 330 zcmV-Q0k!^#P)6QDebXuDjCE+nqwjM3I#qz=(iFwd0>Ac! zfiK104n_r-IfkDfrRq>W-d=QaYt!E^IkLG;552km)ge$RVkB6HMXMq;?|)`zna*&aSR z%+oG;s^y(iP1{0d>uRwbRT2jb1m>Tfu($WL5)X6dM>VtN#0FMpmUgG4ryq|Q>9lQR qd@|#h