def hitShips(self, ship1, ship2): if OdeUtil.areConnected(ship1.body, self.body): self.setPos( Vec3(random.randrange(30), random.randrange(40), 0)) self.PowerUpEffect(ship1) #self.body.disable() #self.visualNode.hide() elif OdeUtil.areConnected(ship2.body, self.body): self.setPos( Vec3(random.randrange(30), random.randrange(40), 0)) self.PowerUpEffect(ship2)
def __simulationTask(self, task): self.DTA += globalClock.getDt() numSteps = int(self.DTA / self.DTAStep) if numSteps > 10: self.notify.warning('phyics steps = %d' % numSteps) startTime = globalClock.getRealTime() while self.DTA >= self.DTAStep: if self.deterministic: OdeUtil.randSetSeed(0) self.DTA -= self.DTAStep self.preStep() self.simulate() self.postStep() if self.canRender: self.placeBodies() return task.cont
def hitShips(self, shipList): for ship in shipList: #get boundaries from somewhere and put the randrange to those if OdeUtil.areConnected(ship.body, self.body): self.setPos( Vec3(random.randrange(30), random.randrange(40), 0)) self.PowerUpEffect(ship)
def hitShips(self, shipList): for ship in shipList: #get boundaries from somewhere and put the randrange to those if OdeUtil.areConnected(ship.body, self.body) and not ship.hasBall(): self.PowerUpEffect(ship)
def checkCollisionList(self, shipList): for ship in shipList: self.insideTrigger( ship ) #self.usingTheForce( ship ) if OdeUtil.collide(ship.collGeom, self.collGeom) and ship.hasBall(): #ship.Ball.Restore(ship) self.game.collision2Sfx.play() pos = ship.getPos() ship.dropBall(x = pos[0], y = pos[1], z = 30, linX = ( (0-pos[0])/7 ), linY = ( (0-pos[1])/7 ), linZ = 2) print str(ship.getShipType()) + " lost its balls! NOOOO!"
def shipsCollide(self, enemy): if OdeUtil.areConnected(self.body, enemy.body): highest = max(self.getVelocity()) eneHighest = max(enemy.getVelocity()) if highest > eneHighest: enemy.releaseBall() else: self.releaseBall() self.game.shakeCam() self.game.collisionSfx.play()
def insideTrigger(self, ship): if OdeUtil.collide(self.triggerGeom, ship.collGeom): # self.setActiveOn() #print str(ship.getShipType()) self.setActive(True, ship) self.usingTheForce( ship ) # print "moo" else: #self.setActiveOff() #print "muu" self.setActive(False, ship)
def setupSimulation(self): DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld.setupSimulation( self) self.world.setGravity(0, 0, -32.173999999999999) self.world.setAutoDisableFlag(1) self.world.setAutoDisableLinearThreshold(0.5 * MetersToFeet) self.world.setAutoDisableAngularThreshold(OdeUtil.getInfinity()) self.world.setAutoDisableSteps(10) self.world.setCfm(1.0000000000000001e-005 * MetersToFeet) self.world.initSurfaceTable(3) self.world.setSurfaceEntry(0, 1, 0.20000000000000001, 0, 0, 0, 0, 0, 0.10000000000000001) self.world.setSurfaceEntry(0, 0, 0.10000000000000001, 0.90000000000000002, 0.10000000000000001, 0, 0, 0, 0) self.world.setSurfaceEntry(0, 2, 0.90000000000000002, 0.90000000000000002, 0.10000000000000001, 0, 0, 0, 0) self.floor = OdePlaneGeom(self.space, Vec4(0.0, 0.0, 1.0, -20.0)) self.floor.setCollideBits(self.allTiresMask) self.floor.setCategoryBits(self.floorMask) self.westWall = OdePlaneGeom( self.space, Vec4(1.0, 0.0, 0.0, IceGameGlobals.MinWall[0])) self.westWall.setCollideBits(self.allTiresMask) self.westWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.westWall, self.fenceSurfaceType) self.space.setCollideId(self.westWall, self.wallCollideId) self.eastWall = OdePlaneGeom( self.space, Vec4(-1.0, 0.0, 0.0, -IceGameGlobals.MaxWall[0])) self.eastWall.setCollideBits(self.allTiresMask) self.eastWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.eastWall, self.fenceSurfaceType) self.space.setCollideId(self.eastWall, self.wallCollideId) self.southWall = OdePlaneGeom( self.space, Vec4(0.0, 1.0, 0.0, IceGameGlobals.MinWall[1])) self.southWall.setCollideBits(self.allTiresMask) self.southWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.southWall, self.fenceSurfaceType) self.space.setCollideId(self.southWall, self.wallCollideId) self.northWall = OdePlaneGeom( self.space, Vec4(0.0, -1.0, 0.0, -IceGameGlobals.MaxWall[1])) self.northWall.setCollideBits(self.allTiresMask) self.northWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.northWall, self.fenceSurfaceType) self.space.setCollideId(self.northWall, self.wallCollideId) self.floorTemp = OdePlaneGeom(self.space, Vec4(0.0, 0.0, 1.0, 0.0)) self.floorTemp.setCollideBits(self.allTiresMask) self.floorTemp.setCategoryBits(self.floorMask) self.space.setSurfaceType(self.floorTemp, self.iceSurfaceType) self.space.setCollideId(self.floorTemp, self.floorCollideId) self.space.setAutoCollideWorld(self.world) self.space.setAutoCollideJointGroup(self.contactgroup) self.totalPhysicsSteps = 0
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 _player_controls(self): avel = self.body.getAngularVel() on_plate = False accelerate = False for level_object in self.level.objects: collide = OdeUtil.collide(level_object.geom, self.geom) if collide: on_plate = True if avel.z < self.initial_spin_velocity and \ isinstance(level_object, Accelerator): accelerate = level_object.player_interact(self) break if accelerate: avel.z += self.exponent / 200.0 self.factor = 0 self.calculate_factor(avel.z) if self.factor > 0.99: return f = self.factor**self.exponent if on_plate: if self.controls.jump: vel = self.body.getLinearVel() self.body.setLinearVel(vel.x, vel.y, vel.z + 5) force = 350 else: force = 25 self.controls.jump = False self.body.addForce(Mat3.rotateMat(self.controls.view_rotation).xform( (self.controls.y*force, -0.8*self.controls.x*force, 0))) hpr = self.model.getHpr() self.model.setHpr(hpr.x, f*hpr.y, f*hpr.z) self.body.setQuaternion(self.model.getQuat(render)) self.body.setAngularVel(f*avel.x, f*avel.y, avel.z)
def setupSimulation(self): DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld.setupSimulation(self) self.world.setGravity(0, 0, -32.174) self.world.setAutoDisableFlag(1) self.world.setAutoDisableLinearThreshold(0.5 * MetersToFeet) self.world.setAutoDisableAngularThreshold(OdeUtil.getInfinity()) self.world.setAutoDisableSteps(10) self.world.setCfm(1e-05 * MetersToFeet) self.world.initSurfaceTable(3) self.world.setSurfaceEntry(0, 1, 0.2, 0, 0, 0, 0, 0, 0.1) self.world.setSurfaceEntry(0, 0, 0.1, 0.9, 0.1, 0, 0, 0, 0) self.world.setSurfaceEntry(0, 2, 0.9, 0.9, 0.1, 0, 0, 0, 0) self.floor = OdePlaneGeom(self.space, Vec4(0.0, 0.0, 1.0, -20.0)) self.floor.setCollideBits(self.allTiresMask) self.floor.setCategoryBits(self.floorMask) self.westWall = OdePlaneGeom(self.space, Vec4(1.0, 0.0, 0.0, IceGameGlobals.MinWall[0])) self.westWall.setCollideBits(self.allTiresMask) self.westWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.westWall, self.fenceSurfaceType) self.space.setCollideId(self.westWall, self.wallCollideId) self.eastWall = OdePlaneGeom(self.space, Vec4(-1.0, 0.0, 0.0, -IceGameGlobals.MaxWall[0])) self.eastWall.setCollideBits(self.allTiresMask) self.eastWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.eastWall, self.fenceSurfaceType) self.space.setCollideId(self.eastWall, self.wallCollideId) self.southWall = OdePlaneGeom(self.space, Vec4(0.0, 1.0, 0.0, IceGameGlobals.MinWall[1])) self.southWall.setCollideBits(self.allTiresMask) self.southWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.southWall, self.fenceSurfaceType) self.space.setCollideId(self.southWall, self.wallCollideId) self.northWall = OdePlaneGeom(self.space, Vec4(0.0, -1.0, 0.0, -IceGameGlobals.MaxWall[1])) self.northWall.setCollideBits(self.allTiresMask) self.northWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.northWall, self.fenceSurfaceType) self.space.setCollideId(self.northWall, self.wallCollideId) self.floorTemp = OdePlaneGeom(self.space, Vec4(0.0, 0.0, 1.0, 0.0)) self.floorTemp.setCollideBits(self.allTiresMask) self.floorTemp.setCategoryBits(self.floorMask) self.space.setSurfaceType(self.floorTemp, self.iceSurfaceType) self.space.setCollideId(self.floorTemp, self.floorCollideId) self.space.setAutoCollideWorld(self.world) self.space.setAutoCollideJointGroup(self.contactgroup) self.totalPhysicsSteps = 0
def osuminen(self, ship1): if OdeUtil.collide(ship1.collGeom, self.collGeom): print "sdfgfdhgdfhxfhdhghcfh" print "ship1 xdfhgxdgxdgfbcdll!!"
def setupSimulation(self): """Setup the ice game specific parameters.""" DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld.setupSimulation( self) # toontown uses feet, 1 meter = 3.2808399 feet # for this game lets express mass in kilograms # so gravity at 9.8 meters per seconds squared becomes self.world.setGravity(0, 0, -32.174) # ODE's default is meter, kilograms, seconds, let's change the defaults # do we need to change global ERP value, # that controls how much error correction is performed in each time step # default is 0.2 self.world.setAutoDisableFlag(1) # lets try auto disable self.world.setAutoDisableLinearThreshold(0.5 * MetersToFeet) # skipping AutoDisableAngularThreshold as that is radians per second # self.world.setAutoDisableAngularThreshold(0.01) # don't consider rotation for auto disable self.world.setAutoDisableAngularThreshold(OdeUtil.getInfinity()) self.world.setAutoDisableSteps(10) # Set and the global CFM (constraint force mixing) value. # Typical values are in the range 10-9 -- 1. # The default is 10-5 if single precision is being used self.world.setCfm(1E-5 * MetersToFeet) # Our surfaces # 0 = tire # 1 = ice # 2 = fence self.world.initSurfaceTable(3) # 3 types of surfaces # PN_uint8 pos1, PN_uint8 pos2, - surface0, surface1 # dReal mu, - 0 frictionless, 1 infinite friction # dReal bounce, # Restitution parameter 0 not bouncy, 1 max bouncy # dReal bounce_vel, #The minimum incoming velocity necessary for bounce. # Incoming velocities below this will # effectively have a bounce parameter of 0. # dReal soft_erp, # Contact normal "softness" parameter. # dReal soft_cfm, # Contact normal "softness" paramete # dReal slip, # The coefficients of force-dependent-slip (FDS) # dReal dampen) # dampening constant # the most usual collision, tire against ice self.world.setSurfaceEntry( 0, 1, 0.2, # near frictionless 0, # not bouncy 0, # bounce_vel 0, # soft_erp 0, # soft_cfm 0, # slip 0.1, # dampen ) # tire against tire self.world.setSurfaceEntry( 0, 0, 0.1, # friction 0.9, # bounciness 0.1, # bounce_vel 0, # soft_erp 0, # soft_cfm 0, # slip 0, # dampen ) # tire against fence self.world.setSurfaceEntry( 0, 2, 0.9, # friction 0.9, # bounciness 0.1, # bounce_vel 0, # soft_erp 0, # soft_cfm 0, # slip 0, # dampen ) # Create a plane geom which prevent the objects from falling forever self.floor = OdePlaneGeom(self.space, Vec4(0.0, 0.0, 1.0, -20.0)) self.floor.setCollideBits( self.allTiresMask) # we only collide against tires self.floor.setCategoryBits(self.floorMask) # normal pointing towards +x axis self.westWall = OdePlaneGeom( self.space, Vec4(1.0, 0.0, 0.0, IceGameGlobals.MinWall[0])) self.westWall.setCollideBits( self.allTiresMask) # we only collide against tires self.westWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.westWall, self.fenceSurfaceType) self.space.setCollideId(self.westWall, self.wallCollideId) # normal pointing towards -x axis self.eastWall = OdePlaneGeom( self.space, Vec4(-1.0, 0.0, 0.0, -IceGameGlobals.MaxWall[0])) self.eastWall.setCollideBits( self.allTiresMask) # we only collide against tires self.eastWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.eastWall, self.fenceSurfaceType) self.space.setCollideId(self.eastWall, self.wallCollideId) # normal pointing toward the +y axis self.southWall = OdePlaneGeom( self.space, Vec4(0.0, 1.0, 0.0, IceGameGlobals.MinWall[1])) self.southWall.setCollideBits( self.allTiresMask) # we only collide against tires self.southWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.southWall, self.fenceSurfaceType) self.space.setCollideId(self.southWall, self.wallCollideId) # normal pointing toward the -y axis self.northWall = OdePlaneGeom( self.space, Vec4(0.0, -1.0, 0.0, -IceGameGlobals.MaxWall[1])) self.northWall.setCollideBits( self.allTiresMask) # we only collide against tires self.northWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.northWall, self.fenceSurfaceType) self.space.setCollideId(self.northWall, self.wallCollideId) # a temporary floor at z=0, until we implement ice with holes self.floorTemp = OdePlaneGeom(self.space, Vec4(0.0, 0.0, 1.0, 0.0)) self.floorTemp.setCollideBits( self.allTiresMask) # we only collide against tires self.floorTemp.setCategoryBits(self.floorMask) self.space.setSurfaceType(self.floorTemp, self.iceSurfaceType) self.space.setCollideId(self.floorTemp, self.floorCollideId) self.space.setAutoCollideWorld(self.world) self.space.setAutoCollideJointGroup(self.contactgroup) self.totalPhysicsSteps = 0
def tick(self, task): if not self.pause: ships = self.getShips() # Check if the ships' positions need to be warped xDistance = abs(ships[0].getPos()[0] - ships[1].getPos()[0]) if xDistance >= Game.SHIPS_MAX_X_DISTANCE: #and self.gameFrames - self.lastWarp > 10: self.warpShips('x') #self.lastWarp = self.gameFrames yDistance = abs(ships[0].getPos()[1] - ships[1].getPos()[1]) if yDistance >= Game.SHIPS_MAX_Y_DISTANCE: self.warpShips('y') # Check if the planet's position needs to be warped planetXDistance = abs(self.getCameraPos()[0] - self.planet.getPos()[0]) if planetXDistance >= Game.PLANET_CAMERA_DISTANCE_MAX: self.warpPlanet('x') planetYDistance = abs(self.getCameraPos()[1] - self.planet.getPos()[1]) if planetYDistance >= Game.PLANET_CAMERA_DISTANCE_MAX: self.warpPlanet('y') # Check collisions col = OdeUtil.collide(ships[0].collisionSphere, ships[1].collisionSphere, 1) if not col.isEmpty(): ships[0].addCollision(point3ToTuple(col.getContactPoint(0))) ships[1].addCollision(point3ToTuple(col.getContactPoint(0))) colPlanet1 = OdeUtil.collide(ships[0].collisionSphere, self.planetCollGeom, 1) colPlanet2 = OdeUtil.collide(ships[1].collisionSphere, self.planetCollGeom, 1) if not colPlanet1.isEmpty(): ships[0].addCollision( point3ToTuple(colPlanet1.getContactPoint(0))) ships[0].planetHit() if not colPlanet2.isEmpty(): ships[1].addCollision( point3ToTuple(colPlanet2.getContactPoint(0))) ships[1].planetHit() # Bullet collisions ship one for bullet in ships[0].bullets: colBulletShip1 = OdeUtil.collide(bullet['physical'], ships[1].collisionSphere, 1) if not colBulletShip1.isEmpty(): ships[0].destroyBullet(bullet) ships[1].bulletHit() colBulletPlanet = OdeUtil.collide(bullet['physical'], self.planetCollGeom, 1) if not colBulletPlanet.isEmpty(): ships[0].destroyBullet(bullet) # Bullet collisions ship two for bullet in ships[1].bullets: colBulletShip2 = OdeUtil.collide(bullet['physical'], ships[0].collisionSphere, 1) if not colBulletShip2.isEmpty(): ships[1].destroyBullet(bullet) ships[0].bulletHit() colBulletPlanet = OdeUtil.collide(bullet['physical'], self.planetCollGeom, 1) if not colBulletPlanet.isEmpty(): ships[1].destroyBullet(bullet) for ship in ships: self.applyGravity(ship, self.getDeltaTime()) ship.update(self.getDeltaTime()) if not ships[0].isAlive: self.showWinnerText(self.players[1]) self.players[1].score += 1 self.restartGame() if not ships[1].isAlive: self.showWinnerText(self.players[0]) self.players[0].score += 1 self.restartGame() if self.cameraMode == Game.CAMERA_MODE_GAME: self.updateCamera() if self.gameFrames >= 125: self.winnerText.hide() self.gameFrames += 1 # Update health points in the HUD # TODO: These should be optimized so that they get updated only when they # change. self.healthPlayerOne.setText("Health: " + str(self.ships[0].health)) self.healthPlayerTwo.setText("Health: " + str(self.ships[1].health)) return task.cont
def hitShips(self, shipList): for ship in shipList: if OdeUtil.areConnected(ship.body, self.body) and not ship.hasBall(): self.PowerUpEffect(ship)
def checkCollision(self, ship): if OdeUtil.collide(ship.collGeom, self.collGeom) and ship.hasBall(): #ship.Ball.Restore(ship) ship.dropBall( z = 300 ) print str(ship.getShipType()) + " lost its balls! ONOES!!"
def checkCollisionList(self, shipList): for ship in shipList: if OdeUtil.collide(ship.collGeom, self.collGeom) and ship.hasBall(): #ship.Ball.Restore(ship) ship.dropBall() print str(ship.getShipType()) + " lost its balls! NOOOO!"
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! "
def tick(self, task): if not self.pause: ships = self.getShips() # Check if the ships' positions need to be warped xDistance = abs(ships[0].getPos()[0] - ships[1].getPos()[0] ) if xDistance >= Game.SHIPS_MAX_X_DISTANCE: #and self.gameFrames - self.lastWarp > 10: self.warpShips('x') #self.lastWarp = self.gameFrames yDistance = abs(ships[0].getPos()[1] - ships[1].getPos()[1] ) if yDistance >= Game.SHIPS_MAX_Y_DISTANCE: self.warpShips('y') # Check if the planet's position needs to be warped planetXDistance = abs( self.getCameraPos()[0] - self.planet.getPos()[0] ) if planetXDistance >= Game.PLANET_CAMERA_DISTANCE_MAX: self.warpPlanet('x') planetYDistance = abs( self.getCameraPos()[1] - self.planet.getPos()[1] ) if planetYDistance >= Game.PLANET_CAMERA_DISTANCE_MAX: self.warpPlanet('y') # Check collisions col = OdeUtil.collide(ships[0].collisionSphere, ships[1].collisionSphere, 1) if not col.isEmpty(): ships[0].addCollision( point3ToTuple( col.getContactPoint(0) ) ) ships[1].addCollision( point3ToTuple( col.getContactPoint(0) ) ) colPlanet1 = OdeUtil.collide(ships[0].collisionSphere, self.planetCollGeom, 1) colPlanet2 = OdeUtil.collide(ships[1].collisionSphere, self.planetCollGeom, 1) if not colPlanet1.isEmpty(): ships[0].addCollision( point3ToTuple( colPlanet1.getContactPoint(0) ) ) ships[0].planetHit() if not colPlanet2.isEmpty(): ships[1].addCollision( point3ToTuple( colPlanet2.getContactPoint(0) ) ) ships[1].planetHit() # Bullet collisions ship one for bullet in ships[0].bullets: colBulletShip1 = OdeUtil.collide( bullet['physical'], ships[1].collisionSphere, 1 ) if not colBulletShip1.isEmpty(): ships[0].destroyBullet(bullet) ships[1].bulletHit() colBulletPlanet = OdeUtil.collide( bullet['physical'], self.planetCollGeom, 1 ) if not colBulletPlanet.isEmpty(): ships[0].destroyBullet(bullet) # Bullet collisions ship two for bullet in ships[1].bullets: colBulletShip2 = OdeUtil.collide( bullet['physical'], ships[0].collisionSphere, 1 ) if not colBulletShip2.isEmpty(): ships[1].destroyBullet(bullet) ships[0].bulletHit() colBulletPlanet = OdeUtil.collide( bullet['physical'], self.planetCollGeom, 1 ) if not colBulletPlanet.isEmpty(): ships[1].destroyBullet(bullet) for ship in ships: self.applyGravity( ship, self.getDeltaTime() ) ship.update( self.getDeltaTime() ) if not ships[0].isAlive: self.showWinnerText(self.players[1]) self.players[1].score += 1 self.restartGame() if not ships[1].isAlive: self.showWinnerText(self.players[0]) self.players[0].score += 1 self.restartGame() if self.cameraMode == Game.CAMERA_MODE_GAME: self.updateCamera() if self.gameFrames >= 125: self.winnerText.hide() self.gameFrames += 1 # Update health points in the HUD # TODO: These should be optimized so that they get updated only when they # change. self.healthPlayerOne.setText( "Health: " + str(self.ships[0].health) ) self.healthPlayerTwo.setText( "Health: " + str(self.ships[1].health) ) return task.cont