-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene.py
92 lines (68 loc) · 2.5 KB
/
scene.py
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
import random
from enum import Enum, auto
from panda3d.core import NodePath, PandaNode
from panda3d.core import Point2, LColor
from goal_gate import GoalGate
from lights import BasicAmbientLight, BasicDayLight
from terrain_creator import Terrains
class Status(Enum):
CLEANUP = auto()
CHANGE = auto()
FINISH = auto()
class Sky(NodePath):
def __init__(self):
super().__init__(PandaNode('sky'))
model = base.loader.load_model('models/blue-sky/blue-sky-sphere')
model.set_color(LColor(2, 2, 2, 1))
model.set_scale(0.2)
model.set_z(0)
model.reparent_to(self)
self.set_shader_off()
class Scene(NodePath):
def __init__(self, world):
super().__init__(PandaNode('scene'))
self.world = world
self.state = None
self.ambient_light = BasicAmbientLight()
self.ambient_light.reparent_to(self)
self.directional_light = BasicDayLight()
self.directional_light.reparent_to(self)
self.sky = Sky()
self.sky.reparent_to(self)
self.terrains = Terrains(self.world)
self.terrains.reparent_to(self)
self.goal_gate = GoalGate(self.world)
self.goal_gate.reparent_to(self)
def setup_scene(self):
pos, angle = self.decide_goal_pos()
self.goal_gate.setup_gate(pos, angle)
self.terrains.setup_nature()
base.taskMgr.add(self.goal_gate.sensor.check_finish, 'check_finish')
def cleanup_scene(self):
self.terrains.natures.remove_from_terrain()
self.goal_gate.cleanup_gate()
def decide_goal_pos(self):
candidates = [
[Point2(230, 230), -45],
[Point2(-230, -230), 135],
[Point2(230, -230), -135],
[Point2(-230, 230), 45],
]
pt, angle = random.choice(candidates)
pos = self.terrains.check_position(*pt, sweep=False)
return pos, angle
def update(self):
match self.state:
case Status.FINISH:
self.state = Status.CLEANUP
case Status.CLEANUP:
self.cleanup_scene()
self.state = Status.CHANGE
case Status.CHANGE:
self.terrains.replace_terrain()
self.state = Status.FINISH
return True
case _:
self.terrains.initialize()
self.state = Status.FINISH
return True