def onHit(self, damage, sound="hit"): if self.state == "DIE": return self.doDamage(damage) #print damage vfx(self.node, texture=self.vfx, scale=.5, Z=1.0, depthTest=True, depthWrite=True).start(0.016) if self.stats['hp'] < 1: self.actor.play("die") #self.sounds["die"].play() if sound: self.common['soundPool'].play(self.soundID, self.sound_names[sound]) self.common['soundPool'].play(self.soundID, self.sound_names["die"]) self.state = "DIE" else: #self.sounds["hit"].play() if sound: self.common['soundPool'].play(self.soundID, self.sound_names[sound])
def onSparkHit(self, damage): if self.state == "DIE": return #print damage self.doDamage(damage) #self.soundset["spark"].play() self.common['soundPool'].play(self.soundID, "spark") if self.stats['hp'] < 1: self.actor.play("die") #self.soundset["die3"].play() self.common['soundPool'].play(self.soundID, "die3") self.state = "DIE" vfx(self.node, texture=self.vfx, scale=.5, Z=1.0, depthTest=True, depthWrite=True).start(0.016) else: short_vfx(self.node, texture="vfx/short_spark.png", scale=.5, Z=1.0, depthTest=True, depthWrite=True).start(0.03)
def damageOverTime(self, task): if self.state=="DIE": return task.done if self.DOT>0: self.doDamage(self.DOT) self.DOT=int((self.DOT*0.9)-1.0) vfx(self.node, texture='vfx/blood_dark.png',scale=.5, Z=1.0, depthTest=True, depthWrite=True).start(0.016) return task.again
def onPlasmaHit(self, damage): if self.state=="DIE": return self.doDamage(damage*1.5, True) #self.soundset["spark"].play() #self.common['soundPool'].play(self.soundID, "spark") if self.stats['hp']<1: self.actor.play("die") #self.soundset["die3"].play() self.common['soundPool'].play(self.soundID, "die3") self.state="DIE" vfx(self.node, texture=self.vfx,scale=.5, Z=1.0, depthTest=True, depthWrite=True).start(0.016)
def onMagmaHit(self): if self.state=="DIE": return damage=self.lastMagmaDmg self.doDamage(damage) self.common['soundPool'].play(self.soundID, "onFire") vfx(self.node, texture="vfx/small_flame.png",scale=.6, Z=.7, depthTest=False, depthWrite=False).start(0.016, stopAtFrame=24) if self.stats['hp']<1: self.actor.play("die") self.common['soundPool'].play(self.soundID, "die3") self.state="DIE" vfx(self.node, texture=self.vfx,scale=.5, Z=1.0, depthTest=True, depthWrite=True).start(0.016)
def damageOverTime(self, task): if self.state=="DIE": return task.done if self.DOT>0: self.doDamage(self.DOT) self.DOT=int((self.DOT*0.9)-1.0) if self.stats['hp']<1: self.actor.play("die") #self.common['soundPool'].play(self.soundID, self.sound_names["hit"]) self.common['soundPool'].play(self.soundID, self.sound_names["die"]) self.state="DIE" vfx(self.node, texture=self.vfx,scale=.5, Z=1.0, depthTest=True, depthWrite=True).start(0.016, 24) return task.again
def damageOverTime(self, task): if self.state == "DIE": return task.done if self.DOT > 0: self.doDamage(self.DOT) self.DOT = int((self.DOT * 0.9) - 1.0) if self.stats['hp'] < 1: self.die(self.sound_names["die"]) vfx(self.node, texture=self.vfx, scale=.5, Z=1.0, depthTest=True, depthWrite=True).start(0.016, 24) return task.again
def onSparkHit(self, damage): if self.state=="DIE": return #print damage self.doDamage(damage) #self.soundset["spark"].play() self.common['soundPool'].play(self.soundID, "spark") if self.stats['hp']<1: self.actor.play("die") #self.soundset["die3"].play() self.common['soundPool'].play(self.soundID, "die3") self.state="DIE" vfx(self.node, texture=self.vfx,scale=.5, Z=1.0, depthTest=True, depthWrite=True).start(0.016) else: short_vfx(self.node, texture="vfx/short_spark.png",scale=.5, Z=1.0, depthTest=True, depthWrite=True).start(0.03)
def onPlasmaHit(self, damage): if self.state == "DIE": return self.doDamage(damage * 1.5, True) #self.soundset["spark"].play() #self.common['soundPool'].play(self.soundID, "spark") if self.stats['hp'] < 1: self.actor.play("die") #self.soundset["die3"].play() self.common['soundPool'].play(self.soundID, "die3") self.state = "DIE" vfx(self.node, texture=self.vfx, scale=.5, Z=1.0, depthTest=True, depthWrite=True).start(0.016)
def onHit(self, damage, sound="hit"): if self.state=="DIE": return self.doDamage(damage) #print damage vfx(self.node, texture=self.vfx,scale=.5, Z=1.0, depthTest=True, depthWrite=True).start(0.016) if self.stats['hp']<1: self.actor.play("die") #self.sounds["die"].play() if sound: self.common['soundPool'].play(self.soundID, self.sound_names[sound]) self.common['soundPool'].play(self.soundID, self.sound_names["die"]) self.state="DIE" else: #self.sounds["hit"].play() if sound: self.common['soundPool'].play(self.soundID, self.sound_names[sound])
def damageOverTime(self, task): if self.state == "DIE": return task.done if self.DOT > 0: self.doDamage(self.DOT) self.DOT = int((self.DOT * 0.9) - 1.0) if self.stats['hp'] < 1: self.actor.play("die") #self.common['soundPool'].play(self.soundID, self.sound_names["hit"]) self.common['soundPool'].play(self.soundID, self.sound_names["die"]) self.state = "DIE" vfx(self.node, texture=self.vfx, scale=.5, Z=1.0, depthTest=True, depthWrite=True).start(0.016, 24) return task.again
def onHit(self, damage, sound="hit", weapon=None): if self.state == "DIE": return if weapon == "magma": damage = self.lastMagmaDmg self.common['soundPool'].play(self.soundID, "onFire") vfx(self.node, texture="vfx/small_flame.png", scale=.6, Z=.7, depthTest=False, depthWrite=False).start(0.016, stopAtFrame=24) elif weapon == "spark": self.common['soundPool'].play(self.soundID, "spark") short_vfx(self.node, texture="vfx/short_spark.png", scale=.5, Z=1.0, depthTest=True, depthWrite=True).start(0.03) else: vfx(self.node, texture=self.vfx, scale=.5, Z=1.0, depthTest=True, depthWrite=True).start(0.016) self.doDamage(damage) if self.stats['hp'] < 1: if sound: self.common['soundPool'].play(self.soundID, self.sound_names[sound]) self.die(self.sound_names["die"]) else: if sound: self.common['soundPool'].play(self.soundID, self.sound_names[sound])
def onMagmaHit(self): if self.state == "DIE": return damage = self.lastMagmaDmg self.doDamage(damage) self.common['soundPool'].play(self.soundID, "onFire") vfx(self.node, texture="vfx/small_flame.png", scale=.6, Z=.7, depthTest=False, depthWrite=False).start(0.016, stopAtFrame=24) if self.stats['hp'] < 1: self.actor.play("die") self.common['soundPool'].play(self.soundID, "die3") self.state = "DIE" vfx(self.node, texture=self.vfx, scale=.5, Z=1.0, depthTest=True, depthWrite=True).start(0.016)
def load(self): self.newGame = True self.font = loader.loadFont('Bitter-Bold.otf') self.common['font'] = self.font self.common['pc_stat1'] = 50 self.common['pc_stat2'] = 50 self.common['pc_stat3'] = 50 #render.setShaderAuto() #base.disableMouse() #render.setAntialias(AntialiasAttrib.MMultisample) #base.setBackgroundColor(0, 0, 0) wp = base.win.getProperties() winX = wp.getXSize() winY = wp.getYSize() self.campmap = loader.loadModel("models/camp3") self.campmap.reparentTo(render) #music self.common['music'] = MusicPlayer(self.common) self.common['music'].loop(0) #self.common['music']=base.loadMusic("music/LuridDeliusion.ogg") #self.common['music'].setLoop(True) #self.common['music'].play() self.common["random-objects-freq"] = 0.65 self.node = render.attachNewNode("node") self.cameraNode = self.node.attachNewNode("cameraNode") self.cameraNode.setZ(-1) base.camera.setY(-8) base.camera.setZ(5) base.camera.lookAt((0, 3, 0)) base.camera.wrtReparentTo(self.cameraNode) self.pointer = self.cameraNode.attachNewNode("pointerNode") #light self.pLight = PointLight('plight') self.pLight.setColor(VBase4(1, .95, .9, 1)) self.pLight.setAttenuation(Point3(.5, 0, 0.1)) self.pLightNode = self.node.attachNewNode(self.pLight) self.pLightNode.setZ(1.0) render.setLight(self.pLightNode) self.sLight = Spotlight('sLight') self.sLight.setColor(VBase4(.4, .25, .25, 1)) if self.common['extra_ambient']: self.sLight.setColor(VBase4(.7, .5, .5, 1)) spot_lens = PerspectiveLens() spot_lens.setFov(40) self.sLight.setLens(spot_lens) self.Ambient = self.cameraNode.attachNewNode(self.sLight) self.Ambient.setPos(base.camera.getPos(render)) self.Ambient.lookAt((0, 3, 0)) render.setLight(self.Ambient) self.fire_node = self.node.attachNewNode("fireNode") self.fire = vfx(self.fire_node, texture='vfx/big_fire3.png', scale=.29, Z=.5, depthTest=True, depthWrite=True) self.fire.show() self.fire.loop(0.02) self.character1 = Actor( "models/pc/male", { "attack": "models/pc/male_attack2", "idle": "models/pc/male_ready2", "block": "models/pc/male_block" }) self.character1.reparentTo(self.node) self.character1.setBlend(frameBlend=True) self.character1.setPos(1, 2, 0) self.character1.setScale(.025) self.character1.setH(-25.0) self.character1.setBin("opaque", 10) self.character1.loop("idle") self.swingSound = base.loader.loadSfx("sfx/swing2.ogg") coll_sphere = self.node.attachNewNode(CollisionNode('monsterSphere')) coll_sphere.node().addSolid(CollisionSphere(1, 2, 1, 1)) coll_sphere.setTag("class", "1") coll_sphere.node().setIntoCollideMask(BitMask32.bit(1)) self.character2 = Actor("models/pc/female", { "attack": "models/pc/female_attack1", "idle": "models/pc/female_idle" }) #self.character2.setPlayRate(.4, "attack") self.character2.reparentTo(self.node) self.character2.setBlend(frameBlend=True) self.character2.setPos(-1, 2, 0) self.character2.setScale(.026) self.character2.setH(25.0) #self.character2.setBin("opaque", 10) self.character2.loop("idle") self.char2_magic = loader.loadModel('vfx/vfx3') self.char2_magic.setPos(self.character2.getPos()) self.char2_magic.setH(self.character2.getH()) self.char2_magic.setP(-10.0) self.char2_magic.setZ(0.71) self.char2_magic.setScale(1, 2, 1) self.char2_magic.wrtReparentTo(self.character2) self.char2_magic.setY(-10) self.char2_magic.setDepthWrite(False) self.char2_magic.setDepthTest(False) self.char2_magic.setLightOff() self.char2_magic.hide() self.vfxU = -0.125 self.vfxV = 0 self.magicSound = base.loader.loadSfx("sfx/thunder3.ogg") coll_sphere = self.node.attachNewNode(CollisionNode('monsterSphere')) coll_sphere.node().addSolid(CollisionSphere(-1, 2, 1, 1)) coll_sphere.setTag("class", "2") coll_sphere.node().setIntoCollideMask(BitMask32.bit(1)) self.character3 = Actor( "models/pc/female2", { "attack": "models/pc/female2_arm", "reset": "models/pc/female2_fire", "idle": "models/pc/female2_idle" }) #self.character2.setPlayRate(.4, "attack") self.character3.reparentTo(self.node) self.character3.setBlend(frameBlend=True) self.character3.setPos(-1.8, 0.9, 0) self.character3.setScale(.026) self.character3.setH(40.0) #self.character2.setBin("opaque", 10) self.character3.loop("idle") coll_sphere = self.node.attachNewNode(CollisionNode('monsterSphere')) coll_sphere.node().addSolid(CollisionSphere(-1.8, 0.9, 0, 1)) coll_sphere.setTag("class", "3") coll_sphere.node().setIntoCollideMask(BitMask32.bit(1)) self.arrow_bone = self.character3.exposeJoint(None, 'modelRoot', 'arrow_bone') self.arrow = loader.loadModel('models/arrow') self.arrow.reparentTo(self.arrow_bone) self.arrow.setP(-45) self.movingArrow = None self.arrowTime = 0.0 self.drawSound = base.loader.loadSfx("sfx/draw_bow2.ogg") self.fireSound = base.loader.loadSfx("sfx/fire_arrow3.ogg") self.character4 = Actor("models/pc/male2", { "attack": "models/pc/male2_aura", "idle": "models/pc/male2_idle" }) #self.character2.setPlayRate(.4, "attack") self.character4.reparentTo(self.node) self.character4.setBlend(frameBlend=True) self.character4.setPos(1.8, 0.9, 0) self.character4.setScale(.024) self.character4.setH(-60.0) #self.character2.setBin("opaque", 10) self.character4.loop("idle") self.FFSound = base.loader.loadSfx("sfx/teleport.ogg") #self.FFSound = base.loader.loadSfx("sfx/walk_new3.ogg") coll_sphere = self.node.attachNewNode(CollisionNode('monsterSphere')) coll_sphere.node().addSolid(CollisionSphere(1.8, 0.9, 0, 1)) coll_sphere.setTag("class", "4") coll_sphere.node().setIntoCollideMask(BitMask32.bit(1)) #gui self.mp_logo = DirectFrame(frameSize=(-512, 0, 0, 128), frameColor=(1, 1, 1, 1), frameTexture='images/mp_logo.png', state=DGG.NORMAL, parent=pixel2d) self.mp_logo.setPos(256 + winX / 2, 0, -winY) self.mp_logo.setBin('fixed', 1) self.mp_logo.hide() self.mp_logo.setTransparency(TransparencyAttrib.MDual) self.mp_logo.bind(DGG.B1PRESS, self.open_www, ['http://www.matthewpablo.com/']) #self.mp_logo.bind(DGG.WITHIN, self.GUIOnEnter, ["MP"]) #self.mp_logo.bind(DGG.WITHOUT, self.GUIOnExit) self.title = DirectFrame(frameSize=(-512, 0, 0, 128), frameColor=(1, 1, 1, 1), frameTexture='images/select.png', parent=pixel2d) self.title.setPos(256 + winX / 2, 0, -128) self.title.setBin('fixed', 1) self.title.setTransparency(TransparencyAttrib.MDual) #self.title.hide() self.close = DirectFrame(frameSize=(-32, 0, 0, 32), frameColor=(1, 1, 1, 1), frameTexture='icon/close.png', state=DGG.NORMAL, parent=pixel2d) self.close.setPos(winX, 0, -32) self.close.setBin('fixed', 1) self.close.bind(DGG.B1PRESS, self.exit) self.new_game_button = DirectButton( frameSize=(-0.2, 0.2, 0, 0.08), frameColor=(1, 1, 1, 1), frameTexture='images/level_select.png', text_font=self.font, text='START NEW GAME', text_pos=(-0.16, 0.026, 0), text_scale=0.035, text_fg=(0, 0, 0, 1), text_align=TextNode.ALeft, textMayChange=1, state=DGG.FLAT, relief=DGG.FLAT, pos=(0, 0, 0.5), command=self.onStart, parent=aspect2d) self.new_game_button.setBin('fixed', 1) self.new_game_button.hide() self.continue_button = DirectButton( frameSize=(-0.2, 0.2, 0, 0.08), frameColor=(1, 1, 1, 1), frameTexture='images/level_select.png', text_font=self.font, text='CONTINUE GAME', text_pos=(-0.16, 0.026, 0), text_scale=0.035, text_fg=(0, 0, 0, 1), text_align=TextNode.ALeft, textMayChange=1, state=DGG.FLAT, relief=DGG.FLAT, pos=(0, 0, 0.4), command=self.loadAndStart, parent=aspect2d) self.continue_button.setBin('fixed', 1) self.continue_button.hide() self.cursor = DirectFrame(frameSize=(-32, 0, 0, 32), frameColor=(1, 1, 1, 1), frameTexture='icon/cursor1.png', parent=pixel2d) self.cursor.setPos(32, 0, -32) self.cursor.flattenLight() self.cursor.setBin('fixed', 10) self.cursor.setTransparency(TransparencyAttrib.MDual) self.frameDesc = DirectFrame(frameSize=(0, 1, 0, 0.3), frameColor=(1, 1, 1, 1), frameTexture='images/frame1.png', state=DGG.NORMAL, pos=(-0.5, 0, 0.6), parent=aspect2d) self.labelDesc = DirectLabel( text="", text_fg=(1, 1, 1, 1), frameColor=(0, 0, 0, 0), #text_font=self.font, text_scale=0.06, text_align=TextNode.ALeft, pos=(0.1, 0, 0.2), parent=self.frameDesc) self.frameDesc.setBin('fixed', 1) self.frameDesc.hide() self.frameDesc.bind(DGG.WITHIN, self.GUIOnEnter, ["3B"]) self.frameDesc.bind(DGG.WITHOUT, self.GUIOnExit) #tooltip #self.font.setPixelsPerUnit(16) #self.font.setMinfilter(Texture.FTNearest ) #self.font.setMagfilter(Texture.FTNearest ) #self.font.setAnisotropicDegree(4) #self.font.setNativeAntialias(False) #self.font.setPageSize(1024,1024) self.Tooltip = DirectLabel( frameColor=(0, 0, 0, 0), text_font=self.font, text= 'Lorem ipsum dolor sit amet,\n consectetur adipisicing elit,\n sed do eiusmod tempor incididunt \nut labore et dolore magna aliqua.', #pos = (0, 0,-35), text_scale=16, text_fg=(1, 1, 1, 1), text_align=TextNode.ALeft, textMayChange=1, parent=pixel2d) self.Tooltip.flattenLight() self.Tooltip.setBin('fixed', 300) self.Tooltip.hide() #collisions #self.traverser=CollisionTraverser("playerTrav") #self.traverser.setRespectPrevTransform(True) #self.queue = CollisionHandlerQueue() self.MousePickerNode = CollisionNode('mouseRay') self.pickerNP = base.camera.attachNewNode(self.MousePickerNode) self.MousePickerNode.setFromCollideMask(BitMask32.bit(1)) self.MousePickerNode.setIntoCollideMask(BitMask32.allOff()) self.pickerRay = CollisionSegment() #Make our ray self.MousePickerNode.addSolid( self.pickerRay) #Add it to the collision node self.common['traverser'].addCollider(self.pickerNP, self.common['queue']) self.accept("mouse1", self.onClick) taskMgr.doMethodLater(0.2, self.flicker, 'flicker') #taskMgr.add(self.camera_spin, "camera_spin") taskMgr.add(self.__getMousePos, "chargenMousePos") self.current_class = None self.currentLevel = 0 self.camLoop = Sequence( LerpHprInterval(self.cameraNode, 10.0, VBase3(-20, 0, 0), bakeInStart=0), LerpHprInterval(self.cameraNode, 10.0, VBase3(20, 0, 0), bakeInStart=0)) self.camLoop.loop() self.accept('window-event', self.windowEventHandler)
def runAI(self, task): #print(self.stats['hp']) #(x,y,z) = self.right_foot.getPos() ## Our model is rotated of 180°, thus we need to move the collision sphere to the opposite directions #self.coll_attack2.setPos(-1*x, -1*y, z) target = self.common['PC'].node if self.state=="DIE": if(self.boss.getCurrentAnim()!="die"): self.common['soundPool'].attachAndPlay(self.boss, "creature_roar_01.ogg") self.boss.play("die") #Check if we have finished the animation if (self.boss.getCurrentFrame() < self.boss.getNumFrames()-1): return task.again else: id = len(self.common["random-objects"]) object = RandomObject(id, self.common, self.node, render, moneyamount=5) self.common["random-objects"].append(object) Interactive(self.common, data.items['key'], self.node.getPos(render)) self.coll_body.node().setIntoCollideMask(BitMask32.allOff()) self.coll_quad.removeNode() Sequence(Wait(2.0),LerpPosInterval(self.node, 2.0, VBase3(self.node.getX(),self.node.getY(),self.node.getZ()-5)),Func(self.destroy)).start() return task.done if self.stats['hp'] < 50: self.AIchar.setMass(self.AIchar.getMass()-20) if (self.state == "HIT"): rn = 0.005 if (type(self.common['PC']).__name__ == "Knight"): rn = 0.4 if (random.random() < rn): if(self.boss.getCurrentAnim()!="hit"): self.boss.play("hit") self.common['soundPool'].attachAndPlay(self.boss, "creature_roar_01.ogg") self.state = "PLAYINGHIT" if (self.state == "PLAYINGHIT"): if (self.boss.getCurrentFrame() == None) or (self.boss.getCurrentFrame() == self.boss.getNumFrames()-1): self.state = self.previous_state return task.again if self.state == "IDLE": if(self.boss.getCurrentAnim()!="idle"): self.boss.play("idle") if self.common['PC'].HP <= 0 or self.node.getDistance(target)>14: self.state="IDLE" self.common['spawner'].monster_limit = 4 else: self.common['spawner'].monster_limit = 2 if self.boss.getAnimControl('scream').isPlaying(): #we must wait until the animation is finished return task.again if (random.random() < 0.001): self.state="SCREAMING" if(self.boss.getCurrentAnim()!="scream"): self.boss.play("scream") self.common['soundPool'].attachAndPlay(self.boss, "awake-the-beast.wav") else: if self.node.getDistance(target)>2: #If the boss is idle or has finished to play an animation (e.g. an attack) he must pursue the player if self.state == "HIT" or self.state == "IDLE" or self.boss.getCurrentAnim() == None: self.state="PURSUING" if self.state == "PURSUING": self.AIworld.update() #self.node.setY(self.node, 1*globalClock.getDt()) if(self.boss.getCurrentAnim()!="walk"): self.common['soundPool'].attachAndPlay(self.boss, "creature_slime_01-2.ogg", 0.7) self.boss.play("walk") else: self.state="ATTACKING" if(self.boss.getCurrentAnim()!="attack2") and (self.boss.getCurrentAnim()!="attack1"): if (type(self.common['PC']).__name__ == "Knight") and (random.random() > 0.1): self.state="IDLE" self.previous_state = self.state return task.again if (random.random() < 0.5): self.boss.play("attack2") self.common['soundPool'].attachAndPlay(self.boss, "Whoosh4.ogg") self.boss.attackdamage = 20 else: self.common['soundPool'].attachAndPlay(self.boss, "explodemini.wav", delay=1) self.boss.play("attack1") self.boss.attackdamage = 30 # Inflict damage only when we played half of the animation (it should be the moment when the attack hits the player) # This function could be called multiple times even if we are at the same frame (probably depends on the frame rate of the animation) # Thus, we should also check if we are seeing the same previous hit (based on the last frame, it must not be the same) elif (self.boss.getCurrentFrame() == int(self.boss.getNumFrames()/2)) and (self.boss.getCurrentFrame() != self.boss.lastFrame): if (self.boss.getCurrentAnim() == "attack1"): #The sound must be played only when the boss hit the floor (it's in the mid of the animation) # Get position of the joint respect to render (i.e. absolute position) (x,y,_) = self.left_thumb.getPos(render) vfx(None, texture='vfx/dust.png',scale=1, Z=0, depthTest=True, depthWrite=True,pos=(x,y,0)).start(0.016) self.common['PC'].hit(self.boss.attackdamage) self.boss.lastFrame = self.boss.getCurrentFrame() self.previous_state = self.state return task.again
def onClick(self): self.common['traverser'].traverse(render) my_class=None for entry in self.common['queue'].getEntries(): if entry.getIntoNodePath().hasTag("class"): my_class=entry.getIntoNodePath().getTag("class") if my_class=="1": self.slider1['value']=50 self.slider2['value']=50 self.slider3['value']=50 self.current_class=my_class self.title.hide() self.start.show() self.button1A.show() self.button1B.show() self.button2A.show() self.button2B.show() self.button3A.show() self.button3B.show() self.button1A['frameTexture']='icon/armor.png' self.button1B['frameTexture']='icon/heart.png' self.button2A['frameTexture']='icon/shield2.png' self.button2B['frameTexture']='icon/move.png' self.button3A['frameTexture']='icon/power.png' self.button3B['frameTexture']='icon/critical.png' #self.skills.show() self.slider1.show() self.slider2.show() self.slider3.show() Sequence(self.character1.actorInterval("attack"),self.character1.actorInterval("block"), Func(self.loopAnim, self.character1, "idle")).start() self.swingSound.play() #self.character1.play("attack") self.character2.loop("idle") elif my_class=="2": self.slider1['value']=50 self.slider2['value']=50 self.slider3['value']=50 self.current_class=my_class self.title.hide() self.start.show() self.button1A.show() self.button1B.show() self.button2A.show() self.button2B.show() self.button3A.show() self.button3B.show() self.button1A['frameTexture']='icon/blast.png' self.button1B['frameTexture']='icon/damage.png' self.button2A['frameTexture']='icon/lightning.png' self.button2B['frameTexture']='icon/thunder.png' self.button3A['frameTexture']='icon/amp.png' self.button3B['frameTexture']='icon/volt.png' self.slider1.show() self.slider2.show() self.slider3.show() Sequence(self.character2.actorInterval("attack", playRate=0.8),Func(self.loopAnim, self.character2, "idle")).start() Sequence(Wait(0.3), Func(self.start_lightning, 0.05)).start() #self.character2.play("attack") self.character1.loop("idle") #RayVfx(self.character2, texture='vfx/lightning.png').start() elif my_class=="3": self.slider1['value']=50 self.slider2['value']=50 self.slider3['value']=50 self.current_class=my_class self.title.hide() self.start.show() self.button1A.show() self.button1B.show() self.button2A.show() self.button2B.show() self.button3A.show() self.button3B.show() self.button1A['frameTexture']='icon/barbs.png' self.button1B['frameTexture']='icon/pierce.png' self.button2A['frameTexture']='icon/bleed.png' self.button2B['frameTexture']='icon/cripple.png' self.button3A['frameTexture']='icon/finese.png' self.button3B['frameTexture']='icon/bow_damage.png' self.slider1.show() self.slider2.show() self.slider3.show() self.drawSound.play() self.character3.play("attack") Sequence(Wait(1.5),Func(self.fireArrow), Func(self.character3.play, "reset"),Wait(1.0),Func(self.loopAnim, self.character3, "idle")).start() elif my_class=="4": self.slider1['value']=50 self.slider2['value']=50 self.slider3['value']=50 self.current_class=my_class self.title.hide() self.start.show() self.button1A.show() self.button1B.show() self.button2A.show() self.button2B.show() self.button3A.show() self.button3B.show() self.button1A['frameTexture']='icon/hand_o_fate.png' self.button1B['frameTexture']='icon/magma_flow.png' self.button2A['frameTexture']='icon/heart_o_fire.png' self.button2B['frameTexture']='icon/vulcanic.png' self.button3A['frameTexture']='icon/warp.png' self.button3B['frameTexture']='icon/thorns.png' #self.skills.show() self.slider1.show() self.slider2.show() self.slider3.show() self.character4.loop("attack") aura=vfx(self.character4, texture='vfx/tele2.png',scale=.5, Z=.85, depthTest=False, depthWrite=False) aura.show() aura.start() self.FFSound.play() Sequence(Wait(2.2), Func(self.loopAnim, self.character4, "idle")).start()
def load(self): self.font = loader.loadFont('Bitter-Bold.otf') self.currentLevel=0 self.common['pc_stat1']=50 self.common['pc_stat2']=50 self.common['pc_stat3']=50 #render.setShaderAuto() #base.disableMouse() #render.setAntialias(AntialiasAttrib.MMultisample) #base.setBackgroundColor(0, 0, 0) wp = base.win.getProperties() winX = wp.getXSize() winY = wp.getYSize() self.campmap=loader.loadModel("models/camp3") self.campmap.reparentTo(render) #music self.common['music']=MusicPlayer(self.common) self.common['music'].loop(0) #self.common['music']=base.loadMusic("music/LuridDeliusion.ogg") #self.common['music'].setLoop(True) #self.common['music'].play() self.node=render.attachNewNode("node") self.cameraNode = self.node.attachNewNode("cameraNode") self.cameraNode.setZ(-1) base.camera.setY(-8) base.camera.setZ(5) base.camera.lookAt((0,3,0)) base.camera.wrtReparentTo(self.cameraNode) self.pointer=self.cameraNode.attachNewNode("pointerNode") #light self.pLight = PointLight('plight') self.pLight.setColor(VBase4(1, .95, .9, 1)) self.pLight.setAttenuation(Point3(.5, 0, 0.1)) self.pLightNode = self.node.attachNewNode(self.pLight) self.pLightNode.setZ(1.0) render.setLight(self.pLightNode) self.sLight=Spotlight('sLight') self.sLight.setColor(VBase4(.4, .25, .25, 1)) if self.common['extra_ambient']: self.sLight.setColor(VBase4(.7, .5, .5, 1)) spot_lens = PerspectiveLens() spot_lens.setFov(40) self.sLight.setLens(spot_lens) self.Ambient = self.cameraNode.attachNewNode( self.sLight) self.Ambient.setPos(base.camera.getPos(render)) self.Ambient.lookAt((0,3,0)) render.setLight(self.Ambient) self.fire_node=self.node.attachNewNode("fireNode") self.fire=vfx(self.fire_node, texture='vfx/big_fire3.png',scale=.29, Z=.5, depthTest=True, depthWrite=True) self.fire.show() self.fire.loop(0.02) self.character1=Actor("models/pc/male", {"attack":"models/pc/male_attack2","idle":"models/pc/male_ready2", "block":"models/pc/male_block"}) self.character1.reparentTo(self.node) self.character1.setBlend(frameBlend = True) self.character1.setPos(1,2, 0) self.character1.setScale(.025) self.character1.setH(-25.0) self.character1.setBin("opaque", 10) self.character1.loop("idle") self.swingSound = base.loader.loadSfx("sfx/swing2.ogg") coll_sphere=self.node.attachNewNode(CollisionNode('monsterSphere')) coll_sphere.node().addSolid(CollisionSphere(1, 2, 1, 1)) coll_sphere.setTag("class", "1") coll_sphere.node().setIntoCollideMask(BitMask32.bit(1)) if self.common['nude']: self.character2=Actor("models/pc/female_nude", {"attack":"models/pc/female_attack1","idle":"models/pc/female_idle"}) else: self.character2=Actor("models/pc/female", {"attack":"models/pc/female_attack1","idle":"models/pc/female_idle"}) #self.character2.setPlayRate(.4, "attack") self.character2.reparentTo(self.node) self.character2.setBlend(frameBlend = True) self.character2.setPos(-1,2, 0) self.character2.setScale(.026) self.character2.setH(25.0) #self.character2.setBin("opaque", 10) self.character2.loop("idle") self.char2_magic= loader.loadModel('vfx/vfx3') self.char2_magic.setPos(self.character2.getPos()) self.char2_magic.setH(self.character2.getH()) self.char2_magic.setP(-10.0) self.char2_magic.setZ(0.71) self.char2_magic.setScale(1,2,1) self.char2_magic.wrtReparentTo(self.character2) self.char2_magic.setY(-10) self.char2_magic.setDepthWrite(False) self.char2_magic.setDepthTest(False) self.char2_magic.setLightOff() self.char2_magic.hide() self.vfxU=-0.125 self.vfxV=0 self.magicSound = base.loader.loadSfx("sfx/thunder3.ogg") coll_sphere=self.node.attachNewNode(CollisionNode('monsterSphere')) coll_sphere.node().addSolid(CollisionSphere(-1, 2, 1, 1)) coll_sphere.setTag("class", "2") coll_sphere.node().setIntoCollideMask(BitMask32.bit(1)) if self.common['nude']: self.character3=Actor("models/pc/female2_nude", {"attack":"models/pc/female2_arm","reset":"models/pc/female2_fire","idle":"models/pc/female2_idle"}) else: self.character3=Actor("models/pc/female2", {"attack":"models/pc/female2_arm","reset":"models/pc/female2_fire","idle":"models/pc/female2_idle"}) #self.character2.setPlayRate(.4, "attack") self.character3.reparentTo(self.node) self.character3.setBlend(frameBlend = True) self.character3.setPos(-1.8,0.9, 0) self.character3.setScale(.026) self.character3.setH(40.0) #self.character2.setBin("opaque", 10) self.character3.loop("idle") coll_sphere=self.node.attachNewNode(CollisionNode('monsterSphere')) coll_sphere.node().addSolid(CollisionSphere(-1.8,0.9, 0, 1)) coll_sphere.setTag("class", "3") coll_sphere.node().setIntoCollideMask(BitMask32.bit(1)) self.arrow_bone=self.character3.exposeJoint(None, 'modelRoot', 'arrow_bone') self.arrow=loader.loadModel('models/arrow') self.arrow.reparentTo(self.arrow_bone) self.arrow.setP(-45) self.movingArrow=None self.arrowTime=0.0 self.drawSound = base.loader.loadSfx("sfx/draw_bow2.ogg") self.fireSound = base.loader.loadSfx("sfx/fire_arrow3.ogg") self.character4=Actor("models/pc/male2", {"attack":"models/pc/male2_aura","idle":"models/pc/male2_idle"}) #self.character2.setPlayRate(.4, "attack") self.character4.reparentTo(self.node) self.character4.setBlend(frameBlend = True) self.character4.setPos(1.8,0.9, 0) self.character4.setScale(.024) self.character4.setH(-60.0) #self.character2.setBin("opaque", 10) self.character4.loop("idle") self.FFSound = base.loader.loadSfx("sfx/teleport.ogg") #self.FFSound = base.loader.loadSfx("sfx/walk_new3.ogg") coll_sphere=self.node.attachNewNode(CollisionNode('monsterSphere')) coll_sphere.node().addSolid(CollisionSphere(1.8,0.9, 0, 1)) coll_sphere.setTag("class", "4") coll_sphere.node().setIntoCollideMask(BitMask32.bit(1)) #gui self.mp_logo=DirectFrame(frameSize=(-512, 0, 0, 128), frameColor=(1,1,1, 1), frameTexture='mp_logo.png', state=DGG.NORMAL, parent=pixel2d) self.mp_logo.setPos(256+winX/2, 0, -winY) self.mp_logo.setBin('fixed', 1) self.mp_logo.hide() self.mp_logo.setTransparency(TransparencyAttrib.MDual) self.mp_logo.bind(DGG.B1PRESS, self.open_www, ['http://www.matthewpablo.com/']) #self.mp_logo.bind(DGG.WITHIN, self.GUIOnEnter, ["MP"]) #self.mp_logo.bind(DGG.WITHOUT, self.GUIOnExit) self.title = DirectFrame(frameSize=(-512, 0, 0, 128), frameColor=(1,1,1, 1), frameTexture='select.png', parent=pixel2d) self.title.setPos(256+winX/2, 0, -128) self.title.setBin('fixed', 1) self.title.setTransparency(TransparencyAttrib.MDual) #self.title.hide() self.close=DirectFrame(frameSize=(-32, 0, 0, 32), frameColor=(1, 1, 1, 1), frameTexture='icon/close.png', state=DGG.NORMAL, parent=pixel2d) self.close.setPos(winX, 0, -32) self.close.setBin('fixed', 1) self.close.bind(DGG.B1PRESS, self.exit) self.start=DirectFrame(frameSize=(-256, 0, 0, 32), frameTexture='icon/level_select.png', frameColor=(1, 1, 1, 1), parent=pixel2d) self.start.setPos(128+winX/2, 0, -164) self.start.setTransparency(TransparencyAttrib.MDual) #self.start.bind(DGG.B1PRESS, self.onStart) self.start.setBin('fixed', 1) #self.start.hide() self.start_main=DirectFrame(frameSize=(-192, 0, 0, 32), frameColor=(1,1,1, 0), text_font=self.font, text='Start in Level 1', text_pos = (-160, 12,0), text_scale = 16, text_fg=(0,0,0,1), text_align=TextNode.ALeft, textMayChange=1, state=DGG.NORMAL, parent=pixel2d) self.start_main.setPos(96+winX/2, 0, -164) self.start_main.setTransparency(TransparencyAttrib.MDual) self.start_main.bind(DGG.B1PRESS, self.onStart) self.start_main.bind(DGG.WITHIN, self.GUIOnEnter, ["4A"]) self.start_main.bind(DGG.WITHOUT, self.GUIOnExit) self.start_main.setBin('fixed', 1) self.start_main.wrtReparentTo(self.start) self.start_back=DirectFrame(frameSize=(-32, 0, 0, 32), frameColor=(1,0,0, 0), state=DGG.NORMAL, parent=pixel2d) self.start_back.setPos(128+winX/2, 0, -164) self.start_back.setTransparency(TransparencyAttrib.MDual) self.start_back.bind(DGG.B1PRESS, self.selectLevel, [1]) self.start_back.bind(DGG.WITHIN, self.GUIOnEnter, ["4B"]) self.start_back.bind(DGG.WITHOUT, self.GUIOnExit) self.start_back.setBin('fixed', 1) self.start_back.wrtReparentTo(self.start) self.start_next=DirectFrame(frameSize=(-32, 0, 0, 32), frameColor=(0,1,0, 0), state=DGG.NORMAL, parent=pixel2d) self.start_next.setPos(-96+winX/2, 0, -164) self.start_next.setTransparency(TransparencyAttrib.MDual) self.start_next.bind(DGG.B1PRESS, self.selectLevel, [-1]) self.start_next.bind(DGG.WITHIN, self.GUIOnEnter, ["4C"]) self.start_next.bind(DGG.WITHOUT, self.GUIOnExit) self.start_next.setBin('fixed', 1) self.start_next.wrtReparentTo(self.start) self.start.hide() self.slider3 = DirectSlider(range=(0,100), value=50, pageSize=10, thumb_relief=DGG.FLAT, thumb_frameTexture='glass1.png', #thumb_frameColor=(1,1,1, 1), frameTexture='glass2.png', scale=96, #frameSize=(-100, 0, 0, 100), command=self.set_slider, extraArgs=["3"], parent=pixel2d) self.slider3.setPos(winX/2, 0, -16) self.slider3.setBin('fixed', 2) self.slider2 = DirectSlider(range=(0,100), value=50, pageSize=10, thumb_relief=DGG.FLAT, thumb_frameTexture='glass1.png', #thumb_frameColor=(1,1,1, 1), frameTexture='glass2.png', scale=96, #frameSize=(-100, 0, 0, 100), command=self.set_slider, extraArgs=["2"], parent=pixel2d) self.slider2.setPos(winX/2, 0, -64) self.slider2.setBin('fixed', 2) self.slider1 = DirectSlider(range=(0,100), value=50, pageSize=10, thumb_relief=DGG.FLAT, thumb_frameTexture='glass1.png', #thumb_frameColor=(1,1,1, 1), frameTexture='glass2.png', scale=96, #frameSize=(-100, 0, 0, 100), command=self.set_slider, extraArgs=["1"], parent=pixel2d) self.slider1.setPos(winX/2, 0, -112) self.slider1.setBin('fixed', 2) self.slider1.hide() self.slider2.hide() self.slider3.hide() self.cursor=DirectFrame(frameSize=(-32, 0, 0, 32), frameColor=(1, 1, 1, 1), frameTexture='icon/cursor1.png', parent=pixel2d) self.cursor.setPos(32,0, -32) self.cursor.flattenLight() self.cursor.setBin('fixed', 10) self.cursor.setTransparency(TransparencyAttrib.MDual) self.button1A=DirectFrame(frameSize=(-32, 0, 0, 32), frameColor=(1, 1, 1, 1), frameTexture='icon/armor.png', state=DGG.NORMAL, parent=pixel2d) self.button1A.setPos(128+winX/2, 0, -128) self.button1A.setBin('fixed', 1) self.button1B=DirectFrame(frameSize=(-32, 0, 0, 32), frameColor=(1, 1, 1, 1), frameTexture='icon/armor.png', state=DGG.NORMAL, parent=pixel2d) self.button1B.setPos(-96+winX/2, 0, -128) self.button1B.setBin('fixed', 1) self.button2A=DirectFrame(frameSize=(-32, 0, 0, 32), frameColor=(1, 1, 1, 1), frameTexture='icon/armor.png', state=DGG.NORMAL, parent=pixel2d) self.button2A.setPos(128+winX/2, 0, -79) self.button2A.setBin('fixed', 1) self.button2B=DirectFrame(frameSize=(-32, 0, 0, 32), frameColor=(1, 1, 1, 1), frameTexture='icon/armor.png', state=DGG.NORMAL, parent=pixel2d) self.button2B.setPos(-96+winX/2, 0, -79) self.button2B.setBin('fixed', 1) self.button3A=DirectFrame(frameSize=(-32, 0, 0, 32), frameColor=(1, 1, 1, 1), frameTexture='icon/armor.png', state=DGG.NORMAL, parent=pixel2d) self.button3A.setPos(128+winX/2, 0, -32) self.button3A.setBin('fixed', 1) self.button3B=DirectFrame(frameSize=(-32, 0, 0, 32), frameColor=(1, 1, 1, 1), frameTexture='icon/armor.png', state=DGG.NORMAL, parent=pixel2d) self.button3B.setPos(-96+winX/2, 0, -32) self.button3B.setBin('fixed', 1) self.button1A.hide() self.button1B.hide() self.button2A.hide() self.button2B.hide() self.button3A.hide() self.button3B.hide() self.button1A.bind(DGG.WITHIN, self.GUIOnEnter, ["1A"]) self.button1A.bind(DGG.WITHOUT, self.GUIOnExit) self.button2A.bind(DGG.WITHIN, self.GUIOnEnter, ["2A"]) self.button2A.bind(DGG.WITHOUT, self.GUIOnExit) self.button3A.bind(DGG.WITHIN, self.GUIOnEnter, ["3A"]) self.button3A.bind(DGG.WITHOUT, self.GUIOnExit) self.button1B.bind(DGG.WITHIN, self.GUIOnEnter, ["1B"]) self.button1B.bind(DGG.WITHOUT, self.GUIOnExit) self.button2B.bind(DGG.WITHIN, self.GUIOnEnter, ["2B"]) self.button2B.bind(DGG.WITHOUT, self.GUIOnExit) self.button3B.bind(DGG.WITHIN, self.GUIOnEnter, ["3B"]) self.button3B.bind(DGG.WITHOUT, self.GUIOnExit) #tooltip #self.font.setPixelsPerUnit(16) #self.font.setMinfilter(Texture.FTNearest ) #self.font.setMagfilter(Texture.FTNearest ) #self.font.setAnisotropicDegree(4) #self.font.setNativeAntialias(False) #self.font.setPageSize(1024,1024) self.Tooltip=DirectLabel(frameColor=(0, 0, 0, 0), text_font=self.font, text='Lorem ipsum dolor sit amet,\n consectetur adipisicing elit,\n sed do eiusmod tempor incididunt \nut labore et dolore magna aliqua.', #pos = (0, 0,-35), text_scale = 16, text_fg=(1,1,1,1), text_align=TextNode.ALeft , textMayChange=1, parent=pixel2d ) self.Tooltip.flattenLight() self.Tooltip.setBin('fixed', 300) self.Tooltip.hide() self.tooltip_text=[None, {"1A":"ARMOR:\nYou have more Hit Points\n", "1B":"REGENERATION:\nYou heal over time\n", "2A":"BLOCK:\nYour block is more effective\n", "2B":"SPEED:\nYour move faster\n", "3A":"DAMAGE:\nYou deal more damage\n", "3B":"CRITICAL HIT:\nChance for a critical hit\n"}, {"1A":"BLAST:\nBigger Magic Bolt explosion\n", "1B":"DAMAGE:\nMagic Bolt deals more damage\n", "2A":"LIGHTNING:\nMore damage to far targets\n", "2B":"THUNDER:\nMore damage to near targets\n", "3A":"RAPID CHARGE:\nExponential damage increase\n", "3B":"STATIC CHARGE:\nLinear damage increase\n"}, {"1A":"BARBS:\nOne hit counts as two\n", "1B":"PIERCE:\nArrows pass through targets\n", "2A":"BLEED:\nDamage over time\n", "2B":"CRIPPLE:\nSlow down enemies\n", "3A":"FINESSE:\nMore critical hits\n", "3B":"PROWESS:\nMore damage\n"}, {"1A":"BURNING DEATH:\nMagma deals more damage\n", "1B":"MAGMA FLOW:\nMore magma at once\n", "2A":"HEART OF FIRE:\nMagma lasts longer\n", "2B":"VOLCANIC ACTIVITY:\nMagma is bigger\n", "3A":"PHASESHIFT:\nYou can teleport more often\n", "3B":"WARP FIELD:\nFaster recovery after teleport\n"} ] #collisions #self.traverser=CollisionTraverser("playerTrav") #self.traverser.setRespectPrevTransform(True) #self.queue = CollisionHandlerQueue() self.MousePickerNode = CollisionNode('mouseRay') self.pickerNP = base.camera.attachNewNode(self.MousePickerNode) self.MousePickerNode.setFromCollideMask(BitMask32.bit(1)) self.MousePickerNode.setIntoCollideMask(BitMask32.allOff()) self.pickerRay = CollisionSegment() #Make our ray self.MousePickerNode.addSolid(self.pickerRay) #Add it to the collision node self.common['traverser'].addCollider(self.pickerNP, self.common['queue']) self.accept("mouse1", self.onClick) taskMgr.doMethodLater(0.2, self.flicker,'flicker') #taskMgr.add(self.camera_spin, "camera_spin") taskMgr.add(self.__getMousePos, "chargenMousePos") self.current_class=None self.camLoop=Sequence(LerpHprInterval(self.cameraNode, 10.0, VBase3(-20,0, 0), bakeInStart=0),LerpHprInterval(self.cameraNode, 10.0, VBase3(20,0, 0),bakeInStart=0)) self.camLoop.loop() self.accept( 'window-event', self.windowEventHandler)
def onClick(self): self.common['traverser'].traverse(render) my_class = None for entry in self.common['queue'].getEntries(): if entry.getIntoNodePath().hasTag("class"): my_class = entry.getIntoNodePath().getTag("class") if Path("save.dat").exists(): self.continue_button.show() if my_class == "1": self.current_class = my_class self.title.hide() self.labelDesc.setText( "Knight:\nHe has greater resistance.\nHe can attack with the sword\nand defend with a shield." ) self.frameDesc.show() self.new_game_button.show() Sequence(self.character1.actorInterval("attack"), self.character1.actorInterval("block"), Func(self.loopAnim, self.character1, "idle")).start() self.swingSound.play() #self.character1.play("attack") self.character2.loop("idle") elif my_class == "2": self.current_class = my_class self.title.hide() self.labelDesc.setText( "Witch:\nShe can throw energy balls and\na long distance beam." ) self.frameDesc.show() self.new_game_button.show() Sequence(self.character2.actorInterval("attack", playRate=0.8), Func(self.loopAnim, self.character2, "idle")).start() Sequence(Wait(0.3), Func(self.start_lightning, 0.05)).start() #self.character2.play("attack") self.character1.loop("idle") #RayVfx(self.character2, texture='vfx/lightning.png').start() elif my_class == "3": self.current_class = my_class self.title.hide() self.labelDesc.setText( "Archer:\nShe can throw arrows\nand run faster.") self.frameDesc.show() self.new_game_button.show() self.drawSound.play() self.character3.play("attack") Sequence(Wait(1.5), Func(self.fireArrow), Func(self.character3.play, "reset"), Wait(1.0), Func(self.loopAnim, self.character3, "idle")).start() elif my_class == "4": self.current_class = my_class self.title.hide() self.labelDesc.setText( "Wizard:\nHe can throw magma balls\nand teleport himself.") self.frameDesc.show() self.new_game_button.show() self.character4.loop("attack") aura = vfx(self.character4, texture='vfx/tele2.png', scale=.5, Z=.85, depthTest=False, depthWrite=False) aura.show() aura.start() self.FFSound.play() Sequence(Wait(2.2), Func(self.loopAnim, self.character4, "idle")).start()