-
Notifications
You must be signed in to change notification settings - Fork 0
/
Environment.py
409 lines (357 loc) · 13.6 KB
/
Environment.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
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
###############################################################################
# Name: Morgan Visnesky
# AndewID: mvisnesk
# FileName: Environment.py
###############################################################################
# class to set up environment models and most other static game objects
# colliders that correspond to the map walls, trees, grass
from direct.showbase.ShowBase import ShowBase
from panda3d.core import Vec4
from direct.actor.Actor import Actor
from panda3d.core import Vec4, Vec3
from panda3d.core import CollisionTraverser
from panda3d.core import CollisionHandlerPusher
from panda3d.core import CollisionSphere, CollisionNode, CollisionBox
from panda3d.core import CollisionTube
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *
from panda3d.core import Point3
import random
class Environment():
def __init__(self, model):
'''
Loads model for ground and walls of the environment and sets
position, and orientation.
'''
self.environment = loader.loadModel(model)
self.environment.setPos(0,54,-3)
self.environment.setH(90)
self.environment.setP(0)
self.environment.reparentTo(render)
#nodePath = NodePath(self.environment)
#nodePath.setTransparency(TransparencyAttrib.MAlpha)
#nodePath.reparentTo(render)
#return 42
def plants(self):
'''
Creates trees and other plant-like game objects.
'''
self.tree1 = loader.loadModel("MorgansModels/tree_one")
self.tree1.setPos(-20,54,-3)
self.tree1.setScale(3)
self.tree1.reparentTo(render)
self.tree2 = loader.loadModel("MorgansModels/tree_two")
self.tree2.setPos(-30,20,-3)
self.tree2.setScale(3)
self.tree2.reparentTo(render)
self.tree3 = loader.loadModel("MorgansModels/tree_three")
self.tree3.setPos(30,75,-3)
self.tree3.setScale(3)
self.tree3.setH(90)
self.tree3.reparentTo(render)
self.tree4 = loader.loadModel("MorgansModels/tree_three")
self.tree4.setPos(-35,100,-3)
self.tree4.setScale(3)
self.tree4.setH(90)
self.tree4.reparentTo(render)
self.seaShell = loader.loadModel("MorgansModels/seashell")
self.seaShell.setPos(33,120,-3)
self.seaShell.setScale(3)
self.seaShell.setH(90)
self.seaShell.reparentTo(render)
self.shrub = loader.loadModel("MorgansModels/shrub")
self.shrub.setPos(35,127,-3)
self.shrub.setScale(2)
self.shrub.setH(90)
self.shrub.reparentTo(render)
self.shrub = loader.loadModel("MorgansModels/shrub2")
self.shrub.setPos(35,114,-3)
self.shrub.setScale(2)
self.shrub.setH(90)
self.shrub.reparentTo(render)
self.tree4 = loader.loadModel("MorgansModels/tree_two")
self.tree4.setPos(29,129,-3)
self.tree4.setScale(6)
self.tree4.setH(90)
self.tree4.reparentTo(render)
self.shrub = loader.loadModel("MorgansModels/shrub2")
self.shrub.setPos(27,129,-3)
self.shrub.setScale(2)
self.shrub.setH(90)
self.shrub.reparentTo(render)
# shrub rows
for i in range(8):
model = ''
if i % 2 == 0:
model = "MorgansModels/shrub"
else:
model = "MorgansModels/shrub2"
self.shrub = loader.loadModel(model)
self.shrub.setPos(-35+i*5,105,-3)
self.shrub.setScale(2)
self.shrub.setH(90+i*30+15)
self.shrub.reparentTo(render)
for i in range(7):
model = ''
if i % 2 == 0:
model = "MorgansModels/shrub"
else:
model = "MorgansModels/shrub2"
self.shrub = loader.loadModel(model)
self.shrub.setPos(-35+i*5,130,-3)
self.shrub.setScale(2)
self.shrub.setH(90+i*30+15)
self.shrub.reparentTo(render)
for i in range(7):
model = ''
if i % 2 == 0:
model = "MorgansModels/shrub"
else:
model = "MorgansModels/shrub2"
self.shrub = loader.loadModel(model)
self.shrub.setPos(-35+i*5,112,-3)
self.shrub.setScale(2)
self.shrub.setH(90+i*30+15)
self.shrub.reparentTo(render)
'''
self.shrub = loader.loadModel("MorgansModels/shrub2")
self.shrub.setPos(-35,105,-3)
self.shrub.setScale(2)
self.shrub.setH(90)
self.shrub.reparentTo(render)
self.shrub = loader.loadModel("MorgansModels/shrub")
self.shrub.setPos(-30,105,-3)
self.shrub.setScale(2)
self.shrub.setH(180)
self.shrub.reparentTo(render)
self.shrub = loader.loadModel("MorgansModels/shrub2")
self.shrub.setPos(-25,105,-3)
self.shrub.setScale(2)
self.shrub.setH(270)
self.shrub.reparentTo(render)
self.shrub = loader.loadModel("MorgansModels/shrub")
self.shrub.setPos(-20,105,-3)
self.shrub.setScale(2)
self.shrub.setH(90)
self.shrub.reparentTo(render)
self.shrub = loader.loadModel("MorgansModels/shrub2")
self.shrub.setPos(-15,105,-3)
self.shrub.setScale(2)
self.shrub.setH(160)
self.shrub.reparentTo(render)
self.shrub = loader.loadModel("MorgansModels/shrub")
self.shrub.setPos(-10,105,-3)
self.shrub.setScale(2)
self.shrub.setH(240)
self.shrub.reparentTo(render)
'''
for i in range(18):
model = ''
if i % 2 == 0:
model = "MorgansModels/shrub"
else:
model = "MorgansModels/shrub2"
self.shrub = loader.loadModel(model)
self.shrub.setPos(-35,95-i*5,-3)
self.shrub.setScale(2)
self.shrub.setH(90+i*30)
self.shrub.reparentTo(render)
for i in range(7):
model = ''
if i % 2 == 0:
model = "MorgansModels/shrub"
else:
model = "MorgansModels/shrub2"
self.shrub = loader.loadModel(model)
self.shrub.setPos(-10,70-i*5,-3)
self.shrub.setScale(2)
self.shrub.setH(90+i*30)
self.shrub.reparentTo(render)
for i in range(4):
model = ''
if i % 2 == 0:
model = "MorgansModels/shrub"
else:
model = "MorgansModels/shrub2"
self.shrub = loader.loadModel(model)
self.shrub.setPos(-10+i*5,35,-3)
self.shrub.setScale(2)
self.shrub.setH(90+i*30)
self.shrub.reparentTo(render)
# grass
self.shrub = loader.loadModel("MorgansModels/grass1")
self.shrub.setPos(20,75,-3)
self.shrub.setScale(2)
self.shrub.setH(90)
self.shrub.reparentTo(render)
self.shrub = loader.loadModel("MorgansModels/grass1")
self.shrub.setPos(20.5,75,-3)
self.shrub.setScale(1.5)
self.shrub.setH(180)
self.shrub.reparentTo(render)
self.shrub = loader.loadModel("MorgansModels/grass2")
self.shrub.setPos(20,95,-3)
self.shrub.setScale(5)
self.shrub.setH(0)
self.shrub.reparentTo(render)
self.shrub = loader.loadModel("MorgansModels/grass1")
self.shrub.setPos(20.5,85,-3)
self.shrub.setScale(1.5)
self.shrub.setH(180)
self.shrub.reparentTo(render)
# grass by big tree, right side of map
self.shrub = loader.loadModel("MorgansModels/grass1")
self.shrub.setPos(30,73.5,-3)
self.shrub.setScale(2)
self.shrub.setH(90)
self.shrub.reparentTo(render)
self.shrub = loader.loadModel("MorgansModels/grass1")
self.shrub.setPos(30.5,73.5,-3)
self.shrub.setScale(1.5)
self.shrub.setH(180)
self.shrub.reparentTo(render)
self.shrub = loader.loadModel("MorgansModels/grass2")
self.shrub.setPos(30,53.5,-3)
self.shrub.setScale(5)
self.shrub.setH(90)
self.shrub.reparentTo(render)
self.shrub = loader.loadModel("MorgansModels/grass2")
self.shrub.setPos(25.5,53.5,-3)
self.shrub.setScale(1.5)
self.shrub.setH(180)
self.shrub.reparentTo(render)
# grass on left side of map
self.shrub = loader.loadModel("MorgansModels/grass2")
self.shrub.setPos(-30,73.5,-3)
self.shrub.setScale(4)
self.shrub.setH(90)
self.shrub.reparentTo(render)
self.shrub = loader.loadModel("MorgansModels/grass2")
self.shrub.setPos(-30.5,73.5,-3)
self.shrub.setScale(2)
self.shrub.setH(180)
self.shrub.reparentTo(render)
self.shrub = loader.loadModel("MorgansModels/grass3")
self.shrub.setPos(-20,40.5,-3)
self.shrub.setScale(4)
self.shrub.setH(90)
self.shrub.reparentTo(render)
self.shrub = loader.loadModel("MorgansModels/grass2")
self.shrub.setPos(-24.5,43.5,-3)
self.shrub.setScale(2)
self.shrub.setH(180)
self.shrub.reparentTo(render)
self.shrub = loader.loadModel("MorgansModels/grass3")
self.shrub.setPos(34,110,-3)
self.shrub.setScale(4)
self.shrub.setH(180)
self.shrub.reparentTo(render)
for i in range(1,30,4):
for j in range(1,40,4):
x = random.randint(0,30)
y = random.randint(0,40)
randScale = random.randint(1,3)
self.shrub = loader.loadModel("MorgansModels/grass2")
self.shrub.setPos(9.5+x,8.7+y,-3)
if i % 2 == 0:
self.shrub.setScale(randScale)
if i % 5 == 0:
self.shrub.setScale(randScale)
if i % 3 == 0 and j % 3 == 0:
self.shrub.setScale(2.)
self.shrub.setH(180+(i*j))
self.shrub.reparentTo(render)
for i in range(1,50,4):
for j in range(1,40,4):
x = random.randint(0,50)
y = random.randint(0,40)
randScale = random.randint(1,4)
self.shrub = loader.loadModel("MorgansModels/grass2")
self.shrub.setPos(-30+x,72+y,-3)
if i % 2 == 0:
self.shrub.setScale(randScale)
if i % 5 == 0:
self.shrub.setScale(randScale)
if i % 3 == 0 and j % 3 == 0:
self.shrub.setScale(2.)
self.shrub.setH(180+(i*j))
self.shrub.reparentTo(render)
def wallColliders(self):
'''
Creates and postions colliders that correspond to the walls of
the game map.
'''
# walls
wallSolid = CollisionTube(-7.0, 39, -2, 7, 39, -2, 1.2)
#wallSolid = CollisionBox(Point3(-5,64,-4), Point3(2.5, 2.5, 0.25))
wallNode = CollisionNode("wall")
wallNode.addSolid(wallSolid)
wall = render.attachNewNode(wallNode)
#wall.setY(8.0)
#wall.show()
wallSolid = CollisionTube(-2.0, 61, -2, 7, 61, -2, 1.2)
wallNode = CollisionNode("wall")
wallNode.addSolid(wallSolid)
wall = render.attachNewNode(wallNode)
wall.setY(8.0)
#wall.show()
wallSolid = CollisionTube(-7.0, 30, -2, -7, 61, -2, 1.2)
wallNode = CollisionNode("wall")
wallNode.addSolid(wallSolid)
wall = render.attachNewNode(wallNode)
wall.setY(8.0)
#wall.show()
wallSolid = CollisionTube(7.0, 40, -2, 7, 61, -2, 1.2)
wallNode = CollisionNode("wall")
wallNode.addSolid(wallSolid)
wall = render.attachNewNode(wallNode)
wall.setY(8.0)
#wall.show()
wallSolid = CollisionTube(-38, -1, -2, -38, 124, -2, 1.2)
wallNode = CollisionNode("wall")
wallNode.addSolid(wallSolid)
wall = render.attachNewNode(wallNode)
wall.setY(8.0)
#wall.show()
wallSolid = CollisionTube(38, -1, -2, 38, 124, -2, 1.2)
wallNode = CollisionNode("wall")
wallNode.addSolid(wallSolid)
wall = render.attachNewNode(wallNode)
wall.setY(8.0)
#wall.show()
wallSolid = CollisionTube(-38, 124, -2, 38, 124, -2, 1.2)
wallNode = CollisionNode("wall")
wallNode.addSolid(wallSolid)
wall = render.attachNewNode(wallNode)
wall.setY(8.0)
#wall.show()
wallSolid = CollisionTube(-38, -1, -2, 38, -1, -2, 1.2)
wallNode = CollisionNode("wall")
wallNode.addSolid(wallSolid)
wall = render.attachNewNode(wallNode)
wall.setY(8.0)
#wall.show()
wallSolid = CollisionTube(-38, 101, -2, 0, 101, -2, 1.2)
wallNode = CollisionNode("wall")
wallNode.addSolid(wallSolid)
wall = render.attachNewNode(wallNode)
wall.setY(8.0)
#wall.show()
wallSolid = CollisionTube(1, 101, -2, 1, 114, -2, 1.2)
wallNode = CollisionNode("wall")
wallNode.addSolid(wallSolid)
wall = render.attachNewNode(wallNode)
wall.setY(8.0)
#wall.show()
wallSolid = CollisionTube(22.5, 62, -2, 22.5, 93, -2, 1.2)
wallNode = CollisionNode("wall")
wallNode.addSolid(wallSolid)
wall = render.attachNewNode(wallNode)
wall.setY(8.0)
#wall.show()
wallSolid = CollisionTube(8, 92.5, -2, 22.5, 92.5, -2, 1.2)
wallNode = CollisionNode("wall")
wallNode.addSolid(wallSolid)
wall = render.attachNewNode(wallNode)
wall.setY(8.0)
#wall.show()