class Saucer(DirectObject): def __init__(self): self.ship = loader.loadModel("Art\ufo.egg") self.beam = loader.loadModel("Art\eam.egg") self.health = 100 #Dummy is used to position the tractor beam collisionsphere self.dummy = NodePath('dummy') self.dummy.reparentTo(render) #Dummy2 used to position abductees self.dummy2 = NodePath('dummy2') self.dummy2.reparentTo(render) self.beam.reparentTo(self.dummy2) self.glownode = self.ship.find("**/l_glownode") self.glownode.setColor(0,0,.5,1) self.glownode2 = self.ship.find("**/r_glownode") self.glownode2.setColor(0,0,.5,1) self.ship.reparentTo(render) self.ship.setScale(1) #self.ship.setH(180) self.ship.setPos(0,0,25) self.dummy.setPos(0,0,25) self.dummy2.setPos(0,0,25) #list of things currently abducting self.abductlist = [] self.animals = [] self.inanimates = [] taskMgr.add(self.abductTask, "abductTask") taskMgr.add(self.lightTask, "lightTask") self.stuntime = 30 self.stunbase = 30 self.updown = False self.beamspeed = 1 self.basebeamspeed = 2 self.collected = 0 self.beamon = True taskMgr.add(self.particleTask, "shipparticleTask") self.mydir = os.path.abspath(sys.path[0]) self.mydir = Filename.fromOsSpecific(self.mydir).getFullpath() self.mydir = Filename(self.mydir) #self.mydir = self.mydir.toOsSpecific() self.abductp = ParticleEffect() self.abductp.loadConfig(self.mydir + '/abduct.ptf') self.pcount = 0 self.particletime = 60 #Must be integer def pickUp(self,object): #Pick up another pickupable if object.stuncount < self.stuntime: object.stunned = True else: if (len(self.abductlist) < 15): if object.type1 == 'inanimate': self.inanimates.append(object) elif object.type1 == 'hostile': self.inanimates.append(object) elif object.type1 == 'animal': self.animals.append(object) self.findSpeed() object.resetStun() object.abduct = True self.abductlist.append(object) object.playPickupSound() object.pickup.reparentTo(self.dummy2) object.pickup.setHpr(0,0,0) object.pickup.setPos(0,0,-37) else: print ("Pickup list full.") def drop(self,env): #Drop all for object in self.abductlist: object.abduct = False object.pickup.wrtReparentTo(env) #object.pickup.setPos(self.dummy2.getX(),self.dummy2.getY(),self.dummy2.getZ()) self.abductlist[:] = [] def lightTask(self,task): if not self.beamon: self.glownode.setColor(.1,.06,.92,1) self.glownode2.setColor(.1,.06,.92,1) if self.beamon: s = self.beamspeed/25 self.glownode.setColor(.12 - s/10,1 - s,.08 - s/10,1) self.glownode2.setColor(.12 - s/10,1 - s,.08- s/10,1) return task.cont def abductTask(self,task): if self.updown: self.dummy.setZ(self.ship.getZ()) self.updown = False else: self.dummy.setZ(36) self.updown = True for obj in self.abductlist: obj.rise(self) return Task.cont def cowbig(self,me): if me > self.panda and me > self.pigs and me > self.sheep: return True def pigbig(self,me): if me > self.cows and me > self.sheep and me > self.panda: return True def sheepbig(self,me): if me > self.cows and me > self.pigs and me > self.panda: return True def pandabig(self,me): if me > self.cows and me > self.pigs and me > self.sheep: return True def biggest(self): if self.cowbig(self.cows): return self.cows - ((self.pigs + self.sheep + self.panda) / 3) if self.pigbig(self.pigs): return self.pigs - ((self.cows + self.sheep + self.panda) / 3) if self.sheepbig(self.sheep): return self.sheep - ((self.pigs + self.cows + self.panda) / 3) if self.pandabig(self.panda): return self.panda - ((self.pigs + self.sheep + self.cows) / 3) return 0 def findSpeed(self): self.cows = 0 self.pigs = 0 self.sheep = 0 self.panda = 0 for animal in self.animals: if animal.type2 == 'cow': self.cows += 1 if animal.type2 == 'pig': self.pigs += 1 if animal.type2 == 'sheep': self.sheep += 1 if animal.type2 == 'panda': self.panda += 1 speedadd = self.biggest() * 1.7 speeddeduct = len(self.inanimates) self.beamspeed = self.basebeamspeed - speeddeduct + speedadd self.stuntime = self.stunbase - (self.beamspeed * 1.5) if self.stuntime < 2: self.stuntime = 2 #Minimum beam speed if self.beamspeed < 2: self.beamspeed = 2 def abductAnimal(self): self.pcount = self.particletime #self.abductp.start(parent = self.ship, renderParent = self.ship) self.collected += 1 def particleTask(self,task): if self.pcount > 0: self.pcount -= 1 elif self.pcount == 0: self.pcount = -1 self.abductp.reset() self.abductp.disable() return task.cont
class Enemy(): def __init__(self, pos, index, app, manager, level, style): self.position = pos self.app = app self.np = app.render.attachNewNode("enemy%d" % index) if style == 1: self.np.setColorScale(1.0, 1.0, 1.0, 1.0) self.movespeed = 2.5 self.max_movespeed = 30 else: self.movespeed = 0.5 self.max_movespeed = 25 if style == 2: self.activate_delay = 0.01 self.np.setColorScale(0.6, 1.0, 1.0, 1.0) else: self.activate_delay = 0.1 if style == 3: self.hp = 50 * level self.np.setColorScale(0.0, 1.0, 0.5, 1.0) else: self.hp = 100 * level if style == 4: self.damage = 20 self.np.setColorScale(1.0, 1.0, 0.0, 1.0) else: self.damage = 10 self.dead = 0.0 self.level = level self.style = style self.particle_clean = False # this allows us to detach the instance nodepath # on death, but keep one with no model to attach particle effects self.dnp = app.render.attachNewNode("enemy_top%d" % index) self.np.setPos(self.position) self.np.setHpr(uniform(1,360),0,0) self.np.setScale(level) colsize = 3.0 self.cn = self.np.attachNewNode(CollisionNode('enemy_cn_%d' % index)) self.cs0 = CollisionSphere(0.0, colsize/2,0.0,colsize) self.cs1 = CollisionSphere(0.0, -colsize/2,0.0,colsize) self.cs2 = CollisionSphere(0.0, -colsize/3*4,0.0,colsize/2) self.cn.node().addSolid(self.cs0) self.cn.node().addSolid(self.cs1) self.cn.node().addSolid(self.cs2) #self.cn.show() # debug self.cqueue = CollisionHandlerQueue() app.cTrav.addCollider(self.cn, self.cqueue) self.cn.node().setIntoCollideMask(BitMask32(0x01)) self.cn.node().setFromCollideMask(BitMask32(0x10)) self.last_activated = 0.0 manager.add_instance(self) # name, nodepath, mass, move_force, max_force self.ai_char = AICharacter('enemy_ai_%d' % index, self.np, 100, self.movespeed, self.max_movespeed) app.ai_world.addAiChar(self.ai_char) self.ai_b = self.ai_char.getAiBehaviors() self.ai_b.pursue(app.player.np) self.load_particle_config() def update(self, time): a = 0 # Handle collsions for i in range(self.cqueue.getNumEntries()): collided_name = self.cqueue.getEntry(i).getIntoNodePath().getName() #handle bullets if collided_name[0] == 'b': bullet = self.app.bullet_manager.get_bullet(collided_name) bullet.apply_effect(self) self.app.bullet_manager.remove_bullet(collided_name) if self.cqueue.getNumEntries() != 0: self.np.setColorScale(1.0, self.hp / 100.0, self.hp / 100.0, 1.0) """ desired = self.app.player.position - self.np.getPos() angle = degrees(atan2(desired.y, desired.x)) hpr = self.np.getHpr() if hpr.x > 360: hpr.x = hpr.x - 360 if hpr.x < -360: hpr.x = hpr.x + 360 diff = angle - hpr.x if diff > 180.0: diff = diff - 360 if diff < -180.0: diff = diff + 360 if diff > 5.0: diff = 5.0 if diff < -5.0: diff = -5.0 new = Vec3(diff, 0, 0) + hpr #self.np.setHpr(new) # move forward r = radians(new.x) curr = self.np.getPos() diff = Vec3(self.movespeed * cos(r), self.movespeed * sin(r), 0) self.np.setPos(curr + diff)""" if self.hp < 0.0 and self.dead == 0.0: self.dead = time self.app.scene.remove(self) # Create particle effect before we go self.dnp.setPos(self.np.getPos()) self.particles.start(parent = self.dnp, renderParent = self.app.render) self.np.detachNode() # Drop some loot self.app.item_manager.add_item(self.np.getPos(), "soul", self.level) # Give the player some points self.app.player.score = self.app.player.score + 100 def apply_effect(self, target, timer): if self.last_activated - timer + self.activate_delay < 0.0: self.last_activated = timer target.hp = target.hp - self.damage if target.np.getName()[0] == 't': target.pursuers.append(self) #self.ai_b = self.ai_char.getAiBehaviors() #self.ai_b.pursue(self.np.getPos()) self.ai_b.pauseAi("pursue") def load_particle_config(self): self.particles = ParticleEffect() self.particles.reset() self.particles.setPos(0.000, 0.000, 0.000) self.particles.setHpr(0.000, 0.000, 0.000) self.particles.setScale(1.000, 1.000, 1.000) p0 = Particles('particles-1') # Particles parameters p0.setFactory("PointParticleFactory") p0.setRenderer("SpriteParticleRenderer") p0.setEmitter("SphereVolumeEmitter") p0.setPoolSize(20) p0.setBirthRate(0.0100) p0.setLitterSize(20) p0.setLitterSpread(0) p0.setSystemLifespan(1.0100) p0.setLocalVelocityFlag(1) p0.setSystemGrowsOlderFlag(1) # Factory parameters p0.factory.setLifespanBase(1.0000) p0.factory.setLifespanSpread(0.0000) p0.factory.setMassBase(1.0000) p0.factory.setMassSpread(0.0100) p0.factory.setTerminalVelocityBase(1200.0000) p0.factory.setTerminalVelocitySpread(0.0000) # Point factory parameters # Renderer parameters p0.renderer.setAlphaMode(BaseParticleRenderer.PRALPHAOUT) p0.renderer.setUserAlpha(0.05) # Sprite parameters p0.renderer.setTexture(self.app.loader.loadTexture('effects/dust.png')) p0.renderer.setColor(Vec4(1.00, 0.10, 0.10, 0.50)) p0.renderer.setXScaleFlag(2) p0.renderer.setYScaleFlag(2) p0.renderer.setAnimAngleFlag(0) p0.renderer.setInitialXScale(0.100 * self.level) p0.renderer.setFinalXScale(0.200 * self.level) p0.renderer.setInitialYScale(0.100 * self.level) p0.renderer.setFinalYScale(0.200 * self.level) p0.renderer.setNonanimatedTheta(0.0000) p0.renderer.setAlphaBlendMethod(BaseParticleRenderer.PPBLENDLINEAR) p0.renderer.setAlphaDisable(0) # Emitter parameters p0.emitter.setEmissionType(BaseParticleEmitter.ETRADIATE) p0.emitter.setAmplitude(1.0000) p0.emitter.setAmplitudeSpread(0.0000) p0.emitter.setOffsetForce(Vec3(0.0000, 0.0000, 0.0000)) p0.emitter.setExplicitLaunchVector(Vec3(1.0000, 0.0000, 0.0000)) p0.emitter.setRadiateOrigin(Point3(0.0000, 0.0000, 0.0000)) # Sphere Volume parameters p0.emitter.setRadius(0.1000) self.particles.addParticles(p0) f0 = ForceGroup('gravity') # Force parameters self.particles.addForceGroup(f0)
class World(DirectObject): def __init__(self): #turn off mouse control, otherwise camera is not repositionable self.lightables = [] self.cameraPositions = [((0, 5000, 5300), (180, -35, 0)),((0, 3000, 1300), (180, -15, 0))] self.cameraIndex = 0 base.disableMouse() base.enableParticles() self.setupLights() self.setupPicking() #Prepare the vehicular manslaughter! self.boosterLightNP = None self.flameLights = None self.player = Vehicle("models/panda-model", "panda-walk4", self) self.loadModels() # self.player.setPos(self.env.find("**/start_point").getPos()) self.player.setPos(0,0,0) self.setupIntervals() camera.reparentTo(self.player) camera.setPosHpr(0, 5000, 5300, 180, -35, 0) self.setupCollisions() render.setShaderAuto() #you probably want to use this self.keyMap = {"left":0, "right":0, "forward":0, "backwards":0} taskMgr.add(self.player.move, "moveTask") #Give the vehicle direct access to the keyMap self.player.addKeyMap(self.keyMap) self.prevtime = 0 self.isMoving = False self.speed_norm = 8 self.speed = self.speed_norm self.accept("escape", sys.exit) self.accept("arrow_up", self.setKey, ["forward", 1]) self.accept("w", self.setKey, ["forward", 1]) self.accept("arrow_right", self.setKey, ["right", 1]) self.accept("d", self.setKey, ["right", 1]) self.accept("arrow_left", self.setKey, ["left", 1]) self.accept("a", self.setKey, ["left", 1]) self.accept("arrow_down", self.setKey, ["backwards", 1]) self.accept("s", self.setKey, ["backwards", 1]) self.accept("arrow_up-up", self.setKey, ["forward", 0]) self.accept("w-up", self.setKey, ["forward", 0]) self.accept("arrow_right-up", self.setKey, ["right", 0]) self.accept("d-up", self.setKey, ["right", 0]) self.accept("arrow_left-up", self.setKey, ["left", 0]) self.accept("a-up", self.setKey, ["left", 0]) self.accept("arrow_down-up", self.setKey, ["backwards", 0]) self.accept("s-up", self.setKey, ["backwards", 0]) self.accept("mouse1", self.startShoot) self.accept("mouse1-up", self.stopShoot) self.accept("tab", self.shiftCamera) self.accept("space", self.player.startBoosters) self.accept("ate-smiley", self.eat) self.accept("ground_collide", self.player.collider) self.p1 = ParticleEffect() self.p2 = ParticleEffect() #Show collisiony stuff base.cTrav.showCollisions(render) def setupPicking(self): self.picker = CollisionTraverser() self.pq = CollisionHandlerQueue() self.pickerNode = CollisionNode('mouseRay') self.pickerNP = camera.attachNewNode(self.pickerNode) self.pickerNode.setFromCollideMask(BitMask32.bit(1)) self.pickerRay = CollisionRay() self.pickerNode.addSolid(self.pickerRay) self.picker.addCollider(self.pickerNP, self.pq) self.targetRoot = render.attachNewNode('targetRoot') self.mouseTask = taskMgr.add(self.mouseTask, 'mouseTask') def mouseTask(self, task): if base.mouseWatcherNode.hasMouse(): mpos = base.mouseWatcherNode.getMouse() self.pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY()) self.picker.traverse(self.targetRoot) if self.pq.getNumEntries() > 0: self.pq.sortEntries() i = int(self.pq.getEntry(0).getIntoNode().getTag('target')) print("Found target: " + str(i)) return Task.cont def setupIntervals(self): self.lightOn = LerpFunc(self.lightModify, fromData=0, toData=100, duration=0.2, blendType='noBlend', extraArgs=[True], name="LightUp") self.lightOff = LerpFunc(self.lightModify, fromData=0, toData=100, duration=0.2, blendType='noBlend', extraArgs=[False], name="LightDown") self.cameraMove = None def setKey(self, key, value): self.keyMap[key] = value def setWorldLight(self, object): self.lightables.append(object) object.setLight(self.keyLightNP) object.setLight(self.fillLightNP) object.setLight(self.boosterLightNP) for light in self.flameLights: object.setLight(light[1]) def shiftCamera(self): if self.cameraMove: self.cameraMove.finish() old = self.cameraIndex self.cameraIndex += 1 if self.cameraIndex == len(self.cameraPositions): self.cameraIndex = 0 self.cameraMove=LerpPosHprInterval(camera, .7, self.cameraPositions[self.cameraIndex][0], self.cameraPositions[self.cameraIndex][1], camera.getPos(), camera.getHpr()) self.cameraMove.start() def loadModels(self): """loads models into the world""" #eat no longer exists? Phooey self.flameLights = [] shadowcam = Spotlight('shadowlight') shadowcam.setColor(VBase4(0,0,0,1)) lens = PerspectiveLens() shadowcam.setLens(lens) shadowcam.setAttenuation(Point3(0, 0.001, 0.001)) shadowNP = self.player.attachNewNode(shadowcam) shadowNP.setPos(0, -1400, 450) shadowNP.lookAt(self.player) shadowNP.setScale(200) shadowNP.node().setShadowCaster(True) self.flameLights.append((shadowcam, shadowNP)) for i in range(2): slight = PointLight('plight') slight.setColor(VBase4(0, 0, 0, 1)) slight.setAttenuation(Point3(0, 0.001, 0.001)) slnp = self.player.attachNewNode(slight) slnp.setPos(0, -750 - (950 * i), 450) slnp.setHpr(180, 0, 0) slnp.setScale(200) self.flameLights.append((slight, slnp)) self.player.setupBooster() #self.env = loader.loadModel("models/environment") #self.env.reparentTo(render) #self.env.setScale(.25) #self.env.setPos(-8, 42, 0) self.env = loader.loadModel("models/terrain2") self.env.reparentTo(render) self.env.setPos(0,0,0) self.setWorldLight(self.env) #load targets self.targets = [] for i in range (10): target = loader.loadModel("smiley") target.setScale(.5) target.setPos(random.uniform(-20, 20), random.uniform(-15, 15), 2) target.reparentTo(self.targetRoot) self.targets.append(target) self.setWorldLight(target) def setupLights(self): #ambient light self.ambientLight = AmbientLight("ambientLight") #four values, RGBA (alpha is largely irrelevent), value range is 0:1 self.ambientLight.setColor((.10, .10, .10, 1)) self.ambientLightNP = render.attachNewNode(self.ambientLight) #the nodepath that calls setLight is what gets illuminated by the light render.setLight(self.ambientLightNP) #call clearLight() to turn it off self.keyLight = DirectionalLight("keyLight") self.keyLight.setColor((.20,.20,.20, 1)) self.keyLightNP = render.attachNewNode(self.keyLight) self.keyLightNP.setHpr(0, -26, 0) self.fillLight = DirectionalLight("fillLight") self.fillLight.setColor((.05,.05,.05, 1)) self.fillLightNP = render.attachNewNode(self.fillLight) self.fillLightNP.setHpr(30, 0, 0) def drive(self): """compound interval for driveing""" #some interval methods: # start(), loop(), pause(), resume(), finish() # start() can take arguments: start(starttime, endtime, playrate) dist = 5 angle = deg2Rad(self.player.getH()) dx = dist * math.sin(angle) dy = dist * -math.cos(angle) playerdrive = Parallel(self.player.posInterval(1, (self.player.getX() + dx, self.player.getY() + dy, 0)), \ self.player.actorInterval("drive", loop=1, duration=2)) playerdrive.start() def setupCollisions(self): #instantiates a collision traverser and sets it to the default base.cTrav = CollisionTraverser() self.cHandler = CollisionHandlerEvent() #set pattern for event sent on collision # "%in" is substituted with the name of the into object self.cHandler.setInPattern("ate-%in") cSphere = CollisionSphere((0,0,200), 450) #because the player is scaled way down self.playerRay = CollisionRay() self.playerRay.setOrigin(0,0,2000) self.playerRay.setDirection(0,0,-1) self.playerNode = CollisionNode("playerRay") self.playerNode.addSolid(self.playerRay) self.playerNode.setFromCollideMask(BitMask32.bit(0)) self.playerNode.setIntoCollideMask(BitMask32.allOff()) self.playerNodePath = self.player.attachNewNode(self.playerNode) self.playerNodePath.show() self.playerGroundHandler = CollisionHandlerFloor() self.playerGroundHandler.addCollider(self.playerNodePath, self.player) base.cTrav.addCollider(self.playerNodePath, self.playerGroundHandler) cNode = CollisionNode("player") cNode.addSolid(cSphere) cNode.setIntoCollideMask(BitMask32.allOff()) #player is *only* a from object #cNode.setFromCollideMask(BitMask32.bit(0)) cNodePath = self.player.attachNewNode(cNode) #registers a from object with the traverser with a corresponding handler base.cTrav.addCollider(cNodePath, self.cHandler) i = 0 for target in self.targets: cSphere = CollisionSphere((0,0,0), 2) cNode = CollisionNode("smiley") cNode.addSolid(cSphere) cNode.setIntoCollideMask(BitMask32.bit(1)) cNode.setTag('target', str(i)) cNodePath = target.attachNewNode(cNode) i += 1 def lightModify(self, t, which_way): if which_way: #which_way == true then make it brighter value = t/100 * MAX_LIGHT else: #which_way == true then make it darker value = (100 - t)/100 * MAX_LIGHT for light in self.flameLights: light[0].setColor(VBase4(value,value,value,1)) def startShoot(self): self.loadParticleConfig('flamethrower4.ptf') self.lightOff.finish() self.lightOn.start() def stopShoot(self): self.p1.softStop() self.p2.softStop() self.lightOn.finish() self.lightOff.start() def loadParticleConfig(self, file): self.p1.reset() self.p1 = ParticleEffect() self.p1.loadConfig(Filename(file)) self.p1.start(self.player) self.p1.setPos(-250, -700, 275) self.p1.setHpr(0, 90, 0) self.p1.setScale(200) self.p1.setLightOff() self.p2.reset() self.p2 = ParticleEffect() self.p2.loadConfig(Filename(file)) self.p2.start(self.player) self.p2.setPos(250, -700, 275) self.p2.setHpr(0, 90, 0) self.p2.setScale(200) self.p2.setLightOff() def eat(self, cEntry): """handles the player eating a smiley""" #remove target from list of targets self.targets.remove(cEntry.getIntoNodePath().getParent()) #remove from scene graph cEntry.getIntoNodePath().getParent().remove()
class Lvl03(DirectObject): def start(self): base.disableMouse() #turn off mouse camera control base.enableParticles() self.music = loader.loadMusic("models/gamedev/DEC.mp3") self.music.play() camera.setPosHpr(Vec3(98,-390,90), Vec3(0,-5,0)) self.ballNum = 10 self.setupStage() self.loadModels() self.setupLighting() self.setupCollisions() self.setupIntervals() taskMgr.add(self.ballMovementTask,'ballMoveTask') self.gameLen = 30 self.player1Weapon = "" self.player2Weapon = "" #hud = OnscreenImage(image = 'models/gamedev/lvl2hud.jpg', pos = (0,1,20),scale=5.0) #hud.reparentTo(render) globalClock.reset() self.timer = OnscreenText("%d" % (self.gameLen-globalClock.getRealTime(),), pos = (98,145), scale = 18.0) self.timer.setColor(1,1,1) taskMgr.add(self.clockTask,"clockTask") self.player1Score = 0 self.player2Score = 0 self.nodeCount1 = 0 self.nodeCount2 = 0 self.player1Invincible = 0 self.player2Invincible = 0 self.jNP = self.playerModel.exposeJoint(None,"modelRoot","ikHandle2") self.jNP2 = self.playerModel2.exposeJoint(None,"modelRoot","ikHandle2") self.climbing1 = 0 self.climbing2 = 0 self.speed1 = 3.0 self.speed2 = 3.0 self.ignoreColl= 0 self.player1IsColliding = 0 self.player2IsColliding = 0 taskMgr.doMethodLater(self.gameLen, self.endGame,'gameFinished') #taskMgr.doMethodLater(self.gameLen/2.0,self.changeMusic,'musicSwitch') #setup key controls self.accept("escape",sys.exit) #self.acceptOnce("space",self.drop) # Player 1 movement self.acceptOnce("a",self.left) self.acceptOnce("d",self.right) self.accept("a-up",self.stopLeft) self.accept("d-up",self.stopRight) self.acceptOnce("w", self.jump) #Player 2 movement keys #self.accept("l",self.fall2) self.acceptOnce("k",self.left2) self.acceptOnce(";",self.right2) self.accept("k-up",self.stopLeft2) self.accept(";-up",self.stopRight2) self.acceptOnce("o", self.jumpT2) def setupStage(self): self.ball = [] self.movement = [] for i in range(self.ballNum+1): z=random.randint(1,2) if z ==1: z=-1 else: z=1 weapBalls.define(self.ball,i,render) self.movement.append(Vec3(random.random()*z,0,random.random()*z)) #self.movement[i].Vec3(random.randint(1,3),0,random.randint(1,3)) self.background2 = OnscreenImage(image = 'models/gamedev/frozenbg.JPG', pos = (98,10,0),scale=500) self.background2.detachNode() self.background = OnscreenImage(image = 'models/gamedev/moltenbg.JPG', pos = (98,10,0),scale=500) self.background.reparentTo(render) self.lava = loader.loadModel("models/gamedev/lava") self.lava.setPosHpr(Vec3(98,0,-18),Vec3(0,5,0)) self.lava.setScale(50) self.lava.reparentTo(render) x1= 196 x2 = 0 m1 = 98 m2 = 107.8 len = 9.8 h = 0 a = 0 p = 0 for j in range(4): if j > 0: x1Old = x1 x2Old = x2 x1 = 196-(random.randint(0,3)*9.8) x2 = 0+random.randint(0,3)*9.8 m1=98-(random.randint(0,3)*9.8) m2= 107.8+random.randint(0,3)*9.8 for count in range(1): l = random.randint(2,5) r = random.randint(2,5) c1 = random.randint(2,5) c2 = random.randint(2,5) if l+r < 4: count = 0 else: l = 4 r = 4 c1 = 2 c2 = 2 ''' if j ==1 or j == 3: self.ladder = loader.loadModel("models/gamedev/ladder") self.ladder.reparentTo(render) self.ladder.setScale(1.5) self.ladder.setPos(x2+4.9,0,h-20) self.ladder2 = loader.loadModel("models/gamedev/ladder") self.ladder2.reparentTo(render) self.ladder2.setScale(1.5) self.ladder2.setPos(x1-4.9,0,h-20) if j == 2: self.ladder = loader.loadModel("models/gamedev/ladder") self.ladder.reparentTo(render) self.ladder.setScale(1.5) self.ladder.setPos(m1-4.9,0,h-20) self.ladder2 = loader.loadModel("models/gamedev/ladder") self.ladder2.reparentTo(render) self.ladder2.setScale(1.5) self.ladder2.setPos(m2+4.9,0,h-20) ''' self.first = 1 for i in range(r): '''Right half of stage''' self.environment = loader.loadModel("models/gamedev/platform") self.environment.reparentTo(render) self.environment.setScale(5) self.environment.setPos(x1,0,h) if self.first == 1: self.first = 0 bounds = self.environment.getChild(0).getBounds() center = bounds.getCenter() poly1 = Point3(center.getX()+1, center.getY()-.5, center.getZ()+.2) poly2 = Point3(center.getX()-(2*r-1), center.getY()-.5, center.getZ()+.2) poly3 = Point3(center.getX()+1, center.getY()+.5, center.getZ()+.2) poly4 = Point3(center.getX()-(2*r-1), center.getY()+.5, center.getZ()+.2) cPoly = CollisionPolygon(poly4, poly2, poly1, poly3) cNode = CollisionNode("platform") cNode.addSolid(cPoly) cNodePath = self.environment.attachNewNode(cNode) cNodePath.show() x1 = x1 - len self.first = 1 for i in range(l): '''Left Half of stage''' self.environment = loader.loadModel("models/gamedev/platform") self.environment.reparentTo(render) self.environment.setScale(5) self.environment.setPos(x2,0,h) if self.first == 1: self.first = 0 bounds = self.environment.getChild(0).getBounds() center = bounds.getCenter() poly1 = Point3(center.getX()+(2*l-1), center.getY()-.5, center.getZ()+.2) poly2 = Point3(center.getX()-1, center.getY()-.5, center.getZ()+.2) poly3 = Point3(center.getX()+(2*l-1), center.getY()+.5, center.getZ()+.2) poly4 = Point3(center.getX()-1, center.getY()+.5, center.getZ()+.2) cPoly = CollisionPolygon(poly4, poly2, poly1, poly3) cNode = CollisionNode("platform") cNode.addSolid(cPoly) cNodePath = self.environment.attachNewNode(cNode) cNodePath.show() x2 = x2 + len self.first = 1 for i in range(c1): '''Right half of stage''' self.environment = loader.loadModel("models/gamedev/platform") self.environment.reparentTo(render) self.environment.setScale(5) self.environment.setPos(m1,0,h) if self.first == 1: self.first = 0 bounds = self.environment.getChild(0).getBounds() center = bounds.getCenter() poly1 = Point3(center.getX()+1, center.getY()-.5, center.getZ()+.2) poly2 = Point3(center.getX()-(2*c1-1), center.getY()-.5, center.getZ()+.2) poly3 = Point3(center.getX()+1, center.getY()+.5, center.getZ()+.2) poly4 = Point3(center.getX()-(2*c1-1), center.getY()+.5, center.getZ()+.2) cPoly = CollisionPolygon(poly4, poly2, poly1, poly3) cNode = CollisionNode("platform") cNode.addSolid(cPoly) cNodePath = self.environment.attachNewNode(cNode) cNodePath.show() m1 = m1 - len self.first = 1 for i in range(c2): '''Left Half of stage''' self.environment = loader.loadModel("models/gamedev/platform") self.environment.reparentTo(render) self.environment.setScale(5) self.environment.setPos(m2,0,h) if self.first == 1: self.first = 0 bounds = self.environment.getChild(0).getBounds() center = bounds.getCenter() poly1 = Point3(center.getX()+(2*c2-1), center.getY()-.5, center.getZ()+.2) poly2 = Point3(center.getX()-1, center.getY()-.5, center.getZ()+.2) poly3 = Point3(center.getX()+(2*c2-1), center.getY()+.5, center.getZ()+.2) poly4 = Point3(center.getX()-1, center.getY()+.5, center.getZ()+.2) cPoly = CollisionPolygon(poly4, poly2, poly1, poly3) cNode = CollisionNode("platform") cNode.addSolid(cPoly) cNodePath = self.environment.attachNewNode(cNode) cNodePath.show() m2 = m2 + len h = h+40 a = 0 def loadModels(self): # ** Load female character that will represent first player** # self.playerModel = Actor("models/gamedev/redguy-model",{"walk":"models/gamedev/redguy-run"}) self.playerModel.reparentTo(render) self.playerModel.setScale(.6) self.playerModel.setH(90) # ** Position player at center of the field with it lying directly above the field. ** # self.playerModel.setPos(0,0,1.76) # ** Load female character that will represent second player** # self.playerModel2 = Actor("models/gamedev/bluegirl-model",{"walk2":"models/gamedev/bluegirl-run"}) self.playerModel2.reparentTo(render) self.playerModel2.setScale(.6) self.playerModel2.setH(0) # ** Position player at center of the field with it lying directly above the field. ** # self.playerModel2.setPos(196,0,2.0) def reset(self): self.an1.getPhysicsObject().setVelocity(Vec3(0,0,0)) self.an2.getPhysicsObject().setVelocity(Vec3(0,0,0)) self.an1.getPhysicsObject().setPosition(Point3(0,0,11.76)) self.an2.getPhysicsObject().setPosition(Point3(196,0,22.0)) self.playerModel.setH(90) self.playerModel.detachNode() self.playerModel.setPos(0,0,1.76) self.anp.setFluidPos(Point3(0,0,1.76)) self.playerModel.reparentTo(self.anp) self.playerModel2.setH(0) self.playerModel2.detachNode() self.playerModel2.setPos(196,0,22.0) self.anp2.setFluidPos(Point3(196,0,22.0)) self.playerModel2.reparentTo(self.anp2) def setupLighting(self): ambientLight = AmbientLight('ambientLight') ambientLight.setColor(Vec4(0.55,0.55,0.55,1.0)) ambientLightNP = render.attachNewNode(ambientLight) render.setLight(ambientLightNP) dirLight = DirectionalLight('dirLight') dirLight.setColor(Vec4(0.6,0.6,0.6,1)) dirLightNP = render.attachNewNode(dirLight) dirLightNP.setHpr(Vec3(0.0,-26.0,0.0)) render.setLight(dirLightNP) def setupIntervals(self): self.charWalk1l = self.playerModel.actorInterval("walk") self.charWalk1l.loop( ) self.charWalk1l.pause( ) self.charWalk1r = self.playerModel.actorInterval("walk") self.charWalk1r.loop( ) self.charWalk1r.pause( ) self.charWalk2l = self.playerModel2.actorInterval("walk2") self.charWalk2l.loop( ) self.charWalk2l.pause( ) self.charWalk2r = self.playerModel2.actorInterval("walk2") self.charWalk2r.loop( ) self.charWalk2r.pause( ) self.jump1 = self.playerModel.actorInterval("jump") self.jump1.loop() self.jump1.pause() self.jump2 = self.playerModel2.actorInterval("jump2") self.jump2.loop() self.jump2.pause() self.climb1 = self.playerModel.actorInterval("climb") self.climb1.loop() self.climb1.pause() self.climb2 = self.playerModel2.actorInterval("climb2") self.climb2.loop() self.climb2.pause() # end setupIntervals # ############################ # Actual Working movement code # ############################ def rise(self): dist = 40 self.playerModel.setH(0) playerJump = self.playerModel.posInterval(1.0,Vec3(self.playerModel.getX(), self.playerModel.getY(),self.playerModel.getZ()+dist)) playerJump.start() def rise2(self): dist = 40 self.playerModel2.setH(90) playerJump2 = self.playerModel2.posInterval(1.0,Vec3(self.playerModel2.getX(), self.playerModel2.getY(),self.playerModel2.getZ()+dist)) playerJump2.start() # PLAYER ONE # def left(self): taskMgr.add(self.leftTask,'leftTask') self.charWalk1l.loop() #end left def leftTask(self,task): if self.climbing1 == 0: self.playerModel.setH(270) self.playerModel.setPos(Vec3(self.playerModel.getX()-self.speed1, self.playerModel.getY(), self.playerModel.getZ())) return Task.cont def right(self): taskMgr.add(self.rightTask,'rightTask') self.charWalk1r.loop() #end right def rightTask(self,task): if self.climbing1 == 0: self.playerModel.setH(90) self.playerModel.setPos(Vec3(self.playerModel.getX()+self.speed1, self.playerModel.getY(), self.playerModel.getZ())) return Task.cont def climbable(self,cEntry): self.nodeCount1+=1 print self.nodeCount1 self.ignore("w") self.ignore("w-up") self.ignore("s") self.ignore("s-up") self.acceptOnce("w",self.climb,[1]) self.accept("w-up",self.noClimb) self.acceptOnce("s",self.climb,[-1]) self.accept("s-up",self.noClimb) def climb(self,dir): self.dir1 = dir self.climbing1 = 1 self.climbSpeed1 = 1 self.ignore("a") self.ignore("a-up") self.ignore("d") self.ignore("d-up") taskMgr.add(self.climbTask,'climbTask') self.climb1.loop() def noClimb(self): taskMgr.remove('climbTask') self.climb1.pause() if self.nodeCount1 == 0: self.climbing = 0 self.climbSpeed1 = 0 self.acceptOnce("w",self.climb,[1]) self.acceptOnce("s",self.climb,[-1]) def jumpable(self,cEntry): self.nodeCount1+=-1 print self.nodeCount1 if self.nodeCount1 == 0: taskMgr.remove('climbTask') self.ignore("w") self.ignore("w-up") self.ignore("s") self.ignore("s-up") self.acceptOnce("w",self.jump) self.acceptOnce("a",self.left) self.acceptOnce("d",self.right) self.accept("a-up",self.stopLeft) self.accept("d-up",self.stopRight) self.climbing1 = 0 self.climbSpeed1 = 0 self.climb1.pause() def walkable(self,cEntry): self.ignore("w") self.ignore("w-up") self.ignore("s") self.ignore("s-up") self.acceptOnce("w",self.climb,[1]) self.accept("w-up",self.noClimb) self.acceptOnce("s",self.climb,[-1]) self.accept("s-up",self.noClimb) self.acceptOnce("a",self.left) self.acceptOnce("d",self.right) self.accept("a-up",self.stopLeft) self.accept("d-up",self.stopRight) self.climbing1 = 0 self.climbSpeed1 = 0 self.climb1.pause() def climbTask(self,task): if self.playerModel.getZ() >=0: self.playerModel.setH(0) self.playerModel.setPos(Vec3(self.playerModel.getX(), self.playerModel.getY(), self.playerModel.getZ()+self.climbSpeed1*self.dir1)) return Task.cont def jump(self): if self.nodeCount1 == 0: self.ignore("w") self.ignore("w-up") z = self.playerModel.getZ() j = ProjectileInterval(self.playerModel, startPos = self.playerModel.getPos(), startVel = Point3(5,0,30), duration = 2.0) j.start() taskMgr.doMethodLater(2,self.jumpTask,"jumpTask") else: self.acceptOnce("w",self.climb,[1]) def jumpTask(self, task): if self.climbing1 == 0: self.jump1.pause() self.acceptOnce("w",self.jump) #return task.cont def allowRight(self): self.acceptOnce("d",self.right) def noRight(self): taskMgr.remove('rightTask') self.charWalk1r.pause() self.acceptOnce("d",self.right) def stopRight(self): self.noRight() #self.allowRight() def rightWall(self,cEntry): self.ignore("d") self.noRight() def rightEdge(self,cEntry): self.ignore("d") self.noRight() def rightOK(self,cEntry): self.allowRight() def allowLeft(self): self.acceptOnce("a",self.left) def noLeft(self): taskMgr.remove('leftTask') self.charWalk1l.pause() self.acceptOnce("a",self.left) def stopLeft(self): self.noLeft() #self.allowLeft() def leftWall(self,cEntry): self.ignore("a") self.noLeft() def leftEdge(self,cEntry): self.ignore("a") self.noLeft() def leftOK(self,cEntry): self.allowLeft() # PLAYERTWO # def left2(self): taskMgr.add(self.leftTask2,'leftTask2') self.charWalk2l.loop() #end left def leftTask2(self,task): if self.climbing2 == 0: self.playerModel2.setH(0) self.playerModel2.setPos(Vec3(self.playerModel2.getX()-self.speed2, self.playerModel2.getY(), self.playerModel2.getZ())) return Task.cont def right2(self): taskMgr.add(self.rightTask2,'rightTask2') self.charWalk2r.loop() #end right def rightTask2(self,task): if self.climbing2 == 0: self.playerModel2.setH(180) self.playerModel2.setPos(Vec3(self.playerModel2.getX()+self.speed2, self.playerModel2.getY(), self.playerModel2.getZ())) return Task.cont def climbable2(self,cEntry): self.nodeCount2+=1 #print self.nodeCount1 self.ignore("o") self.ignore("o-up") self.ignore("l") self.ignore("l-up") self.acceptOnce("o",self.climbT2,[1]) self.accept("o-up",self.noClimb2) self.acceptOnce("l",self.climbT2,[-1]) self.accept("l-up",self.noClimb2) def climbT2(self,dir): self.dir2 = dir self.climbing2 = 1 self.climbSpeed2 = 1 self.ignore("k") self.ignore("k-up") self.ignore(";") self.ignore(";-up") taskMgr.add(self.climbTask2,'climbTask2') self.climb2.loop() def noClimb2(self): taskMgr.remove('climbTask2') self.climb2.pause() if self.nodeCount2 == 0: self.climbing2 = 0 self.climbSpeed2 = 0 self.acceptOnce("o",self.climbT2,[1]) self.acceptOnce("l",self.climbT2,[-1]) def jumpable2(self,cEntry): self.nodeCount2+=-1 #print self.nodeCount2 if self.nodeCount2 == 0: taskMgr.remove('climbTask2') self.ignore("o") self.ignore("o-up") self.ignore("l") self.ignore("l-up") self.acceptOnce("o",self.jumpT2) self.acceptOnce("k",self.left2) self.acceptOnce(";",self.right2) self.accept("k-up",self.stopLeft2) self.accept(";-up",self.stopRight2) self.climbing2 = 0 self.climbSpeed2 = 0 self.climb2.pause() def walkable2(self,cEntry): self.ignore("o") self.ignore("o-up") self.ignore("l") self.ignore("l-up") self.acceptOnce("o",self.climbT2,[1]) self.accept("o-up",self.noClimb2) self.acceptOnce("l",self.climbT2,[-1]) self.accept("l-up",self.noClimb2) self.acceptOnce("k",self.left2) self.acceptOnce(";",self.right2) self.accept("k-up",self.stopLeft) self.accept(";-up",self.stopRight) self.climbing2 = 0 self.climbSpeed2 = 0 self.climb2.pause() def climbTask2(self,task): if self.playerModel2.getZ() >=0: self.playerModel2.setH(90) self.playerModel2.setPos(Vec3(self.playerModel2.getX(), self.playerModel2.getY(), self.playerModel2.getZ()+self.climbSpeed2*self.dir2)) return Task.cont def jumpT2(self): if self.nodeCount2 == 0: self.ignore("o") self.ignore("o-up") z = self.playerModel2.getZ() j = ProjectileInterval(self.playerModel2, startPos = self.playerModel2.getPos(), startVel = Point3(3,0,30), duration = 2.0) j.start() taskMgr.doMethodLater(3,self.jumpTask2,"jumpTask2") else: self.acceptOnce("w",self.climb,[1]) def jumpTask2(self, task): if self.climbing2 == 0: self.jump2.pause() self.acceptOnce("o",self.jumpT2) #return task.cont def allowRight2(self): self.acceptOnce(";",self.right2) def noRight2(self): taskMgr.remove('rightTask2') self.charWalk2r.pause() self.acceptOnce(";",self.right2) def stopRight2(self): self.noRight2() #self.allowRight() def rightWall2(self,cEntry): self.ignore(";") self.noRight2() def rightEdge2(self,cEntry): self.ignore(";") self.noRight2() def rightOK2(self,cEntry): self.allowRight2() def allowLeft2(self): self.acceptOnce("k",self.left2) def noLeft2(self): taskMgr.remove('leftTask2') self.charWalk2l.pause() self.acceptOnce("k",self.left2) def stopLeft2(self): self.noLeft2() #self.allowLeft() def leftWall2(self,cEntry): self.ignore("k") self.noLeft2() def leftEdge2(self,cEntry): self.ignore("k") self.noLeft2() def leftOK2(self,cEntry): self.allowLeft2() def setupCollisions(self): self.cHandler = PhysicsCollisionHandler() #self.cHandler.setInPattern("ate-%in") self.cHandler.addInPattern('%fn-into-%in') #self.cHandler2.addInPattern('%fn-into-%in') self.cHandler.setAgainPattern('%fn-again-%in') self.cHandler.setOutPattern('%fn-outof-%in') self.cTrav = CollisionTraverser() #self.cTrav2 = CollisionTraverser() base.cTrav = self.cTrav #Player 1 collision solid bounds = self.playerModel.getChild(0).getBounds() center = bounds.getCenter()-Vec3(0,0,12) radius = bounds.getRadius()-18 boundsB = self.playerModel.getChild(0).getBounds() centerB = bounds.getCenter()-Vec3(0,0,-4) radiusB = bounds.getRadius()-20 cSphere = CollisionSphere(center,radius) cSphereB = CollisionSphere(centerB,radiusB) cNode = CollisionNode("player1") #print radius, radiusB cNode.addSolid(cSphere) cNode.addSolid(cSphereB) cNodePath = self.playerModel.attachNewNode(cNode) cNodePath.show() Node=NodePath(PandaNode("PhysicsNode")) Node.reparentTo(render) self.an1=ActorNode("player1-physics") self.anp=Node.attachNewNode(self.an1) base.physicsMgr.attachPhysicalNode(self.an1) self.playerModel.reparentTo(self.anp) #self.anp.reparentTo(self.playerModel) #Player 2 collision solid bounds2 = self.playerModel2.getChild(0).getBounds() center2 = bounds2.getCenter()-Vec3(0,0,-4) radius2 = bounds2.getRadius()-20 cSphere2 = CollisionSphere(center2,radius2) bounds2B = self.playerModel2.getChild(0).getBounds() center2B = bounds2B.getCenter()-Vec3(0,0,12) radius2B = bounds2B.getRadius()-18 cSphere2B = CollisionSphere(center2B,radius2B) cNode2 = CollisionNode("player2") #print radius2, radius2B cNode2.addSolid(cSphere2) cNode2.addSolid(cSphere2B) cNodePath2 = self.playerModel2.attachNewNode(cNode2) cNodePath2.show() Node2=NodePath(PandaNode("PhysicsNode")) Node2.reparentTo(render) self.an2=ActorNode("player2-physics") self.anp2=Node2.attachNewNode(self.an2) base.physicsMgr.attachPhysicalNode(self.an2) self.playerModel2.reparentTo(self.anp2) #self.anp2.reparentTo(self.playerModel2) gravityFN=ForceNode('world-forces') gravityFNP=render.attachNewNode(gravityFN) gravityForce=LinearVectorForce(0,0,-9.8) #gravity acceleration gravityFN.addForce(gravityForce) base.physicsMgr.addLinearForce(gravityForce) self.an1.getPhysicsObject().setMass(15) self.an2.getPhysicsObject().setMass(15) gravityForce.setMassDependent(1) self.cHandler.addCollider(cNodePath, self.anp) self.cHandler.addCollider(cNodePath2, self.anp2) self.cTrav.addCollider(cNodePath,self.cHandler) self.cTrav.addCollider(cNodePath2,self.cHandler) self.cTrav.addCollider(cNodePath,self.cHandler) self.cTrav.addCollider(cNodePath2,self.cHandler) #self.cTrav.addCollider(cNodePath,self.cHandler2) #self.cTrav.addCollider(cNodePath2,self.cHandler2) #self.cTrav2.addCollider(cNodePath,self.cHandler2) #self.cTrav2.addCollider(cNodePath2,self.cHandler2) #cHandler2 = CollisionHandlerEvent() #cHandler2.addInPattern('%fn-into-%in') #self.cTrav.addCollider(cNodePath1,cHandler2) #self.cTrav.addCollider(cNodePath2,cHandler2) for i in range(self.ballNum+1): boundsB = self.ball[i].getChild(0).getBounds() centerB = boundsB.getCenter() radiusB = boundsB.getRadius()*0.65 cSphereB = CollisionSphere(centerB,radiusB) cNodeB = CollisionNode("ball") cNodeB.addSolid(cSphereB) cNodePathB = self.ball[i].attachNewNode(cNodeB) #self.cTrav.addCollider(cNodePathB,self.cHandler) #cNodePathB.show() self.accept("player1-into-ball",self.acquire1) #self.accept("ball-into-player1",self.acquire1) self.accept("player2-into-ball",self.acquire2) #self.accept("ball-into-player2",self.acquire2) #self.accept( 'player1-into2-platform', self.wall1) #self.accept( 'player2-into2-platform', self.wall2) def wall1(self,cEntry): self.an1.getPhysicsObject().setVelocity(Vec3(0,0,0)) def wall2(self,cEntry): self.an2.getPhysicsObject().setVelocity(Vec3(0,0,0)) def player1Wins(self,cEntry): if self.player2Invincible == 0: self.player1Score+=10 self.reset() def player2Wins(self,cEntry): if self.player1Invincible == 0: self.player2Score+=10 self.reset() def acquire1(self,cEntry): self.playerModel.setY(0) if str(cEntry.getIntoNodePath().getParent()) == "render/sawball": self.player1Weapon = "saw" saw = loader.loadModel("models/gamedev/saw") saw.setScale(2.5) self.jNP.getChildren().detach() saw.reparentTo(self.jNP) self.acceptOnce("e",self.useWeapon1) self.acceptOnce("q",self.useWeapon1) elif str(cEntry.getIntoNodePath().getParent()) == "render/moltovball": self.player1Weapon = "molotov" molo = loader.loadModel("models/gamedev/moltov") molo.setScale(2.5) #self.jNP = self.playerModel.exposeJoint(None,"modelRoot","ikHandle2") self.jNP.getChildren().detach() molo.reparentTo(self.jNP) self.acceptOnce("e",self.useWeapon1) self.acceptOnce("q",self.useWeapon1) elif str(cEntry.getIntoNodePath().getParent()) == "render/grenadeball": self.player1Weapon = "grenade" gren = loader.loadModel("models/gamedev/grenade") gren.setScale(2.5) #self.jNP = self.playerModel.exposeJoint(None,"modelRoot","ikHandle2") self.jNP.getChildren().detach() gren.reparentTo(self.jNP) self.acceptOnce("e",self.useWeapon1) self.acceptOnce("q",self.useWeapon1) elif str(cEntry.getIntoNodePath().getParent()) == "render/pogo": #done self.jNP.getChildren().detach() self.player1Weapon = "jump" self.acceptOnce("e",self.useWeapon1) self.acceptOnce("q",self.useWeapon1) elif str(cEntry.getIntoNodePath().getParent()) == "render/golden": #done self.jNP.getChildren().detach() self.player1Weapon = "speedUp" self.acceptOnce("e",self.useWeapon1) self.acceptOnce("q",self.useWeapon1) elif str(cEntry.getIntoNodePath().getParent()) == "render/crystalball": self.jNP.getChildren().detach() self.player1Weapon = "icestage" self.acceptOnce("e",self.useWeapon1) self.acceptOnce("q",self.useWeapon1) elif str(cEntry.getIntoNodePath().getParent()) == "render/fireball": #done self.jNP.getChildren().detach() self.player1Weapon = "meteo" self.acceptOnce("e",self.useWeapon1) self.acceptOnce("q",self.useWeapon1) elif str(cEntry.getIntoNodePath().getParent()) == "render/blackball": #done self.jNP.getChildren().detach() self.player1Weapon = "blind" self.acceptOnce("e",self.useWeapon1) self.acceptOnce("q",self.useWeapon1) elif str(cEntry.getIntoNodePath().getParent()) == "render/translucent": self.jNP.getChildren().detach() self.player1Weapon = "invis" self.acceptOnce("e",self.useWeapon1) self.acceptOnce("q",self.useWeapon1) elif str(cEntry.getIntoNodePath().getParent()) == "render/superball": #done self.jNP.getChildren().detach() self.player1Weapon = "invincible" self.acceptOnce("e",self.useWeapon1) self.acceptOnce("q",self.useWeapon1) elif str(cEntry.getIntoNodePath().getParent()) == "render/death": #done self.jNP.getChildren().detach() if self.player1Invincible == 0: self.player2Deaths+= 1 self.reset() cEntry.getIntoNodePath().getParent().removeNode() #Drop a New Ball self.ballNum+=1 z=random.randint(1,2) if z ==1: z=-1 else: z=1 self.movement.append(Vec3(random.random()*z,0,random.random()*z)) weapBalls.define(self.ball,self.ballNum,render) boundsB = self.ball[self.ballNum].getChild(0).getBounds() centerB = boundsB.getCenter() radiusB = boundsB.getRadius()*.65 cSphereB = CollisionSphere(centerB,radiusB) cNodeB = CollisionNode("ball") cNodeB.addSolid(cSphereB) cNodePathB = self.ball[self.ballNum].attachNewNode(cNodeB) def acquire2(self,cEntry): if str(cEntry.getIntoNodePath().getParent()) == "render/sawball": self.player2Weapon = "saw" saw = loader.loadModel("models/gamedev/saw") saw.setScale(2.5) self.jNP2.getChildren().detach() saw.reparentTo(self.jNP2) self.acceptOnce("e",self.useWeapon2) self.acceptOnce("q",self.useWeapon2) elif str(cEntry.getIntoNodePath().getParent()) == "render/moltovball": self.player2Weapon = "molotov" molo = loader.loadModel("models/gamedev/moltov") molo.setScale(2.5) #self.jNP = self.playerModel.exposeJoint(None,"modelRoot","ikHandle2") self.jNP.getChildren().detach() molo.reparentTo(self.jNP) self.acceptOnce("e",self.useWeapon2) self.acceptOnce("q",self.useWeapon2) elif str(cEntry.getIntoNodePath().getParent()) == "render/grenadeball": self.player2Weapon = "grenade" gren = loader.loadModel("models/gamedev/grenade") gren.setScale(2.5) #self.jNP = self.playerModel.exposeJoint(None,"modelRoot","ikHandle2") self.jNP.getChildren().detach() gren.reparentTo(self.jNP) self.acceptOnce("e",self.useWeapon2) self.acceptOnce("q",self.useWeapon2) elif str(cEntry.getIntoNodePath().getParent()) == "render/pogo": #done self.jNP.getChildren().detach() self.player2Weapon = "jump" self.acceptOnce("e",self.useWeapon2) self.acceptOnce("q",self.useWeapon2) elif str(cEntry.getIntoNodePath().getParent()) == "render/golden": #done self.jNP.getChildren().detach() self.player2Weapon = "speedUp" self.acceptOnce("e",self.useWeapon2) self.acceptOnce("q",self.useWeapon2) elif str(cEntry.getIntoNodePath().getParent()) == "render/crystalball": self.jNP.getChildren().detach() self.player2Weapon = "icestage" self.acceptOnce("e",self.useWeapon2) self.acceptOnce("q",self.useWeapon2) elif str(cEntry.getIntoNodePath().getParent()) == "render/fireball": #done self.jNP.getChildren().detach() self.player2Weapon = "meteo" self.acceptOnce("e",self.useWeapon2) self.acceptOnce("q",self.useWeapon2) elif str(cEntry.getIntoNodePath().getParent()) == "render/blackball": #done self.jNP.getChildren().detach() self.player2Weapon = "blind" self.acceptOnce("e",self.useWeapon2) self.acceptOnce("q",self.useWeapon2) elif str(cEntry.getIntoNodePath().getParent()) == "render/translucent": self.jNP.getChildren().detach() self.player2Weapon = "invis" self.acceptOnce("e",self.useWeapon2) self.acceptOnce("q",self.useWeapon2) elif str(cEntry.getIntoNodePath().getParent()) == "render/superball": #done self.jNP.getChildren().detach() self.player2Weapon = "invincible" self.acceptOnce("e",self.useWeapon2) self.acceptOnce("q",self.useWeapon2) elif str(cEntry.getIntoNodePath().getParent()) == "render/death": #done self.jNP.getChildren().detach() if self.player2Invincible == 0: self.player1Score+=3 self.reset() cEntry.getIntoNodePath().getParent().removeNode() #Drop a New Ball self.ballNum+=1 z=random.randint(1,2) if z ==1: z=-1 else: z=1 self.movement.append(Vec3(random.random()*z,0,random.random()*z)) weapBalls.define(self.ball,self.ballNum,render) boundsB = self.ball[self.ballNum].getChild(0).getBounds() centerB = boundsB.getCenter() radiusB = boundsB.getRadius()*.65 cSphereB = CollisionSphere(centerB,radiusB) cNodeB = CollisionNode("ball") cNodeB.addSolid(cSphereB) cNodePathB = self.ball[self.ballNum].attachNewNode(cNodeB) def useWeapon1(self): if self.player1Weapon == "meteo": fireRain = Sequence(Func(self.rain), Wait(.5), Func(self.rain), Wait(.5), Func(self.rain), Wait(.5), Func(self.rain), Wait(.5), Func(self.rain), Wait(.5), Func(self.rain), Wait(.5), Func(self.rain), Wait(.5), Func(self.rain)) fireRain.start() elif self.player1Weapon == "jump": self.playerModel.detachNode() self.playerModel.reparentTo(render) angle = (self.playerModel.getH())*math.pi/180.0 ProjectileInterval(self.playerModel, startPos = Point3(self.playerModel.getPos()),startVel = Point3(math.sin(angle)*30,0,100), duration= 4.0).start() elif self.player1Weapon == "speedUp": self.speed1 = 6 taskMgr.doMethodLater(5,self.restoreSpeedBG,"restoreStuff") elif self.player1Weapon == "blind": camera.setPos(Vec3(-50,0,0)) taskMgr.doMethodLater(5,self.restoreCamera,"restoreCamera") elif self.player1Weapon == "invincible": self.player1Invincible = 1 taskMgr.doMethodLater(5,self.notInvince1,"mortal1") elif self.player1Weapon == "grenade": self.jNP.getChildren().detach() gren = loader.loadModel("models/gamedev/grenade") gren.setScale(2.5) gren.reparentTo(render) angle = (self.playerModel.getH())*math.pi/180.0 ProjectileInterval(gren, startPos = Point3(self.playerModel.getPos()),startVel = Point3(math.sin(angle)*30,0,10), endZ = -50).start() if gren.getZ() == -50: gren.removeNode() cHandler = CollisionHandlerEvent() cHandler.addInPattern('%fn-into-%in') boundsB = gren.getChild(0).getBounds() centerB = boundsB.getCenter() radiusB = boundsB.getRadius()*0.65 cSphereB = CollisionSphere(centerB,radiusB) cNodeB = CollisionNode("grenade") cNodeB.addSolid(cSphereB) cNodePathB = gren.attachNewNode(cNodeB) self.cTrav.addCollider(cNodePathB,cHandler) self.acceptOnce("grenade-into-platform",self.explode) elif self.player1Weapon == "molotov": self.jNP.getChildren().detach() elif self.player1Weapon == "saw": self.jNP.getChildren().detach() elif self.player1Weapon == "invis": self.jNP.getChildren().detach() self.playerModel2.hide() taskMgr.doMethodLater(4.0,self.showPlayer,"showPlayer") elif self.player1Weapon == "icestage": self.jNP.getChildren().detach() self.speed1 = 6 self.speed2 = 6 self.background.detachNode() self.background2.reparentTo(render) taskMgr.doMethodLater(5,self.restoreSpeedBG,"restoreStuff") def restoreSpeedBG(self,task): self.speed1 = 3 self.speed2 = 3 self.background2.detachNode() self.background.reparentTo(render) def showPlayer(self,task): self.playerModel.show() self.playerModel2.show() def useWeapon2(self): if self.player2Weapon == "meteo": fireRain = Sequence(Func(self.rain), Wait(.5), Func(self.rain), Wait(.5), Func(self.rain), Wait(.5), Func(self.rain), Wait(.5), Func(self.rain), Wait(.5), Func(self.rain), Wait(.5), Func(self.rain), Wait(.5), Func(self.rain)) fireRain.start() elif self.player2Weapon == "jump": angle = self.playerModel2.getH()/90 ProjectileInterval(self.playerModel2, startPos = Point3(self.playerModel2.getPos()),startVel = Point3(angle*30,0,100), endZ = self.playerModel2.getZ()).start() elif self.player2Weapon == "speedUp": self.speed2 = 6 elif self.player2Weapon == "blind": camera.setPos(Vec3(-50,0,0)) taskMgr.doMethodLater(5,self.restoreCamera,"restoreCamera") elif self.player2Weapon == "invincible": self.player2Invincible = 1 taskMgr.doMethodLater(5,self.notInvince2,"mortal2") elif self.player2Weapon == "grenade": self.jNP2.getChildren().detach() gren = loader.loadModel("models/gamedev/grenade") gren.setScale(2.5) gren.reparentTo(render) angle = (self.playerModel2.getH())*math.pi/180.0 ProjectileInterval(gren, startPos = Point3(self.playerModel2.getPos()),startVel = Point3(math.sin(angle)*30,0,10), endZ = -50).start() if gren.getZ() == -50: gren.removeNode() cHandler = CollisionHandlerEvent() cHandler.addInPattern('%fn-into-%in') boundsB = gren.getChild(0).getBounds() centerB = boundsB.getCenter() radiusB = boundsB.getRadius()*0.65 cSphereB = CollisionSphere(centerB,radiusB) cNodeB = CollisionNode("grenade") cNodeB.addSolid(cSphereB) cNodePathB = gren.attachNewNode(cNodeB) self.cTrav.addCollider(cNodePathB,cHandler) self.acceptOnce("grenade-into-platform",self.explode) elif self.player2Weapon == "molotov": self.jNP.getChildren().detach() elif self.player2Weapon == "saw": self.jNP.getChildren().detach() elif self.player2Weapon == "invis": self.jNP.getChildren().detach() self.playerModel1.hide() taskMgr.doMethodLater(4.0,self.showPlayer,"showPlayer") elif self.player2Weapon == "icestage": self.jNP2.getChildren().detach() self.speed1 = 6 self.speed2 = 6 self.background.detachNode() self.background2.reparentTo(render) taskMgr.doMethodLater(5,self.restoreSpeedBG,"restoreStuff") def rain(self): meteoBall = Actor("models/gamedev/fireball") meteoBall.reparentTo(render) meteoBall.setScale(2) meteoBall.setH(-15) boundsB = meteoBall.getChild(0).getBounds() centerB = boundsB.getCenter() radiusB = boundsB.getRadius()*0.65 cSphereB = CollisionSphere(centerB,radiusB) cNodeB = CollisionNode("meteor") cNodeB.addSolid(cSphereB) cNodePathB = meteoBall.attachNewNode(cNodeB) #cNodePathB.show() ProjectileInterval(meteoBall, startPos = Point3(random.randint(15,211),0,170),startVel = Point3(-12,0,0), endZ = -50).start() cHandler = CollisionHandlerEvent() cHandler.addInPattern('%fn-into-%in') self.cTrav.addCollider(cNodePathB,cHandler) self.accept("meteor-into-player1",self.player2Wins) self.accept("meteor-into-player2",self.player1Wins) def showBalls(self,task): for i in self.ball: i.show() def notInvince1(self,task): self.player1Invincible = 0 def notInvince2(self,task): self.player2Invincible = 0 def restoreCamera(self,task): camera.setPosHpr(Vec3(98,-390,90), Vec3(0,-5,0)) def switch(self,task): self.environment.setColor(0,1,0.3) def colliding1( self, collEntry ): # accept a collision entry argument if self.ignoreColl == 0: self.player1IsColliding = 1 # we are colliding self.stopWalk( ) # pause all walking animation and movement disp = ( collEntry.getSurfacePoint( render ) - collEntry.getInteriorPoint( render ) ) newPos = self.playerModel2.getPos( ) + disp # get new position self.playerModel2.setPos( newPos ) # and set it to tiny's position # end colliding def notColliding1( self, collEntry ): self.player1IsColliding = 0 def colliding2( self, collEntry ): # accept a collision entry argument if self.ignoreColl == 0: self.player2IsColliding = 1 # we are colliding self.stopWalk2( ) # pause all walking animation and movement disp = ( collEntry.getSurfacePoint( render ) - collEntry.getInteriorPoint( render ) ) newPos = self.playerModel2B.getPos( ) + disp # get new position self.playerModel2B.setPos( newPos ) # and set it to tiny's position # end colliding def notColliding2( self, collEntry ): self.player2IsColliding = 0 def returnSpeeds(self,task): self.speed1 = 8.0 self.speed2 = 8.0 self.turnSpeed1 = 80.0 self.turnSpeed2 = 80.0 def returnSpeeds2(self,task): self.acceptOnce("w",self.walk) self.acceptOnce("o",self.walk2) self.speed1 = 8.0 self.speed2 = 8.0 self.turnSpeed1 = 80.0 self.turnSpeed2 = 80.0 def returnSpeeds3(self,task): self.speed1 = 8.0 self.speed2 = 8.0 self.turnSpeed1 = 80.0 self.turnSpeed2 = 80.0 def changeMusic(self,task): self.music.stop() self.music2 = loader.loadMusic("models/gamedev/ADRENALINE.mp3") self.music2.play() def clockTask(self,task): self.timer.detachNode() self.timer = OnscreenText("%d" % (self.gameLen-globalClock.getRealTime(),), pos = (98,145), scale = 18.0) self.timer.setColor(1,1,1) self.timer.reparentTo(render) return Task.cont def ballMovementTask(self,task): self.anp.setY(0) self.anp2.setY(0) for i in range(self.ballNum+1): if i < len(self.ball): if self.ball[i].getX() > 234 or self.ball[i].getX() < -38 or self.ball[i].getZ() < -10 or self.ball[i].getZ() > 132: self.ball[i].setPos(self.ball[i].getPos()/1.005) z=random.randint(1,2) if z ==1: z=-1 else: z=1 self.movement[i]=Vec3(random.random()*z,0,random.random()*z) else: self.ball[i].setPos(self.ball[i].getPos()+self.movement[i]) return Task.cont def fire(self): self.fire = ParticleEffect() self.fire.reset() self.fire.setPos(0.000, 0.000, 0.000) self.fire.setHpr(0.000, 0.000, 0.000) self.fire.setScale(10.000, 10.000, 10.000) p0 = Particles('particles-1') # Particles parameters p0.setFactory("PointParticleFactory") p0.setRenderer("SpriteParticleRenderer") p0.setEmitter("DiscEmitter") p0.setPoolSize(1024) p0.setBirthRate(0.0200) p0.setLitterSize(10) p0.setLitterSpread(0) p0.setSystemLifespan(1200.0000) p0.setLocalVelocityFlag(1) p0.setSystemGrowsOlderFlag(0) # Factory parameters p0.factory.setLifespanBase(2.0000) p0.factory.setLifespanSpread(0.0000) p0.factory.setMassBase(1.0000) p0.factory.setMassSpread(0.0000) p0.factory.setTerminalVelocityBase(400.0000) p0.factory.setTerminalVelocitySpread(0.0000) # Point factory parameters # Renderer parameters p0.renderer.setAlphaMode(BaseParticleRenderer.PRALPHAOUT) p0.renderer.setUserAlpha(0.22) # Sprite parameters p0.renderer.addTextureFromFile('models/gamedev/sparkle.png') p0.renderer.setColor(Vec4(1.00, 1.00, 1.00, 1.00)) p0.renderer.setXScaleFlag(1) p0.renderer.setYScaleFlag(1) p0.renderer.setAnimAngleFlag(0) p0.renderer.setInitialXScale(0.5000) p0.renderer.setFinalXScale(2.0000) p0.renderer.setInitialYScale(1.0000) p0.renderer.setFinalYScale(2.0000) p0.renderer.setNonanimatedTheta(0.0000) p0.renderer.setAlphaBlendMethod(BaseParticleRenderer.PPNOBLEND) p0.renderer.setAlphaDisable(0) # Emitter parameters p0.emitter.setEmissionType(BaseParticleEmitter.ETRADIATE) p0.emitter.setAmplitude(1.0000) p0.emitter.setAmplitudeSpread(0.0000) p0.emitter.setOffsetForce(Vec3(0.0000, 0.0000, 3.0000)) p0.emitter.setExplicitLaunchVector(Vec3(1.0000, 0.0000, 0.0000)) p0.emitter.setRadiateOrigin(Point3(0.0000, 0.0000, 0.0000)) # Disc parameters p0.emitter.setRadius(0.5000) self.fire.addParticles(p0) self.fire.setPos(self.playerModel2.getPos()) t = Sequence(Func(self.fire.start, render, render),Wait(20),Func(self.cleanFire)) t.start() def cleanFire(self): self.fire.cleanup() def explode(self,cEntry): self.explosion = ParticleEffect() self.explosion.reset() self.explosion.setPos(cEntry.getIntoNodePath().getParent().getPos()) self.explosion.setHpr(0.000, 0.000, 0.000) self.explosion.setScale(10.000, 10.000, 10.000) p0 = Particles('particles-1') # Particles parameters p0.setFactory("PointParticleFactory") p0.setRenderer("LineParticleRenderer") p0.setEmitter("SphereVolumeEmitter") p0.setPoolSize(10000) p0.setBirthRate(0.0500) p0.setLitterSize(10000) p0.setLitterSpread(0) p0.setSystemLifespan(2.0000) p0.setLocalVelocityFlag(1) p0.setSystemGrowsOlderFlag(1) # Factory parameters p0.factory.setLifespanBase(2.0000) p0.factory.setLifespanSpread(0.0000) p0.factory.setMassBase(.5000) p0.factory.setMassSpread(0.0500) p0.factory.setTerminalVelocityBase(400.0000) p0.factory.setTerminalVelocitySpread(0.0000) # Point factory parameters # Renderer parameters p0.renderer.setAlphaMode(BaseParticleRenderer.PRALPHAOUT) p0.renderer.setUserAlpha(1.00) # Line parameters p0.renderer.setHeadColor(Vec4(1.00, 0.00, 0.00, 1.00)) p0.renderer.setTailColor(Vec4(1.00, 1.00, 0.00, 1.00)) p0.renderer.setLineScaleFactor(3.00) # Emitter parameters p0.emitter.setEmissionType(BaseParticleEmitter.ETRADIATE) p0.emitter.setAmplitude(10.0000) p0.emitter.setAmplitudeSpread(0.0000) p0.emitter.setOffsetForce(Vec3(0.0000, 0.0000, -0.4930)) p0.emitter.setExplicitLaunchVector(Vec3(1.0000, 0.0000, 0.0000)) p0.emitter.setRadiateOrigin(Point3(0.0000, 0.0000, 0.0000)) # Sphere Volume parameters p0.emitter.setRadius(0.5000) self.explosion.addParticles(p0) f0 = ForceGroup('gravity') # Force parameters self.explosion.addForceGroup(f0) cHandler = CollisionHandlerEvent() cHandler.addInPattern('%fn-into-%in') cSphereB = CollisionSphere(cEntry.getIntoNodePath().getParent().getPos(),1) cNodeB = CollisionNode("explosion") cNodeB.addSolid(cSphereB) cNodePathB = self.explosion.attachNewNode(cNodeB) self.cTrav.addCollider(cNodePathB,cHandler) cNodePathB.show() self.accept("player1-into-explosion",self.player2Wins) self.accept("player2-into-explosion",self.player1Wins) #f.reparentTo(self.playerModel) #self.explosion.setPos(self.playerModel.getPos()) t = Sequence(Func(self.explosion.start, render, render),Wait(2),Func(self.cleanExplo)) t.start() cEntry.getFromNodePath().getParent().removeNode() def cleanExplo(self): self.explosion.cleanup() def endGame(self,task): taskMgr.removeTasksMatching('returnSpeedsToNormal') taskMgr.removeTasksMatching('restoreCamera') taskMgr.removeTasksMatching('clockTask') taskMgr.removeTasksMatching('ballMoveTask') self.music.stop() self.music3 = loader.loadMusic("models/gamedev/CSTAR.mp3") self.music3.play() self.speed1 = 0 self.speed2 = 0 def getScores(self): return (self.player1Score, self.player2Score) def getGameLen(self): return self.gameLen def stopMusic(self): self.music3.stop() def destroy(self): self.playerModel.detachNode() self.playerModel2.detachNode() self.background.destroy() self.lava.detachNode() self.ladder.detachNode() self.ladder2.detachNode() for i in range(self.ballNum+1): self.ball[i].detachNode() def stopMusic(self): self.music3.stop() #world = Lvl03() #world.start() #run()
class World(DirectObject): def __init__(self): self.winprops=WindowProperties() self.winprops.setCursorFilename(Filename.binaryFilename("question-icon.ico")) base.win.setClearColorActive(True) base.win.setClearColor(VBase4(0, 0, 0, 1)) base.win.requestProperties(self.winprops) self.enemyLights = [] self.cameraPositions = [((0, 95, 75), (180, -27, 0)),((0, 55, 25), (180, -15, 0)),((0, -55, 25), (0, -15, 0))] self.cameraIndex = 0 base.disableMouse() base.enableParticles() self.setupLights() self.setupPicking() #Prepare the vehicular manslaughter! self.boosterLightNP = None self.flameLights = None self.player = Vehicle("ralph_models/vampire_car", "ralph_models/vampire_car", self, "player") self.finalGas = None self.livesFrame = DirectFrame(frameColor=(0, 0, 0, 0), parent = base.a2dTopLeft) self.livesSprites = list() for i in range(0,self.player.health): sprite = OnscreenImage(image = 'images/healthicon.png', parent = self.livesFrame, scale = 0.08, pos = (0.2*i+0.1,0,-0.1)) sprite.setTransparency(TransparencyAttrib.MAlpha) self.livesSprites.append(sprite) self.progressFrame = DirectFrame(frameColor=(0, 0, 0, 0), parent = base.a2dpTopRight) gasIcon = OnscreenImage(image = 'images/gas_icon.png', parent = self.progressFrame, scale = 0.04, pos = (-1,0,-0.05)) # gasIcon.reparentTo(aspect2d) gasIcon.setTransparency(TransparencyAttrib.MAlpha) # gasBar = OnscreenImage(image = 'images/gas_bar.png', parent = self.progressFrame, scale = 0.4)#, pos = (-0.9,0,-0.05)) self.gasMax = DirectFrame(frameColor=(.133, .149, .149, 1),frameSize=(-1, 1, -1, 1), parent = self.progressFrame, scale = (0.432,1,0.055625), pos = (-.5,0,-0.04)) self.gasLevel = DirectFrame(frameColor=(.433, .149, .149, 1),frameSize=(-1, -1, -1, 1), parent = self.progressFrame, scale = (0.432,1,0.055625), pos = (-.5,0,-0.04)) gasBar = OnscreenImage(image = 'images/gas_bar_border.png', scale = (1,1,.9), pos = (-.0005,0,-0.04)) gasBar.reparentTo(self.gasLevel) gasBar.setTransparency(TransparencyAttrib.MAlpha) timeBar = OnscreenImage(image = 'images/time_bar.png', parent = self.progressFrame, scale = (0.44,1,0.0525), pos = (-.47,0,-0.15)) self.timePointer = OnscreenImage(image = 'images/time_bar_marker.png', parent = timeBar, scale = (0.05, 0, .2222), pos = (-.83,0,-0.15)) # self.timePointer = OnscreenImage(image = 'images/time_bar_marker.png', parent = self.timeBar, scale = (0.44,1,0.0525), pos = (-.47,0,-0.2)) timeBar.setTransparency(TransparencyAttrib.MAlpha) taskMgr.add(self.updateGasBar, "Update gas") self.loadModels() self.player.setPos(0,0,0) self.setupIntervals() camera.reparentTo(self.player) camera.setPos(self.cameraPositions[0][0][0],self.cameraPositions[0][0][1],self.cameraPositions[0][0][2]) camera.setHpr(self.cameraPositions[0][1][0],self.cameraPositions[0][1][1],self.cameraPositions[0][1][2]) self.setupCollisions() render.setShaderAuto() #you probably want to use this self.keyMap = {"left":0, "right":0, "forward":0, "backwards":0} taskMgr.add(self.player.move, "moveTask") #Give the vehicle direct access to the keyMap self.player.addKeyMap(self.keyMap) #Player Death taskMgr.add(self.deathChecker, "deathTask") #Sounds! self.loadSounds() self.currIcon = "" self.prevtime = 0 self.isMoving = False self.accept("escape", sys.exit) self.accept("arrow_up", self.setKey, ["forward", 1]) self.accept("w", self.setKey, ["forward", 1]) self.accept("arrow_right", self.setKey, ["right", 1]) self.accept("d", self.setKey, ["right", 1]) self.accept("arrow_left", self.setKey, ["left", 1]) self.accept("a", self.setKey, ["left", 1]) self.accept("arrow_down", self.setKey, ["backwards", 1]) self.accept("s", self.setKey, ["backwards", 1]) self.accept("arrow_up-up", self.setKey, ["forward", 0]) self.accept("w-up", self.setKey, ["forward", 0]) self.accept("arrow_right-up", self.setKey, ["right", 0]) self.accept("d-up", self.setKey, ["right", 0]) self.accept("arrow_left-up", self.setKey, ["left", 0]) self.accept("a-up", self.setKey, ["left", 0]) self.accept("arrow_down-up", self.setKey, ["backwards", 0]) self.accept("s-up", self.setKey, ["backwards", 0]) self.accept("mouse1", self.startShoot) self.accept("mouse1-up", self.stopShoot) self.accept("mouse3", self.startDrain ) self.accept("mouse3-up" , self.stopDrain) self.accept("tab", self.shiftCamera) self.accept("space", self.player.startBoosters) self.accept("ate-smiley", self.eat) self.p1 = ParticleEffect() self.p2 = ParticleEffect() self.alan_var = False #Show collisiony stuff if DEBUG: base.cTrav.showCollisions(render) #f = open('testLog.txt', 'r+') #self.dfs(file = f) self.gasPlaying = False self.setLights() self.draining = False taskMgr.add(self.drain, 'drain') self.drainTime = 0.0 self.flamethrowerActive = False self.gasLossTime = 0.0 self.gasLossRate = 1.0 taskMgr.add(self.loseHealth, "loseGas") #After all the loading, we need to calculate our start time self.startTime = datetime.datetime.now() self.timeLimit = datetime.timedelta(seconds=175) timeInterval = LerpPosInterval(self.timePointer, self.timeLimit.seconds, (.8,0,-0.2)) timeInterval.start() def setupPicking(self): self.picker = CollisionTraverser() self.pq = CollisionHandlerQueue() self.pickerNode = CollisionNode('mouseRay') self.pickerNP = camera.attachNewNode(self.pickerNode) self.pickerNode.setFromCollideMask(BitMask32.bit(1)) self.pickerRay = CollisionRay() self.pickerNode.addSolid(self.pickerRay) self.picker.addCollider(self.pickerNP, self.pq) self.staticRoot = render.attachNewNode('staticRoot') self.mouseTask = taskMgr.add(self.mouseTask, 'mouseTask') def dfs(self, item = render, depth = 0, file = None): if file: file.write(("-" * depth) + item.getName() + ": \n") # print(("-" * depth) + item.getName() + ": ") for i in range(item.getNumNodes()): if file: file.write((" " * depth) + "+" + item.getNode(i).getName() + ": " + str(item.getNode(i).getClassType()) + "\n") # print((" " * depth) + "+" + item.getNode(i).getName() + ": " + str(item.getNode(i).getClassType())) for i in range(item.getNumChildren()): self.dfs(item.getChild(i), depth + 1, file) def startDrain(self): if not self.flamethrowerActive: prevDraining = self.draining #previous value of draining if base.mouseWatcherNode.hasMouse(): mpos = base.mouseWatcherNode.getMouse() self.pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY()) self.picker.traverse(self.staticRoot) if self.pq.getNumEntries() > 0: self.pq.sortEntries() for i in range(self.pq.getNumEntries()): if self.pq.getEntry(i).getIntoNode().getTag('car') != "": self.target = int(self.pq.getEntry(i).getIntoNode().getTag('car')) self.draining = True #Start sounds if self.draining started if self.draining and not prevDraining: self.drainSound.play() def drain(self, task): if self.draining and task.time - self.drainTime > DRAIN_DELAY: carpos = self.staticCars[self.target].getPos() playerpos = self.player.getPos() dist = math.sqrt( (carpos[0] - playerpos[0])**2 + (carpos[1] - playerpos[1])**2 + (carpos[2] - playerpos[2])**2 ) if self.gasList[self.target] > 0 and dist < DRAIN_DIST: if not self.gasPlaying: self.gasP.reset() self.gasP = ParticleEffect() self.gasP.loadConfig(Filename('oil.ptf')) self.gasP.start(self.player) self.gasNode.lookAt(self.staticCars[self.target]) self.gasP.setPos(0,0,2) self.gasP.setScale(1.5) self.gasP.setLightOff() self.gasPlaying = True self.alan_var = False self.gasNode.lookAt(self.staticCars[self.target]) self.gasP.setHpr(self.gasNode.getH() + 180, 90, 0) self.player.totalGas = self.player.totalGas + 1 self.gasList[self.target] = self.gasList[self.target] - 1 else: self.alan_var = True # print "TotalGas: " + str(self.player.totalGas) self.drainTime = task.time elif not self.draining or self.alan_var: self.gasP.softStop() self.drainSound.stop() self.gasPlaying = False return Task.cont def stopDrain(self): self.draining = False def loseHealth(self, task): if task.time - self.gasLossTime > GAS_TIME: if self.player.direction != 0: self.player.totalGas = self.player.totalGas - self.gasLossRate elif self.flamethrowerActive: self.player.totalGas = self.player.totalGas - self.gasLossRate self.gasLossTime = task.time # print self.player.totalGas return Task.cont def mouseTask(self, task): j = -1 if base.mouseWatcherNode.hasMouse(): mpos = base.mouseWatcherNode.getMouse() self.pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY()) self.picker.traverse(self.staticRoot) if self.pq.getNumEntries() > 0: self.pq.sortEntries() for i in range(self.pq.getNumEntries()): if self.pq.getEntry(i).getIntoNode().getTag('car') != "": j = int(self.pq.getEntry(i).getIntoNode().getTag('car')) carpos = self.staticCars[j].getPos() playerpos = self.player.getPos() dist = math.sqrt( (carpos[0] - playerpos[0])**2 + (carpos[1] - playerpos[1])**2 + (carpos[2] - playerpos[2])**2 ) if self.gasList[j] > 0 and dist < DRAIN_DIST: self.winprops.setCursorFilename(Filename.binaryFilename("vamp-icon.ico")) base.win.requestProperties(self.winprops) elif self.gasList[j] > 0: self.winprops.setCursorFilename(Filename.binaryFilename("vamp-off.ico")) base.win.requestProperties(self.winprops) else: self.winprops.setCursorFilename(Filename.binaryFilename("empty-icon.ico")) base.win.requestProperties(self.winprops) break if j == -1: self.winprops.setCursorFilename(Filename.binaryFilename("question-icon.ico")) base.win.requestProperties(self.winprops) #print j return Task.cont def setupIntervals(self): self.lightOn = LerpFunc(self.lightModify, fromData=0, toData=100, duration=0.2, blendType='noBlend', extraArgs=[True], name="LightUp") self.lightOff = LerpFunc(self.lightModify, fromData=0, toData=100, duration=0.2, blendType='noBlend', extraArgs=[False], name="LightDown") self.cameraMove = None def setKey(self, key, value): self.keyMap[key] = value def setWorldLight(self, object): object.setLight(self.keyLightNP) object.setLight(self.fillLightNP) object.setLight(self.boosterLightNP) for light in self.enemyLights: object.setLight(light) def setLights(self): self.setWorldLight(self.player) self.setWorldLight(self.env) for enemy in self.enemies: self.setWorldLight(enemy) for car in self.staticCars: self.setWorldLight(car) def shiftCamera(self): if self.cameraMove: self.cameraMove.finish() old = self.cameraIndex self.cameraIndex += 1 if self.cameraIndex == len(self.cameraPositions): self.cameraIndex = 0 self.cameraMove=LerpPosHprInterval(camera, .7, self.cameraPositions[self.cameraIndex][0], self.cameraPositions[self.cameraIndex][1], camera.getPos(), camera.getHpr()) self.cameraMove.start() def loadModels(self): self.player.setupBooster() self.env = loader.loadModel("ralph_models/final_terrain") self.env.reparentTo(render) self.env.setScale(8) # Gas particles self.gasP = ParticleEffect() self.gasNode = self.player.attachNewNode('gasNode') # Node Map map = Node.NodeMap("nodes.txt") # enemies self.enemies = [] file = open('levels/enemies.txt' ) line = file.readline().rstrip() self.staticCars = [] self.gasList = [] for currCar in carLocations.cars: target = loader.loadModel("ralph_models/" + currCar['color'] + "_car") target.setPos(currCar['position']) target.setHpr(currCar['direction']) target.reparentTo(self.staticRoot) self.staticCars.append(target) self.gasList.append(currCar['gas']) while line != "" : nums = line.split(',') convertedNums = [] for i in range(len(nums)): if i != 0: convertedNums.append(int(nums[i])) nodePos = map.nodeList[int(nums[0])].getPos() newEnemy = Enemy.Enemy(map, convertedNums, self, nodePos[0], nodePos[1], nodePos[2] ) self.enemies.append( newEnemy ) taskMgr.add(newEnemy.move, "Enemy Move " + str(i), extraArgs = [map], appendTask = True) line = file.readline().rstrip() i = i + 1 def loadSounds(self): self.flamethrowerSound = base.loader.loadSfx("sound/dragonflameloop2.wav") self.flamethrowerEndSound = base.loader.loadSfx("sound/dragonflameend.wav") self.collideSound = base.loader.loadSfx("sound/collide.wav") self.drainSound = base.loader.loadSfx("sound/gas_pump.wav") self.drainSound.setLoop(True) def setupLights(self): #ambient light self.ambientLight = AmbientLight("ambientLight") #four values, RGBA (alpha is largely irrelevent), value range is 0:1 self.ambientLight.setColor((.30, .30, .30, 1)) self.ambientLightNP = render.attachNewNode(self.ambientLight) #the nodepath that calls setLight is what gets illuminated by the light render.setLight(self.ambientLightNP) #call clearLight() to turn it off self.keyLight = DirectionalLight("keyLight") self.keyLight.setColor((.50,.50,.50, 1)) self.keyLightNP = render.attachNewNode(self.keyLight) self.keyLightNP.setHpr(0, -26, 0) self.fillLight = DirectionalLight("fillLight") self.fillLight.setColor((.05,.05,.05, 1)) self.fillLightNP = render.attachNewNode(self.fillLight) self.fillLightNP.setHpr(30, 0, 0) def setupCollisions(self): base.cTrav = CollisionTraverser() self.playerRay = CollisionRay() self.playerRay.setOrigin(0,0,1000) self.playerRay.setDirection(0,0,-1) self.playerNode = CollisionNode("playerRay") self.playerNode.addSolid(self.playerRay) self.playerNode.setFromCollideMask(BitMask32.bit(0)) self.playerNode.setIntoCollideMask(BitMask32.allOff()) self.playerNodePath = self.player.attachNewNode(self.playerNode) self.playerNodePath.show() self.playerGroundHandler = CollisionHandlerQueue() base.cTrav.addCollider(self.playerNodePath, self.playerGroundHandler) envcNode1 = CollisionNode("lot_bottom") envcNode1.setFromCollideMask(BitMask32.bit(0)) temp = CollisionPolygon(Point3(12.56, 19.182, 0), Point3(12.56, -21.261, 0), Point3(-13.217, -21.261, 0), Point3(-13.217, 19.182, 0)) envcNode1.addSolid(temp) envcNode2 = CollisionNode("lot_ramp_bottom") envcNode2.setFromCollideMask(BitMask32.bit(0)) temp = CollisionPolygon(Point3(32.715, -14.923, 3.5), Point3(32.715, -21.261, 3.5), Point3(12.56, -21.261, 0), Point3(12.56, -14.923, 0)) envcNode2.addSolid(temp) envcNode3 = CollisionNode("lot_middle") envcNode3.setFromCollideMask(BitMask32.bit(0)) temp = CollisionPolygon(Point3(42.715, -14.923, 3.5), Point3(42.715, -21.261, 3.5), Point3(32.715, -21.261, 3.5), Point3(32.715, -14.923, 3.5)) envcNode3.addSolid(temp) envcNode4 = CollisionNode("lot_ramp_top") envcNode4.setFromCollideMask(BitMask32.bit(0)) temp = CollisionPolygon(Point3(42.715, -8.845, 6), Point3(42.715, -14.923, 3.5), Point3(32.715, -14.923, 3.5), Point3(32.715, -8.845, 6)) envcNode4.addSolid(temp) envcNode5 = CollisionNode("lot_top") envcNode5.setFromCollideMask(BitMask32.bit(0)) temp = CollisionPolygon(Point3(42.715, 16.155, 6), Point3(42.715, -8.845, 6), Point3(17.715, -8.845, 6), Point3(17.715, 16.155, 6)) envcNode5.addSolid(temp) wallCNode = CollisionNode("fence") wallCNode.setFromCollideMask(BitMask32.bit(0)) temp = CollisionPolygon(Point3(12.56, 19.182, 0), Point3(12.56, -14.923, 0), Point3(12.56, -14.923, 10), Point3(12.56, 19.182, 10)) wallCNode.addSolid(temp) temp = CollisionPolygon(Point3(12.56, -14.923, 0), Point3(32.715, -14.923, 3.5), Point3(32.715, -14.923, 10), Point3(12.56, -14.923, 10)) wallCNode.addSolid(temp) temp = CollisionPolygon(Point3(32.715, -14.923, 3.5), Point3(32.715, -8.845, 6), Point3(32.715, -8.845, 10), Point3(32.715, -14.923, 10)) wallCNode.addSolid(temp) temp = CollisionPolygon(Point3(32.715, -8.845, 6), Point3(17.715, -8.845, 6), Point3(17.715, -8.845, 10), Point3(32.715, -8.845, 10)) wallCNode.addSolid(temp) temp = CollisionPolygon(Point3(17.715, -8.845, 6), Point3(17.715, 16.155, 6), Point3(17.715, 16.155, 10), Point3(17.715, -8.845, 10)) wallCNode.addSolid(temp) temp = CollisionPolygon(Point3(17.715, 16.155, 6), Point3(42.715, 16.155, 6), Point3(42.715, 16.155, 10), Point3(17.715, 16.155, 10)) wallCNode.addSolid(temp) temp = CollisionPolygon(Point3(42.715, 16.155, 6), Point3(42.715, -8.845, 6), Point3(42.715, -8.845, 10), Point3(42.715, 16.155, 10)) wallCNode.addSolid(temp) temp = CollisionPolygon(Point3(42.715, -8.845, 6), Point3(42.715, -14.923, 3.5), Point3(42.715, -14.923, 10), Point3(42.715, -8.845, 10)) wallCNode.addSolid(temp) temp = CollisionPolygon(Point3(42.715, -14.923, 3.5), Point3(42.715, -21.261, 3.5), Point3(42.715, -21.261, 10), Point3(42.715, -14.923, 10)) wallCNode.addSolid(temp) temp = CollisionPolygon(Point3(42.715, -21.261, 3.5), Point3(32.715, -21.261, 3.5), Point3(32.715, -21.261, 10), Point3(42.715, -21.261, 10)) wallCNode.addSolid(temp) temp = CollisionPolygon(Point3(32.715, -21.261, 3.5), Point3(12.56, -21.261, 0), Point3(12.56, -21.261, 10), Point3(32.715, -21.261, 10)) wallCNode.addSolid(temp) temp = CollisionPolygon(Point3(12.56, -21.261, 0), Point3(-13.217, -21.261, 0), Point3(-13.217, -21.261, 10), Point3(12.56, -21.261, 10)) wallCNode.addSolid(temp) temp = CollisionPolygon(Point3(-13.217, -21.261, 0), Point3(-13.217, 19.182, 0), Point3(-13.217, 19.182, 10), Point3(-13.217, -21.261, 10)) wallCNode.addSolid(temp) temp = CollisionPolygon(Point3(-13.217, 19.182, 0), Point3(12.56, 19.182, 0), Point3(12.56, 19.182, 10), Point3(-13.217, 19.182, 10)) wallCNode.addSolid(temp) envcNodePath1 = self.env.attachNewNode(envcNode1) envcNodePath2 = self.env.attachNewNode(envcNode2) envcNodePath3 = self.env.attachNewNode(envcNode3) envcNodePath4 = self.env.attachNewNode(envcNode4) envcNodePath5 = self.env.attachNewNode(envcNode5) self.cHandler = CollisionHandlerEvent() pusher = CollisionHandlerPusher() self.wallNode = self.env.attachNewNode('wallNode') wallCNodePath = self.wallNode.attachNewNode(wallCNode) if DEBUG: wallCNodePath.show() cNode = CollisionNode("player") temp = CollisionSphere((0,-5.5,10), 4) cNode.addSolid(temp) temp = CollisionSphere((0,-0.5,10), 4) cNode.addSolid(temp) temp = CollisionSphere((0,3.5,10), 4) cNode.addSolid(temp) cNode.setIntoCollideMask(BitMask32.allOff()) #player is *only* a from object cNodePath = self.player.attachNewNode(cNode) if DEBUG: cNodePath.show() base.cTrav.addCollider(cNodePath, pusher) pusher.addCollider(cNodePath, self.player) pusher.addInPattern('%fn-into-%in') self.accept('player-into-fence', self.collideWithFence) self.accept('player-into-staticCar', self.collideOther) self.accept('player-into-droneNode', self.collideOther) self.playerLightCollision = CollisionHandlerEvent() self.playerLightCollision.addInPattern('into-%in') cNode2 = CollisionNode("playerinto") #cNode.addSolid(segment1) #cNode.addSolid(segment2) #cNode.addSolid(segment3) #cNode.addSolid(segment4) temp = CollisionSphere((0,-5.5,1), 4) cNode2.addSolid(temp) temp = CollisionSphere((0,-0.5,1), 4) cNode2.addSolid(temp) temp = CollisionSphere((0,3.5,1), 4) cNode2.addSolid(temp) cNode2.setFromCollideMask(BitMask32.allOff()) #player is *only* a from object cNodePath2 = self.player.attachNewNode(cNode2) if DEBUG: cNodePath2.show() # FLAMETHROWER COLLISIONS # left flamethrowerLeft = CollisionSegment() flamethrowerLeft.setPointA(-2 , -4, 10) flamethrowerLeft.setPointB( -2 , -20 , 10 ) # middle flamethrowerMiddle = CollisionSegment() flamethrowerMiddle.setPointA(0 , -4, 10) flamethrowerMiddle.setPointB( 0 , -20 , 10 ) # right flamethrowerRight = CollisionSegment() flamethrowerRight.setPointA(2, -4, 10) flamethrowerRight.setPointB( 2 , -20 , 10 ) flamethrowerNode = CollisionNode("flamethrower") flamethrowerNode.addSolid(flamethrowerLeft) flamethrowerNode.addSolid(flamethrowerMiddle) flamethrowerNode.addSolid(flamethrowerRight) flamethrowerNode.setIntoCollideMask(BitMask32.allOff()) flamethrowerNode.setFromCollideMask(BitMask32.allOn()) flamethrowerNodePath = self.player.attachNewNode(flamethrowerNode) #flamethrowerNodePath.show() self.flamethrowerCollision = CollisionHandlerEvent() self.flamethrowerCollision.addInPattern('into-%in') base.cTrav.addCollider(flamethrowerNodePath, self.flamethrowerCollision) self.accept('into-droneNode', self.hitEnemy) for i in range(len(self.staticCars)): staticNode = CollisionNode("staticCar") temp = CollisionSphere((0,-5.2,10), 4) staticNode.addSolid(temp) temp = CollisionSphere((0,-0.5,10), 4) staticNode.addSolid(temp) temp = CollisionSphere((0,5.5,10), 4) staticNode.addSolid(temp) staticNode.setIntoCollideMask(BitMask32.bit(1)) staticNode.setFromCollideMask(BitMask32.bit(0)) staticNodePath = self.staticCars[i].attachNewNode(staticNode) temp = CollisionTube(0,7,3,0,-6,3,3.5) sN = CollisionNode("staticTube") sN.addSolid(temp) staticNode.setFromCollideMask(BitMask32.bit(0)) sNP = self.staticCars[i].attachNewNode(sN) sN.setTag('car', str(i)) self.enemyHandler = CollisionHandlerEvent() for i in range(len(self.enemies)): collideNode = CollisionNode("droneNode") temp = CollisionSphere((0,0,10), 4) collideNode.addSolid(temp) collideNode.setIntoCollideMask(BitMask32.bit(1)) collideNode.setFromCollideMask(BitMask32.bit(0)) enemycollideNodePath = self.enemies[i].attachNewNode(collideNode) collideNode.setTag('enemy',str(i)) self.enemies[i].lightRay = CollisionSegment() self.enemies[i].lightRay.setPointA(0, -4, 4) self.enemies[i].lightRay.setPointB( 0 , -100 , 0 ) # left self.enemies[i].lightRayLeft = CollisionSegment() self.enemies[i].lightRayLeft.setPointA(0, -4, 4) self.enemies[i].lightRayLeft.setPointB( -5 , -100 , 0 ) # right self.enemies[i].lightRayRight = CollisionSegment() self.enemies[i].lightRayRight.setPointA(0, -4, 4) self.enemies[i].lightRayRight.setPointB( 5 , -100 , 0 ) self.enemies[i].lightRayNode = CollisionNode("lightRay") self.enemies[i].lightRayNode.addSolid(self.enemies[i].lightRay) self.enemies[i].lightRayNode.addSolid(self.enemies[i].lightRayLeft) self.enemies[i].lightRayNode.addSolid(self.enemies[i].lightRayRight) self.enemies[i].lightRayNode.setTag('enemy',str(i)) self.enemies[i].lightRayNode.setIntoCollideMask(BitMask32.allOff()) self.enemies[i].lightRayNodePath = self.enemies[i].attachNewNode(self.enemies[i].lightRayNode) if DEBUG: self.enemies[i].lightRayNodePath.show() base.cTrav.addCollider(self.enemies[i].lightRayNodePath, self.playerLightCollision) self.accept('into-playerinto', self.player.takeHit) def collideWithFence(self, entry): self.player.speed = self.player.speed * 0.9 if self.collideSound.status() != AudioSound.PLAYING: self.collideSound.play() def collideOther(self, entry): self.player.speed = self.player.speed * 0.9 if self.collideSound.status() != AudioSound.PLAYING: self.collideSound.play() def lightModify(self, t, which_way): if which_way: #which_way == true then make it brighter value = t/100 * MAX_LIGHT else: #which_way == true then make it darker value = (100 - t)/100 * MAX_LIGHT for light in self.flameLights: light[0].setColor(VBase4(value,value,value,1)) def startShoot(self): self.loadParticleConfig('flamethrower6.ptf') #self.lightOff.finish() #self.lightOn.start() #Get the flame noise started! self.flamethrowerSound.setLoop(True) self.flamethrowerSound.play() self.flamethrowerActive = True self.draining = False self.gasLossRate = 2.0 def stopShoot(self): self.p1.softStop() self.p2.softStop() #self.lightOn.finish() #self.lightOff.start() self.flamethrowerSound.stop() self.flamethrowerEndSound.play() self.flamethrowerActive = False self.gasLossRate = 1.0 def hitEnemy(self, entry): if self.flamethrowerActive: index = int(entry.getIntoNode().getTag('enemy')) if self.enemies[index].phase != STOPPED: self.enemies[index].prevPhase = self.enemies[index].phase self.enemies[index].phase = STOPPED self.enemies[index].headlight1.setColor(VBase4(0, 0, 0, 0)) def loadParticleConfig(self, file): self.p1.reset() self.p1 = ParticleEffect() self.p1.loadConfig(Filename(file)) self.p1.start(self.player) self.p1.setPos(-1.75, -10, 1.375) self.p1.setHpr(0, 90, 0) self.p1.setScale(2.0) self.p1.setLightOff() self.p2.reset() self.p2 = ParticleEffect() self.p2.loadConfig(Filename(file)) self.p2.start(self.player) self.p2.setPos(1.75, -10, 1.375) self.p2.setHpr(0, 90, 0) self.p2.setScale(2.0) self.p2.setLightOff() def eat(self, cEntry): """handles the player eating a smiley""" #remove target from list of targets self.targets.remove(cEntry.getIntoNodePath().getParent()) #remove from scene graph cEntry.getIntoNodePath().getParent().remove() def changeMouseCursor(self, cursorFile): if self.currIcon != cursorFile: self.currIcon = cursorFile # winprops.getParentWindow().getXSize() # print winprops.getXSize() # print "test" self.winprops.setCursorFilename(Filename.binaryFilename(cursorFile)) def deathChecker(self, task): font = loader.loadFont('fonts/beneg.ttf') #Check for out of time currTime = datetime.datetime.now() if currTime > self.startTime + self.timeLimit or self.player.totalGas >= MAX_GAS: #print "OUT OF TIME!!!!!!!!!!!" if self.finalGas is None: self.finalGas = self.player.totalGas taskMgr.doMethodLater(5, self.STOPGAME, 'tickTask') self.loading = OnscreenImage(image = 'images/victory.png', scale = (1.3333333,0, 1)) self.text = OnscreenText(text = "Gas Collected%s" %(self.finalGas), font = font, pos = (0,.2), fg = (255,255,255,1)) #Check for death elif self.player.dead: if self.finalGas is None: self.finalGas = self.player.totalGas #print "THE PLAYER IS DEAD!!!!!!!!!!" taskMgr.doMethodLater(5, self.STOPGAME, 'tickTask') self.loading = OnscreenImage(image = 'images/lose_death.png', scale = (1.3333333,0, 1)) self.text = OnscreenText(text = "Gas Collected %s" %(self.finalGas), font = font, pos = (0,.1), fg = (255,255,255,1)) elif self.player.totalGas <= 0: #print "YOU SUCK. YOU RAN OUT OF GAS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" taskMgr.doMethodLater(5, self.STOPGAME, 'tickTask') self.loading = OnscreenImage(image = 'images/lose_nogas.png', scale = (1.3333333,0, 1)) return Task.cont def updateGasBar(self, task): self.gasLevel['frameSize'] = (-1,(self.player.totalGas / MAX_GAS)*2 - 1, -1, 1) return Task.cont def STOPGAME(self, SOMETHNG): taskMgr.stop()