forked from i-k/SpaceGrabem
/
ShipTypes.py
173 lines (141 loc) · 4.92 KB
/
ShipTypes.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
import math
from pandac.PandaModules import (
AmbientLight,
DirectionalLight,
PointLight,
NodePath,
Vec3,
Vec4,
Point3,
Quat,
OdeUtil,
OdeWorld,
OdeHashSpace,
OdeJointGroup,
OdeMass,
OdeBody,
OdeSphereGeom,
OdeBoxGeom,
BitMask32,
TextNode
)
from Ship import Ship
class Ship_1(Ship):
POWER = 100
SHIP_TYPE = "UFO"
def __init__(self, game, color):
#self.POWER = 100
self.game = game
self.thrust = False
self.thrustLeft = False
self.thrustRight = False
self.thrustBack = False
self.rotation = 0
self.body = OdeBody(game.physicsWorld)
self.mass = OdeMass()
self.mass.setBox(10,1,1,1)
self.body.setMass(self.mass)
#odespheregeom(... , size of hitbox sphere)
self.collGeom = OdeSphereGeom( self.game.physicsSpace, 5)
self.collGeom.setBody(self.body)
self.collGeom.setCategoryBits( BitMask32(0xffffffff) )
self.collGeom.setCollideBits( BitMask32(0xffffffff) )
self.visualNode = NodePath('Visual node')
self.visualNode.reparentTo(render)
model = loader.loadModel('lautanen2.egg')
model.reparentTo(self.visualNode)
plight = PointLight('plight')
plight.setPoint( Point3(0.6, 0, 5) )
plight.setColor( color )
plight.setAttenuation( Vec3(0.5, 0.01, 0.01) )
plightNodePath = model.attachNewNode(plight)
model.setLight(plightNodePath)
# setMoreKeys in ship class = BAD IDEA
#def setMoreKeys(self):
# base.accept('arrow_down', self.thrustBackOn)
# base.accept('arrow_down-up', self.thrustBackOff)
def applyForces(self):
if self.thrust:
heading = self.getHeading()
self.body.addForce(
-math.sin( math.radians(heading) ) * self.POWER,
math.cos( math.radians(heading) ) * self.POWER,
0
)
if self.thrustLeft:
heading = self.getHeading()
self.body.addForce(
-math.sin( math.radians(heading) + math.pi/2 ) * self.POWER,
math.cos( math.radians(heading) + math.pi/2 ) * self.POWER,
0
)
if self.thrustRight:
heading = self.getHeading()
self.body.addForce(
-math.sin( math.radians(heading) - math.pi/2 ) * self.POWER,
math.cos( math.radians(heading) - math.pi/2 ) * self.POWER,
0
)
if self.thrustBack:
heading = self.getHeading()
self.body.addForce(
-math.sin( math.radians(heading) + math.pi ) * self.POWER,
math.cos( math.radians(heading) + math.pi ) * self.POWER,
0
)
class Ship_2(Ship):
ROTATING_SPEED = 1
MAX_ROTATE_SPEED = 3.0
SHIP_TYPE = "RAKETTI"
def __init__(self, game, color):
self.POWER = 100
self.game = game
self.thrust = False
self.thrustLeft = False
self.thrustRight = False
self.thrustBack = False
self.rotation = 0
self.body = OdeBody(game.physicsWorld)
self.mass = OdeMass()
self.mass.setBox(10,1,1,1)
self.body.setMass(self.mass)
#odespheregeom(... , size of hitbox sphere)
self.collGeom = OdeSphereGeom( self.game.physicsSpace, 2)
self.collGeom.setBody(self.body)
self.collGeom.setCategoryBits( BitMask32(0xffffffff) )
self.collGeom.setCollideBits( BitMask32(0xffffffff) )
self.visualNode = NodePath('Visual node')
self.visualNode.reparentTo(render)
model = loader.loadModel('testipalikka.egg')
model.reparentTo(self.visualNode)
plight = PointLight('plight')
plight.setPoint( Point3(0.6, 0, 5) )
plight.setColor( color )
plight.setAttenuation( Vec3(0.5, 0.01, 0.01) )
plightNodePath = model.attachNewNode(plight)
model.setLight(plightNodePath)
def rotating(self):
if self.thrustLeft:
self.setRotation(self.ROTATING_SPEED)
if self.thrustRight:
self.setRotation(-(self.ROTATING_SPEED))
if not self.thrustRight and not self.thrustLeft:
self.setRotation(0)
def applyForces(self):
if self.thrust:
heading = self.getHeading()
#addForce (x, y, z)
self.body.addForce(
-math.sin( math.radians(heading) ) * self.POWER,
math.cos( math.radians(heading) ) * self.POWER,
0
)
# uncomment for backwards thrust (eli siis pakki)
# if self.thrustBack:
# heading = self.getHeading()
# self.body.addForce(
# math.sin( math.radians(heading) ) * self.POWER,
# -math.cos( math.radians(heading) ) * self.POWER,
# 0
# )
self.rotating()