-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathChecking Ursina Installation in Python.txt
More file actions
5624 lines (5588 loc) ยท 91.1 KB
/
Checking Ursina Installation in Python.txt
File metadata and controls
5624 lines (5588 loc) ยท 91.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Checking Ursina Installation in Python - Grok
try a python program to see if i have ursina installed
Here's a simple Python program to check if Ursina is installed:
python
Collapse
Wrap
Copy
try
:
import
ursina
print
(
"Ursina is installed! Version:"
, ursina.__version__)
except
ImportError:
print
(
"Ursina is not installed."
)
Save this as a
.py
file and run it. If Ursina is installed, it will display the version number; if not, it will let you know it's missing. Make sure to run this in the same Python environment where you think Ursina might be installed.
bonobo@Memex:ursina(main)$ ./is-it-installed.py
Traceback (most recent call last):
File "/mnt/c/Users/Mechachleopteryx/OneDrive/Documents/GitHub/ursina/./is-it-installed.py", line 5, in <module>
print("Ursina is installed! Version:", ursina.__version__)
AttributeError: module 'ursina' has no attribute '__version__'
The error indicates that Ursina is installed (since there's no
ImportError
), but the module doesn't have a
__version__
attribute, which is why the script fails. Some Ursina installations, especially older or custom versions, might not expose a
__version__
attribute.
Here's a modified Python program to handle this gracefully:
python
Collapse
Wrap
Copy
try
:
import
ursina
# Try to get version, fallback if it doesn't exist
version =
getattr
(ursina,
'__version__'
,
'unknown'
)
print
(
f"Ursina is installed! Version:
{version}
"
)
except
ImportError:
print
(
"Ursina is not installed."
)
Save and run this updated script. It will confirm Ursina is installed and either show the version (if available) or indicate "unknown" if the
__version__
attribute is missing. Since you're running this in what looks like a development environment (
ursina(main)
branch), the missing
__version__
might be due to a local or unreleased build. If you need to confirm the exact version, you could also check your
pip
installation with:
bash
Collapse
Wrap
Copy
pip show ursina
This will display metadata, including the version, if it's installed via pip. Let me know if you need further help!
it's working how do I see if I can make a 3d model?
Since Ursina is installed, you can create a 3D model in Ursina by writing a simple Python program to test rendering a basic 3D object, like a cube. Ursina is a game engine built on Panda3D, so it supports 3D models out of the box, but you'll need to ensure your environment is set up to display graphics (e.g., a working OpenGL context and a display server if you're on Linux).
Here's a minimal Python program to test if you can create and display a 3D model (a cube) in Ursina:
python
Collapse
Wrap
Copy
from
ursina
import
*
# Create the Ursina app
app = Ursina()
# Create a 3D cube
cube = Entity(model=
'cube'
, color=color.red, scale=(
1
,
1
,
1
))
# Add a camera to view the cube
camera.position = (
0
,
0
, -
5
)
# Move camera back to see the cube
# Add basic lighting
DirectionalLight(direction=(
0
,
1
,
1
), color=color.white)
# Run the app
app.run()
Steps to Run:
Save this as
test_3d.py
.
Run it with Python:
python test_3d.py
.
If everything works, a window should open showing a red 3D cube that you can rotate with the mouse (hold right-click and drag).
What This Tests:
Ursina Setup
: Confirms Ursina can initialize a window and render a 3D scene.
Graphics Environment
: Verifies your system supports OpenGL and Ursina's rendering pipeline.
3D Model Creation
: The cube is a built-in 3D model, proving you can create and display 3D objects.
Troubleshooting:
No Window Appears
: Ensure your system has a graphical environment (e.g., X11 or Wayland on Linux, or WSL2 with a GUI setup if you're on WSL). You might need to install dependencies like
libgl1-mesa-glx
or
freeglut3
on Linux.
Errors About OpenGL
: Update your graphics drivers or check if your Python environment is using the correct display settings.
Module Errors
: If Ursina imports but fails to run, ensure all dependencies (like Panda3D) are installed. You can reinstall Ursina with
pip install ursina --force-reinstall
to fix missing dependencies.
Notes:
The path in your error (
/mnt/c/...
) suggests you might be using WSL. If so, ensure you have a GUI backend like VcXsrv or WSLg set up for graphical apps.
Ursina supports custom 3D models (e.g.,
.obj
or
.blend
files), but this cube test confirms the basics. If you want to load custom models, let me know, and I can provide a follow-up example.
If you're in a virtual environment or specific branch (
ursina(main)
), ensure it's activated when running the script.
Run the program and let me know what happens! If you get errors or want to try something specific (like loading a custom model), I can dig deeper.
try a spinning cube with more contrast
Since you confirmed Ursina is working and want a spinning cube with more contrast, I'll modify the previous program to make a cube rotate automatically and enhance visual contrast by adjusting the cube's color, lighting, and background. A bright cube (e.g., vivid cyan) against a dark background with stronger lighting will pop more.
Here's the Python program:
python
Collapse
Wrap
Copy
from
ursina
import
*
# Create the Ursina app
app = Ursina()
# Set a dark background for contrast
scene.clear_color = color.rgb(
20
,
20
,
30
)
# Near-black with slight blue tint
# Create a 3D cube with a vivid color
cube = Entity(model=
'cube'
, color=color.cyan, scale=(
1
,
1
,
1
))
# Make the cube spin
def
update
():
cube.rotation_y += time.dt *
100
# Rotate 100 degrees per second around Y-axis
cube.rotation_x += time.dt *
50
# Rotate 50 degrees per second around X-axis
# Position the camera to view the cube
camera.position = (
0
,
0
, -
5
)
# Add strong directional light for high contrast
DirectionalLight(direction=(
0.5
,
0.5
,
1
), color=color.white, intensity=
1.5
)
# Add ambient light to soften shadows slightly
AmbientLight(color=color.rgba(
0.2
,
0.2
,
0.2
,
1
))
# Run the app
app.run()
What's Changed:
Spinning Cube
: The
update()
function rotates the cube on both Y and X axes using
time.dt
for smooth, frame-rate-independent rotation.
Higher Contrast
:
Cube Color
: Vivid cyan (
color.cyan
) for a bright, eye-catching look.
Background
: Dark, near-black with a slight blue tint (
rgb(20, 20, 30)
) to make the cube stand out.
Lighting
: Strong directional light (
intensity=1.5
) to emphasize the cube's edges, plus a subtle ambient light to prevent harsh shadows.
Camera and Scale
: Kept the same for consistency, but the cube's vivid color and lighting make it visually sharper.
How to Run:
Save this as
spinning_cube.py
.
Run it:
python spinning_cube.py
.
You should see a cyan cube spinning in a window against a dark background. You can still rotate the view with the mouse (right-click and drag) if you want to inspect it.
Troubleshooting:
No Window or Crashes
: Since you're likely on WSL (
/mnt/c/...
), ensure your GUI setup (e.g., VcXsrv or WSLg) is active. If you're on native Linux, verify OpenGL with
glxinfo | grep "OpenGL version"
.
Cube Not Visible
: If the cube doesn't appear, try adjusting
camera.position
(e.g., to
(0, 0, -10)
) in case it's too close or clipped.
Contrast Not Enough
: If you want even more pop, let me knowโe.g., I can add a glowing shader or tweak colors further.
Let me know how it looks or if you want to tweak it (e.g., different colors, faster spin, or adding textures)! Also, since you're in the
ursina(main)
branch, are you working on Ursina development, or just testing locally? That might help me tailor advice.
Ok it is awesome, I am going to want to have a kind of 3d scene with a round pool table for my La Ronde game with cue sticks and 4 sink holes, two working cue balls with ying yang symbol on them, points and so we can rotate the table or room with additional buttons or controls, change the tilt of the view, and so on. Here is a partially working protototype we worked on before if you can try to incorporate it into the game: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Swoo Ball</title>
<style>
body {
margin: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: #202020;
}
canvas {
border: 2px solid #fff;
background-color: #3b3b3b;
border-radius: 50%;
}
</style>
</head>
<body>
<canvas id="gameCanvas" width="600" height="600"></canvas>
<script>
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
const center = { x: canvas.width / 2, y: canvas.height / 2 };
const radius = canvas.width / 2 - 10;
const balls = [];
const POCKET_RADIUS = 20;
const COLORS = { cue: '#ffffff', blue: '#0074D9', green: '#2ECC40', swoo: '#cccccc' };
function Ball(x, y, color, number, type) {
this.x = x;
this.y = y;
this.vx = 0;
this.vy = 0;
this.radius = 12;
this.color = color;
this.number = number;
this.type = type; // 'cue', 'blue', 'green', 'swoo'
}
function initBalls() {
balls.push(new Ball(center.x, center.y + 100, COLORS.cue, null, 'cue'));
for (let i = 1; i <= 6; i++) {
const angle = (i * Math.PI) / 3;
const x = center.x + 50 * Math.cos(angle);
const y = center.y + 50 * Math.sin(angle);
balls.push(new Ball(x, y, COLORS.blue, i, 'blue'));
}
for (let i = 1; i <= 6; i++) {
const angle = (i * Math.PI) / 3 + Math.PI / 6;
const x = center.x + 70 * Math.cos(angle);
const y = center.y + 70 * Math.sin(angle);
balls.push(new Ball(x, y, COLORS.green, i, 'green'));
}
balls.push(new Ball(center.x, center.y, COLORS.swoo, null, 'swoo'));
}
function drawTable() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.beginPath();
ctx.arc(center.x, center.y, radius, 0, Math.PI * 2);
ctx.fillStyle = '#3b3b3b';
ctx.fill();
[0, 1, 2, 3, 4, 5].forEach(i => {
const angle = (i * Math.PI) / 3;
const x = center.x + radius * Math.cos(angle);
const y = center.y + radius * Math.sin(angle);
ctx.beginPath();
ctx.arc(x, y, POCKET_RADIUS, 0, Math.PI * 2);
ctx.fillStyle = '#000';
ctx.fill();
});
}
function drawBalls() {
balls.forEach(ball => {
ctx.beginPath();
ctx.arc(ball.x, ball.y, ball.radius, 0, Math.PI * 2);
ctx.fillStyle = ball.color;
ctx.fill();
if (ball.number) {
ctx.fillStyle = '#fff';
ctx.font = '12px Arial';
ctx.textAlign = 'center';
ctx.fillText(ball.number, ball.x, ball.y + 4);
}
});
}
function checkCollision(ball1, ball2) {
const dx = ball2.x - ball1.x;
const dy = ball2.y - ball1.y;
const distance = Math.sqrt(dx * dx + dy * dy);
if (distance < ball1.radius + ball2.radius) {
// Normalize collision vector
const nx = dx / distance;
const ny = dy / distance;
// Project velocities onto the normal
const v1n = ball1.vx * nx + ball1.vy * ny;
const v2n = ball2.vx * nx + ball2.vy * ny;
// Assume equal mass, swap normal components for perfect momentum transfer
const v1nAfter = v2n;
const v2nAfter = v1n;
// Tangential components remain unchanged
const v1t = ball1.vx - v1n * nx;
const v1tY = ball1.vy - v1n * ny;
const v2t = ball2.vx - v2n * nx;
const v2tY = ball2.vy - v2n * ny;
// Update velocities
ball1.vx = v1nAfter * nx + v1t;
ball1.vy = v1nAfter * ny + v1tY;
ball2.vx = v2nAfter * nx + v2t;
ball2.vy = v2nAfter * ny + v2tY;
// Separate overlapping balls
const overlap = (ball1.radius + ball2.radius - distance) / 2;
ball1.x -= overlap * nx;
ball1.y -= overlap * ny;
ball2.x += overlap * nx;
ball2.y += overlap * ny;
}
}
function checkWallCollision(ball) {
const distFromCenter = Math.sqrt((ball.x - center.x) ** 2 + (ball.y - center.y) ** 2);
if (distFromCenter + ball.radius > radius) {
const angle = Math.atan2(ball.y - center.y, ball.x - center.x);
const speed = Math.sqrt(ball.vx * ball.vx + ball.vy * ball.vy);
ball.vx = -speed * Math.cos(angle) * 0.9;
ball.vy = -speed * Math.sin(angle) * 0.9;
ball.x = center.x + (radius - ball.radius) * Math.cos(angle);
ball.y = center.y + (radius - ball.radius) * Math.sin(angle);
}
}
function checkPockets(ball) {
[0, 1, 2, 3, 4, 5].forEach(i => {
const angle = (i * Math.PI) / 3;
const pocketX = center.x + radius * Math.cos(angle);
const pocketY = center.y + radius * Math.sin(angle);
const dist = Math.sqrt((ball.x - pocketX) ** 2 + (ball.y - pocketY) ** 2);
if (dist < POCKET_RADIUS) {
balls.splice(balls.indexOf(ball), 1);
}
});
}
function updatePhysics() {
for (let i = 0; i < balls.length; i++) {
balls[i].x += balls[i].vx;
balls[i].y += balls[i].vy;
balls[i].vx *= 0.995; // Reduced friction from 0.98 to 0.995
balls[i].vy *= 0.995;
checkWallCollision(balls[i]);
checkPockets(balls[i]);
for (let j = i + 1; j < balls.length; j++) {
checkCollision(balls[i], balls[j]);
}
}
}
canvas.addEventListener('click', (e) => {
const cueBall = balls.find(b => b.type === 'cue');
if (cueBall) {
const rect = canvas.getBoundingClientRect();
const mouseX = e.clientX - rect.left;
const mouseY = e.clientY - rect.top;
const angle = Math.atan2(mouseY - cueBall.y, mouseX - cueBall.x);
const power = 20; // Increased from 15 to 20
cueBall.vx = power * Math.cos(angle);
cueBall.vy = power * Math.sin(angle);
}
});
function gameLoop() {
drawTable();
drawBalls();
updatePhysics();
requestAnimationFrame(gameLoop);
}
initBalls();
gameLoop();
</script>
</body>
</html>
Your vision for a 3D
La Ronde
game with a round pool table, yin-yang cue balls, four sink holes, and interactive controls sounds fantastic! The HTML prototype you shared is a 2D canvas-based pool game with circular boundaries, ball physics, and pockets, which gives a great foundation. I'll adapt its core concepts into a 3D Ursina scene, incorporating your requirements: a round pool table, two yin-yang cue balls, four pockets, cue sticks, scoring, and controls to rotate the table/room and adjust the camera tilt. I'll also ensure it feels dynamic and visually appealing, building on the spinning cube's success.
Since the prototype is 2D JavaScript, I'll translate its mechanics (circular table, ball collisions, pockets) into 3D while adding the new features. Ursina's physics are simpler than coding collisions from scratch, so I'll use its built-in capabilities where possible, but I'll mimic the prototype's pocket and boundary logic. For yin-yang cue balls, I'll use textures or shaders to approximate the symbol. The controls will use keyboard/mouse inputs for rotation and tilt, with optional buttons in the Ursina UI.
Here's the Python program to create this 3D scene in Ursina:
python
Collapse
Wrap
Copy
from
ursina
import
*
from
ursina.prefabs.first_person_controller
import
FirstPersonController
import
numpy
as
np
app = Ursina()
# Scene setup
scene.clear_color = color.rgb(
20
,
20
,
30
)
# Dark background for contrast
table_radius =
3
table_thickness =
0.2
ball_radius =
0.1
pocket_radius =
0.2
score = {
'player1'
:
0
,
'player2'
:
0
}
# Round pool table
table = Entity(
model=Cylinder(resolution=
64
, radius=table_radius, height=table_thickness),
texture=
'white_cube'
,
# Green felt-like appearance
color=color.rgb(
0
,
100
,
0
),
position=(
0
,
0
,
0
),
collider=
'mesh'
)
# Table rim (slightly raised)
rim = Entity(
model=Cylinder(resolution=
64
, radius=table_radius +
0.1
, height=table_thickness +
0.1
),
color=color.rgb(
50
,
50
,
50
),
position=(
0
, table_thickness /
2
,
0
),
collider=
'mesh'
)
# Pockets (four, evenly spaced)
pockets = []
for
i
in
range
(
4
):
angle = i * np.pi /
2
pocket = Entity(
model=
'sphere'
,
color=color.black,
position=(table_radius * np.cos(angle), table_thickness, table_radius * np.sin(angle)),
scale=pocket_radius *
2
,
collider=
'sphere'
)
pockets.append(pocket)
# Balls
balls = []
# Yin-yang cue balls
cue_ball1 = Entity(
model=
'sphere'
,
color=color.white,
position=(
0
, table_thickness + ball_radius,
0.5
),
scale=ball_radius *
2
,
collider=
'sphere'
,
tag=
'cue1'
)
cue_ball2 = Entity(
model=
'sphere'
,
color=color.white,
position=(
0
, table_thickness + ball_radius, -
0.5
),
scale=ball_radius *
2
,
collider=
'sphere'
,
tag=
'cue2'
)
balls.extend([cue_ball1, cue_ball2])
# Placeholder for yin-yang texture (approximated with color for now)
#
TODO:
Add custom texture or shader later
cue_ball1.texture =
'white_cube'
# Stand-in; replace with yin-yang later
cue_ball2.texture =
'white_cube'
# Other balls (simplified from prototype)
for
i
in
range
(
6
):
# Blue balls
angle = i * np.pi /
3
ball = Entity(
model=
'sphere'
,
color=color.blue,
position=(
0.5
* np.cos(angle), table_thickness + ball_radius,
0.5
* np.sin(angle)),
scale=ball_radius *
2
,
collider=
'sphere'
,
tag=
'blue'
)
balls.append(ball)
for
i
in
range
(
6
):
# Green balls
angle = i * np.pi /
3
+ np.pi /
6
ball = Entity(
model=
'sphere'
,
color=color.green,
position=(
0.7
* np.cos(angle), table_thickness + ball_radius,
0.7
* np.sin(angle)),
scale=ball_radius *
2
,
collider=
'sphere'
,
tag=
'green'
)
balls.append(ball)
# Cue sticks (simple cylinders for now)
cue_stick1 = Entity(
model=
'cube'
,
color=color.brown,
position=(
0
, table_thickness +
0.5
, table_radius +
0.5
),
scale=(
0.05
,
0.05
,
1.5
),
rotation=(
0
,
0
,
90
),
visible=
False
)
cue_stick2 = Entity(
model=
'cube'
,
color=color.brown,
position=(
0
, table_thickness +
0.5
, -(table_radius +
0.5
)),
scale=(
0.05
,
0.05
,
1.5
),
rotation=(
0
,
0
,
90
),
visible=
False
)
# Camera control
camera.position = (
0
,
5
, -
10
)
camera.rotation_x =
30
player = FirstPersonController(position=(
0
,
5
, -
10
), enabled=
False
)
table_rotation_speed =
0
tilt_speed =
0
# Lighting
DirectionalLight(direction=(
0.5
, -
0.5
,
0.5
), color=color.white, intensity=
1.2
)
AmbientLight(color=color.rgba(
0.3
,
0.3
,
0.3
,
1
))
# Physics and game logic
def
update
():
global
table_rotation_speed, tilt_speed
# Rotate table/room
table.rotation_y += table_rotation_speed * time.dt
# Tilt camera
camera.rotation_x += tilt_speed * time.dt
camera.rotation_x = clamp(camera.rotation_x,
10
,
80
)
# Limit tilt
# Check for pocketed balls
for
ball
in
balls[:]:
for
pocket
in
pockets:
dist = distance(ball, pocket)
if
dist < pocket_radius + ball_radius:
if
ball.tag.startswith(
'cue'
):
ball.position = (
0
, table_thickness + ball_radius,
0.5
if
ball.tag ==
'cue1'
else
-
0.5
)
else
:
score[
'player1'
if
ball.tag ==
'blue'
else
'player2'
] +=
1
balls.remove(ball)
destroy(ball)
update_score_text()
# Input handling
def
input
(
key
):
global
table_rotation_speed, tilt_speed
if
key ==
'r'
:
# Rotate table clockwise
table_rotation_speed =
50
elif
key ==
'r up'
:
table_rotation_speed =
0
elif
key ==
'e'
:
# Rotate table counter-clockwise
table_rotation_speed = -
50
elif
key ==
'e up'
:
table_rotation_speed =
0
elif
key ==
'w'
:
# Tilt up
tilt_speed =
20
elif
key ==
'w up'
:
tilt_speed =
0
elif
key ==
's'
:
# Tilt down
tilt_speed = -
20
elif
key ==
's up'
:
tilt_speed =
0
elif
key ==
'c'
:
# Toggle camera control
player.enabled =
not
player.enabled
elif
key ==
'space'
:
# Shoot cue ball (placeholder)
cue_ball = cue_ball1
if
held_keys[
'1'
]
else
cue_ball2
cue_ball.position += Vec3(
0
,
0
,
0.5
)
# Simple push for testing
# UI for controls
Text(text=
'R/E: Rotate Table | W/S: Tilt View | C: Free Camera | Space: Shoot | 1/2: Select Cue'
, y=
0.4
, origin=(
0
,
0
))
score_text = Text(text=
'Player 1: 0\nPlayer 2: 0'
, y=
0.3
, origin=(
0
,
0
))
def
update_score_text
():
score_text.text =
f'Player 1:
{score[
"player1"
]}
\nPlayer 2:
{score[
"player2"
]}
'
# Run the app
app.run()
How It Incorporates Your Prototype:
Round Table
: Uses a
Cylinder
model to mimic the circular table, with a rim and green felt-like texture.
Pockets
: Four pockets (instead of six for simplicity, adjustable if needed) placed at 90-degree intervals, like the prototype's evenly spaced holes.
Balls
: