From 51968f66fc7d253faa39ad5a75b2cdffbbc3c17a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Sun, 11 Oct 2020 08:19:24 +0800 Subject: [PATCH 01/27] =?UTF-8?q?=E6=9C=89=20=20=E6=84=8F=20=20=E6=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++ __pycache__/lib.cpython-38.pyc | Bin 0 -> 1766 bytes lib.py | 50 +++++++++++++++++++++++++++++++++ main.py | 46 ++++-------------------------- 4 files changed, 58 insertions(+), 41 deletions(-) create mode 100644 __pycache__/lib.cpython-38.pyc create mode 100644 lib.py diff --git a/README.md b/README.md index 9c2113d2..4e95da2d 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ Simple Minecraft-inspired demo written in Python and Pyglet. http://www.youtube.com/watch?v=kC3lwK631X8 +this flok is py shenjackyuanjie + + **Like this project?** You might also like my other Minecraft clone written in C using modern OpenGL (GL shader language). It performs better, has better terrain generation and saves state to a sqlite database. See here: diff --git a/__pycache__/lib.cpython-38.pyc b/__pycache__/lib.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..74d27c77b3a3e90033079db4c112e3db114dd529 GIT binary patch literal 1766 zcmcIky>1*g5GHr`R(q@akz)Z;U<6=ioFS-4X&A9#8*p4WMPfG#0f*C)cUpLV&Lr2; z9acpE!=(#9fm6EoWB3W!1_+=owW`dJy7O9Rm*Ijl!*6GX!Xc$9{}QGoePMCjHrot z_BvBpRsIHx4i~R#fkIYHW+>1*Kzh%`nXaXHBCC2n@{IpdEKH}UY9-PD{ag){pTc|u zQ+=X@G^FwONkbcdk2Ic@uOWZ~0(7mjiGYW-707Ep&gy%J^W%1RI-3aK*F3j%K!&|G z5oZNB#N77WM%p^g&nD9L{5?NT$9Z;s+E#7E={P@bFQDrP+laGrh_hNDvtOY#=<+H1 zT|m7{rcVTWEu_v;p;$Gw>$E-=Y@*q`QkjOnVP^+yaln@BG}9+cWlO<+zEd8?F@y1u zi~>W?3|$zyG_;gmXbnp)_a5Ipnq~UvSyqZvPNw=O&yEl03)9CP#;a|I*h}w$kWNUx z`O$BpB>cbeONp^vVAH2~#aAN)0gq{K!95T-ZM<9L+{a$qCFcQF1$d_k8l2c+UpTH1 z2R@CU8s745yBfz;UGl7)ZIng3E6UWXdLqSD`e!btfA8Crk3xwLmE1W zpbhy8o#io_CeW|PY0Xwd=t_n6OIdmdlr9tjM zOe4<*ZbC?uC^__{4<;sbCP{$$CX_gTpN@63KaK4!3LQBl4>AJO-J?5xG>GH>08iX#9RL6T literal 0 HcmV?d00001 diff --git a/lib.py b/lib.py new file mode 100644 index 00000000..daf78fab --- /dev/null +++ b/lib.py @@ -0,0 +1,50 @@ +from __future__ import division + +import sys +import math +import random +import time + +from collections import deque +from pyglet import image +from pyglet.gl import * +from pyglet.graphics import TextureGroup +from pyglet.window import key, mouse + + +def cube_vertices(x, y, z, n): + """ Return the vertices of the cube at position x, y, z with size 2*n. + + """ + return [ + x-n, y+n, z-n, x-n, y+n, z+n, x+n, y+n, z+n, x+n, y+n, z-n, # top + x-n, y-n, z-n, x+n, y-n, z-n, x+n, y-n, z+n, x-n, y-n, z+n, # bottom + x-n, y-n, z-n, x-n, y-n, z+n, x-n, y+n, z+n, x-n, y+n, z-n, # left + x+n, y-n, z+n, x+n, y-n, z-n, x+n, y+n, z-n, x+n, y+n, z+n, # right + x-n, y-n, z+n, x+n, y-n, z+n, x+n, y+n, z+n, x-n, y+n, z+n, # front + x+n, y-n, z-n, x-n, y-n, z-n, x-n, y+n, z-n, x+n, y+n, z-n, # back + ] + + +def tex_coord(x, y, n=4): + """ Return the bounding vertices of the texture square. + + """ + m = 1.0 / n + dx = x * m + dy = y * m + return dx, dy, dx + m, dy, dx + m, dy + m, dx, dy + m + + +def tex_coords(top, bottom, side): + """ Return a list of the texture squares for the top, bottom and side. + + """ + top = tex_coord(*top) + bottom = tex_coord(*bottom) + side = tex_coord(*side) + result = [] + result.extend(top) + result.extend(bottom) + result.extend(side * 4) + return result diff --git a/main.py b/main.py index b0590ad9..40ae042b 100644 --- a/main.py +++ b/main.py @@ -10,6 +10,7 @@ from pyglet.gl import * from pyglet.graphics import TextureGroup from pyglet.window import key, mouse +from lib import * TICKS_PER_SEC = 60 @@ -20,7 +21,8 @@ FLYING_SPEED = 15 GRAVITY = 20.0 -MAX_JUMP_HEIGHT = 1.0 # About the height of a block. +MAX_JUMP_HEIGHT = 1.0 +# About the height of a block. # To derive the formula for calculating jump speed, first solve # v_t = v_0 + a * t # for the time at which you achieve maximum height, where a is the acceleration @@ -36,44 +38,6 @@ if sys.version_info[0] >= 3: xrange = range -def cube_vertices(x, y, z, n): - """ Return the vertices of the cube at position x, y, z with size 2*n. - - """ - return [ - x-n,y+n,z-n, x-n,y+n,z+n, x+n,y+n,z+n, x+n,y+n,z-n, # top - x-n,y-n,z-n, x+n,y-n,z-n, x+n,y-n,z+n, x-n,y-n,z+n, # bottom - x-n,y-n,z-n, x-n,y-n,z+n, x-n,y+n,z+n, x-n,y+n,z-n, # left - x+n,y-n,z+n, x+n,y-n,z-n, x+n,y+n,z-n, x+n,y+n,z+n, # right - x-n,y-n,z+n, x+n,y-n,z+n, x+n,y+n,z+n, x-n,y+n,z+n, # front - x+n,y-n,z-n, x-n,y-n,z-n, x-n,y+n,z-n, x+n,y+n,z-n, # back - ] - - -def tex_coord(x, y, n=4): - """ Return the bounding vertices of the texture square. - - """ - m = 1.0 / n - dx = x * m - dy = y * m - return dx, dy, dx + m, dy, dx + m, dy + m, dx, dy + m - - -def tex_coords(top, bottom, side): - """ Return a list of the texture squares for the top, bottom and side. - - """ - top = tex_coord(*top) - bottom = tex_coord(*bottom) - side = tex_coord(*side) - result = [] - result.extend(top) - result.extend(bottom) - result.extend(side * 4) - return result - - TEXTURE_PATH = 'texture.png' GRASS = tex_coords((1, 0), (0, 1), (0, 0)) @@ -419,8 +383,8 @@ def process_queue(self): add_block() or remove_block() was called with immediate=False """ - start = time.clock() - while self.queue and time.clock() - start < 1.0 / TICKS_PER_SEC: + start = time.perf_counter() + while self.queue and time.perf_counter() - start < 1.0 / TICKS_PER_SEC: self._dequeue() def process_entire_queue(self): From 9130b5221208c62db141b02a9a866fd1adc3f0c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Sun, 11 Oct 2020 12:10:53 +0800 Subject: [PATCH 02/27] NICE --- textures/minecraft_py/blocks/bedrock.png | Bin 0 -> 1887 bytes textures/minecraft_py/blocks/bricks.png | Bin 0 -> 1943 bytes textures/minecraft_py/blocks/dirt.png | Bin 0 -> 1958 bytes .../minecraft_py/blocks/grass_block_side.png | Bin 0 -> 2112 bytes textures/minecraft_py/blocks/grass_block_top.png | Bin 0 -> 2880 bytes textures/minecraft_py/blocks/sand.png | Bin 0 -> 1924 bytes textures/minecraft_py/texture.png | Bin 0 -> 5257 bytes 7 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 textures/minecraft_py/blocks/bedrock.png create mode 100644 textures/minecraft_py/blocks/bricks.png create mode 100644 textures/minecraft_py/blocks/dirt.png create mode 100644 textures/minecraft_py/blocks/grass_block_side.png create mode 100644 textures/minecraft_py/blocks/grass_block_top.png create mode 100644 textures/minecraft_py/blocks/sand.png create mode 100644 textures/minecraft_py/texture.png diff --git a/textures/minecraft_py/blocks/bedrock.png b/textures/minecraft_py/blocks/bedrock.png new file mode 100644 index 0000000000000000000000000000000000000000..ba5bf33ee11aaf1abc3ef75ac62e3ab618dc36df GIT binary patch literal 1887 zcmbVN4Qvx-815Lbu?Y#X4O9rnp#hw|zph<-uH8>NwkjQ?ENt@!IPSi#=i0mD?zVQ5 zq5MXaA2p~j1QbyO;{d0Funoiohy;Qf5+Weej8!MdAj+R}>UY? zalH&?)|ZsA_0_D6LvtNSPMC%SL7*~7I2aHVI&4REUK*}7F^(cSM6I@?`I_VY6ne)+J*VLFT_+>}^ zsw&Yq9twr9kO>pzDx9?0Y&b#T6lH`6qf#fROxP$W69*VvKw)KGQh8B8G)88gSfkoe z=xH>BpcJPSlvtWz!tgL7;Uq?AA?ZMljpL*mIiMToSR4dE5D2OQv1A-8`9)P!{Nle* z$G2}Y08{Jn#BJQsmtZh%LQxBAVHmN5+!3vm)ky&N0!6HmSx{ID-JGaJBhgM7Fsdk* ziDF>jph^c^Mko@akjdq|z=h1(JS!t8`HYh9^j!~Jrf;pD6<%JkQaT6`0J{Y@g9)vv5X| z&4Me|3XDXS)dH+cHtVxy59qr@wni&~0e$X&>Q9$>*n&*po_Vy!)M|$=<`sCVb+Oi& z3FgOE0UpuIg=Sc-4eThZoj>5vn3%uk3`A)|egH}Tqb{N_Mf9m5Mh5v+Fk5%6I~+QX zYYiKX1OI1;`ra+gJphLjLtDm275s<~J0QRbC&N+pYh==SgCU{U?aD9nFZ!kN;Ho8g z_Z4Zvo=7Nu_`3Sqpn}xxi!**2a_M|tLeGS^(sph8%yIvmzL7~sUhn+!od=e7 z@4mU|-MyW?t+^lYr$7EdrPnvK&py7;vDx>6WAh=hgIL#J-~MNVWA(wl+>g%PNOdQ* zP5F6W%PTu}WF&1oQPn)ZA@h1`lc|+&JoIDN+5Nr89b-rMninLGU!;D%p>jl9r`SBd zf5Oo*gHPEbiB0^_K4C53Yi}fPO+1&j=ge_z-KPA~Gb_9N*Sh7(1tXfCUD`8#*~x-V zS2*eAt}Fi06{jluXU*L=B>%f*r-w0hFEu==s~-FG)h*L2#G{9i58u1oy1N#OJg3Vq zzTrr}y2g88#?G#1+IAiT?dFIxs_=Wla&OTALdt4Q;BaT|Uk+sOQD( z=Jpva^Hj;`^wW8rK1QL bcR4b81$#r>QaY5<{sP^FC9bA|xr_e>2n?qc literal 0 HcmV?d00001 diff --git a/textures/minecraft_py/blocks/bricks.png b/textures/minecraft_py/blocks/bricks.png new file mode 100644 index 0000000000000000000000000000000000000000..f8d02c91c893227e8d5e6fef11651dc445653608 GIT binary patch literal 1943 zcmbVN3rrJd94}0HIfqU%ndrD2o9MK?N1?PQ<<%lITE?J>Xx!wuyS687@3=c`LC0gt z9BeMQB_`WcL|tT=QFL>QbEeDUmZ%wN0C@?M!*aBaA z*e*#tfgoAaxFiu^u^^VWa}p=o zxqnd|JbuUk2(8&1wDCwTPG``BC}pn$ZUh4INVI6F;2ETV5xH`KVzSo(nhCNuJYf(R zQsM*)$2lewl|M-t!Z8&NEm*<2XwEGzd_aIPk`kkb<*X?&aAOt>BXE$oIe5t z21CBUSy=}-5DRj$AXBzMgXuIHC9cAJbj@bMwN>OUHs9Kq#CTR_dC6{P5^rXCzqsrwHn3Sjgr~E4d3tEtLJh2|RG3DAJa#;~% zwIa|ug-lss%E zY~3M%JR&!&-w))UF8aBXhII6%$aM&>}FyRC+%HXdY?<*9ci6&#F#a?@B z)v>(L%$TX_!bQ^FtUpJyN1>a}V2 z3{h`%Z3r{gI9poA;|4Xch3~%pNtDbZ)hCFs&@@DfnAWXx-ww-2Spd)@wCs zSJf@?XFoMJ96e4JEYtclpS;qyXwLrj&V;W0b@%*~PbD|m8#l(yA5S||vNqDww9AXs zdYe8RNJuOU2ra!IlIrE8u$Y`%k=It;JlIRdoPSd*Y;O$`=y%qkuE~$&<(1i z{qM|)Mq&=`uJZ53+#S-6g;WfT?H=LJ^nSN9V{Vl$?zKcMk}+@R_OsA?-h=p&DMJa% kFLbR9+cf+pF literal 0 HcmV?d00001 diff --git a/textures/minecraft_py/blocks/dirt.png b/textures/minecraft_py/blocks/dirt.png new file mode 100644 index 0000000000000000000000000000000000000000..ba36d70d11e0c6b7dc71de30ecddfba8813485d8 GIT binary patch literal 1958 zcmbVN4@?tR7(aCLzXLaA4peUE=2W=eT?+*+RKyl-H!BP~taU+W2413p>Mi)0TFL%9n@BQBI z`@Y}%zOR+Jix!L@6E_Aykntv?ArHRiD$l54@b}HJ*DK*`w8ywiLXfeqC{Gl!bJt`9 zc`=r^SY@kuA#V<^w*u%#(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7)v(=hpq~p1M<+V5iUbS2kHx^Q>WQP5ZLg@UW`%edIsl{RHQj$}RS(E?W*L z9a_pS#G7Ri|BP`CpOU_^RIqih zKMnnH|De)?h$>WX2mJQ*3q-|F=9f2rI`M$6E#`CcIB|_C!AhC-i`2XyFUf%HNyR!r7c75H|&mKg`JvWq|nAYfYIe%iGOaAiS#$z*+?vBXyh$~Ta z?$4=N{Mbu&rBxZZsxRc*%KRF_>%RFiu1I?+|6jSSh($ literal 0 HcmV?d00001 diff --git a/textures/minecraft_py/blocks/sand.png b/textures/minecraft_py/blocks/sand.png new file mode 100644 index 0000000000000000000000000000000000000000..17a627376b0aec59285d40f823452fe1d0b55782 GIT binary patch literal 1924 zcmbVNeNYr-7(YP_Ff`MV4-K~!5|g|AxZ~hfPlP*!b2>avjKfKWWp}w-x!YZL7w@%Y-}m?a ze$Vr~&-3hhTXA7Rd`i4ZrAn|AneE^?N4a97z&(9*&wB8P6N<_tm1^{OqVY&uJf4VzBo{0PZiEB!NVHT^D=>(ik@y;sVhWZ6Gp8!v2!u&w zNSPN)c-}pHP_|){Aso}-P(~@s(Y#lh{=f#tOv;QAR!&Wgfj?G)VFaE<=&%`R4uPUW zP%BTfRke?TYV{98LCVmiOgmi*CB5+O^iiD9c@oruO!oWK1gYy=X z$tLnutQ#yy_QHI~Qee_!2EAU5Yp{^HRx4rQB$?zW#$q0N z9CZ$@qtpgUn+<{6HRdF|_tTaSy{m$54imRs~)n&5q$fhZ8|7yEL#api)Imu$c2oT&r&` zK2jWwJ@c7qlw8}Gkpa(&x8J%uqUGHwjUQc%&N!8CUuA~!#!WBEkI!hjWlh`Y7@c-u z-ptP54|Lygo$Wq<=j!E-nt?U<9=#TOW7^U)q&|Od z!-?zLyJjZ^H-^N7q+sUU^ugU}ucKRHPc+w`A72`GJ#JTLer8Ws&{}`x{@AFKw-3g& zrKC024{gY)z!G2mYpt|z&-ov?m_Ql#=9T0?DjN0irOLj;U9EE**BZxszqo)(K5#;e z`TX{rMIUT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;05i<0@*BTW{?veqGkDS^gyqr?rG^@~uA#j+>}xnf;CTLy4R8jlXo<#~{ID+vs!T zeIcrRR%2&^Ac40tk*CLl1?Hyvh#Sf}s^qRCT1Zw@tD$#Qhqu^*G4v z2ngDQW6%ViM0sAkE#ciuUR+|JaF#qEfldl9UE2O}oRDaDa2Tksjxdh)Zm33c>tT#& z?;vqy{^w$MzKx1r@x=!HKP!`^yp_8~P!%EDUfFmq~(lV&x~_Uy>4xZJv++PF>FoROl^P+p$$ zQ?|Co?JP4L=I(XNT4)K3w`p5y)Mqv?`v$ibvQtr7+^&AfF(e45?;?BW7AAykR zB`%ogM1Q-7CujG6Y0X7iMI+~!JP0kYS5IlGwL>^}BUFtq74ugodlwAyrUN6pG8@ho zup_NZ5VZStcSm7y;9#~-pN%v-ZL#1kud>bMV1v_Y9Kq3(`6tExTh30wQttt5W; z{_=EnB%PiP2`#xu>%ZPWPCzAdKWhg@=Qzj+Z0%Le)PfLc<|~OTOl*jset;Nr^|$|~ z;zokh9%xqB-1ie;S`BL~(%mn)8WV@dsO_6(xOd*vxKoF2-FC{g8%YPs>EGHRw17w< zO}q@{@XCB-;*4}BA8^rVmX>z!>54%aiVKX922iR#Ehy~S%R~4grP6!3-NP1$1)pyo tZXY)`ICb#Xax+y7?`HqVj7PH^u;uCX Date: Sun, 11 Oct 2020 21:09:33 +0800 Subject: [PATCH 03/27] no star? --- .vscode/settings.json | 3 +++ __pycache__/lib.cpython-38.pyc | Bin 1766 -> 0 bytes codes/__pycache__/lib.cpython-38.pyc | Bin 0 -> 1746 bytes lib.py => codes/lib.py | 2 +- main.py | 6 +++--- 5 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 __pycache__/lib.cpython-38.pyc create mode 100644 codes/__pycache__/lib.cpython-38.pyc rename lib.py => codes/lib.py (98%) diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..946473de --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "C:\\Users\\36958\\AppData\\Local\\Programs\\Python\\Python38\\python.exe" +} \ No newline at end of file diff --git a/__pycache__/lib.cpython-38.pyc b/__pycache__/lib.cpython-38.pyc deleted file mode 100644 index 74d27c77b3a3e90033079db4c112e3db114dd529..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1766 zcmcIky>1*g5GHr`R(q@akz)Z;U<6=ioFS-4X&A9#8*p4WMPfG#0f*C)cUpLV&Lr2; z9acpE!=(#9fm6EoWB3W!1_+=owW`dJy7O9Rm*Ijl!*6GX!Xc$9{}QGoePMCjHrot z_BvBpRsIHx4i~R#fkIYHW+>1*Kzh%`nXaXHBCC2n@{IpdEKH}UY9-PD{ag){pTc|u zQ+=X@G^FwONkbcdk2Ic@uOWZ~0(7mjiGYW-707Ep&gy%J^W%1RI-3aK*F3j%K!&|G z5oZNB#N77WM%p^g&nD9L{5?NT$9Z;s+E#7E={P@bFQDrP+laGrh_hNDvtOY#=<+H1 zT|m7{rcVTWEu_v;p;$Gw>$E-=Y@*q`QkjOnVP^+yaln@BG}9+cWlO<+zEd8?F@y1u zi~>W?3|$zyG_;gmXbnp)_a5Ipnq~UvSyqZvPNw=O&yEl03)9CP#;a|I*h}w$kWNUx z`O$BpB>cbeONp^vVAH2~#aAN)0gq{K!95T-ZM<9L+{a$qCFcQF1$d_k8l2c+UpTH1 z2R@CU8s745yBfz;UGl7)ZIng3E6UWXdLqSD`e!btfA8Crk3xwLmE1W zpbhy8o#io_CeW|PY0Xwd=t_n6OIdmdlr9tjM zOe4<*ZbC?uC^__{4<;sbCP{$$CX_gTpN@63KaK4!3LQBl4>AJO-J?5xG>GH>08iX#9RL6T diff --git a/codes/__pycache__/lib.cpython-38.pyc b/codes/__pycache__/lib.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1633393c01cf048bed6987f0e4af183da445f08c GIT binary patch literal 1746 zcmcIlJC74F5Vm(WdwY9H?sy205Ry9-bh?5PAvggNP(Z<>S)CN+)=qB4K7#G#F45i< zh?;_503|)Y#w`^c6$KSD_9ZMADDlcO<1aJg@yytH+3Upw#_o@|!;=mnUvbeMJ}h=& zsuLibaGH~XCX}M=a($L1gOd8M1 zXAr;v0lL&#MZm+-3go39XZ0_{`Ek2DomB+zGoITzAj4j(h_eD5Vs3kGBW)e$XBBCC z{+A!8<2*Y*ZL2oobetcz7tm#dZNynQ#91wn$s_0rI)BWb38;6;^nqY+gw$Co6syK| zo!0w;jWnB9D$~$1>}Z?Kw%ME=X8M4sY%bW%8|6+MGZ>%AATadE(3zogLrWP!YgqF0 z+JjqrlT7bD$x4yR(OB=L6&GqR&-QnwGt&}N>bmTR;}+2xtsnpUNw^33Yp&H}P;duJP#{4y6ab z7+=kl35t^ZrH1bfmR)W*{~h`oQdw$bgP;&m?Wz&lOUB_LhTl{WIav Date: Sun, 11 Oct 2020 22:35:00 +0800 Subject: [PATCH 04/27] updates!! --- codes/updates/block.py | 3 +++ main.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 codes/updates/block.py diff --git a/codes/updates/block.py b/codes/updates/block.py new file mode 100644 index 00000000..5cf185d1 --- /dev/null +++ b/codes/updates/block.py @@ -0,0 +1,3 @@ + +def place_block_update(): + return \ No newline at end of file diff --git a/main.py b/main.py index 25fe0ad3..d719bd88 100644 --- a/main.py +++ b/main.py @@ -831,7 +831,7 @@ def setup_fog(): glFogi(GL_FOG_MODE, GL_LINEAR) # How close and far away fog starts and ends. The closer the start and end, # the denser the fog in the fog range. - glFogf(GL_FOG_START, 40.0) + glFogf(GL_FOG_START, 50.0) glFogf(GL_FOG_END, 60.0) From b3dbfbe50f230c36f297e725e7149cc23c2a2670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Wed, 14 Oct 2020 19:13:50 +0800 Subject: [PATCH 05/27] mabe better? --- .vscode/settings.json | 3 --- codes/__pycache__/lib.cpython-38.pyc | Bin 1746 -> 0 bytes codes/blocks/grass_block.py | 7 +++++++ codes/blocks/sand.py | 8 ++++++++ main.py | 28 ++++++++++++++------------- 5 files changed, 30 insertions(+), 16 deletions(-) delete mode 100644 .vscode/settings.json delete mode 100644 codes/__pycache__/lib.cpython-38.pyc create mode 100644 codes/blocks/grass_block.py create mode 100644 codes/blocks/sand.py diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 946473de..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "python.pythonPath": "C:\\Users\\36958\\AppData\\Local\\Programs\\Python\\Python38\\python.exe" -} \ No newline at end of file diff --git a/codes/__pycache__/lib.cpython-38.pyc b/codes/__pycache__/lib.cpython-38.pyc deleted file mode 100644 index 1633393c01cf048bed6987f0e4af183da445f08c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1746 zcmcIlJC74F5Vm(WdwY9H?sy205Ry9-bh?5PAvggNP(Z<>S)CN+)=qB4K7#G#F45i< zh?;_503|)Y#w`^c6$KSD_9ZMADDlcO<1aJg@yytH+3Upw#_o@|!;=mnUvbeMJ}h=& zsuLibaGH~XCX}M=a($L1gOd8M1 zXAr;v0lL&#MZm+-3go39XZ0_{`Ek2DomB+zGoITzAj4j(h_eD5Vs3kGBW)e$XBBCC z{+A!8<2*Y*ZL2oobetcz7tm#dZNynQ#91wn$s_0rI)BWb38;6;^nqY+gw$Co6syK| zo!0w;jWnB9D$~$1>}Z?Kw%ME=X8M4sY%bW%8|6+MGZ>%AATadE(3zogLrWP!YgqF0 z+JjqrlT7bD$x4yR(OB=L6&GqR&-QnwGt&}N>bmTR;}+2xtsnpUNw^33Yp&H}P;duJP#{4y6ab z7+=kl35t^ZrH1bfmR)W*{~h`oQdw$bgP;&m?Wz&lOUB_LhTl{WIav Date: Wed, 14 Oct 2020 19:23:29 +0800 Subject: [PATCH 06/27] Create .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..da8d1e24 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +.vscode/settings.json From 69471c0c3a0691238aea4cd648850561736df648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Wed, 14 Oct 2020 21:44:44 +0800 Subject: [PATCH 07/27] trying to add block updates --- .gitignore | 1 + codes/blocks/dirt.py | 7 +++++++ codes/updates/block.py | 16 ++++++++++++++-- main.py | 5 ++++- 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 codes/blocks/dirt.py diff --git a/.gitignore b/.gitignore index da8d1e24..9c532667 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode/settings.json +*.pyc diff --git a/codes/blocks/dirt.py b/codes/blocks/dirt.py new file mode 100644 index 00000000..e10564a9 --- /dev/null +++ b/codes/blocks/dirt.py @@ -0,0 +1,7 @@ + + +def ben_update(): + return + +def ben_random_tick(): + return \ No newline at end of file diff --git a/codes/updates/block.py b/codes/updates/block.py index 5cf185d1..e63cc651 100644 --- a/codes/updates/block.py +++ b/codes/updates/block.py @@ -1,3 +1,15 @@ -def place_block_update(): - return \ No newline at end of file +def place_block_update(position, world): + """ + position : tuple of len 3 + The (x, y, z) position of the ben place block to update. + """ + return + + +def remove_block_update(position, world): + """ + position : tuple of len 3 + The (x, y, z) position of the ben remove block to update. + """ + return diff --git a/main.py b/main.py index 92a2cd32..425417b8 100644 --- a/main.py +++ b/main.py @@ -11,6 +11,7 @@ from pyglet.graphics import TextureGroup from pyglet.window import key, mouse from codes.lib import * +from codes import * TICKS_PER_SEC = 60 @@ -820,6 +821,7 @@ def draw_reticle(self): def setup_fog(): """ Configure the OpenGL fog properties. + """ """ # Enable fog. Fog "blends a fog color with each rasterized pixel fragment's # post-texturing color." @@ -834,6 +836,7 @@ def setup_fog(): # the denser the fog in the fog range. glFogf(GL_FOG_START, 50.0) glFogf(GL_FOG_END, 60.0) + """ def setup(): @@ -856,7 +859,7 @@ def setup(): def main(): - window = Window(width=800, height=600, + window = Window(width=1800, height=800, caption='minecraft PE', resizable=True) # Hide the mouse cursor and prevent the mouse from leaving the window. window.set_exclusive_mouse(True) From 541289f82220ad575e9e085a4462abdf84678811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Wed, 14 Oct 2020 21:50:55 +0800 Subject: [PATCH 08/27] try to merging! --- main.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 425417b8..c5d8398f 100644 --- a/main.py +++ b/main.py @@ -821,7 +821,6 @@ def draw_reticle(self): def setup_fog(): """ Configure the OpenGL fog properties. - """ """ # Enable fog. Fog "blends a fog color with each rasterized pixel fragment's # post-texturing color." @@ -834,9 +833,8 @@ def setup_fog(): glFogi(GL_FOG_MODE, GL_LINEAR) # How close and far away fog starts and ends. The closer the start and end, # the denser the fog in the fog range. - glFogf(GL_FOG_START, 50.0) + glFogf(GL_FOG_START, 40.0) glFogf(GL_FOG_END, 60.0) - """ def setup(): @@ -859,7 +857,7 @@ def setup(): def main(): - window = Window(width=1800, height=800, + window = Window(width=800, height=600, caption='minecraft PE', resizable=True) # Hide the mouse cursor and prevent the mouse from leaving the window. window.set_exclusive_mouse(True) From 7a039af5e83fc4f4849dc349e72ead79d9bbfa8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Thu, 15 Oct 2020 20:42:29 +0800 Subject: [PATCH 09/27] MORE thing MORE textures! --- codes/blocks/dirt.py | 4 +++- codes/blocks/grass_block.py | 4 +++- codes/blocks/sand.py | 3 ++- codes/lib.py | 37 +++++++++++++++++++++++++++++++++++++ codes/updates/block.py | 2 ++ 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/codes/blocks/dirt.py b/codes/blocks/dirt.py index e10564a9..a5a71403 100644 --- a/codes/blocks/dirt.py +++ b/codes/blocks/dirt.py @@ -1,7 +1,9 @@ +from codes import * def ben_update(): return + def ben_random_tick(): - return \ No newline at end of file + return diff --git a/codes/blocks/grass_block.py b/codes/blocks/grass_block.py index e10564a9..a5a71403 100644 --- a/codes/blocks/grass_block.py +++ b/codes/blocks/grass_block.py @@ -1,7 +1,9 @@ +from codes import * def ben_update(): return + def ben_random_tick(): - return \ No newline at end of file + return diff --git a/codes/blocks/sand.py b/codes/blocks/sand.py index f4acaf43..a5a71403 100644 --- a/codes/blocks/sand.py +++ b/codes/blocks/sand.py @@ -1,3 +1,4 @@ +from codes import * def ben_update(): @@ -5,4 +6,4 @@ def ben_update(): def ben_random_tick(): - return \ No newline at end of file + return diff --git a/codes/lib.py b/codes/lib.py index 3e5fec10..d69b5b8c 100644 --- a/codes/lib.py +++ b/codes/lib.py @@ -4,12 +4,15 @@ import math import random import time +import os +import re from collections import deque from pyglet import image # from pyglet.gl import * from pyglet.graphics import TextureGroup from pyglet.window import key, mouse +from codes import * def cube_vertices(x, y, z, n): @@ -48,3 +51,37 @@ def tex_coords(top, bottom, side): result.extend(bottom) result.extend(side * 4) return result + + +def get_TEXTURES(main_path): + png_re = re.compile(r'.*\\.png') + folder_re = re.compile(r'.*\\..*') + main_lists = os.listdir(main_path) + png_list = [] + folder_list = [] + for dir in main_lists(): + if png_re.match(dir): + png_list.append(dir) + elif not(folder_re.match(dir)): + folder_list.append(dir) + return + +def folder_open(path, open_all=False, re_match=None): + """ + path + """ + main_lists = os.listdir(path) + get_items = [] + for dir in main_lists(): + if (re_match) and (re_match.match(dir)): + get_items.append(dir) + continue + if (open_all) and (not(re.search(r'.*\\..*', dir))): + print(path, dir) + open_path = path.join('\\', dir) + print(open_path) + folder_open(open_path, open_all=True, re_match=re_match) + else: + pass + return get_items + diff --git a/codes/updates/block.py b/codes/updates/block.py index e63cc651..6288f6f8 100644 --- a/codes/updates/block.py +++ b/codes/updates/block.py @@ -1,3 +1,5 @@ +from codes import * + def place_block_update(position, world): """ From 0a60b0f36c35faa5750a9dc64719be63b045b8a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Thu, 15 Oct 2020 21:10:01 +0800 Subject: [PATCH 10/27] hhhh! --- codes/lib.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/codes/lib.py b/codes/lib.py index d69b5b8c..09fa3f6e 100644 --- a/codes/lib.py +++ b/codes/lib.py @@ -67,8 +67,18 @@ def get_TEXTURES(main_path): return def folder_open(path, open_all=False, re_match=None): - """ - path + """folder opener by shenjackyuanjie + Parameters + ---------- + path : str of path + + open_all : bool open every folder? + + re_match : re.compile do match? + + Returns + ------- + list of what you want """ main_lists = os.listdir(path) get_items = [] From 0637bbaaeeb8891c1cc0fa3bc8d9555d2030a65b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Thu, 15 Oct 2020 21:35:48 +0800 Subject: [PATCH 11/27] readme-cn update --- README-cn.md | 120 +++++++++++++++++++++++++++++++++++++++++ codes/updates/block.py | 4 ++ 2 files changed, 124 insertions(+) create mode 100644 README-cn.md diff --git a/README-cn.md b/README-cn.md new file mode 100644 index 00000000..44dcf680 --- /dev/null +++ b/README-cn.md @@ -0,0 +1,120 @@ +[English]() + +# 此文档为机翻+部分手动修改,有建议请发中文issue并标明[README-cn] + +# Minecraft + +以Python和Pyglet编写的受Minecraft启发的简单演示。 + +http://www.youtube.com/watch?v=kC3lwK631X8 + +这是皮申杰克元杰 + +**像这个项目?** + +您可能也喜欢我的另一个Minecraft克隆,使用现代OpenGL(GL着色器语言)用C编写。它的性能更好,有更好的地形生成,并将状态保存到sqlite数据库中。请看这里: + +https://github.com/fogleman/Craft + +## 目标和愿景 + +我希望这个项目变成一个教育工具。孩子们喜欢Minecraft,Python是很棒的第一语言。 + +这是一个让孩子们对编程感到兴奋的好机会。 + +代码应该得到很好的注释,并且更容易配置。做一些简单的改变应该很容易 + +很快就能看到结果。 + +我认为把这个项目变成一个库/API会很棒。。。导入一个Python包,然后 + +使用/configure设置一个世界并运行它。沿着这些线索。。。 + +```python +import mc + +world = mc.World(...) +world.set_block(x, y, z, mc.DIRT) +mc.run(world) +``` + +API可以包含以下功能: + +-容易配置的参数,如重力,跳跃速度,步行速度等。 + +-地形生成挂钩。 + +##怎么跑 + +```shell +pip install pyglet +git clone https://github.com/fogleman/Minecraft.git +cd Minecraft +python main.py +``` + +### Mac + +在Mac OS X上,在64位模式下运行Pyglet可能有问题。请先尝试在32位模式下运行Python: + +```shell +arch -i386 python main.py +``` + +如果不起作用,请将Python默认设置为以32位模式运行: + +```shell +defaults write com.apple.versioner.python Prefer-32-Bit -bool yes +``` + +这假设您使用的是OSX默认Python。可以在Lion10.7上使用默认的Python2.7,也可以在其他版本上使用。如果没有,请提出问题。 + +或者试试Pyglet 1.2 alpha,它支持64位模式: + +```shell +pip install https://pyglet.googlecode.com/files/pyglet-1.2alpha1.tar.gz +``` + +### 如果你没有pip或git + +对于pip: + +-在Linux软件包中安装类似于Linux的pip或者类似于pip的软件包。 + +-Windows:[安装分发然后Pip](http://stackoverflow.com/a/12476379/992887)使用链接的.MSI安装程序。 + +对于git: + +-Mac:安装[自制](homebrew网站http://mxhub.com/)首先,然后是“brew install git”。 + +-Windows或Linux:请参阅[安装Git](http://git-scm.com/book/en/Getting-Started-Installing-git)从你的专业博客上。 + +[见维基](https://github.com/fogleman/Minecraft/wiki)为这个项目安装Python等提示。 + +## 怎么玩 + +### 移动 + +-W:前进 +-S:后退 +-A:向左 +-D:向右 + +-鼠标移动:看看周围 +-空格:跳跃 +-Tab:切换飞行模式 + +### 建筑 + +-选择要创建的块类型: + -1:砖 + -2:草 + -3:沙子 + +-鼠标左键单击:删除块 + +-鼠标右键单击:创建块 + +### 退出 + +-释放鼠标,然后关闭窗口 diff --git a/codes/updates/block.py b/codes/updates/block.py index 6288f6f8..1f4302f5 100644 --- a/codes/updates/block.py +++ b/codes/updates/block.py @@ -6,6 +6,10 @@ def place_block_update(position, world): position : tuple of len 3 The (x, y, z) position of the ben place block to update. """ + if (position[1] == 0) or (position[1] == 1): + send_poi = position[0] -= 1, position[1], position[2] + world[position[0] -= 1] + world[] return From ee7135546c3fef4f3a950ae72afa5e6f343397c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <54507071+shenjackyuanjie@users.noreply.github.com> Date: Fri, 16 Oct 2020 22:24:46 +0800 Subject: [PATCH 12/27] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 4e95da2d..61f55475 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,6 @@ Simple Minecraft-inspired demo written in Python and Pyglet. http://www.youtube.com/watch?v=kC3lwK631X8 -this flok is py shenjackyuanjie - **Like this project?** From bda54eeb8ce8544c40cf19ca56d12e2592d9e26c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Thu, 5 Nov 2020 19:12:37 +0800 Subject: [PATCH 13/27] some readme change --- README-cn.md => doc/README-cn.md | 0 doc/self.World{}.md | 23 +++++++++++++++++++++++ main.py | 32 ++++++++------------------------ 3 files changed, 31 insertions(+), 24 deletions(-) rename README-cn.md => doc/README-cn.md (100%) create mode 100644 doc/self.World{}.md diff --git a/README-cn.md b/doc/README-cn.md similarity index 100% rename from README-cn.md rename to doc/README-cn.md diff --git a/doc/self.World{}.md b/doc/self.World{}.md new file mode 100644 index 00000000..eb52d91c --- /dev/null +++ b/doc/self.World{}.md @@ -0,0 +1,23 @@ + +### now + +``` +self.World = {} +{[x, y, z]: TEXTURE} +``` + +## TEXTURE: + +``` +GRASS = tex_coords((1, 0), (0, 1), (0, 0)) +SAND = tex_coords((1, 1), (1, 1), (1, 1)) +BRICK = tex_coords((2, 0), (2, 0), (2, 0)) +STONE = tex_coords((2, 1), (2, 1), (2, 1)) +``` + +### want to be + +``` +self.World = {} +{[chunk_id]: {[x, y, z]: [block_states, ]}} +``` diff --git a/main.py b/main.py index c5d8398f..83e376e4 100644 --- a/main.py +++ b/main.py @@ -66,9 +66,7 @@ def normalize(position): Returns ------- - block_position : tuple of ints of len 3 - - """ + block_position : tuple of ints of len 3""" x, y, z = position x, y, z = (int(round(x)), int(round(y)), int(round(z))) return (x, y, z) @@ -83,9 +81,7 @@ def sectorize(position): Returns ------- - sector : tuple of len 3 - - """ + sector : tuple of len 3""" x, y, z = normalize(position) x, y, z = x // SECTOR_SIZE, y // SECTOR_SIZE, z // SECTOR_SIZE return (x, 0, z) @@ -121,9 +117,7 @@ def __init__(self): self._initialize() def _initialize(self): - """ Initialize the world by placing all the blocks. - - """ + """ Initialize the world by placing all the blocks.""" n = 80 # 1/2 width and height of world s = 1 # step size y = 0 # initial y height @@ -169,9 +163,7 @@ def hit_test(self, position, vector, max_distance=8): vector : tuple of len 3 The line of sight vector. max_distance : int - How many blocks away to search for a hit. - - """ + How many blocks away to search for a hit.""" m = 8 x, y, z = position dx, dy, dz = vector @@ -186,9 +178,7 @@ def hit_test(self, position, vector, max_distance=8): def exposed(self, position): """ Returns False is given `position` is surrounded on all 6 sides by - blocks, True otherwise. - - """ + blocks, True otherwise.""" x, y, z = position for dx, dy, dz in FACES: if (x + dx, y + dy, z + dz) not in self.world: @@ -206,9 +196,7 @@ def add_block(self, position, texture, immediate=True): The coordinates of the texture squares. Use `tex_coords()` to generate. immediate : bool - Whether or not to draw the block immediately. - - """ + Whether or not to draw the block immediately.""" if position in self.world: self.remove_block(position, immediate) self.world[position] = texture @@ -226,9 +214,7 @@ def remove_block(self, position, immediate=True): position : tuple of len 3 The (x, y, z) position of the block to remove. immediate : bool - Whether or not to immediately remove block from canvas. - - """ + Whether or not to immediately remove block from canvas.""" del self.world[position] self.sectors[sectorize(position)].remove(position) if immediate: @@ -240,9 +226,7 @@ def check_neighbors(self, position): """ Check all blocks surrounding `position` and ensure their visual state is current. This means hiding blocks that are not exposed and ensuring that all exposed blocks are shown. Usually used after a block - is added or removed. - - """ + is added or removed.""" x, y, z = position for dx, dy, dz in FACES: key = (x + dx, y + dy, z + dz) From c44bfccc44f6521b132a453a6c2db108f9fcd531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Thu, 5 Nov 2020 19:21:26 +0800 Subject: [PATCH 14/27] readme change --- doc/self.World{}.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/doc/self.World{}.md b/doc/self.World{}.md index eb52d91c..b256bb6f 100644 --- a/doc/self.World{}.md +++ b/doc/self.World{}.md @@ -2,8 +2,9 @@ ### now ``` -self.World = {} -{[x, y, z]: TEXTURE} +self.World = { + [x, y, z]: TEXTURE + } ``` ## TEXTURE: @@ -18,6 +19,10 @@ STONE = tex_coords((2, 1), (2, 1), (2, 1)) ### want to be ``` -self.World = {} -{[chunk_id]: {[x, y, z]: [block_states, ]}} +self.World = { + [chunk_id]: { + [x, y, z]: + [block_id, block_states] + } + } ``` From 1d6706958776781aab8736f7b106bde05db2018c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Thu, 5 Nov 2020 20:44:41 +0800 Subject: [PATCH 15/27] lot changes(of readme --- doc/self.World{}.md | 28 ----------------------- doc/want changes/self.World{}.md | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 28 deletions(-) delete mode 100644 doc/self.World{}.md create mode 100644 doc/want changes/self.World{}.md diff --git a/doc/self.World{}.md b/doc/self.World{}.md deleted file mode 100644 index b256bb6f..00000000 --- a/doc/self.World{}.md +++ /dev/null @@ -1,28 +0,0 @@ - -### now - -``` -self.World = { - [x, y, z]: TEXTURE - } -``` - -## TEXTURE: - -``` -GRASS = tex_coords((1, 0), (0, 1), (0, 0)) -SAND = tex_coords((1, 1), (1, 1), (1, 1)) -BRICK = tex_coords((2, 0), (2, 0), (2, 0)) -STONE = tex_coords((2, 1), (2, 1), (2, 1)) -``` - -### want to be - -``` -self.World = { - [chunk_id]: { - [x, y, z]: - [block_id, block_states] - } - } -``` diff --git a/doc/want changes/self.World{}.md b/doc/want changes/self.World{}.md new file mode 100644 index 00000000..e80e98fa --- /dev/null +++ b/doc/want changes/self.World{}.md @@ -0,0 +1,38 @@ + +# now form of self.World + +``` +self.World = { + [x, y, z]: TEXTURE + } +``` + +## TEXTURE are: + +``` +GRASS = tex_coords((1, 0), (0, 1), (0, 0)) +SAND = tex_coords((1, 1), (1, 1), (1, 1)) +BRICK = tex_coords((2, 0), (2, 0), (2, 0)) +STONE = tex_coords((2, 1), (2, 1), (2, 1)) +``` + +# the form want to be of self.World + +``` +self.World = { + [chunk_id]: { + [x1, y1, z1]: + [block_id, block_states, [x2, y2 z2]] + } + } +``` + +## inputs + +``` +x/y/z 1 -> the poi in the world +x/y/z 2 -> the poi in the subchunk +block_id : grass block/brick/stone···· +block_states : sand:[float/on ground] +chunk_id : [0, 0]/[0, 1] +``` From 7ecda94a15413945374fb7ea69463c8fd91cf5f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Fri, 6 Nov 2020 22:39:59 +0800 Subject: [PATCH 16/27] add up logging sys and some other updates preapring --- codes/LT.py | 14 ++++++++++++++ codes/blocks/textures.json | 11 +++++++++++ main.py | 24 +++++++++++++++++++----- 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 codes/LT.py create mode 100644 codes/blocks/textures.json diff --git a/codes/LT.py b/codes/LT.py new file mode 100644 index 00000000..263a7836 --- /dev/null +++ b/codes/LT.py @@ -0,0 +1,14 @@ + +import json +import pyglet +from pyglet import image +from pyglet.graphics import TextureGroup + + +def old_load_textures(textures): + old_image = pyglet.image.load("texture.png").get_texture() + return old_image + + +def load_textures(block_id, block_states, batch): + pass diff --git a/codes/blocks/textures.json b/codes/blocks/textures.json new file mode 100644 index 00000000..a675253e --- /dev/null +++ b/codes/blocks/textures.json @@ -0,0 +1,11 @@ +{ + "textures" : { + "blocks" : { + "grass_block" : { + "top" : "grass_block_side", + "side" : "grass_block_top", + "buttom" : "dirt" + } + } + } +} \ No newline at end of file diff --git a/main.py b/main.py index 83e376e4..f17ce265 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ import math import random import time +import logging from collections import deque from pyglet import image @@ -13,7 +14,14 @@ from codes.lib import * from codes import * -TICKS_PER_SEC = 60 +# get time when the prgram to start the logging +start_time = time.time() +start_time_date = time.strftime("%Y-%m-%d %H-%M-%S", time.gmtime(start_time)) + +# logging started +logging.basicConfig(filename=".\\log\\"+start_time_date+".txt") + +TICKS_PER_SEC = 20 # Size of sectors used to ease block loading. SECTOR_SIZE = 16 @@ -267,15 +275,18 @@ def _show_block(self, position, texture): The (x, y, z) position of the block to show. texture : list of len 3 The coordinates of the texture squares. Use `tex_coords()` to - generate. - - """ + generate.""" x, y, z = position vertex_data = cube_vertices(x, y, z, 0.5) texture_data = list(texture) # create vertex list # FIXME Maybe `add_indexed()` should be used instead - self._shown[position] = self.batch.add(24, GL_QUADS, self.group, + try: + texture_test = old_load_textures(TEXTURE_PATH) + self._shown[position] = self.batch.add(24, GL_QUADS, texture_test, + ('v3f/static', vertex_data),('t2f/static', texture_data)) + except: + self._shown[position] = self.batch.add(24, GL_QUADS, self.group, ('v3f/static', vertex_data), ('t2f/static', texture_data)) @@ -843,9 +854,12 @@ def setup(): def main(): window = Window(width=800, height=600, caption='minecraft PE', resizable=True) + logging.info('start up the main window!') # Hide the mouse cursor and prevent the mouse from leaving the window. window.set_exclusive_mouse(True) + logging.debug('lock the mouse') setup() + logging.info('setup finish!') pyglet.app.run() From cbbbe265cbc1d47c5417efd02c38bba09fce6981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Fri, 6 Nov 2020 22:42:28 +0800 Subject: [PATCH 17/27] woops i forget to change the tick per sec --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index f17ce265..22c114b5 100644 --- a/main.py +++ b/main.py @@ -21,7 +21,7 @@ # logging started logging.basicConfig(filename=".\\log\\"+start_time_date+".txt") -TICKS_PER_SEC = 20 +TICKS_PER_SEC = 60 # Size of sectors used to ease block loading. SECTOR_SIZE = 16 From 2b9343b68a05b2572c3ddaa0020b2ec2f082b32f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Sat, 7 Nov 2020 10:38:06 +0800 Subject: [PATCH 18/27] OMG sorry bu i forget to add the "__init__.py" file also still making --- codes/__init__.py | 0 codes/blocks/__init__.py | 0 codes/{LT.py => load_textures.py} | 10 ++++++++-- codes/updates/__init__.py | 0 main.py | 13 ++++++++----- 5 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 codes/__init__.py create mode 100644 codes/blocks/__init__.py rename codes/{LT.py => load_textures.py} (54%) create mode 100644 codes/updates/__init__.py diff --git a/codes/__init__.py b/codes/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/codes/blocks/__init__.py b/codes/blocks/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/codes/LT.py b/codes/load_textures.py similarity index 54% rename from codes/LT.py rename to codes/load_textures.py index 263a7836..23406e7e 100644 --- a/codes/LT.py +++ b/codes/load_textures.py @@ -5,10 +5,16 @@ from pyglet.graphics import TextureGroup -def old_load_textures(textures): +def old_l_t(textures): + """ + old_l_t stand for old_load_textuers + """ old_image = pyglet.image.load("texture.png").get_texture() return old_image -def load_textures(block_id, block_states, batch): +def l_t(block_id, block_states): + """ + l_t stand for load_textures + """ pass diff --git a/codes/updates/__init__.py b/codes/updates/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/main.py b/main.py index 22c114b5..c2298896 100644 --- a/main.py +++ b/main.py @@ -14,21 +14,24 @@ from codes.lib import * from codes import * +# ---------- option start ---------- +log_level = logging.DEBUG # log level +TICKS_PER_SEC = 60 # FPS +WALKING_SPEED = 5 +FLYING_SPEED = 15 +# ---------- option end ---------- + # get time when the prgram to start the logging start_time = time.time() start_time_date = time.strftime("%Y-%m-%d %H-%M-%S", time.gmtime(start_time)) # logging started logging.basicConfig(filename=".\\log\\"+start_time_date+".txt") - -TICKS_PER_SEC = 60 +logging.basicConfig(level=log_level) # Size of sectors used to ease block loading. SECTOR_SIZE = 16 -WALKING_SPEED = 5 -FLYING_SPEED = 15 - GRAVITY = 20.0 MAX_JUMP_HEIGHT = 1.0 # About the height of a block. From 26883da5748ed6ad50eb50747f31293eadd0a8b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Sat, 7 Nov 2020 11:41:19 +0800 Subject: [PATCH 19/27] some fix of #issue 108 and also worked in py3.7and py3.8 --- main.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index c2298896..6c2c9d95 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,7 @@ import random import time import logging +import codes from collections import deque from pyglet import image @@ -285,7 +286,7 @@ def _show_block(self, position, texture): # create vertex list # FIXME Maybe `add_indexed()` should be used instead try: - texture_test = old_load_textures(TEXTURE_PATH) + texture_test = codes.load_textures.old_l_t(TEXTURE_PATH) self._shown[position] = self.batch.add(24, GL_QUADS, texture_test, ('v3f/static', vertex_data),('t2f/static', texture_data)) except: @@ -382,9 +383,14 @@ def process_queue(self): add_block() or remove_block() was called with immediate=False """ - start = time.perf_counter() - while self.queue and time.perf_counter() - start < 1.0 / TICKS_PER_SEC: - self._dequeue() + if sys.version_info[0] <= 3.8: + start = time.clock() + while self.queue and time.clock() - start < 1.0 / TICKS_PER_SEC: + self._dequeue() + else: # sys.version_info[0] >= 3.8: + start = time.perf_counter() + while self.queue and time.perf_counter() - start < 1.0 / TICKS_PER_SEC: + self._dequeue() def process_entire_queue(self): """ Process the entire queue with no breaks. From 4bc19fb136a2faafb02d75a30e75ddd36be7344d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Sat, 7 Nov 2020 13:35:02 +0800 Subject: [PATCH 20/27] some logging sys change --- .gitignore | 1 + main.py | 36 ++++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 9c532667..1f48ff55 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .vscode/settings.json *.pyc +*.log diff --git a/main.py b/main.py index 6c2c9d95..d0fb8f27 100644 --- a/main.py +++ b/main.py @@ -15,21 +15,25 @@ from codes.lib import * from codes import * +# get time when the prgram to start the logging +start_time = time.time() +start_time_date = time.strftime("%Y-%m-%d %H-%M-%S", time.gmtime(start_time)) + # ---------- option start ---------- -log_level = logging.DEBUG # log level -TICKS_PER_SEC = 60 # FPS +log_level = logging.DEBUG # log level +log_file_name = ".\\log\\"+start_time_date + ".log" +# minecraft/log/2020-11-07 12-23-22 +TICKS_PER_SEC = 60 # FPS WALKING_SPEED = 5 FLYING_SPEED = 15 # ---------- option end ---------- -# get time when the prgram to start the logging -start_time = time.time() -start_time_date = time.strftime("%Y-%m-%d %H-%M-%S", time.gmtime(start_time)) - # logging started -logging.basicConfig(filename=".\\log\\"+start_time_date+".txt") -logging.basicConfig(level=log_level) +logging.basicConfig(filename=log_file_name, level=log_level, + format="[%(asctime)s] : %(message)s", datefmt="%d %H:%M:%S") +logging.info("Minecraft Python Edition Started ") +logging.info("running on python vision "+ sys.version[:2]) # Size of sectors used to ease block loading. SECTOR_SIZE = 16 @@ -288,11 +292,11 @@ def _show_block(self, position, texture): try: texture_test = codes.load_textures.old_l_t(TEXTURE_PATH) self._shown[position] = self.batch.add(24, GL_QUADS, texture_test, - ('v3f/static', vertex_data),('t2f/static', texture_data)) + ('v3f/static', vertex_data), ('t2f/static', texture_data)) except: self._shown[position] = self.batch.add(24, GL_QUADS, self.group, - ('v3f/static', vertex_data), - ('t2f/static', texture_data)) + ('v3f/static', vertex_data), + ('t2f/static', texture_data)) def hide_block(self, position, immediate=True): """ Hide the block at the given `position`. Hiding does not remove the @@ -383,14 +387,14 @@ def process_queue(self): add_block() or remove_block() was called with immediate=False """ - if sys.version_info[0] <= 3.8: - start = time.clock() - while self.queue and time.clock() - start < 1.0 / TICKS_PER_SEC: - self._dequeue() - else: # sys.version_info[0] >= 3.8: + try: start = time.perf_counter() while self.queue and time.perf_counter() - start < 1.0 / TICKS_PER_SEC: self._dequeue() + except: + start = time.clock() + while self.queue and time.clock() - start < 1.0 / TICKS_PER_SEC: + self._dequeue() def process_entire_queue(self): """ Process the entire queue with no breaks. From 460b7ec8beca06d1684270dc59dfd4bd47e6e6f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Sat, 7 Nov 2020 14:16:49 +0800 Subject: [PATCH 21/27] O NICE --- main.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index d0fb8f27..561486ea 100644 --- a/main.py +++ b/main.py @@ -30,10 +30,10 @@ # logging started logging.basicConfig(filename=log_file_name, level=log_level, - format="[%(asctime)s] : %(message)s", datefmt="%d %H:%M:%S") + format="[%(asctime)s] : %(message)s", datefmt="%Y%m%d %H:%M:%S") logging.info("Minecraft Python Edition Started ") -logging.info("running on python vision "+ sys.version[:2]) +logging.info("running on python vision " + sys.version[:5]) # Size of sectors used to ease block loading. SECTOR_SIZE = 16 @@ -841,8 +841,13 @@ def setup_fog(): glFogi(GL_FOG_MODE, GL_LINEAR) # How close and far away fog starts and ends. The closer the start and end, # the denser the fog in the fog range. - glFogf(GL_FOG_START, 40.0) - glFogf(GL_FOG_END, 60.0) + fog_start = 40.0 + fog_end = 60.0 + glFogf(GL_FOG_START, fog_start) + glFogf(GL_FOG_END, fog_end) + logging.debug("fog will start at %f" % (fog_start)) + logging.debug("fog will end at %f" % (fog_end)) + logging.info("fog setup finish") def setup(): @@ -861,6 +866,7 @@ def setup(): # as smooth." glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) + logging.debug("some openGL setup done") setup_fog() From 3f6165a30c6e6ac0a54ac4da9af05c69a8b8b218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Sat, 7 Nov 2020 15:22:16 +0800 Subject: [PATCH 22/27] config sys and logging sys --- config.json | 3 +++ main.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 config.json diff --git a/config.json b/config.json new file mode 100644 index 00000000..43a3c3c0 --- /dev/null +++ b/config.json @@ -0,0 +1,3 @@ +{ + "Minecraft_PE config" +} \ No newline at end of file diff --git a/main.py b/main.py index 561486ea..b3b288c0 100644 --- a/main.py +++ b/main.py @@ -30,7 +30,7 @@ # logging started logging.basicConfig(filename=log_file_name, level=log_level, - format="[%(asctime)s] : %(message)s", datefmt="%Y%m%d %H:%M:%S") + format="[%(asctime)s]:[%(levelname)s] %(message)s", datefmt="%Y%m%d %H:%M:%S") logging.info("Minecraft Python Edition Started ") logging.info("running on python vision " + sys.version[:5]) From f85f969add5a39324788214130892ed6f418270c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Sat, 7 Nov 2020 17:29:18 +0800 Subject: [PATCH 23/27] hmmmm testing --- codes/load_textures.py | 3 +-- main.py | 32 ++++++++++++++++---------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/codes/load_textures.py b/codes/load_textures.py index 23406e7e..7df929a8 100644 --- a/codes/load_textures.py +++ b/codes/load_textures.py @@ -1,4 +1,3 @@ - import json import pyglet from pyglet import image @@ -17,4 +16,4 @@ def l_t(block_id, block_states): """ l_t stand for load_textures """ - pass + return diff --git a/main.py b/main.py index b3b288c0..1f8b4952 100644 --- a/main.py +++ b/main.py @@ -28,12 +28,12 @@ FLYING_SPEED = 15 # ---------- option end ---------- -# logging started +# MAINLOG.started logging.basicConfig(filename=log_file_name, level=log_level, - format="[%(asctime)s]:[%(levelname)s] %(message)s", datefmt="%Y%m%d %H:%M:%S") - -logging.info("Minecraft Python Edition Started ") -logging.info("running on python vision " + sys.version[:5]) + format="[%(asctime)s][%(name)s]:[%(levelname)s] %(message)s", datefmt="%Y%m%d %H:%M:%S") +MAINLOG = logging.getLogger("main logger") +MAINLOG.info("Minecraft Python Edition Started ") +MAINLOG.info("running on python vision " + sys.version[:5]) # Size of sectors used to ease block loading. SECTOR_SIZE = 16 @@ -289,14 +289,14 @@ def _show_block(self, position, texture): texture_data = list(texture) # create vertex list # FIXME Maybe `add_indexed()` should be used instead - try: - texture_test = codes.load_textures.old_l_t(TEXTURE_PATH) - self._shown[position] = self.batch.add(24, GL_QUADS, texture_test, - ('v3f/static', vertex_data), ('t2f/static', texture_data)) + texture_test = codes.load_textures.old_l_t(TEXTURE_PATH) + self._shown[position] = self.batch.add(24, GL_QUADS, texture_test,('v3f/static', vertex_data), ('t2f/static', texture_data)) + """ except: self._shown[position] = self.batch.add(24, GL_QUADS, self.group, ('v3f/static', vertex_data), ('t2f/static', texture_data)) + """ def hide_block(self, position, immediate=True): """ Hide the block at the given `position`. Hiding does not remove the @@ -845,9 +845,9 @@ def setup_fog(): fog_end = 60.0 glFogf(GL_FOG_START, fog_start) glFogf(GL_FOG_END, fog_end) - logging.debug("fog will start at %f" % (fog_start)) - logging.debug("fog will end at %f" % (fog_end)) - logging.info("fog setup finish") + MAINLOG.debug("fog will start at %f" % (fog_start)) + MAINLOG.debug("fog will end at %f" % (fog_end)) + MAINLOG.info("fog setup finish") def setup(): @@ -866,19 +866,19 @@ def setup(): # as smooth." glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) - logging.debug("some openGL setup done") + MAINLOG.debug("some openGL setup done") setup_fog() def main(): window = Window(width=800, height=600, caption='minecraft PE', resizable=True) - logging.info('start up the main window!') + MAINLOG.info('start up the main window!') # Hide the mouse cursor and prevent the mouse from leaving the window. window.set_exclusive_mouse(True) - logging.debug('lock the mouse') + MAINLOG.debug('lock the mouse') setup() - logging.info('setup finish!') + MAINLOG.info('setup finish!') pyglet.app.run() From ed32eb8815fa1f4ec0d128f4d081899e3b1d947b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Sat, 7 Nov 2020 17:56:34 +0800 Subject: [PATCH 24/27] ha? --- codes/{load_textures.py => test.py} | 0 main.py | 3 +-- 2 files changed, 1 insertion(+), 2 deletions(-) rename codes/{load_textures.py => test.py} (100%) diff --git a/codes/load_textures.py b/codes/test.py similarity index 100% rename from codes/load_textures.py rename to codes/test.py diff --git a/main.py b/main.py index 1f8b4952..e94f17d6 100644 --- a/main.py +++ b/main.py @@ -13,7 +13,6 @@ from pyglet.graphics import TextureGroup from pyglet.window import key, mouse from codes.lib import * -from codes import * # get time when the prgram to start the logging start_time = time.time() @@ -289,7 +288,7 @@ def _show_block(self, position, texture): texture_data = list(texture) # create vertex list # FIXME Maybe `add_indexed()` should be used instead - texture_test = codes.load_textures.old_l_t(TEXTURE_PATH) + texture_test = codes.texture_load.old_l_t(TEXTURE_PATH) self._shown[position] = self.batch.add(24, GL_QUADS, texture_test,('v3f/static', vertex_data), ('t2f/static', texture_data)) """ except: From 4af62a8d2b7d5b6c078a34e47b7a0ed0d3ea2462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Sat, 7 Nov 2020 18:56:36 +0800 Subject: [PATCH 25/27] damn it! --- codes/__init__.py | 7 +++++++ codes/blocks/dirt.py | 1 - codes/blocks/grass_block.py | 1 - codes/blocks/sand.py | 1 - codes/lib.py | 1 - codes/{test.py => load_textures.py} | 0 codes/updates/block.py | 5 ----- 7 files changed, 7 insertions(+), 9 deletions(-) rename codes/{test.py => load_textures.py} (100%) diff --git a/codes/__init__.py b/codes/__init__.py index e69de29b..929bae0a 100644 --- a/codes/__init__.py +++ b/codes/__init__.py @@ -0,0 +1,7 @@ +# import .py +from codes import lib +from codes import load_textures + +# import folders +from codes import blocks +from codes import updates \ No newline at end of file diff --git a/codes/blocks/dirt.py b/codes/blocks/dirt.py index a5a71403..fd585de1 100644 --- a/codes/blocks/dirt.py +++ b/codes/blocks/dirt.py @@ -1,4 +1,3 @@ -from codes import * def ben_update(): diff --git a/codes/blocks/grass_block.py b/codes/blocks/grass_block.py index a5a71403..fd585de1 100644 --- a/codes/blocks/grass_block.py +++ b/codes/blocks/grass_block.py @@ -1,4 +1,3 @@ -from codes import * def ben_update(): diff --git a/codes/blocks/sand.py b/codes/blocks/sand.py index a5a71403..fd585de1 100644 --- a/codes/blocks/sand.py +++ b/codes/blocks/sand.py @@ -1,4 +1,3 @@ -from codes import * def ben_update(): diff --git a/codes/lib.py b/codes/lib.py index 09fa3f6e..b3549bf1 100644 --- a/codes/lib.py +++ b/codes/lib.py @@ -12,7 +12,6 @@ # from pyglet.gl import * from pyglet.graphics import TextureGroup from pyglet.window import key, mouse -from codes import * def cube_vertices(x, y, z, n): diff --git a/codes/test.py b/codes/load_textures.py similarity index 100% rename from codes/test.py rename to codes/load_textures.py diff --git a/codes/updates/block.py b/codes/updates/block.py index 1f4302f5..3eb2d92a 100644 --- a/codes/updates/block.py +++ b/codes/updates/block.py @@ -1,4 +1,3 @@ -from codes import * def place_block_update(position, world): @@ -6,10 +5,6 @@ def place_block_update(position, world): position : tuple of len 3 The (x, y, z) position of the ben place block to update. """ - if (position[1] == 0) or (position[1] == 1): - send_poi = position[0] -= 1, position[1], position[2] - world[position[0] -= 1] - world[] return From f59d6b165f0c74edf58c6ee9f3441aa3d779afdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Fri, 27 Nov 2020 23:50:34 +0800 Subject: [PATCH 26/27] some changes --- codes/__init__.py | 3 +- codes/lib.py | 81 ------------------------------------ codes/load_textures.py | 19 --------- main.py | 93 ++++++++++++++++++++++++++++++++++++++---- 4 files changed, 86 insertions(+), 110 deletions(-) delete mode 100644 codes/load_textures.py diff --git a/codes/__init__.py b/codes/__init__.py index 929bae0a..50d87b4d 100644 --- a/codes/__init__.py +++ b/codes/__init__.py @@ -1,6 +1,5 @@ -# import .py +# import file from codes import lib -from codes import load_textures # import folders from codes import blocks diff --git a/codes/lib.py b/codes/lib.py index b3549bf1..9d38b14b 100644 --- a/codes/lib.py +++ b/codes/lib.py @@ -13,84 +13,3 @@ from pyglet.graphics import TextureGroup from pyglet.window import key, mouse - -def cube_vertices(x, y, z, n): - """ Return the vertices of the cube at position x, y, z with size 2*n. - - """ - return [ - x-n, y+n, z-n, x-n, y+n, z+n, x+n, y+n, z+n, x+n, y+n, z-n, # top - x-n, y-n, z-n, x+n, y-n, z-n, x+n, y-n, z+n, x-n, y-n, z+n, # bottom - x-n, y-n, z-n, x-n, y-n, z+n, x-n, y+n, z+n, x-n, y+n, z-n, # left - x+n, y-n, z+n, x+n, y-n, z-n, x+n, y+n, z-n, x+n, y+n, z+n, # right - x-n, y-n, z+n, x+n, y-n, z+n, x+n, y+n, z+n, x-n, y+n, z+n, # front - x+n, y-n, z-n, x-n, y-n, z-n, x-n, y+n, z-n, x+n, y+n, z-n, # back - ] - - -def tex_coord(x, y, n=4): - """ Return the bounding vertices of the texture square. - - """ - m = 1.0 / n - dx = x * m - dy = y * m - return dx, dy, dx + m, dy, dx + m, dy + m, dx, dy + m - - -def tex_coords(top, bottom, side): - """ Return a list of the texture squares for the top, bottom and side. - - """ - top = tex_coord(*top) - bottom = tex_coord(*bottom) - side = tex_coord(*side) - result = [] - result.extend(top) - result.extend(bottom) - result.extend(side * 4) - return result - - -def get_TEXTURES(main_path): - png_re = re.compile(r'.*\\.png') - folder_re = re.compile(r'.*\\..*') - main_lists = os.listdir(main_path) - png_list = [] - folder_list = [] - for dir in main_lists(): - if png_re.match(dir): - png_list.append(dir) - elif not(folder_re.match(dir)): - folder_list.append(dir) - return - -def folder_open(path, open_all=False, re_match=None): - """folder opener by shenjackyuanjie - Parameters - ---------- - path : str of path - - open_all : bool open every folder? - - re_match : re.compile do match? - - Returns - ------- - list of what you want - """ - main_lists = os.listdir(path) - get_items = [] - for dir in main_lists(): - if (re_match) and (re_match.match(dir)): - get_items.append(dir) - continue - if (open_all) and (not(re.search(r'.*\\..*', dir))): - print(path, dir) - open_path = path.join('\\', dir) - print(open_path) - folder_open(open_path, open_all=True, re_match=re_match) - else: - pass - return get_items - diff --git a/codes/load_textures.py b/codes/load_textures.py deleted file mode 100644 index 7df929a8..00000000 --- a/codes/load_textures.py +++ /dev/null @@ -1,19 +0,0 @@ -import json -import pyglet -from pyglet import image -from pyglet.graphics import TextureGroup - - -def old_l_t(textures): - """ - old_l_t stand for old_load_textuers - """ - old_image = pyglet.image.load("texture.png").get_texture() - return old_image - - -def l_t(block_id, block_states): - """ - l_t stand for load_textures - """ - return diff --git a/main.py b/main.py index e94f17d6..07589510 100644 --- a/main.py +++ b/main.py @@ -71,6 +71,88 @@ ] +def cube_vertices(x, y, z, n): + """ Return the vertices of the cube at position x, y, z with size 2*n. + + """ + return [ + x-n, y+n, z-n, x-n, y+n, z+n, x+n, y+n, z+n, x+n, y+n, z-n, # top + x-n, y-n, z-n, x+n, y-n, z-n, x+n, y-n, z+n, x-n, y-n, z+n, # bottom + x-n, y-n, z-n, x-n, y-n, z+n, x-n, y+n, z+n, x-n, y+n, z-n, # left + x+n, y-n, z+n, x+n, y-n, z-n, x+n, y+n, z-n, x+n, y+n, z+n, # right + x-n, y-n, z+n, x+n, y-n, z+n, x+n, y+n, z+n, x-n, y+n, z+n, # front + x+n, y-n, z-n, x-n, y-n, z-n, x-n, y+n, z-n, x+n, y+n, z-n, # back + ] + + +def tex_coord(x, y, n=4): + """ Return the bounding vertices of the texture square. + + """ + m = 1.0 / n + dx = x * m + dy = y * m + return dx, dy, dx + m, dy, dx + m, dy + m, dx, dy + m + + +def tex_coords(top, bottom, side): + """ Return a list of the texture squares for the top, bottom and side. + + """ + top = tex_coord(*top) + bottom = tex_coord(*bottom) + side = tex_coord(*side) + result = [] + result.extend(top) + result.extend(bottom) + result.extend(side * 4) + return result + + +def get_TEXTURES(main_path): + png_re = re.compile(r'.*\\.png') + folder_re = re.compile(r'.*\\..*') + main_lists = os.listdir(main_path) + png_list = [] + folder_list = [] + for dir in main_lists(): + if png_re.match(dir): + png_list.append(dir) + elif not(folder_re.match(dir)): + folder_list.append(dir) + return + + +def folder_open(path, open_all=False, re_match=None): + """folder opener by shenjackyuanjie + Parameters + ---------- + path : str of path + + open_all : bool open every folder? + + re_match : re.compile do match? + + Returns + ------- + list of what you want + """ + main_lists = os.listdir(path) + get_items = [] + for dir in main_lists(): + if (re_match) and (re_match.match(dir)): + get_items.append(dir) + continue + if (open_all) and (not(re.search(r'.*\\..*', dir))): + print(path, dir) + open_path = path.join('\\', dir) + print(open_path) + folder_open(open_path, open_all=True, re_match=re_match) + else: + pass + return get_items + + def normalize(position): """ Accepts `position` of arbitrary precision and returns the block containing that position. @@ -288,14 +370,9 @@ def _show_block(self, position, texture): texture_data = list(texture) # create vertex list # FIXME Maybe `add_indexed()` should be used instead - texture_test = codes.texture_load.old_l_t(TEXTURE_PATH) - self._shown[position] = self.batch.add(24, GL_QUADS, texture_test,('v3f/static', vertex_data), ('t2f/static', texture_data)) - """ - except: - self._shown[position] = self.batch.add(24, GL_QUADS, self.group, - ('v3f/static', vertex_data), - ('t2f/static', texture_data)) - """ + self._shown[position] = self.batch.add(24, GL_QUADS, self.group, + ('v3f/static', vertex_data), + ('t2f/static', texture_data)) def hide_block(self, position, immediate=True): """ Hide the block at the given `position`. Hiding does not remove the From 964e65ec30098eba56c481faa78a5c11dbe5bcbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Sun, 7 Feb 2021 13:50:21 +0800 Subject: [PATCH 27/27] reeee --- main.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 07589510..8f3253f5 100644 --- a/main.py +++ b/main.py @@ -56,6 +56,21 @@ TEXTURE_PATH = 'texture.png' + +def tex_coords(top, bottom, side): + """ Return a list of the texture squares for the top, bottom and side. + + """ + top = tex_coord(*top) + bottom = tex_coord(*bottom) + side = tex_coord(*side) + result = [] + result.extend(top) + result.extend(bottom) + result.extend(side * 4) + return result + + GRASS = tex_coords((1, 0), (0, 1), (0, 0)) SAND = tex_coords((1, 1), (1, 1), (1, 1)) BRICK = tex_coords((2, 0), (2, 0), (2, 0)) @@ -95,18 +110,6 @@ def tex_coord(x, y, n=4): return dx, dy, dx + m, dy, dx + m, dy + m, dx, dy + m -def tex_coords(top, bottom, side): - """ Return a list of the texture squares for the top, bottom and side. - - """ - top = tex_coord(*top) - bottom = tex_coord(*bottom) - side = tex_coord(*side) - result = [] - result.extend(top) - result.extend(bottom) - result.extend(side * 4) - return result def get_TEXTURES(main_path):