/
shooter.py
97 lines (74 loc) · 2.71 KB
/
shooter.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
from bge import logic,types,events,render
from mathutils import Vector
from key import StrategyKey
import bge
from fireCommand import FireCommand
from aimCommand import AimCommand
def shooter():
strategyKey = StrategyKey()
cont = bge.logic.getCurrentController()
own = cont.owner
scene = logic.getCurrentScene()
gun = None
gunPlayer = None
#gun = scene.objects["AK.004"]
for gobj in scene.objects:
if gobj.name == "ClientGun":
gun = gobj
elif gobj.name == "Lowpoly..002":
gunPlayer = gobj
elif gobj.name == "player1":
orientationPlayer = gobj
elif gobj.name == "character":
orientation = gobj
elif gobj.name == "player_mesh_basic_Client":
healthMonitor = gobj
if gun:
keyPressed = strategyKey.keyDown
fireCommand = FireCommand(gun)
aimCommand = AimCommand(gun)
target = getThreat(scene,gun)
hud(healthMonitor["healt"],gun)
endGame(healthMonitor["healt"])
#print(orientation.health)
if keyPressed(events.SPACEKEY):
fireCommand.execute()
if target:
aimCommand.execute(target.worldPosition)
else:
gun.worldOrientation = orientation.worldOrientation
#pass
#fix aim
if gunPlayer:
#keyPressed = strategyKey.keyDown
fireCommand = FireCommand(gunPlayer)
aimCommand = AimCommand(gunPlayer)
target = getThreat(scene,gunPlayer)
if target:
fireCommand.execute()
aimCommand.execute(target.worldPosition)
else:
gunPlayer.worldOrientation = orientationPlayer.worldOrientation
#pass
#fix orientation
#if target:
def hud(health,weapon):
sceneList = logic.getSceneList()
try:
if(sceneList):
displayAmmo = sceneList[1].objects["Ammo.001"]
displayHealth = sceneList[1].objects["Health.001"]
displayAmmo.text = str(weapon.ammo)
displayHealth.text = str(health)
except:
pass
def getThreat(scene,gun):
for gobj in scene.objects:
if "enemy_mesh" in gobj.name:
delta = gobj.worldPosition - gun.worldPosition
if delta.magnitude < 25:
return gobj
def endGame(health):
if health<0:
logic.restartGame()
shooter()