Skip to content

Commit 5079c5c

Browse files
committed
Merge branch 'revert'
2 parents 6963a16 + 44db366 commit 5079c5c

14 files changed

Lines changed: 471 additions & 27 deletions

File tree

filesystem/Games/TestGames/JingleTest/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
circle = Circle2DNode()
1010
cam = CameraNode()
1111

12+
import os
13+
os.chdir("Games/JingleTest")
14+
1215
wave = WaveSoundResource("ThumbyColorJingle1.wav")
1316

1417
while True:
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
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()
2.13 KB
Binary file not shown.
44.1 KB
Binary file not shown.
44.1 KB
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main=voxel_example.py
2+
name=VoxelExample
4.07 KB
Binary file not shown.
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
import engine_main
2+
3+
import engine
4+
import engine_draw
5+
import engine_debug
6+
import engine_io
7+
import engine_physics
8+
from engine_nodes import EmptyNode, Sprite2DNode, Rectangle2DNode, Circle2DNode, CameraNode, VoxelSpaceNode, VoxelSpaceSpriteNode
9+
from engine_math import Vector3, Vector2, Rectangle
10+
from engine_resources import TextureResource
11+
import gc
12+
import math
13+
import os
14+
import time
15+
16+
# import machine
17+
18+
# machine.freq(250 * 1000 * 1000)
19+
20+
21+
engine.fps_limit(60)
22+
engine_draw.set_background_color(engine_draw.skyblue)
23+
24+
25+
C18W = TextureResource("C18W.bmp", True)
26+
D18 = TextureResource("D18.bmp", True)
27+
tree_bmp = TextureResource("tree.bmp", True)
28+
tc_bmp = TextureResource("32x32.bmp", True)
29+
30+
vox0 = VoxelSpaceNode(texture=C18W, heightmap=D18)
31+
vox0.position.x = 0
32+
vox0.position.y = 30
33+
vox0.scale.y = 35
34+
vox0.scale.x = 2
35+
vox0.scale.z = 2
36+
vox0.flip = True
37+
vox0.repeat = True
38+
39+
40+
41+
vox1 = VoxelSpaceNode(texture=C18W, heightmap=D18)
42+
vox1.position.x = 0
43+
vox1.position.y = 0
44+
vox1.position.z = 0
45+
vox1.scale.y = 32
46+
vox1.scale.x = 0.75
47+
vox1.scale.z = 0.75
48+
vox1.flip = False
49+
vox1.thickness = 100
50+
# vox1.repeat = True
51+
# vox1.layer = 1
52+
53+
tree = VoxelSpaceSpriteNode(texture=tree_bmp, position=Vector3(0, 0, 0), scale=Vector3(1.0, 1.0, 1.0))
54+
tree.transparent_color = engine_draw.white
55+
tree.opacity = 1.0
56+
tree.position.x = 75
57+
tree.position.z = 75
58+
tree.position.y = vox1.get_abs_height(tree.position.x, tree.position.z)
59+
tree.scale.x = 0.1
60+
tree.scale.y = 0.1
61+
tree.texture_offset.y = tree_bmp.height/2
62+
tree.rotation = math.pi
63+
# tree.texture_offset.x = tree_bmp.width/2
64+
tree.fov_distort = False
65+
# # tree.layer = 0
66+
67+
68+
bmp = VoxelSpaceSpriteNode(texture=tc_bmp, position=Vector3(0, 0, 0), scale=Vector3(1.0, 1.0, 1.0))
69+
# bmp.transparent_color = engine_draw.black
70+
bmp.opacity = 1.0
71+
bmp.position.x = 32
72+
bmp.position.z = 16
73+
bmp.position.y = vox1.get_abs_height(bmp.position.x, bmp.position.z)
74+
75+
76+
77+
class MyCam(CameraNode):
78+
def __init__(self):
79+
super().__init__(self)
80+
self.distance = 0.25
81+
self.mode = 0
82+
self.t = 0
83+
84+
def adjust(self):
85+
vox0_height = vox0.get_abs_height(self.position.x, self.position.z)
86+
vox1_height = vox1.get_abs_height(self.position.x, self.position.z)
87+
88+
if(vox1_height != None and self.position.y < vox1_height):
89+
self.position.y = vox1_height
90+
91+
if(vox0_height != None and self.position.y > vox0_height):
92+
self.position.y = vox0_height
93+
94+
def forward(self):
95+
self.position.x += math.cos(self.rotation.y) * self.distance
96+
self.position.z += math.sin(self.rotation.y) * self.distance
97+
self.adjust()
98+
99+
def backward(self):
100+
self.position.x -= math.cos(self.rotation.y) * self.distance
101+
self.position.z -= math.sin(self.rotation.y) * self.distance
102+
self.adjust()
103+
104+
def left(self):
105+
self.position.x -= math.cos(self.rotation.y+(math.pi/2)) * self.distance
106+
self.position.z -= math.sin(self.rotation.y+(math.pi/2)) * self.distance
107+
self.adjust()
108+
109+
def right(self):
110+
self.position.x += math.cos(self.rotation.y+(math.pi/2)) * self.distance
111+
self.position.z += math.sin(self.rotation.y+(math.pi/2)) * self.distance
112+
self.adjust()
113+
114+
def tick(self, dt):
115+
gc.collect()
116+
print(self.position)
117+
# print(engine.get_running_fps())
118+
self.t += 0.01
119+
# vox0.position.y = 20 + math.sin(self.t)
120+
121+
if engine_io.RB.is_pressed:
122+
if self.mode == 0:
123+
self.rotation.y += 0.025
124+
elif self.mode == 2:
125+
self.rotation.z += 0.005
126+
# self.rotation.x -= 0.005
127+
elif self.mode == 3:
128+
vox0.lod += 0.001
129+
vox1.lod += 0.001
130+
elif self.mode == 4:
131+
vox0.curvature += 0.005
132+
vox1.curvature += 0.005
133+
elif self.mode == 5:
134+
vox0.scale.y += 1
135+
vox1.scale.y += 1
136+
elif self.mode == 6:
137+
self.fov += 0.05
138+
if engine_io.LB.is_pressed:
139+
if self.mode == 0:
140+
self.rotation.y -= 0.025
141+
elif self.mode == 2:
142+
self.rotation.z -= 0.005
143+
self.rotation.x += 0.005
144+
elif self.mode == 3:
145+
vox0.lod -= 0.001
146+
vox1.lod -= 0.001
147+
elif self.mode == 4:
148+
vox0.curvature -= 0.005
149+
vox1.curvature -= 0.005
150+
elif self.mode == 5:
151+
vox0.scale.y -= 1
152+
vox1.scale.y -= 1
153+
elif self.mode == 6:
154+
self.fov -= 0.05
155+
156+
157+
if engine_io.UP.is_pressed:
158+
self.forward()
159+
if engine_io.DOWN.is_pressed:
160+
self.backward()
161+
if engine_io.LEFT.is_pressed:
162+
self.left()
163+
if engine_io.RIGHT.is_pressed:
164+
self.right()
165+
166+
if engine_io.A.is_pressed:
167+
if self.mode == 0:
168+
self.position.y += 0.1
169+
self.adjust()
170+
elif self.mode == 1:
171+
self.rotation.x -= 0.1
172+
if engine_io.B.is_pressed:
173+
if self.mode == 0:
174+
self.position.y -= 0.1
175+
self.adjust()
176+
elif self.mode == 1:
177+
self.rotation.x += 0.1
178+
179+
if engine_io.MENU.is_just_pressed:
180+
# vox.scale.y += 0.5
181+
# print(vox.scale.y)
182+
self.mode = self.mode + 1
183+
if self.mode >= 7:
184+
self.mode = 0
185+
186+
print(self.mode)
187+
188+
189+
camera = MyCam()
190+
camera.position.x = 0
191+
camera.position.y = 0
192+
camera.position.z = 0
193+
# camera.rotation.x = 0.3
194+
camera.view_distance = 350
195+
# camera.fov = 32 * (math.pi/180)
196+
camera.fov = 70 * (math.pi/180)
197+
198+
camera.add_child(Circle2DNode(radius=1, color=engine_draw.green, outline=True))
199+
200+
engine.start()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
John Doe,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Mary Jane,

0 commit comments

Comments
 (0)