gamengine3d 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gamengine3d/__init__.py +18 -0
- gamengine3d/assets/__init__.py +0 -0
- gamengine3d/assets/circular_crosshair.png +0 -0
- gamengine3d/assets/plus_sign_crosshair.png +0 -0
- gamengine3d/cli.py +83 -0
- gamengine3d/context.py +319 -0
- gamengine3d/engine.py +715 -0
- gamengine3d/examples/__init__.py +0 -0
- gamengine3d/examples/basics.py +66 -0
- gamengine3d/examples/parkour.py +285 -0
- gamengine3d/examples/player_movement.py +161 -0
- gamengine3d/examples/reactor.py +526 -0
- gamengine3d/examples/scripts/__init__.py +0 -0
- gamengine3d/examples/scripts/bouncer.py +18 -0
- gamengine3d/examples/scripts/breaker_coil.py +17 -0
- gamengine3d/examples/scripts/breaker_decoder.py +39 -0
- gamengine3d/examples/scripts/breaker_gate.py +23 -0
- gamengine3d/examples/scripts/breaker_shield.py +28 -0
- gamengine3d/examples/scripts/coin.py +12 -0
- gamengine3d/examples/scripts/collector.py +13 -0
- gamengine3d/examples/scripts/confetti.py +27 -0
- gamengine3d/examples/scripts/director.py +213 -0
- gamengine3d/examples/scripts/drone.py +21 -0
- gamengine3d/examples/scripts/ghost_pulse.py +24 -0
- gamengine3d/examples/scripts/horror_atmosphere.py +96 -0
- gamengine3d/examples/scripts/interact.py +45 -0
- gamengine3d/examples/scripts/orbiter.py +25 -0
- gamengine3d/examples/scripts/player_controller.py +165 -0
- gamengine3d/examples/scripts/pulse.py +22 -0
- gamengine3d/examples/scripts/reactor_core.py +29 -0
- gamengine3d/examples/scripts/spin.py +13 -0
- gamengine3d/examples/scripts/sway.py +19 -0
- gamengine3d/examples/scripts/void_guard.py +26 -0
- gamengine3d/examples/transparency.py +92 -0
- gamengine3d/game_objects.py +975 -0
- gamengine3d/helper.py +720 -0
- gamengine3d/obj_reader.py +29 -0
- gamengine3d/objects/0.obj +964 -0
- gamengine3d/objects/1.obj +48 -0
- gamengine3d/objects/2.obj +983 -0
- gamengine3d/objects/3.obj +1623 -0
- gamengine3d/objects/4.obj +163 -0
- gamengine3d/objects/5.obj +861 -0
- gamengine3d/objects/6.obj +1314 -0
- gamengine3d/objects/7.obj +70 -0
- gamengine3d/objects/8.obj +1932 -0
- gamengine3d/objects/9.obj +1458 -0
- gamengine3d/objects/A_capital.obj +124 -0
- gamengine3d/objects/B_capital.obj +1118 -0
- gamengine3d/objects/C_capital.obj +1082 -0
- gamengine3d/objects/D_capital.obj +548 -0
- gamengine3d/objects/E_capital.obj +128 -0
- gamengine3d/objects/F_capital.obj +108 -0
- gamengine3d/objects/G_capital.obj +1125 -0
- gamengine3d/objects/H_capital.obj +128 -0
- gamengine3d/objects/I_capital.obj +48 -0
- gamengine3d/objects/J_capital.obj +454 -0
- gamengine3d/objects/K_capital.obj +125 -0
- gamengine3d/objects/L_capital.obj +68 -0
- gamengine3d/objects/M_capital.obj +163 -0
- gamengine3d/objects/N_capital.obj +112 -0
- gamengine3d/objects/O_capital.obj +968 -0
- gamengine3d/objects/P_capital.obj +620 -0
- gamengine3d/objects/Q_capital.obj +1362 -0
- gamengine3d/objects/R_capital.obj +1036 -0
- gamengine3d/objects/S_capital.obj +1346 -0
- gamengine3d/objects/T_capital.obj +88 -0
- gamengine3d/objects/U_capital.obj +860 -0
- gamengine3d/objects/V_capital.obj +81 -0
- gamengine3d/objects/W_capital.obj +147 -0
- gamengine3d/objects/X_capital.obj +136 -0
- gamengine3d/objects/Y_capital.obj +103 -0
- gamengine3d/objects/Z_capital.obj +90 -0
- gamengine3d/objects/__init__.py +0 -0
- gamengine3d/objects/a.obj +1920 -0
- gamengine3d/objects/ampersand.obj +2186 -0
- gamengine3d/objects/asterisk.obj +2512 -0
- gamengine3d/objects/at.obj +2682 -0
- gamengine3d/objects/b.obj +1104 -0
- gamengine3d/objects/backslash.obj +48 -0
- gamengine3d/objects/brace_close.obj +1179 -0
- gamengine3d/objects/brace_open.obj +1179 -0
- gamengine3d/objects/bracket_close.obj +88 -0
- gamengine3d/objects/bracket_open.obj +88 -0
- gamengine3d/objects/c.obj +1082 -0
- gamengine3d/objects/caret.obj +81 -0
- gamengine3d/objects/colon.obj +912 -0
- gamengine3d/objects/comma.obj +675 -0
- gamengine3d/objects/d.obj +861 -0
- gamengine3d/objects/dash.obj +48 -0
- gamengine3d/objects/dollar.obj +1671 -0
- gamengine3d/objects/dot.obj +532 -0
- gamengine3d/objects/doublequote.obj +114 -0
- gamengine3d/objects/e.obj +1094 -0
- gamengine3d/objects/equals.obj +76 -0
- gamengine3d/objects/exclamation.obj +1336 -0
- gamengine3d/objects/f.obj +660 -0
- gamengine3d/objects/g.obj +2694 -0
- gamengine3d/objects/greater.obj +81 -0
- gamengine3d/objects/h.obj +628 -0
- gamengine3d/objects/hash.obj +332 -0
- gamengine3d/objects/i.obj +558 -0
- gamengine3d/objects/j.obj +824 -0
- gamengine3d/objects/k.obj +104 -0
- gamengine3d/objects/l.obj +48 -0
- gamengine3d/objects/less.obj +81 -0
- gamengine3d/objects/m.obj +1177 -0
- gamengine3d/objects/n.obj +628 -0
- gamengine3d/objects/o.obj +968 -0
- gamengine3d/objects/p.obj +861 -0
- gamengine3d/objects/paren_close.obj +554 -0
- gamengine3d/objects/paren_open.obj +554 -0
- gamengine3d/objects/percent.obj +1767 -0
- gamengine3d/objects/plus.obj +128 -0
- gamengine3d/objects/q.obj +861 -0
- gamengine3d/objects/question.obj +1306 -0
- gamengine3d/objects/r.obj +608 -0
- gamengine3d/objects/s.obj +1478 -0
- gamengine3d/objects/semicolon.obj +1185 -0
- gamengine3d/objects/singlequote.obj +70 -0
- gamengine3d/objects/slash.obj +48 -0
- gamengine3d/objects/t.obj +639 -0
- gamengine3d/objects/u.obj +618 -0
- gamengine3d/objects/underscore.obj +48 -0
- gamengine3d/objects/v.obj +81 -0
- gamengine3d/objects/w.obj +147 -0
- gamengine3d/objects/x.obj +136 -0
- gamengine3d/objects/y.obj +92 -0
- gamengine3d/objects/z.obj +90 -0
- gamengine3d/renderer.py +1390 -0
- gamengine3d/shaders/__init__.py +0 -0
- gamengine3d/shaders/default.frag +143 -0
- gamengine3d/shaders/default.vert +43 -0
- gamengine3d/shaders/depth.frag +2 -0
- gamengine3d/shaders/depth.vert +9 -0
- gamengine3d-0.5.0.dist-info/METADATA +177 -0
- gamengine3d-0.5.0.dist-info/RECORD +141 -0
- gamengine3d-0.5.0.dist-info/WHEEL +5 -0
- gamengine3d-0.5.0.dist-info/entry_points.txt +2 -0
- gamengine3d-0.5.0.dist-info/licenses/LICENSE.txt +21 -0
- gamengine3d-0.5.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import random
|
|
2
|
+
|
|
3
|
+
from gamengine3d import vector3d
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Confetti:
|
|
7
|
+
def __init__(self, obj, context):
|
|
8
|
+
self.obj = obj
|
|
9
|
+
self.context = context
|
|
10
|
+
self.age = 0.0
|
|
11
|
+
self.life = random.uniform(1.2, 2.6)
|
|
12
|
+
self.vx = random.uniform(-2.5, 2.5)
|
|
13
|
+
self.vz = random.uniform(-2.5, 2.5)
|
|
14
|
+
self.vy = random.uniform(4.0, 8.0)
|
|
15
|
+
self.g = 16.0
|
|
16
|
+
|
|
17
|
+
def update(self, dt):
|
|
18
|
+
self.age += dt
|
|
19
|
+
self.vy -= self.g * dt
|
|
20
|
+
self.obj.pos += vector3d(self.vx * dt, self.vy * dt, self.vz * dt)
|
|
21
|
+
self.obj.rotation.x += 240.0 * dt
|
|
22
|
+
self.obj.rotation.z += 300.0 * dt
|
|
23
|
+
if self.age >= self.life:
|
|
24
|
+
try:
|
|
25
|
+
self.context.functions.remove_object(self.obj.name)
|
|
26
|
+
except Exception:
|
|
27
|
+
pass
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import math
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from gamengine3d import Color, Cuboid, vector3d
|
|
5
|
+
|
|
6
|
+
SCRIPT_DIR = Path(__file__).parent
|
|
7
|
+
|
|
8
|
+
# (name, base intensity, pulse amplitude, pulse speed, phase offset)
|
|
9
|
+
LIGHTS = [
|
|
10
|
+
("HallLamp0", 0.8, 0.10, 1.4, 0.0),
|
|
11
|
+
("HallLamp1", 0.8, 0.10, 1.4, 1.6),
|
|
12
|
+
("DomeA", 0.7, 0.25, 3.4, 0.6),
|
|
13
|
+
("DomeB", 0.6, 0.25, 3.4, 2.2),
|
|
14
|
+
("CoreGlow", 0.9, 0.35, 2.6, 0.0),
|
|
15
|
+
("CoreBright", 0.0, 0.0, 0.0, 0.0),
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
# station key -> (runtime var controlling power, pad pulse phase)
|
|
19
|
+
STATIONS = {
|
|
20
|
+
"Gate": ("gate_powered", 0.0),
|
|
21
|
+
"Coil": ("coil_powered", 1.3),
|
|
22
|
+
"Shield": ("shield_powered", 2.6),
|
|
23
|
+
"Decoder": ("decoder_powered", 3.9),
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
GREEN = Color.RGB(120, 230, 130)
|
|
27
|
+
PAD_SOLVED = Color.RGB(28, 52, 32)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _get(context, name):
|
|
31
|
+
try:
|
|
32
|
+
return context.functions.get_game_object(name)
|
|
33
|
+
except Exception:
|
|
34
|
+
return None
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class Director:
|
|
38
|
+
def __init__(self, obj, context):
|
|
39
|
+
self.obj = obj
|
|
40
|
+
self.context = context
|
|
41
|
+
self.t = 0.0
|
|
42
|
+
self.prev_count = -1
|
|
43
|
+
self.won_shown = False
|
|
44
|
+
self.hovered_key = None
|
|
45
|
+
self.prev_core_hovered = False
|
|
46
|
+
self.using_plus_crosshair = True
|
|
47
|
+
self.stations = {}
|
|
48
|
+
context.on_key_press("c", self.swap_crosshair)
|
|
49
|
+
context.on_key_press("k", self.save_scene)
|
|
50
|
+
|
|
51
|
+
def start(self):
|
|
52
|
+
self.lights = {light.name: light for light in self.context.lights}
|
|
53
|
+
for key in STATIONS:
|
|
54
|
+
self.stations[key] = {
|
|
55
|
+
"solved": False,
|
|
56
|
+
"halo": _get(self.context, f"Halo{key}"),
|
|
57
|
+
"crystal": _get(self.context, f"Crystal{key}"),
|
|
58
|
+
"glow": _get(self.context, f"CrystalGlow{key}"),
|
|
59
|
+
"tip": _get(self.context, f"Tip{key}"),
|
|
60
|
+
"pad": _get(self.context, f"Solid_{key}Pad"),
|
|
61
|
+
"ring": _get(self.context, f"Solid_{key}Ring"),
|
|
62
|
+
"light": self.lights.get(f"Pad{key}"),
|
|
63
|
+
"beacon_caps": [
|
|
64
|
+
_get(self.context, f"BeaconCap{key}0"),
|
|
65
|
+
_get(self.context, f"BeaconCap{key}1"),
|
|
66
|
+
],
|
|
67
|
+
"base_size": None,
|
|
68
|
+
}
|
|
69
|
+
crystal = self.stations[key]["crystal"]
|
|
70
|
+
if crystal is not None:
|
|
71
|
+
self.stations[key]["base_size"] = vector3d(crystal.size.x, crystal.size.y, crystal.size.z)
|
|
72
|
+
self.halo_core = _get(self.context, "HaloCore")
|
|
73
|
+
|
|
74
|
+
def update(self, dt):
|
|
75
|
+
self.t += dt
|
|
76
|
+
hover = getattr(self.context.runtime_vars, "hover", None)
|
|
77
|
+
self.set_hover(hover)
|
|
78
|
+
self.handle_solves()
|
|
79
|
+
self.pulse_lights()
|
|
80
|
+
self.refresh_hud()
|
|
81
|
+
self.celebrate()
|
|
82
|
+
|
|
83
|
+
# ------------------------------------------------------------ targeting
|
|
84
|
+
|
|
85
|
+
@staticmethod
|
|
86
|
+
def station_from_hover(hover):
|
|
87
|
+
if not hover:
|
|
88
|
+
return None
|
|
89
|
+
if hover.startswith("Breaker_") and hover.endswith("Console"):
|
|
90
|
+
return hover[len("Breaker_"):-len("Console")]
|
|
91
|
+
return None
|
|
92
|
+
|
|
93
|
+
def set_hover(self, hover):
|
|
94
|
+
key = self.station_from_hover(hover)
|
|
95
|
+
if key == self.hovered_key:
|
|
96
|
+
return
|
|
97
|
+
if self.hovered_key is not None and self.hovered_key in self.stations:
|
|
98
|
+
station = self.stations[self.hovered_key]
|
|
99
|
+
station["halo"].visible = False
|
|
100
|
+
if not station["solved"]:
|
|
101
|
+
station["crystal"].size = station["base_size"]
|
|
102
|
+
self.hovered_key = key
|
|
103
|
+
if key is not None and key in self.stations:
|
|
104
|
+
station = self.stations[key]
|
|
105
|
+
station["halo"].visible = True
|
|
106
|
+
if not station["solved"]:
|
|
107
|
+
station["crystal"].size = station["base_size"] * 1.25
|
|
108
|
+
core_hovered = hover == "CoreMarker"
|
|
109
|
+
if core_hovered != self.prev_core_hovered:
|
|
110
|
+
self.prev_core_hovered = core_hovered
|
|
111
|
+
if self.halo_core is not None:
|
|
112
|
+
self.halo_core.visible = core_hovered
|
|
113
|
+
|
|
114
|
+
# -------------------------------------------------------------- solving
|
|
115
|
+
|
|
116
|
+
def handle_solves(self):
|
|
117
|
+
for key, (var_name, _phase) in STATIONS.items():
|
|
118
|
+
station = self.stations[key]
|
|
119
|
+
if station["solved"] or not getattr(self.context.runtime_vars, var_name, False):
|
|
120
|
+
continue
|
|
121
|
+
station["solved"] = True
|
|
122
|
+
for name in ("crystal", "glow"):
|
|
123
|
+
obj = station[name]
|
|
124
|
+
if obj is not None:
|
|
125
|
+
obj.color = GREEN
|
|
126
|
+
cap = self.stations[key]["beacon_caps"]
|
|
127
|
+
for obj in cap:
|
|
128
|
+
if obj is not None:
|
|
129
|
+
obj.color = GREEN
|
|
130
|
+
tip = station["tip"]
|
|
131
|
+
if tip is not None:
|
|
132
|
+
tip.text = "OK"
|
|
133
|
+
tip.color = GREEN
|
|
134
|
+
pad = station["pad"]
|
|
135
|
+
if pad is not None:
|
|
136
|
+
pad.color = PAD_SOLVED
|
|
137
|
+
ring = station["ring"]
|
|
138
|
+
if ring is not None:
|
|
139
|
+
ring.color = GREEN
|
|
140
|
+
|
|
141
|
+
# --------------------------------------------------------------- lights
|
|
142
|
+
|
|
143
|
+
def pulse_lights(self):
|
|
144
|
+
t = self.t
|
|
145
|
+
core = getattr(self.context.runtime_vars, "reactor_open", False)
|
|
146
|
+
won = getattr(self.context.runtime_vars, "won", False)
|
|
147
|
+
for name, base, amp, speed, phase in LIGHTS:
|
|
148
|
+
light = self.lights.get(name)
|
|
149
|
+
if light is None:
|
|
150
|
+
continue
|
|
151
|
+
if name == "CoreGlow":
|
|
152
|
+
if core:
|
|
153
|
+
light.intensity = 1.4 + 0.4 * math.sin(t * 6.0)
|
|
154
|
+
else:
|
|
155
|
+
light.intensity = base + amp * math.sin(t * speed + phase)
|
|
156
|
+
elif name == "CoreBright":
|
|
157
|
+
light.intensity = 2.6 if won else 0.0
|
|
158
|
+
else:
|
|
159
|
+
light.intensity = base + amp * math.sin(t * speed + phase)
|
|
160
|
+
|
|
161
|
+
for key, (_var, phase) in STATIONS.items():
|
|
162
|
+
station = self.stations[key]
|
|
163
|
+
light = station["light"]
|
|
164
|
+
if light is None:
|
|
165
|
+
continue
|
|
166
|
+
if station["solved"]:
|
|
167
|
+
light.intensity = 1.15 + 0.1 * math.sin(t * 3.0 + phase)
|
|
168
|
+
elif key == self.hovered_key:
|
|
169
|
+
light.intensity = 1.6 + 0.25 * math.sin(t * 7.0)
|
|
170
|
+
else:
|
|
171
|
+
light.intensity = 0.7 + 0.2 * math.sin(t * 2.4 + phase)
|
|
172
|
+
|
|
173
|
+
# ------------------------------------------------------------------ HUD
|
|
174
|
+
|
|
175
|
+
def refresh_hud(self):
|
|
176
|
+
count = getattr(self.context.runtime_vars, "restored_count", 0)
|
|
177
|
+
if count == self.prev_count:
|
|
178
|
+
return
|
|
179
|
+
self.prev_count = count
|
|
180
|
+
hud = self.context.functions.get_game_object("Hud_Objective")
|
|
181
|
+
hud.text = f"RESTORE_CORE:{count}:4"
|
|
182
|
+
|
|
183
|
+
def celebrate(self):
|
|
184
|
+
if getattr(self.context.runtime_vars, "won", False) and not self.won_shown:
|
|
185
|
+
self.won_shown = True
|
|
186
|
+
hud = self.context.functions.get_game_object("Hud_Win")
|
|
187
|
+
hud.visible = True
|
|
188
|
+
for i in range(40):
|
|
189
|
+
self.spawn_confetti(i)
|
|
190
|
+
|
|
191
|
+
def spawn_confetti(self, i):
|
|
192
|
+
color = Color.RGB(255, 200 + (i * 29) % 55, 40 + (i * 73) % 180)
|
|
193
|
+
c = Cuboid(
|
|
194
|
+
pos=vector3d(0, 4.5, 0),
|
|
195
|
+
size=vector3d(0.14),
|
|
196
|
+
color=color,
|
|
197
|
+
emit=True,
|
|
198
|
+
name=f"Confetti{self.t:.2f}_{i}",
|
|
199
|
+
)
|
|
200
|
+
c.shadow_caster = False
|
|
201
|
+
c.attach(str(SCRIPT_DIR / "confetti.py"), self.context)
|
|
202
|
+
self.context.functions.add_object(c)
|
|
203
|
+
|
|
204
|
+
def swap_crosshair(self):
|
|
205
|
+
self.using_plus_crosshair = not self.using_plus_crosshair
|
|
206
|
+
self.context.engine.crosshair = "plus-sign-crosshair" if self.using_plus_crosshair else "circular-crosshair"
|
|
207
|
+
|
|
208
|
+
def save_scene(self):
|
|
209
|
+
try:
|
|
210
|
+
self.context.functions.save_scene("reactor_save.json")
|
|
211
|
+
print("[Director] scene saved")
|
|
212
|
+
except Exception as e:
|
|
213
|
+
print(f"[Director] save failed: {e}")
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import math
|
|
2
|
+
|
|
3
|
+
from gamengine3d import vector3d
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Drone:
|
|
7
|
+
def __init__(self, obj, context):
|
|
8
|
+
self.obj = obj
|
|
9
|
+
self.context = context
|
|
10
|
+
self.center = getattr(obj, "drone_center", vector3d.zero)
|
|
11
|
+
self.radius = getattr(obj, "drone_radius", 6.0)
|
|
12
|
+
self.speed = getattr(obj, "drone_speed", 0.6)
|
|
13
|
+
self.t = 0.0
|
|
14
|
+
|
|
15
|
+
def update(self, dt):
|
|
16
|
+
self.t += dt * self.speed
|
|
17
|
+
self.obj.pos = self.center + vector3d(
|
|
18
|
+
math.cos(self.t) * self.radius,
|
|
19
|
+
1.5 * math.sin(self.t * 2.0),
|
|
20
|
+
math.sin(self.t) * self.radius,
|
|
21
|
+
)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import math
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class GhostPulse:
|
|
5
|
+
"""Pulse the `transparency` of named objects between translucent (~0.85)
|
|
6
|
+
and nearly invisible (~0.1), proving transparency is live-editable.
|
|
7
|
+
|
|
8
|
+
Attach at engine level and list targets via
|
|
9
|
+
``context.pulse_targets = ["GlassBox", "GhostText"]``.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
def __init__(self, obj, context):
|
|
13
|
+
self.context = context
|
|
14
|
+
self.time = 0.0
|
|
15
|
+
|
|
16
|
+
def update(self, dt):
|
|
17
|
+
self.time += dt * 1.8
|
|
18
|
+
k = 0.5 + 0.5 * math.sin(self.time)
|
|
19
|
+
alpha = 0.1 + 0.8 * k
|
|
20
|
+
for name in getattr(self.context, "pulse_targets", []):
|
|
21
|
+
try:
|
|
22
|
+
self.context.functions.get_game_object(name).transparency = alpha
|
|
23
|
+
except Exception:
|
|
24
|
+
pass
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import math
|
|
2
|
+
import random
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class HorrorAtmosphere:
|
|
6
|
+
"""Engine-level script that makes the arena feel alive and hostile:
|
|
7
|
+
lamps stutter and die, void glows breathe, the whole room periodically
|
|
8
|
+
blacks out for a moment, and the summit eye wakes as you climb to it."""
|
|
9
|
+
|
|
10
|
+
STROBES = ["Main", "StartLamp", "LampA", "LampB"]
|
|
11
|
+
FLICK_LEVELS = (1.0, 0.92, 0.82, 0.6, 0.92, 1.0, 0.3, 0.12)
|
|
12
|
+
FLICK_WEIGHTS = (6, 4, 3, 2, 4, 6, 1, 1)
|
|
13
|
+
BREATHE = {
|
|
14
|
+
"VoidMagenta": (2.2, 1.3, 0.35),
|
|
15
|
+
"VoidAmber": (1.3, 2.1, 0.30),
|
|
16
|
+
"VoidTeal": (1.8, 4.0, 0.30),
|
|
17
|
+
"VoidCrimson": (0.9, 5.1, 0.45),
|
|
18
|
+
"GlowPink": (1.5, 0.4, 0.30),
|
|
19
|
+
"GlowLime": (1.1, 2.6, 0.30),
|
|
20
|
+
"GlowBlue": (1.7, 5.2, 0.30),
|
|
21
|
+
"GlowYellow": (2.4, 3.3, 0.30),
|
|
22
|
+
}
|
|
23
|
+
SCALE_ALWAYS = ["ColdGloom"]
|
|
24
|
+
|
|
25
|
+
def __init__(self, obj, context):
|
|
26
|
+
self.context = context
|
|
27
|
+
self.t = 0.0
|
|
28
|
+
self.by_name = {l.name: l for l in context.lights}
|
|
29
|
+
self.design = {n: l.intensity for n, l in self.by_name.items()}
|
|
30
|
+
self.timers = {}
|
|
31
|
+
self.surge_timer = random.uniform(8.0, 14.0)
|
|
32
|
+
self.surge_left = 0.0
|
|
33
|
+
self.surge_total = 0.0
|
|
34
|
+
|
|
35
|
+
def update(self, dt):
|
|
36
|
+
self.t += dt
|
|
37
|
+
lights = self.by_name
|
|
38
|
+
|
|
39
|
+
# Periodic blackout: the room dies for half a second, then wakes back.
|
|
40
|
+
self.surge_timer -= dt
|
|
41
|
+
if self.surge_timer <= 0:
|
|
42
|
+
self.surge_total = 0.5
|
|
43
|
+
self.surge_left = self.surge_total
|
|
44
|
+
self.surge_timer = random.uniform(9.0, 16.0)
|
|
45
|
+
scale = 1.0
|
|
46
|
+
if self.surge_left > 0:
|
|
47
|
+
self.surge_left -= dt
|
|
48
|
+
frac = max(0.0, self.surge_left / self.surge_total)
|
|
49
|
+
if frac > 0.5:
|
|
50
|
+
scale = 0.05
|
|
51
|
+
else:
|
|
52
|
+
scale = min(1.0, 0.05 + (0.5 - frac) * 1.9)
|
|
53
|
+
|
|
54
|
+
# Electric stutter on the working lamps.
|
|
55
|
+
for name in self.STROBES:
|
|
56
|
+
light = lights.get(name)
|
|
57
|
+
if light is None:
|
|
58
|
+
continue
|
|
59
|
+
t = self.timers.get(name, 0.0) - dt
|
|
60
|
+
if t <= 0:
|
|
61
|
+
self.timers[name] = random.uniform(0.025, 0.16)
|
|
62
|
+
level = random.choices(self.FLICK_LEVELS, self.FLICK_WEIGHTS)[0]
|
|
63
|
+
light.intensity = self.design.get(name, 0.8) * level * scale
|
|
64
|
+
else:
|
|
65
|
+
self.timers[name] = t
|
|
66
|
+
|
|
67
|
+
# Slow breathing glows in the void and around the course.
|
|
68
|
+
for name, (speed, phase, depth) in self.BREATHE.items():
|
|
69
|
+
light = lights.get(name)
|
|
70
|
+
if light is None:
|
|
71
|
+
continue
|
|
72
|
+
base = self.design.get(name, 0.5)
|
|
73
|
+
pull = 0.5 + 0.5 * math.sin(self.t * speed + phase)
|
|
74
|
+
light.intensity = base * (1.0 - depth + depth * pull) * scale
|
|
75
|
+
|
|
76
|
+
# The summit eye beats faster, and blazes as the player draws near.
|
|
77
|
+
eye = lights.get("Summit")
|
|
78
|
+
if eye is not None:
|
|
79
|
+
base = self.design.get("Summit", 0.8)
|
|
80
|
+
beat = 0.5 + 0.5 * math.sin(self.t * 2.6 + 0.7)
|
|
81
|
+
eye.intensity = base * beat * scale
|
|
82
|
+
try:
|
|
83
|
+
player = self.context.functions.get_game_object("Player")
|
|
84
|
+
marker = self.context.functions.get_game_object("SummitEye")
|
|
85
|
+
d = (player.pos - marker.pos).sqr_magnitude
|
|
86
|
+
if d < 36.0:
|
|
87
|
+
wake = (1.0 - d / 36.0) * 1.5
|
|
88
|
+
eye.intensity = max(eye.intensity, base * (beat + wake) * scale)
|
|
89
|
+
except Exception:
|
|
90
|
+
pass
|
|
91
|
+
|
|
92
|
+
# Constant dim lights also obey the blackout.
|
|
93
|
+
for name in self.SCALE_ALWAYS:
|
|
94
|
+
light = lights.get(name)
|
|
95
|
+
if light is not None:
|
|
96
|
+
light.intensity *= scale
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from gamengine3d import vector3d
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Interact:
|
|
5
|
+
def __init__(self, obj, context):
|
|
6
|
+
self.obj = obj
|
|
7
|
+
self.context = context
|
|
8
|
+
self.range_m = 8.0
|
|
9
|
+
self.step_m = 0.35
|
|
10
|
+
self.targets = []
|
|
11
|
+
context.on_key_press("e", self.press_interact)
|
|
12
|
+
|
|
13
|
+
def start(self):
|
|
14
|
+
self.targets = [
|
|
15
|
+
o.name
|
|
16
|
+
for o in self.context.game_objects
|
|
17
|
+
if o.name.startswith("Breaker_") or o.name == "CoreMarker"
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
def ray_origin_dir(self):
|
|
21
|
+
player = self.context.functions.get_game_object("Player")
|
|
22
|
+
origin = player.pos + vector3d(0, player.size.y * 0.85, 0)
|
|
23
|
+
look = self.context.camera.look_dir
|
|
24
|
+
return origin, look.normalized
|
|
25
|
+
|
|
26
|
+
def look_target(self):
|
|
27
|
+
origin, look = self.ray_origin_dir()
|
|
28
|
+
for i in range(1, int(self.range_m / self.step_m) + 1):
|
|
29
|
+
point = origin + look * (self.step_m * i)
|
|
30
|
+
for name in self.targets:
|
|
31
|
+
try:
|
|
32
|
+
if self.context.functions.is_colliding_pos(name, point):
|
|
33
|
+
return name
|
|
34
|
+
except Exception:
|
|
35
|
+
continue
|
|
36
|
+
return None
|
|
37
|
+
|
|
38
|
+
def update(self, dt):
|
|
39
|
+
self.context.runtime_vars.hover = self.look_target()
|
|
40
|
+
|
|
41
|
+
def press_interact(self):
|
|
42
|
+
target_name = self.look_target()
|
|
43
|
+
if target_name is not None:
|
|
44
|
+
target = self.context.functions.get_game_object(target_name)
|
|
45
|
+
target.message(message="activate", sender=self.obj.name)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import math
|
|
2
|
+
|
|
3
|
+
from gamengine3d import vector3d
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Orbiter:
|
|
7
|
+
def __init__(self, obj, context):
|
|
8
|
+
self.obj = obj
|
|
9
|
+
self.context = context
|
|
10
|
+
self.center = getattr(obj, "orbit_center", vector3d.zero)
|
|
11
|
+
self.radius = getattr(obj, "orbit_radius", 3.0)
|
|
12
|
+
self.speed = getattr(obj, "orbit_speed", 1.0)
|
|
13
|
+
self.height = getattr(obj, "orbit_height", 2.0)
|
|
14
|
+
self.t = 0.0
|
|
15
|
+
|
|
16
|
+
def update(self, dt):
|
|
17
|
+
speed = self.speed
|
|
18
|
+
if getattr(self.context.runtime_vars, "coil_powered", False):
|
|
19
|
+
speed *= 4.0
|
|
20
|
+
self.t += dt * speed
|
|
21
|
+
self.obj.pos = self.center + vector3d(
|
|
22
|
+
math.cos(self.t) * self.radius,
|
|
23
|
+
self.height,
|
|
24
|
+
math.sin(self.t) * self.radius,
|
|
25
|
+
)
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
from gamengine3d import Color, Light, vector3d
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class PlayerController:
|
|
5
|
+
def __init__(self, obj, context):
|
|
6
|
+
self.obj = obj
|
|
7
|
+
self.context = context
|
|
8
|
+
|
|
9
|
+
self.speed = 5.0
|
|
10
|
+
self.sprint_multiplier = 1.9
|
|
11
|
+
self.jump_speed = 7.5
|
|
12
|
+
self.gravity = 22.0
|
|
13
|
+
self.velocity = vector3d.zero
|
|
14
|
+
self.grounded = True
|
|
15
|
+
self.score = 0
|
|
16
|
+
self.total_coins = 8
|
|
17
|
+
|
|
18
|
+
self.flashlight = Light(
|
|
19
|
+
position=self.obj.pos + vector3d(0, self.eye_height, 0),
|
|
20
|
+
color=Color.RGB(255, 240, 205),
|
|
21
|
+
intensity=0.0,
|
|
22
|
+
name="Flashlight",
|
|
23
|
+
)
|
|
24
|
+
context.functions.add_light(self.flashlight)
|
|
25
|
+
|
|
26
|
+
context.on_key_press("space", callback=self.jump)
|
|
27
|
+
context.on_key_press("f", callback=self.toggle_flashlight)
|
|
28
|
+
context.on_key_press("m", callback=self.grab_mouse)
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def eye_height(self):
|
|
32
|
+
return self.obj.size.y * 0.85
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def feet(self):
|
|
36
|
+
return self.obj.pos.y - self.obj.size.y / 2
|
|
37
|
+
|
|
38
|
+
def update(self, dt):
|
|
39
|
+
dt = min(dt, 0.05)
|
|
40
|
+
self.move_horizontally(dt)
|
|
41
|
+
self.move_vertically(dt)
|
|
42
|
+
self.collect_coins()
|
|
43
|
+
self.follow_camera()
|
|
44
|
+
self.point_flashlight()
|
|
45
|
+
|
|
46
|
+
def solids(self):
|
|
47
|
+
return [o for o in self.context.game_objects if o.name.startswith("Solid_")]
|
|
48
|
+
|
|
49
|
+
def move_horizontally(self, dt):
|
|
50
|
+
look = self.context.camera.look_dir
|
|
51
|
+
forward = vector3d(look.x, 0, look.z).normalized
|
|
52
|
+
right = vector3d.up.cross(forward)
|
|
53
|
+
|
|
54
|
+
move = vector3d.zero
|
|
55
|
+
keys = self.context.keys_held
|
|
56
|
+
if "w" in keys:
|
|
57
|
+
move += forward
|
|
58
|
+
if "s" in keys:
|
|
59
|
+
move -= forward
|
|
60
|
+
if "d" in keys:
|
|
61
|
+
move += right
|
|
62
|
+
if "a" in keys:
|
|
63
|
+
move -= right
|
|
64
|
+
|
|
65
|
+
if move.magnitude == 0:
|
|
66
|
+
return
|
|
67
|
+
|
|
68
|
+
if "left shift" in keys:
|
|
69
|
+
move *= self.sprint_multiplier
|
|
70
|
+
delta = move.normalized * self.speed * dt
|
|
71
|
+
|
|
72
|
+
self.obj.pos.x += delta.x
|
|
73
|
+
if self.hits_wall():
|
|
74
|
+
self.obj.pos.x -= delta.x
|
|
75
|
+
self.obj.pos.z += delta.z
|
|
76
|
+
if self.hits_wall():
|
|
77
|
+
self.obj.pos.z -= delta.z
|
|
78
|
+
|
|
79
|
+
def hits_wall(self):
|
|
80
|
+
hx = self.obj.size.x / 2 - 0.02
|
|
81
|
+
hz = self.obj.size.z / 2 - 0.02
|
|
82
|
+
corners = [
|
|
83
|
+
vector3d(hx, 0, hz),
|
|
84
|
+
vector3d(hx, 0, -hz),
|
|
85
|
+
vector3d(-hx, 0, hz),
|
|
86
|
+
vector3d(-hx, 0, -hz),
|
|
87
|
+
]
|
|
88
|
+
head = self.obj.pos.y + self.obj.size.y / 2 - 0.1
|
|
89
|
+
for solid in self.solids():
|
|
90
|
+
top = solid.pos.y + solid.size.y / 2
|
|
91
|
+
bottom = solid.pos.y - solid.size.y / 2
|
|
92
|
+
if top <= self.feet + 0.02:
|
|
93
|
+
continue
|
|
94
|
+
if bottom >= head:
|
|
95
|
+
continue
|
|
96
|
+
test_y = max(bottom, min(solid.pos.y, head))
|
|
97
|
+
for corner in corners:
|
|
98
|
+
if self.context.functions.is_colliding_pos(
|
|
99
|
+
solid.name,
|
|
100
|
+
self.obj.pos + vector3d(corner.x, test_y - self.obj.pos.y, corner.z),
|
|
101
|
+
):
|
|
102
|
+
return True
|
|
103
|
+
return False
|
|
104
|
+
|
|
105
|
+
def move_vertically(self, dt):
|
|
106
|
+
self.velocity.y -= self.gravity * dt
|
|
107
|
+
self.obj.pos.y += self.velocity.y * dt
|
|
108
|
+
|
|
109
|
+
if self.velocity.y > 0:
|
|
110
|
+
self.grounded = False
|
|
111
|
+
return
|
|
112
|
+
|
|
113
|
+
solid = self.solid_below()
|
|
114
|
+
if solid is not None:
|
|
115
|
+
self.obj.pos.y = solid.pos.y + solid.size.y / 2 + self.obj.size.y / 2
|
|
116
|
+
self.velocity.y = 0
|
|
117
|
+
self.grounded = True
|
|
118
|
+
else:
|
|
119
|
+
self.grounded = False
|
|
120
|
+
|
|
121
|
+
def solid_below(self):
|
|
122
|
+
landing = None
|
|
123
|
+
for solid in self.solids():
|
|
124
|
+
top = solid.pos.y + solid.size.y / 2
|
|
125
|
+
if not (self.feet - 0.5 <= top <= self.feet + 0.15):
|
|
126
|
+
continue
|
|
127
|
+
if self.context.functions.is_colliding(self.obj.name, solid.name):
|
|
128
|
+
if landing is None or top > landing.pos.y + landing.size.y / 2:
|
|
129
|
+
landing = solid
|
|
130
|
+
return landing
|
|
131
|
+
|
|
132
|
+
def jump(self):
|
|
133
|
+
if self.grounded:
|
|
134
|
+
self.velocity.y = self.jump_speed
|
|
135
|
+
self.grounded = False
|
|
136
|
+
|
|
137
|
+
def collect_coins(self):
|
|
138
|
+
for obj in list(self.context.game_objects):
|
|
139
|
+
if not obj.name.startswith("Coin"):
|
|
140
|
+
continue
|
|
141
|
+
if (obj.pos - self.obj.pos).sqr_magnitude <= 4.0:
|
|
142
|
+
self.context.functions.remove_object(obj.name)
|
|
143
|
+
self.score += 1
|
|
144
|
+
hud = self.context.functions.get_game_object("Hud_Score")
|
|
145
|
+
hud.text = f"coins:{self.score}_of_{self.total_coins}"
|
|
146
|
+
|
|
147
|
+
def follow_camera(self):
|
|
148
|
+
camera = self.context.camera
|
|
149
|
+
camera.position = self.obj.pos + vector3d(0, self.eye_height, 0)
|
|
150
|
+
camera.look_at(camera.position + camera.look_dir)
|
|
151
|
+
|
|
152
|
+
def point_flashlight(self):
|
|
153
|
+
if self.flashlight.intensity <= 0:
|
|
154
|
+
return
|
|
155
|
+
look = self.context.camera.look_dir.normalized
|
|
156
|
+
self.flashlight.position = self.obj.pos + vector3d(0, self.eye_height, 0) + look * 1.5
|
|
157
|
+
|
|
158
|
+
def toggle_flashlight(self):
|
|
159
|
+
if self.flashlight.intensity > 0:
|
|
160
|
+
self.flashlight.intensity = 0.0
|
|
161
|
+
else:
|
|
162
|
+
self.flashlight.intensity = 2.6
|
|
163
|
+
|
|
164
|
+
def grab_mouse(self):
|
|
165
|
+
self.context.set_mouse_look(True)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import math
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Pulse:
|
|
5
|
+
def __init__(self, obj, context):
|
|
6
|
+
self.obj = obj
|
|
7
|
+
self.context = context
|
|
8
|
+
self.speed = getattr(obj, "pulse_speed", 3.0)
|
|
9
|
+
self.lo = getattr(obj, "pulse_lo", 0.7)
|
|
10
|
+
self.hi = getattr(obj, "pulse_hi", 1.3)
|
|
11
|
+
self.phase = getattr(obj, "pulse_phase", 0.0)
|
|
12
|
+
self.base_radius = getattr(obj, "radius", None)
|
|
13
|
+
self.base_size = getattr(obj, "size", None)
|
|
14
|
+
|
|
15
|
+
def update(self, dt):
|
|
16
|
+
self.phase += dt * self.speed
|
|
17
|
+
k = 0.5 + 0.5 * math.sin(self.phase)
|
|
18
|
+
s = self.lo + (self.hi - self.lo) * k
|
|
19
|
+
if self.base_radius is not None:
|
|
20
|
+
self.obj.radius = self.base_radius * s
|
|
21
|
+
elif self.base_size is not None:
|
|
22
|
+
self.obj.size = self.base_size * s
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
class ReactorCore:
|
|
2
|
+
RESTORED = {"restored_gate", "restored_coil", "restored_shield", "restored_decoder"}
|
|
3
|
+
|
|
4
|
+
def __init__(self, obj, context):
|
|
5
|
+
self.obj = obj
|
|
6
|
+
self.context = context
|
|
7
|
+
self.received = set()
|
|
8
|
+
self.opened = False
|
|
9
|
+
|
|
10
|
+
def update(self, dt):
|
|
11
|
+
if self.opened:
|
|
12
|
+
return
|
|
13
|
+
for m in self.obj.messages:
|
|
14
|
+
if m.message in self.RESTORED:
|
|
15
|
+
self.received.add(m.message)
|
|
16
|
+
self.obj.messages.clear()
|
|
17
|
+
self.context.runtime_vars.restored_count = len(self.received)
|
|
18
|
+
if len(self.received) == 4:
|
|
19
|
+
self.open_up()
|
|
20
|
+
|
|
21
|
+
def open_up(self):
|
|
22
|
+
self.opened = True
|
|
23
|
+
self.context.runtime_vars.reactor_open = True
|
|
24
|
+
self.obj.radius = 1.7
|
|
25
|
+
marker = self.context.functions.get_game_object("CoreMarker")
|
|
26
|
+
marker.visible = True
|
|
27
|
+
for i in range(4):
|
|
28
|
+
petal = self.context.functions.get_game_object(f"Petal{i}")
|
|
29
|
+
self.context.add_delay(0.12 * i + 0.05, lambda petal=petal: setattr(petal, "visible", False))
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class Spin:
|
|
2
|
+
def __init__(self, obj, context):
|
|
3
|
+
self.obj = obj
|
|
4
|
+
self.context = context
|
|
5
|
+
self.speed = getattr(obj, "spin_speed", 90.0)
|
|
6
|
+
self.t = 0.0
|
|
7
|
+
|
|
8
|
+
def update(self, dt):
|
|
9
|
+
speed = self.speed
|
|
10
|
+
if getattr(self.context.runtime_vars, "coil_powered", False):
|
|
11
|
+
speed *= 5.0
|
|
12
|
+
self.t += dt * speed
|
|
13
|
+
self.obj.rotation.z = self.t % 360.0
|