-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathroboSaver.py
More file actions
1626 lines (1429 loc) · 79.5 KB
/
Copy pathroboSaver.py
File metadata and controls
1626 lines (1429 loc) · 79.5 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
from math import sin, cos,pi
import sys
import time
from direct.showbase.ShowBase import ShowBase
from pandac.PandaModules import TransparencyAttrib
from direct.actor.Actor import Actor
from direct.showbase.DirectObject import DirectObject
from direct.showbase.InputStateGlobal import inputState
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *
from panda3d.core import *
from panda3d.core import AmbientLight
from panda3d.core import DirectionalLight
from panda3d.core import Vec3
from panda3d.core import Vec4
from panda3d.core import Point3
from panda3d.core import BitMask32
from panda3d.core import NodePath
from panda3d.core import PandaNode
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *
from direct.interval.LerpInterval import LerpPosInterval
from panda3d.core import *
from panda3d.bullet import BulletWorld
from panda3d.bullet import BulletHelper
from panda3d.bullet import BulletPlaneShape
from panda3d.bullet import BulletBoxShape
from panda3d.bullet import BulletRigidBodyNode
from panda3d.bullet import BulletDebugNode
from panda3d.bullet import BulletSphereShape
from panda3d.bullet import BulletCapsuleShape
from panda3d.bullet import BulletCharacterControllerNode
from panda3d.bullet import BulletHeightfieldShape
from panda3d.bullet import BulletTriangleMesh
from panda3d.bullet import BulletTriangleMeshShape
from panda3d.bullet import BulletSoftBodyNode
from panda3d.bullet import BulletSoftBodyConfig
from panda3d.bullet import ZUp
from panda3d.bullet import BulletGhostNode
from direct.interval.IntervalGlobal import *
DEG_TO_RAD = pi / 180 # translates degrees to radians for sin and cos
BULLET_LIFE = 2 # How long bullets stay on screen before removed
BULLET_REPEAT = .2 # How often bullets can be fired
BULLET_SPEED = 10 # Speed bullets move
counter = 0;
health = 100;
enemiess = 7;
enemiesss = 5;
counterBullet = 0;
tempCount = 0
enemy1Counter = 0
enemy2Counter = 0
enemy3Counter = 0
enemy4Counter = 0
enemy5Counter = 0
enemy6Counter = 0
enemy7Counter = 0
enemy8Counter = 0
enemy9Counter = 0
enemy10Counter = 0
enemy11Counter = 0
enemy12Counter = 0
enemy13Counter = 0
level1 = False
level2 = False
welcomeword = 0
def addInstructions(pos, msg):
return OnscreenText(text=msg, style=1, fg=(1,1,1,1),
pos=(-0.10,0.93,pos), align=TextNode.ALeft, scale = .05)
def addInstructions1(pos, msg):
return OnscreenText(text=msg, style=1, fg=(1,1,1,1),
pos=(0.65,0.93,pos), align=TextNode.ALeft, scale = .05)
def addInstructions2(pos, msg):
return OnscreenText(text=msg, style=1, fg=(1,1,1,1),
pos=(0.25,0.93,0.55), align=TextNode.ALeft, scale = .05)
def storyModeConversation(pos, msg):
return OnscreenText(text=msg, style=1, fg=(1,1,1,1),
pos=(-0.90,-0.97,0), align=TextNode.ALeft, scale = .05)
def gameOverText(pos, msg):
return OnscreenText(text=msg, style=2, fg=(1,1,1,1),
pos=(-1.0,0,0), align=TextNode.ALeft, scale = 0.10)
def helpMenu(pos1,pos, msg):
return OnscreenText(text=msg, style=1, fg=(1,1,1,1),bg=(0,0,0,1),
pos=(0,pos1, pos), align=TextNode.ALeft, scale = 0.05)
def welcomeText(pos1,pos, msg):
return OnscreenText(text=msg, style=1, fg=(1,1,1,1),bg=(0,0,0,1),
pos=(-0.97,pos1, pos), align=TextNode.ALeft, scale = 0.05)
# def enemyNumber(pos, msg):
# return OnscreenText(text=msg, style=1, fg=(1,1,1,1),
# pos=(0.10,0.93,0.55), align=TextNode.ALeft, scale = .05)
class CharacterController(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.bombs = []
self.keys = {"fire":0}
self.setupLights()
fire=1
self.bullet=[]
self.enemy1Bullet = []
# Input
self.accept('escape', self.doExit)
# self.accept('r', self.doReset)
self.accept('f3', self.toggleDebug)
self.accept('control', self.doJump)
self.accept('space',self.fire)
#self.accept('b',self.secondaryFire)
#self.accept('enter',self.respawn)
#self.accept('fire','space')
self.isMoving = False
self.isEnemyFire = False
#inputState.watchWithModifiers('fire','space')
#inputState.watchWithModifiers('respawn','z')
inputState.watchWithModifiers('forward', 'arrow_up')
inputState.watchWithModifiers('reverse', 'arrow_down')
inputState.watchWithModifiers('turnLeft', 'arrow_left')
inputState.watchWithModifiers('turnRight', 'arrow_right')
inputState.watchWithModifiers('topView','w')
inputState.watchWithModifiers('bottomView','s')
inputState.watchWithModifiers('leftView','a')
inputState.watchWithModifiers('rightView','d')
self.backGroundMusic = base.loader.loadSfx("models/bassRemix.flac")
self.backGroundMusic.setLoop(True)
self.backGroundMusic.play()
self.backGroundMusic.setVolume(0.5)
# Stores the time at which the next bullet may be fired.
self.nextBullet = 0.0
self.myFrame = DirectFrame(frameColor=(0, 0, 0, 1),
frameSize=(-1.00, 1.00, 0.90, 1.0 ))
self.storyMode = DirectFrame(frameColor=(0,0,0,1),
frameSize=(1.00,-1.00,-1.0,-0.9),pos=(0,-3,0))
self.bullets = []
self.isFire = False
self.inst3 = addInstructions(0.65, "Enemies left: 5 ")
self.inst4 = addInstructions1(0.55, "Health: 100")
self.inst5 = addInstructions2(0.55,"Time Left: 00:00")
self.story = storyModeConversation(0.10,"Hello, There are 4 enemies on ground and 3 on planks. Kill them'll")
# Task
taskMgr.add(self.update, 'updateWorld')
self.setup()
base.setBackgroundColor(0.1, 0.1, 0.8, 1)
base.setFrameRateMeter(True)
base.disableMouse()
base.camera.setPos(self.characterNP.getPos())
base.camera.setHpr(self.characterNP.getHpr())
base.camera.lookAt(self.characterNP)
# Create a floater object. We use the "floater" as a temporary
# variable in a variety of calculations.
self.floater = NodePath(PandaNode("floater"))
self.floater.reparentTo(render)
def doExit(self):
self.cleanup()
sys.exit(1)
def doReset(self):
self.cleanup()
self.setup()
def toggleDebug(self):
if self.debugNP.isHidden():
self.debugNP.show()
else:
self.debugNP.hide()
def doJump(self):
self.character.setMaxJumpHeight(5.0)
self.character.setJumpSpeed(8.0)
self.jumpSound = base.loader.loadSfx("models/armMoving.ogg")
self.actorNP.play("jump")
#self.actorNP.pose("jump",5)
self.character.doJump()
self.jumpSound.setVolume(0.3)
#self.actorNP.loop("idle")
self.jumpSound.play()
def processInput(self, dt):
speed = Vec3(0, 0, 0)
omega = 0.0
if inputState.isSet('forward'):
speed.setY( 2.0)
# if inputState.isSet('respawn'):
# print "hello i am inside"
# taskMgr.add(self.update,'updateWorld')
if inputState.isSet('reverse'):
speed.setY(-2.0)
if inputState.isSet('left'): speed.setX(-2.0)
if inputState.isSet('right'): speed.setX( 2.0)
if inputState.isSet('turnLeft'): omega = 120.0
if inputState.isSet('turnRight'): omega = -120.0
if (inputState.isSet('forward')!=0) or (inputState.isSet('reverse')!=0) or (inputState.isSet('left')!=0) or (inputState.isSet('right')!=0):
if self.isMoving is False:
self.actorNP.loop("run")
#self.actorNP.play('attack')
self.mySound.setVolume(0.3)
self.mySound.setLoop(True)
self.mySound.play()
self.isMoving = True
else:
if self.isMoving:
self.actorNP.stop()
#self.actorNP.pause("",5)
self.actorNP.pose("walk",5)
self.actorNP.loop("walk")
self.mySound.stop()
self.isMoving = False
#self.actorNP.loop('idle')
self.character.setAngularMovement(omega)
self.character.setLinearMovement(speed, True)
# def updateTime(self):
# self.myText.setText(str (nowTime))
def update(self, task):
global health
global enemy1Counter
global enemy2Counter
global enemy3Counter
global enemy4Counter
global enemy5Counter
global enemy6Counter
global enemy7Counter
global enemy8Counter
global enemy9Counter
global enemy10Counter
global enemy11Counter
global enemy12Counter
global enemy13Counter
global enemiesss
global welcomeword
#print taskMgr
dt = globalClock.getDt()
self.processInput(dt)
self.world.doPhysics(dt, 4, 1./240.)
timer = health - dt
self.inst5.remove_node()
h = int(round(timer))
#print h
nowTime = globalClock.getFrameTime() - self.startTime
h = int(round(nowTime))
j = 600 - h
self.inst5 = addInstructions2(0.68,' Time Left : {}'.format(j))
if j == 0:
taskMgr.remove('updateWorld')
self.inst6 = gameOverText(0,'Game Over')
# if welcomeword == 0:
# self.instStory = welcomeText(0.10, "Hi this is the story of Robot who's trying to save his master from evil druglord\'s army and evil scientist who are hell bent to get the technology of making robot army who can take over the world. Our aim is to save our master and kill everybody coming between us. Environment is supposed to be a jungle so army can hide in it and attack you, so mesh has not been made used here to follow the story.")
# self.close = DirectButton(text = ("Close Welcome Text"), scale=.05,pos=(-0.50,0,0.15), command= self.closeStory)
# If the camera is too far from ralph, move it closer.
# If the camera is too close to ralph, move it farther.
camvec = self.characterNP.getPos() - base.camera.getPos()
camvec.setZ(0)
camdist = camvec.length()
camvec.normalize()
if (camdist > 15.0):
base.camera.setPos(base.camera.getPos() + camvec*(camdist-15))
camdist = 15.0
if (camdist < 5.0):
base.camera.setPos(base.camera.getPos() - camvec*(5-camdist))
camdist = 5.0
if inputState.isSet('topView'): base.camera.setZ(base.camera,+20 * globalClock.getDt())
if inputState.isSet('bottomView'): base.camera.setZ(base.camera, -20 * globalClock.getDt())
if inputState.isSet('rightView'): base.camera.setX(base.camera, +20 * globalClock.getDt())
if inputState.isSet('leftView'): base.camera.setX(base.camera, -20 * globalClock.getDt())
self.floater.setPos(self.characterNP.getPos())
self.floater.setZ(self.characterNP.getZ() + 0.7)
base.camera.lookAt(self.floater)
global tempCount
if self.characterNP.getZ()>4.33:
#print self.characterNP.getZ()
tempCount = 0
if self.characterNP.getZ()<2.50 and tempCount == 0:
tempCount= 1
health = health - 5
self.inst4.remove_node()
self.inst4 = addInstructions1(0.55,"Health: {}".format(health))
print health
print self.characterNP.getZ()
# self.processContacts()
radius = 0.05
global enemiess
global counterBullet
enemy0 = self.beefyManNP.getPos()
enemy1 = self.beefyManNP1.getPos()
enemy2 = self.beefyManNP2.getPos()
enemy3 = self.beefyManNP3.getPos()
enemy5 = self.beefyManNP5.getPos()
enemy6 = self.beefyManNP6.getPos()
enemy7 = self.beefyManNP7.getPos()
enemy8 = self.beefyManNP8.getPos()
enemy9 = self.beefyManNP9.getPos()
enemy10 = self.beefyManNP10.getPos()
enemy11 = self.beefyManNP11.getPos()
enemy12 = self.beefyManNP12.getPos()
master = self.masterNP.getPos()
evil = self.evilNP.getPos()
actor = self.characterNP.getPos()
distance1 = actor - enemy0
distance2 = actor - enemy1
distance3 = actor -enemy2
distance4 = actor - enemy3
distance5 = actor - enemy5
distance6 = actor - enemy6
distance7 = actor - enemy7
distance8 = actor - master
distance9 = actor - evil
distance10 = actor - enemy8
distance11 = actor - enemy9
distance12 = actor - enemy10
distance13 = actor - enemy11
distance14 = actor - enemy12
# distance1.setZ(0)
# distance2.setZ(0)
# distance3.setZ(0)
# distance4.setZ(0)
# distance5.setZ(0)
# distance6.setZ(0)
# distance7.setZ(0)
# distance8.setZ(0)
# distance9.setZ(0)
enemyDist = distance1.length()
enemyDist1 = distance2.length()
enemyDist2 = distance3.length()
enemyDist3 = distance4.length()
enemyDist4 = distance5.length()
enemyDist5 = distance6.length()
enemyDist6 = distance7.length()
enemyDist7 = distance8.length()
enemyDist8 = distance9.length()
enemyDist9 = distance10.length()
enemyDist10 = distance11.length()
enemyDist11 = distance12.length()
enemyDist12 = distance13.length()
enemyDist13 = distance14.length()
#print "this is enemy distance",enemyDist1
#global isFire
####################################################################### Enemy 1 ###########################################################################
if enemyDist < 15 :
self.story.destroy()
self.story = storyModeConversation(0.10,"First Enemy: Do you hear something?")
#counterBullet = 0
if enemyDist < 10 and counterBullet == 0 and enemy1Counter == 0:
self.beefyManNP.lookAt(self.characterNP.getPos())
self.beefyManNP.setH(self.beefyManNP.getH()+180)
counterBullet =1
self.enemyFire(self.beefyManNP)
self.isEnemyFire = False
health = health - 5
self.inst4.remove_node()
self.inst4 = addInstructions1(0.55,"Health: {}".format(health))
if enemyDist < 6 and self.isFire == True:
#self.actorNP.setPos(self.beefyManNP.getPos()+distance1*(3-enemyDist))
self.beefyManNP.hide()
self.story.destroy()
counterBullet = 0
self.isFire = False
if self.beefyManNP.hide() is None and enemy1Counter == 0:
#print "gela re.."
enemiess = enemiess - 1
enemy1Counter = 1
self.inst3.destroy()
self.inst3 = addInstructions(0.65, "Enemies left: "+ str(enemiess))
if enemyDist < 2 and enemy1Counter is not 1:
self.characterNP.setPos(self.characterNP.getPos()-enemyDist+1)
############################################################################## Enemy 2 ##########################################################################
if enemyDist1 < 15:
self.story.destroy()
self.story = storyModeConversation(0.10,"Second Enemy: Don't move, I hear something..")
if enemyDist1 < 10 and counterBullet == 0 and enemy2Counter == 0:
self.beefyManNP1.lookAt(self.characterNP.getPos())
self.beefyManNP1.setH(self.beefyManNP1.getH()+180)
counterBullet = 1
self.enemyFire(self.beefyManNP1)
health = health - 5
self.inst4.remove_node()
self.inst4 = addInstructions1(0.55,"Health: {}".format(health))
if enemyDist1 < 6 and self.isFire == True:
self.beefyManNP1.hide()
self.story.destroy()
counterBullet = 0
if self.beefyManNP1.hide() is None and enemy2Counter == 0:
enemiess = enemiess - 1
enemy2Counter = 1
self.inst3.destroy()
self.inst3 = addInstructions(0.65, "Enemies left: "+str(enemiess))
self.isFire = False
if enemyDist1 < 2 and enemy2Counter is not 1:
self.characterNP.setPos(self.characterNP.getPos()-enemyDist1+1)
############################################################################# ENEMY 3 ######################################################################
if enemyDist2 < 15 :
self.story.destroy()
self.story = storyModeConversation(0.10,"Third Enemy: who's there? come out or I'll fire.....*HEY*")
if enemyDist2 < 10 and counterBullet == 0 and enemy3Counter == 0:
self.beefyManNP2.lookAt(self.characterNP.getPos())
self.beefyManNP2.setH(self.beefyManNP2.getH()+180)
counterBullet = 1
self.enemyFire(self.beefyManNP2)
health = health - 5
self.inst4.remove_node()
self.inst4 = addInstructions1(0.55,"Health: {}".format(health))
self.isEnemyFire = False
if enemyDist2 < 6 and self.isFire == True:
self.beefyManNP2.hide()
self.story.destroy()
self.isFire = False
counterBullet = 0
if self.beefyManNP2.hide() is None and enemy3Counter == 0:
enemiess = enemiess - 1
enemy3Counter = 1
self.inst3.destroy()
self.inst3 = addInstructions(0.65, "Enemies left: "+str(enemiess))
if enemyDist2 < 2 and enemy3Counter is not 1 :
self.characterNP.setPos(self.characterNP.getPos()-enemyDist2+1)
################################################################### ENEMY 4 ############################################################################
if enemyDist3 <15:
self.story.destroy()
self.story = storyModeConversation(0.10,"Forth Enemy: Do you hear something? Srgt Thomas come in..anybody listening?")
if enemyDist3 < 10 and counterBullet == 0 and enemy4Counter == 0:
self.beefyManNP3.lookAt(self.characterNP.getPos())
self.beefyManNP3.setH(self.beefyManNP3.getH()+180)
counterBullet =1
self.enemyFire(self.beefyManNP3)
health = health - 5
self.inst4.remove_node()
self.inst4 = addInstructions1(0.55,"Health: {}".format(health))
self.isEnemyFire = False
if enemyDist3 < 6 and self.isFire == True:
self.beefyManNP3.hide()
self.story.destroy()
self.isFire = False
counterBullet = 0
if self.beefyManNP3.hide() is None and enemy4Counter == 0:
enemiess = enemiess - 1
self.inst3.destroy()
enemy4Counter = 1
self.inst3 = addInstructions(0.65, "Enemies left: "+str(enemiess))
if enemyDist3 < 2 and enemy4Counter is not 1:
self.characterNP.setPos(self.characterNP.getPos()-enemyDist3+1)
################################################################# ENEMY 5 ##########################################################################
if enemyDist4 <15:
self.story.destroy()
self.story = storyModeConversation(0.10,"Fifth Enemy: We got company, take cover..take cover")
self.beefyManNP5.lookAt(self.characterNP.getPos())
self.beefyManNP5.setH(self.beefyManNP5.getH()+180)
if enemyDist4 < 10 and counterBullet == 0 and enemy5Counter == 0:
#self.beefyManNP5.lookAt(self.characterNP.getPos())
#self.beefyManNP5.setH(self.beefyManNP5.getH()+180)
counterBullet =1
self.enemyFire(self.beefyManNP5)
health = health - 5
self.inst4.remove_node()
self.inst4 = addInstructions1(0.55,"Health: {}".format(health))
if enemyDist4 < 6 and self.isFire == True:
self.beefyManNP5.hide()
self.story.destroy()
counterBullet = 0
self.isFire = False
if self.beefyManNP5.hide() is None and enemy5Counter == 0:
enemiess = enemiess - 1
self.inst3.destroy()
self.inst3 = addInstructions(0.65, "Enemies left: "+str(enemiess))
enemy5Counter = 1
if enemyDist4 < 2 and enemy5Counter is not 1:
self.characterNP.setPos(self.characterNP.getPos()-enemyDist4+1)
############################################################ ENEMY 6 ##################################################################################
#self.beefyManNP5.loop('idle')
if enemyDist5 <15:
self.story.destroy()
self.story = storyModeConversation(0.10,"Sixth Enemy: I got this..")
if enemyDist5 < 10 and counterBullet == 0 and enemy6Counter == 0:
self.beefyManNP6.lookAt(self.characterNP.getPos())
self.beefyManNP6.setH(self.beefyManNP6.getH()+180)
counterBullet =1
self.enemyFire(self.beefyManNP6)
health = health - 5
self.inst4.remove_node()
self.inst4 = addInstructions1(0.55,"Health: {}".format(health))
if enemyDist5 < 6 and self.isFire == True:
self.beefyManNP6.hide()
counterBullet = 0
self.story.destroy()
self.isFire =False
if self.beefyManNP6.hide() is None and enemy6Counter == 0:
enemiess = enemiess - 1
self.inst3.destroy()
enemy6Counter = 1
self.inst3 = addInstructions(0.65, "Enemies left: "+str(enemiess))
if enemyDist5 < 2 and enemy6Counter is not 1:
self.characterNP.setPos(self.characterNP.getPos()-enemyDist5+1)
##################################################################### ENEMY 7 #######################################################################
if enemyDist6 < 15:
self.story.destroy()
self.story = storyModeConversation(0.10,"Master: I knew he would come, I had faith in my creation")
if enemyDist6 < 10 and counterBullet == 0 and enemy7Counter == 0:
self.beefyManNP7.lookAt(self.characterNP.getPos())
self.beefyManNP7.setH(self.beefyManNP7.getH()+180)
counterBullet =1
self.enemyFire(self.beefyManNP7)
health = health - 5
self.inst4.remove_node()
self.inst4 = addInstructions1(0.55,"Health: {}".format(health))
if enemyDist6 < 6 and self.isFire == True:
self.beefyManNP7.hide()
self.story.destroy()
self.isFire = False
counterBullet = 0
if self.beefyManNP7.hide() is None and enemy7Counter ==0:
enemiess = enemiess - 1
enemy7Counter = 1
self.inst3.destroy()
self.inst3 = addInstructions(0.65, "Enemies left: "+str(enemiess))
if enemyDist6 < 2 and enemy7Counter is not 1:
self.characterNP.setPos(self.characterNP.getPos()-enemyDist6+1)
########################################################################################################################################################################
## ###########
## ##
## #########
######### ########## Vel 1 Enemies
####################################################################################################################################################################33
############################################################################ ENEMY 8 #############################################################
if enemyDist9 < 4:
self.story.destroy()
self.story = storyModeConversation(0.10,"Press Space To Kill This Enemy..")
self.beefyManNP8.lookAt(self.characterNP.getPos())
self.beefyManNP8.setH(self.characterNP.getH()-55)
counterBullet =0
if self.isFire == True and enemy13Counter == 0:
#counterBullet = 1
self.beefyManNP8.hide()
enemy13Counter = 1
self.story.destroy()
enemiesss = enemiesss - 1
self.inst3.destroy()
self.inst3 = addInstructions(0.65, "Enemies left: "+str(enemiesss))
self.story = storyModeConversation(0.10,"Up arrow will move forward and Left, Right arrow for directions. press help")
self.characterNP.setPos(self.characterNP.getPos())
self.isFire = False
if enemyDist9 < 2 and enemy13Counter is not 1:
self.characterNP.setPos(self.characterNP.getPos() - enemyDist9+1.2)
####################################################################### ENEMY 10 ##################################################################
if enemyDist10 < 10:
self.story.destroy()
self.story = storyModeConversation(0.10,"You've to kill all enemy to reach level 2 and win this game")
if enemyDist10 < 7 and counterBullet == 0 and enemy9Counter == 0:
self.beefyManNP9.lookAt(self.characterNP.getPos())
self.beefyManNP9.setH(self.characterNP.getH()-55)
counterBullet = 1
self.enemyFire(self.beefyManNP9)
health = health - 3
self.inst4.remove_node()
self.inst4 = addInstructions1(0.55,"Health: {}".format(health))
self.story.destroy()
self.story = storyModeConversation(0.10,"You'll lose 3 health each attack. Enemy will start to get stronger and powerful later.'")
if enemyDist10 < 6 and self.isFire == True:
self.beefyManNP9.hide()
self.story.destroy()
self.isFire = False
self.story.destroy()
self.story = storyModeConversation(0.10,"You'll lose 3 health each attack. Enemy will start to get stronger and powerful later.'")
counterBullet = 0
if self.beefyManNP9.hide() is None and enemy9Counter ==0:
enemiesss = enemiesss - 1
enemy9Counter = 1
self.inst3.destroy()
self.inst3 = addInstructions(0.65, "Enemies left: "+str(enemiesss))
if enemyDist10 < 2 and enemy9Counter is not 1:
self.characterNP.setPos(self.characterNP.getPos() - enemyDist10)
#######################################################################3 ENemy 11 #############################################################
if enemyDist11 < 10:
if enemyDist11 < 7 and counterBullet == 0 and enemy10Counter == 0:
#self.beefyManNP10.lookAt(self.characterNP.getPos())
#self.beefyManNP10.setH(self.characterNP.getH()-55)
counterBullet = 1
self.enemyFire(self.beefyManNP10)
health = health - 3
self.inst4.remove_node()
self.inst4 = addInstructions1(0.55,"Health: {}".format(health))
self.story.destroy()
self.story = storyModeConversation(0.10,"You'll lose 3 health each attack. Enemy will start to get stronger and powerful later.'")
if enemyDist11 < 6 and self.isFire == True:
self.beefyManNP10.hide()
self.isFire = False
counterBullet = 0
if self.beefyManNP10.hide() is None and enemy10Counter ==0:
enemiesss = enemiesss - 1
enemy10Counter = 1
self.inst3.destroy()
self.inst3 = addInstructions(0.65, "Enemies left: "+str(enemiesss))
if enemyDist11 < 2 and enemy10Counter is not 1:
self.characterNP.setPos(self.characterNP.getPos() - enemyDist11+1)
########################################################################## Enemy 12 ##################################################################
if enemyDist12 < 10:
#self.beefyManNP12.pose(5,'idle')
if enemyDist12 < 7 and counterBullet == 0 and enemy11Counter == 0:
#self.beefyManNP10.lookAt(self.characterNP.getPos())
#self.beefyManNP10.setH(self.characterNP.getH()-55)
counterBullet = 1
self.enemyFire(self.beefyManNP11)
health = health - 3
self.inst4.remove_node()
self.inst4 = addInstructions1(0.55,"Health: {}".format(health))
self.story.destroy()
self.story = storyModeConversation(0.10,"You'll lose 3 health each attack. Enemy will start to get stronger and powerful later.'")
if enemyDist12 < 6 and self.isFire == True:
self.beefyManNP11.hide()
self.isFire = False
counterBullet = 0
if self.beefyManNP11.hide() is None and enemy11Counter ==0:
enemiesss = enemiesss - 1
enemy11Counter = 1
self.inst3.destroy()
self.inst3 = addInstructions(0.65, "Enemies left: "+str(enemiesss))
if enemyDist12 < 2 and enemy11Counter is not 1:
self.characterNP.setPos(self.characterNP.getPos() - enemyDist12)
########################################################################## ENEMY 13 ##################################################################
if enemyDist13 < 10:
#self.beefyManNP12.pose(5,'idle')
if enemyDist13 < 7 and counterBullet == 0 and enemy12Counter == 0:
#self.beefyManNP10.lookAt(self.characterNP.getPos())
#self.beefyManNP10.setH(self.characterNP.getH()-55)
counterBullet = 1
self.enemyFire(self.beefyManNP12)
health = health - 3
self.inst4.remove_node()
self.inst4 = addInstructions1(0.55,"Health: {}".format(health))
self.story.destroy()
self.story = storyModeConversation(0.10,"You'll lose 3 health each attack. Enemy will start to get stronger and powerful later.'")
if enemyDist13 < 6 and self.isFire == True:
self.beefyManNP12.hide()
self.isFire = False
counterBullet = 0
if self.beefyManNP12.hide() is None and enemy12Counter ==0:
enemiesss = enemiesss - 1
enemy12Counter = 1
# enemiesss = enemiesss - 1
self.inst3.destroy()
self.inst3 = addInstructions(0.65, "Enemies left: "+str(enemiesss))
if enemyDist12 < 2 and enemy7Counter is not 1:
self.characterNP.setPos(self.characterNP.getPos() - enemyDist13)
########################################################################### ENEMY LEADER SCIENTIST #######################################################
if enemyDist8 < 15:
self.story.destroy()
self.story = storyModeConversation(0.10,"I'll explode this iron tin")
if enemyDist8 < 10 and counterBullet == 0 and enemy8Counter == 0 :
counterBullet =1
self.enemyFire(self.evilNP)
health = health - 15
self.inst4.remove_node()
self.inst4 = addInstructions1(0.55,"Health: {}".format(health))
if enemyDist8 < 6 and self.isFire == True :
self.evilNP.hide()
self.story.destroy()
counterBullet = 0
self.isFire = False
if self.evilNP.hide() is None and enemy8Counter == 0:
enemiess = enemiess - 1
self.inst3.destroy()
enemy8Counter = 1
self.inst3 = addInstructions(0.65, "Enemies left: "+str(enemiess))
if enemiess == 0 and enemy8Counter == 1 and enemy8Counter == 0:
taskMgr.remove('updateWorld')
self.inst6 = gameOverText(0,'You Won')
welcomeword = 1
if enemyDist8 < 1.3 and enemy8Counter is not 1:
self.characterNP.setPos(self.characterNP.getPos()-enemyDist8+1)
for healthis in render.findAllMatches("**/=healthFull"):
distOfPlayer = self.characterNP.getPos() - healthis.getPos()
if (self.characterNP.getPos() - healthis.getPos()) < radius:
#global counter
#global addInstructions
# global health
global enemiess
enemiess = 7
# print "i got the health"
if health < 100:
health = 100
self.story.destroy()
self.story = storyModeConversation(0.10,"Your health is refilled and you\'re on level 2. Go Down and Kill Others")
healthis.removeNode()
self.inst4.remove_node()
self.inst4 = addInstructions1(0.55,"Health: {}".format(health))
for coin in render.findAllMatches("**/=coin" ):
distOfPlayer = self.characterNP.getPos() - coin.getPos()
if (self.characterNP.getPos() - coin.getPos())< radius:
#global counter
#global addInstructions
global health
#tempCount= 1
if health < 100:
health = health + 5
self.story.destroy()
self.story = storyModeConversation(0.10,"You Just received 5 health")
coin.removeNode()
elif health == 100 and health > 100:
health = health
self.inst4.remove_node()
self.inst4 = addInstructions1(0.55,"Health: {}".format(health))
for bomb in self.bombs:
timeAsString = bomb.getTag("timer")
#print type(timeAsString), timeAsString
timeSinceBombWasCreated = globalClock.getRealTime() - float(timeAsString)
#print "Time Diff: ", timeSinceBombWasCreated
if timeSinceBombWasCreated > 3.0:
# print "Removing Node"
bomb.removeNode()
self.bombs.remove(bomb)
for bomb in self.enemy1Bullet:
timeAsString = bomb.getTag("timerForEnemy")
#print type(timeAsString), timeAsString
timeSinceBombWasCreated = globalClock.getRealTime() - float(timeAsString)
#print "Time Diff: ", timeSinceBombWasCreated
if timeSinceBombWasCreated > 3.0:
#print "Removing Node"
bomb.removeNode()
self.enemy1Bullet.remove(bomb)
if health == 0 or health <0:
taskMgr.remove('updateWorld')
# self.evilNP.setPos(self.evilNP.getPos()+1)
# self.evilNP.setHpr(90,0,0)
self.evilNP.loop('dance')
self.inst6 = gameOverText(0,'Game Over and You\'re dead meat..Err...Dead Tin')
welcomeword = 1
#print "hello"
return task.cont
def cleanup(self):
self.world = None
self.render.removeNode()
def setupLights(self):
# Light
alight = AmbientLight('ambientLight')
alight.setColor(Vec4(0.5, 0.5, 0.5, 1))
alightNP = render.attachNewNode(alight)
dlight = DirectionalLight('directionalLight')
dlight.setDirection(Vec3(1, 1, -1))
dlight.setColor(Vec4(0.7, 0.7, 0.7, 1))
dlightNP = render.attachNewNode(dlight)
self.render.clearLight()
self.render.setLight(alightNP)
self.render.setLight(dlightNP)
def setup(self):
# World
self.debugNP = self.render.attachNewNode(BulletDebugNode('Debug'))
self.debugNP.show()
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, -9.81))
self.world.setDebugNode(self.debugNP.node())
self.startTime = globalClock.getFrameTime()
# Floor
shape = BulletPlaneShape(Vec3(0, 0, 1), 0)
floorNP = self.render.attachNewNode(BulletRigidBodyNode('Floor'))
floorNP.node().addShape(shape)
floorNP.setPos(0, 0, 0)
#floorNP.setCollideMask(BitMask32.allOn())
self.world.attachRigidBody(floorNP.node())
self.environ = loader.loadModel("models/environment")
self.environ.reparentTo(floorNP)
self.grass = loader.loadTexture("models/grass1.jpg")
self.environ.setTexture(self.grass, 1)
# Stair
origin2 = Point3(2, 0, 0)
size = Vec3(4, 4.75, 1.0)
#ballSize= Vec3(4.75,5.75,2.75)
height = 0
angle = -25
######################################################### Stairs 1 ######################################################################
for i in range(10):
shape = BulletBoxShape(size * 0.55)
pos = origin2 * i + size * i
pos.setY(0)
pos.setX(pos.getX()+6)
# pos.setZ(1)
stairNP = self.render.attachNewNode(BulletRigidBodyNode('Stair%i' % i))
stairNP.node().addShape(shape)
stairNP.setPos(pos)
stairNP.setCollideMask(BitMask32.allOn())
if i % 2 == 0:
#print "soiumik"
stairHprInterval1 = stairNP.hprInterval(4, Point3(pos),
startHpr=Point3(360, 0, 0))
stairHprInterval = stairNP.hprInterval(4, Point3(pos),
startHpr=Point3(360, 0, 0))
self.actorRobot = Sequence(stairHprInterval,stairHprInterval1)
self.actorRobot.loop()
modelNP = loader.loadModel('models/box.egg')
modelNP.reparentTo(stairNP)
modelNP.setPos(-size.x/2.0, -size.y/2.0, -size.z/2.0)
modelNP.setScale(size)
self.world.attachRigidBody(stairNP.node())
#origin1 = Point3(-70,3,8.50)
#finalBattlePlatSize = Vec3(14,28.75,2)
# finalBattlePlatShape = BulletBoxShape(finalBattlePlatSize * 0.5)
#shape = Vec3(6.5,9.75,1.0)
###################################################################### PLANK 1 ##########################################################################
plank1 = BulletBoxShape(Vec3(6.5, 9.75, 0.75))
plankNP1 = self.render.attachNewNode(BulletRigidBodyNode('PLANK1'))
plankNP1.setCollideMask(BitMask32.allOn())
plankNP1.node().addShape(plank1)
plankNP1.setPos(70, 0, 10)
plankPosInterval1 = plankNP1.posInterval(8, Point3(plankNP1.getX(),plankNP1.getY()+4,plankNP1.getZ()),
startPos=Point3(plankNP1.getX(),plankNP1.getY()-4,plankNP1.getZ()))
plankPosInterval = plankNP1.posInterval(8, Point3(plankNP1.getX(),plankNP1.getY()-4,plankNP1.getZ()),
startPos=Point3(plankNP1.getX(),plankNP1.getY()+4,plankNP1.getZ()))
self.plankStair = Sequence(plankPosInterval1,plankPosInterval)
self.plankStair.loop()
#print pos.getX(),'sadsa',pos.getY(),"Z",pos.getZ()
self.stoner1 = loader.loadModel("models/stone")
self.stoner1.reparentTo(plankNP1)
self.stoner1.setPos(0,0,0) #pos.getX()-6,pos.getY(),pos.getZ()-1
self.stoner1.setScale(13 ,20 , 0)
self.world.attachRigidBody(plankNP1.node())
################################################################### PLANK 2 #########################################################################
plank1 = BulletBoxShape(Vec3(6, 9.75, 0.75))
plankNP1 = self.render.attachNewNode(BulletRigidBodyNode('PLANK1'))
plankNP1.setCollideMask(BitMask32.allOn())
plankNP1.node().addShape(plank1)
plankNP1.setPos(80, 1, 14)
#print pos.getX(),'sadsa',pos.getY(),"Z",pos.getZ()
self.stoner1 = loader.loadModel("models/stone")
self.stoner1.reparentTo(plankNP1)
self.stoner1.setPos(0,0,0) #pos.getX()-6,pos.getY(),pos.getZ()-1
self.stoner1.setScale(13 ,20 , 0)
self.world.attachRigidBody(plankNP1.node())
############################################################### PLANK 3 #####################################################################
plank1 = BulletBoxShape(Vec3(6, 9.75, 0.75))
plankNP1 = self.render.attachNewNode(BulletRigidBodyNode('PLANK1'))
plankNP1.setCollideMask(BitMask32.allOn())
plankNP1.node().addShape(plank1)
plankNP1.setPos(90, 1, 17)
plankPosInterval1 = plankNP1.posInterval(8, Point3(plankNP1.getX(),plankNP1.getY()+4,plankNP1.getZ()),
startPos=Point3(plankNP1.getX(),plankNP1.getY()-4,plankNP1.getZ()))
plankPosInterval = plankNP1.posInterval(8, Point3(plankNP1.getX(),plankNP1.getY()-4,plankNP1.getZ()),
startPos=Point3(plankNP1.getX(),plankNP1.getY()+4,plankNP1.getZ()))
self.plankStair = Sequence(plankPosInterval1,plankPosInterval)
self.plankStair.loop()
#print pos.getX(),'sadsa',pos.getY(),"Z",pos.getZ()
self.stoner1 = loader.loadModel("models/stone")
self.stoner1.reparentTo(plankNP1)
self.stoner1.setPos(0,0,0) #pos.getX()-6,pos.getY(),pos.getZ()-1
self.stoner1.setScale(13 ,20 , 0)
self.world.attachRigidBody(plankNP1.node())
############################################################ PLANK 4 #########################################################################
plank1 = BulletBoxShape(Vec3(6, 9.75, 0.75))
plankNP1 = self.render.attachNewNode(BulletRigidBodyNode('PLANK1'))
plankNP1.setCollideMask(BitMask32.allOn())
plankNP1.node().addShape(plank1)
plankNP1.setPos(100, 1, 20)
#print pos.getX(),'sadsa',pos.getY(),"Z",pos.getZ()
self.stoner1 = loader.loadModel("models/stone")
self.stoner1.reparentTo(plankNP1)
self.stoner1.setPos(0,0,0) #pos.getX()-6,pos.getY(),pos.getZ()-1
self.stoner1.setScale(13 ,20 , 0)
self.world.attachRigidBody(plankNP1.node())
###################################################################### Stairs 2 ##########################################################################
origin = Point3(2, 0, 0)
size = Vec3(4, 4.75, 1.0)
#ballSize= Vec3(4.75,5.75,2.75)
height = 0
angle = -25
for i in range(10):
shape = BulletBoxShape(size * 0.55)
pos = origin * i + size * i
#ballPos = origin * i + 1 + size * i +2
pos.setY(0)
pos.setX(pos.getX()*-1)
#print actorNP.getZ()
if i % 2 == 0 and i > 0:
#print "soiumik"
stairHprInterval1 = stairNP.hprInterval(3, Point3(),
startHpr=Point3(360, 0, 0))
stairHprInterval = stairNP.hprInterval(3, Point3(pos),
startHpr=Point3(360, 0, 0))
self.actorRobot = Sequence(stairHprInterval,stairHprInterval1)
self.actorRobot.loop()
stairNP = self.render.attachNewNode(BulletRigidBodyNode('Stair%i' % i))
stairNP.node().addShape(shape)
stairNP.setPos(pos)
stairNP.setCollideMask(BitMask32.allOn())
if i % 2 == 0:
coinModel = loader.loadModel('models/coin')
coinModel.reparentTo(self.render)
coinModel.setPos(pos+1)
# coinModel.setZ(1.0)
coinModel.setScale(0.5)
coinModel.setHpr(0,0,90)
# coinHprInterval = coinModel.hprInterval(3, Point3(), startHpr = Point3(360,0,0))
# coinHprInterval1 = coinModel.hprInterval(3, Point3(), startHpr = Point3(360,0,0))
#
# self.coinRotate = Sequence(coinHprInterval,coinHprInterval1)
# self.coinRotate.loop()
coinModel.setTag("coin",str(i))
self.moon_tex = loader.loadTexture("models/gold.jpg")
coinModel.setTexture(self.moon_tex, 1)
modelNP = loader.loadModel('models/box.egg')