class Base(StaticObject): #17.12.2009: collGeomInner -> collGeom, dropBall(x, y ,z, linX, linY), collectible.setPos() ja setVelocity() def __init__(self, game): self.game = game #poista se fysiikka-avaruus ja vaan tee se alue... justiinsa self.collGeom = OdeBoxGeom( 24,8,2 ) #self.collGeom.setBody(self.body) self.collGeom.setCategoryBits( BitMask32(1) ) self.collGeom.setCollideBits( BitMask32(1) ) # self.collGeomOuter = OdeBoxGeom( self.game.physicsSpace, 28,6,2) # #self.collGeom.setBody(self.body) # self.collGeomOuter.setCategoryBits( BitMask32(1) ) # self.collGeomOuter.setCollideBits( BitMask32(1) ) self.visualNode = NodePath('Visual node') self.visualNode.reparentTo(render) model = loader.loadModel('Base.egg') model.reparentTo(self.visualNode) plight = PointLight('baselight') plight.setPoint( Point3(0, 0, 12) ) plight.setColor( Vec4(1,1,1,1) ) plight.setAttenuation( Vec3(0.1, 0.1, 0.005) ) self.visualNode.setLight(model.attachNewNode(plight)) def checkCollision( self, ship, collectiblelist ): if OdeUtil.collide(ship.collGeom, self.collGeom) and ship.hasBall(): #if ship.hasBall(): ship.addPoints( (ship.Ball.getValue()*2) ) pos = self.getPos() ship.dropBall( x = pos[0], y = pos[1], z = 50, linX = random.randrange(-10,10), linY = (0-pos[1]) / 4 ) print ship.SHIP_TYPE + " " + str(ship.getPoints()) + " Points! " if (self.game.goalSfx.status() == 1): self.game.goalSfx.play() self.game.updateHUD() #print " Base One! " for collectible in collectiblelist: if OdeUtil.collide(collectible.collGeom, self.collGeom): pos = self.getPos() ship.addPoints(collectible.getValue()) collectible.setPos( Vec3(pos[0], pos[1], 50)) collectible.setVelocity(x = random.randrange(-10,10), y = (0-pos[1]) / 4) self.game.goalSfx.play() self.game.updateHUD() print ship.SHIP_TYPE + " " + str(ship.getPoints()) + " Points! by throwing the ball" def addToBaseList(self, baseList): baseList.append(self) def setPos(self, pos, pos2): self.visualNode.setPos( pos ) self.collGeom.setPosition( pos2 )
def createCubicObstacle(self, pos, obstacleIndex): self.notify.debug('create obstacleindex %s' % obstacleIndex) sideLength = IceGameGlobals.TireRadius * 2 geom = OdeBoxGeom(self.space, sideLength, sideLength, sideLength) geom.setCollideBits(self.allTiresMask) geom.setCategoryBits(self.obstacleMask) self.space.setCollideId(geom, self.obstacleCollideId) tireModel = loader.loadModel('phase_4/models/minigames/ice_game_crate') tireModel.setPos(pos) tireModel.reparentTo(render) geom.setPosition(tireModel.getPos()) tireModel.setZ(0) return tireModel
def createCubicObstacle(self, pos, obstacleIndex): """Create one physics obstacle. Returns a nodePath""" self.notify.debug("create obstacleindex %s" % (obstacleIndex)) sideLength = IceGameGlobals.TireRadius * 2 geom = OdeBoxGeom(self.space, sideLength, sideLength, sideLength) geom.setCollideBits(self.allTiresMask) # we only collide against tires geom.setCategoryBits(self.obstacleMask) self.space.setCollideId(geom, self.obstacleCollideId) #tireModel = render.attachNewNode('cubicObstacle-%d'% obstacleIndex) #BuildGeometry.addBoxGeom(tireModel, sideLength, sideLength, sideLength) #tireModel.setPos(pos) #tireModel.setColor(0.5,0.5,0.5) tireModel = loader.loadModel("phase_4/models/minigames/ice_game_crate") tireModel.setPos(pos) tireModel.reparentTo(render) geom.setPosition(tireModel.getPos()) # the real assets are set at Z zero tireModel.setZ(0) return tireModel
class Plate: def __init__(self, x, y, z, width, height): self.model = loader.loadModel("models/cube") self.model.reparentTo(render) self.model.setScale(width, height, 0.2) self.model.setPos(x, y, z) self.model.setHpr(0, 0, 0) self.model.setColor(0.7, 0.3, 0.1, 1) self.model.setTexture(loader.loadTexture('textures/texture.png')) self.width = width self.height = height def enable_physics(self, physics): self.geom = OdeBoxGeom(physics.space, self.width, self.height, 0.2) self.geom.setPosition(self.model.getPos()) self.geom.setQuaternion(self.model.getQuat()) def reset(self): pass
class Base(StaticObject): def __init__(self, game): self.game = game self.collGeomInner = OdeBoxGeom( self.game.physicsSpace, 24,8,2) #self.collGeom.setBody(self.body) self.collGeomInner.setCategoryBits( BitMask32(1) ) self.collGeomInner.setCollideBits( BitMask32(1) ) self.collGeomOuter = OdeBoxGeom( self.game.physicsSpace, 28,6,2) #self.collGeom.setBody(self.body) self.collGeomOuter.setCategoryBits( BitMask32(1) ) self.collGeomOuter.setCollideBits( BitMask32(1) ) self.visualNode = NodePath('Visual node') self.visualNode.reparentTo(render) model = loader.loadModel('Base.egg') model.reparentTo(self.visualNode) def checkCollision(self, ship): if OdeUtil.collide(ship.collGeom, self.collGeomInner) and ship.hasBall(): #if ship.hasBall(): ship.addPoints(ship.Ball.getValue()) ship.dropBall( z = 300 ) print ship.SHIP_TYPE + " " + str(ship.getPoints()) + " Points! " #print " Base One! " def addToBaseList(self, baseList): baseList.append(self) def setPos(self, pos): self.visualNode.setPos( pos ) self.collGeomInner.setPosition( pos ) self.collGeomOuter.setPosition( pos )
class MovingPlane: ''' moving plane ''' id = 0 MODEL = "../egg/box.egg" def __init__(self, space, pos, dim, surface=SurfaceType.FLOOR): ''' kirjoita numerot float muodossa 1.0 @param space: fysiikka-avaruus? ''' MovingPlane.id += 1 self.id = id self.dim = dim # dimension self.pos = pos # position self.h = (dim[0] / 2, dim[1] / 2, dim[2] / 2) # center self.t = 0 self.geom = OdeBoxGeom(space, dim[0], dim[1], dim[2]) space.setSurfaceType(self.geom, surface) self.model = loader.loadModel(self.MODEL) self.model.setScale(dim[0], dim[1], dim[2]) # http://www.panda3d.org/wiki/index.php/Creating_a_New_Node_Class self.model.flattenLight() self.model.reparentTo(render) self.rotate = False if surface == SurfaceType.SAND: self.model.setColor(1, 0, 0) self.updateModelNode() def updateModelNode(self): pos = self.pos h = self.h if (self.rotate): self.t = self.t + 0.03 rot = pos[2] + 2 * sin(self.t) self.geom.setPosition(pos[0], pos[1], rot) self.model.setPos(pos[0] - h[0], pos[1] - h[1], rot - h[2]) else: self.geom.setPosition(pos[0], pos[1], pos[2]) self.model.setPos(pos[0] - h[0], pos[1] - h[1], pos[2] - h[2]) def getId(self): return id def getGeom(self): return self.geom def removeNode(self): self.model.removeNode() self.geom = None def setPosition(self, pos): self.pos = pos def setInterval(pos1, pos2): pass def setSpeed(self, speed): pass