1+ import engine_main
2+
3+ import engine
4+ from engine_nodes import CameraNode , MeshNode
5+ from engine_math import Vector3 , Matrix4x4
6+ from engine_resources import NoiseResource
7+ import engine_io
8+ import math
9+ # import machine
10+ # machine.freq(250 * 1000 * 1000)
11+
12+ engine .fps_limit (60 )
13+
14+ class MyCam (CameraNode ):
15+ def __init__ (self ):
16+ super ().__init__ (self )
17+ self .distance = 0.75
18+ self .mode = 0
19+ self .position .z = - 25
20+
21+ def forward (self ):
22+ self .position .x += math .cos (self .rotation .y ) * self .distance
23+ self .position .z += math .sin (self .rotation .y ) * self .distance
24+
25+ def backward (self ):
26+ self .position .x -= math .cos (self .rotation .y ) * self .distance
27+ self .position .z -= math .sin (self .rotation .y ) * self .distance
28+
29+ def left (self ):
30+ self .position .x -= math .cos (self .rotation .y + (math .pi / 2 )) * self .distance
31+ self .position .z -= math .sin (self .rotation .y + (math .pi / 2 )) * self .distance
32+
33+ def right (self ):
34+ self .position .x += math .cos (self .rotation .y + (math .pi / 2 )) * self .distance
35+ self .position .z += math .sin (self .rotation .y + (math .pi / 2 )) * self .distance
36+
37+ def tick (self , dt ):
38+ # print(engine.get_running_fps())
39+ # print(self.position.x, self.position.y, self.position.z)
40+
41+ if engine_io .RB .is_pressed :
42+ self .rotation .y += 0.05
43+ engine_io .rumble (self .rotation .y )
44+ if engine_io .LB .is_pressed :
45+ self .rotation .y -= 0.05
46+ engine_io .rumble (self .rotation .y )
47+
48+
49+ if engine_io .UP .is_pressed :
50+ self .forward ()
51+ if engine_io .DOWN .is_pressed :
52+ self .backward ()
53+ if engine_io .LEFT .is_pressed :
54+ self .left ()
55+ if engine_io .RIGHT .is_pressed :
56+ self .right ()
57+
58+ if engine_io .A .is_pressed :
59+ if self .mode == 0 :
60+ self .position .y -= 1
61+ else :
62+ self .rotation .x -= 0.5
63+ if engine_io .B .is_pressed :
64+ if self .mode == 0 :
65+ self .position .y += 1
66+ else :
67+ self .rotation .x += 0.5
68+
69+ if engine_io .MENU .is_pressed :
70+ if self .mode == 0 :
71+ self .mode = 1
72+ else :
73+ self .mode = 0
74+
75+
76+ camera = MyCam ()
77+ mesh = MeshNode ()
78+ noise = NoiseResource ()
79+
80+
81+ quad_count = 0
82+
83+
84+ def add_quad (v1 , v2 , v3 , v4 ):
85+ quad_count += 1
86+ mesh .vertices .append (v1 )
87+ mesh .vertices .append (v2 )
88+ mesh .vertices .append (v3 )
89+
90+ mesh .vertices .append (v3 )
91+ mesh .vertices .append (v4 )
92+ mesh .vertices .append (v1 )
93+
94+
95+ def is_solid (x , y , z ):
96+ if noise .noise_3d (x * 3 , y * 3 , z * 3 ) < 0.25 :
97+ return True
98+ else :
99+ return False
100+
101+ size = 4
102+
103+ for x in range (16 ):
104+ for y in range (16 ):
105+ for z in range (16 ):
106+ gx = x * size - 8 * size
107+ gy = y * size - 8 * size
108+ gz = z * size - 8 * size
109+
110+ this_solid = is_solid (x , y , z )
111+
112+ if this_solid != is_solid (x + 1 , y , z ):
113+ if this_solid :
114+ add_quad (Vector3 (gx , gy - size , gz - size ),
115+ Vector3 (gx , gy , gz - size ),
116+ Vector3 (gx , gy , gz ),
117+ Vector3 (gx , gy - size , gz ))
118+ else :
119+ add_quad (Vector3 (gx , gy - size , gz - size ),
120+ Vector3 (gx , gy - size , gz ),
121+ Vector3 (gx , gy , gz ),
122+ Vector3 (gx , gy , gz - size ))
123+
124+ if this_solid != is_solid (x , y + 1 , z ):
125+ if this_solid :
126+ add_quad (Vector3 (gx - size , gy , gz - size ),
127+ Vector3 (gx - size , gy , gz ),
128+ Vector3 (gx , gy , gz ),
129+ Vector3 (gx , gy , gz - size ))
130+ else :
131+ add_quad (Vector3 (gx - size , gy , gz - size ),
132+ Vector3 (gx , gy , gz - size ),
133+ Vector3 (gx , gy , gz ),
134+ Vector3 (gx - size , gy , gz ))
135+
136+ if this_solid != is_solid (x , y , z + 1 ):
137+ if this_solid :
138+ add_quad (Vector3 (gx - size , gy - size , gz ),
139+ Vector3 (gx , gy - size , gz ),
140+ Vector3 (gx , gy , gz ),
141+ Vector3 (gx - size , gy , gz ))
142+ else :
143+ add_quad (Vector3 (gx - size , gy - size , gz ),
144+ Vector3 (gx - size , gy , gz ),
145+ Vector3 (gx , gy , gz ),
146+ Vector3 (gx , gy - size , gz ))
147+
148+
149+ print (quad_count )
150+
151+
152+ # mesh.vertices.append(Vector3(-5, -5, 1))
153+ # mesh.vertices.append(Vector3(5, -5, 1))
154+ # mesh.vertices.append(Vector3(0, 5, 5))
155+
156+ # mesh.vertices.append(Vector3(-5, -5, -1))
157+ # mesh.vertices.append(Vector3(5, -5, -1))
158+ # mesh.vertices.append(Vector3(0, 5, -5))
159+
160+ # mesh.vertices.append(Vector3(-5, -5, 1))
161+ # mesh.vertices.append(Vector3(5, -5, 1))
162+ # mesh.vertices.append(Vector3(0, -10, 5))
163+
164+ # mesh.vertices.append(Vector3(-5, -5, -1))
165+ # mesh.vertices.append(Vector3(5, -5, -1))
166+ # mesh.vertices.append(Vector3(0, -10, -5))
167+
168+
169+ # print(mesh.vertices)
170+
171+ engine .start ()
0 commit comments