def renderQuadInto(self, mul=1, div=1, align=1, depthtex=None, colortex=None, auxtex0=None, auxtex1=None): texgroup = (depthtex, colortex, auxtex0, auxtex1) (winx, winy) = self.getScaledSize(mul, div, align) depthbits = bool(depthtex != None) buffer = self.createBuffer('filter-stage', winx, winy, texgroup, depthbits) if buffer == None: return None cm = CardMaker('filter-stage-quad') cm.setFrameFullscreenQuad() quad = NodePath(cm.generate()) quad.setDepthTest(0) quad.setDepthWrite(0) quad.setColor(Vec4(1, 0.5, 0.5, 1)) quadcamnode = Camera('filter-quad-cam') lens = OrthographicLens() lens.setFilmSize(2, 2) lens.setFilmOffset(0, 0) lens.setNearFar(-1000, 1000) quadcamnode.setLens(lens) quadcam = quad.attachNewNode(quadcamnode) buffer.getDisplayRegion(0).setCamera(quadcam) buffer.getDisplayRegion(0).setActive(1) self.buffers.append(buffer) self.sizes.append((mul, div, align)) return quad
def renderSceneInto(self, depthtex=None, colortex=None, auxtex=None, auxbits=0, textures=None): if textures: colortex = textures.get('color', None) depthtex = textures.get('depth', None) auxtex = textures.get('aux', None) if colortex == None: colortex = Texture('filter-base-color') colortex.setWrapU(Texture.WMClamp) colortex.setWrapV(Texture.WMClamp) texgroup = (depthtex, colortex, auxtex, None) (winx, winy) = self.getScaledSize(1, 1, 1) buffer = self.createBuffer('filter-base', winx, winy, texgroup) if buffer == None: return None cm = CardMaker('filter-base-quad') cm.setFrameFullscreenQuad() quad = NodePath(cm.generate()) quad.setDepthTest(0) quad.setDepthWrite(0) quad.setTexture(colortex) quad.setColor(Vec4(1, 0.5, 0.5, 1)) cs = NodePath('dummy') cs.setState(self.camstate) if auxbits: cs.setAttrib(AuxBitplaneAttrib.make(auxbits)) self.camera.node().setInitialState(cs.getState()) quadcamnode = Camera('filter-quad-cam') lens = OrthographicLens() lens.setFilmSize(2, 2) lens.setFilmOffset(0, 0) lens.setNearFar(-1000, 1000) quadcamnode.setLens(lens) quadcam = quad.attachNewNode(quadcamnode) self.region.setCamera(quadcam) dr = buffer.getDisplayRegion(0) self.setStackedClears(dr, self.rclears, self.wclears) if auxtex: dr.setClearActive(GraphicsOutput.RTPAuxRgba0, 1) dr.setClearValue(GraphicsOutput.RTPAuxRgba0, Vec4(0.5, 0.5, 1.0, 0.0)) self.region.disableClears() if self.isFullscreen(): self.win.disableClears() dr.setCamera(self.camera) dr.setActive(1) self.buffers.append(buffer) self.sizes.append((1, 1, 1)) return quad
def renderQuadInto(self, mul=1, div=1, align=1, depthtex=None, colortex=None, auxtex0=None, auxtex1=None): """ Creates an offscreen buffer for an intermediate computation. Installs a quad into the buffer. Returns the fullscreen quad. The size of the buffer is initially equal to the size of the main window. The parameters 'mul', 'div', and 'align' can be used to adjust that size. """ texgroup = (depthtex, colortex, auxtex0, auxtex1) winx, winy = self.getScaledSize(mul, div, align) depthbits = bool(depthtex != None) buffer = self.createBuffer("filter-stage", winx, winy, texgroup, depthbits) if (buffer == None): return None cm = CardMaker("filter-stage-quad") cm.setFrameFullscreenQuad() quad = NodePath(cm.generate()) quad.setDepthTest(0) quad.setDepthWrite(0) quad.setColor(Vec4(1, 0.5, 0.5, 1)) quadcamnode = Camera("filter-quad-cam") lens = OrthographicLens() lens.setFilmSize(2, 2) lens.setFilmOffset(0, 0) lens.setNearFar(-1000, 1000) quadcamnode.setLens(lens) quadcam = quad.attachNewNode(quadcamnode) dr = buffer.makeDisplayRegion((0, 1, 0, 1)) dr.disableClears() dr.setCamera(quadcam) dr.setActive(True) dr.setScissorEnabled(False) # This clear stage is important if the buffer is padded, so that # any pixels accidentally sampled in the padded region won't # be reading from unititialised memory. buffer.setClearColor((0, 0, 0, 1)) buffer.setClearColorActive(True) self.buffers.append(buffer) self.sizes.append((mul, div, align)) return quad
def createSprite(self, sprite): ''' Creates a new sprite and returns a SpriteRenderInterface for controlling this sprite instance. The newly created sprite is located at (0,0) in screen coordinates its dimensions are specified by the given Sprite argument. @param sprite: A Sprite resource that describes the properties of the sprite to created. @return: A SpriteRenderInterface instance or None if it failed to create the sprite. ''' if sprite.eggFile is not None: spriteNP = self.resources.loadModel(sprite.eggFile) tex = None else: if sprite.video is not None: card = self.cardMaker.generate() tex = VideoPlayer.renderToTexture(self.resources, video=sprite.video, audio=sprite.audio) elif sprite.image is not None: card = self.cardMaker.generate() tex = self.resources.loadTexture(sprite.image) sprite.width = tex.getXSize() sprite.height = tex.getYSize() else: self.log.error('Could not determine type for sprite: %s' % sprite.name) return None spriteNP = NodePath(card) spriteNP.setTexture(tex) nodeName = self.getSpriteNodeName(sprite.name) spriteNP.setName(nodeName) spriteNP.setPos(0, 1, 0) spriteNP.setScale(sprite.width, 1.0, sprite.height) spriteNP.setTransparency(1) spriteNP.reparentTo(self.sprite2d) spriteNP.setDepthTest(False) spriteNP.setDepthWrite(False) spriteNP.setBin("fixed", PanoConstants.RENDER_ORDER_SPRITES) spriteNP.setPythonTag('sprite', sprite) if sprite.video is not None: spriteNP.setPythonTag('video', tex) tex.setLoop(True) tex.play() return SpriteRenderInterface(spriteNP)
def setSky(directory, ext=".jpg"): """Sets up a skybox. 'directory' is the directory whitch contains 6 pictures with the names right.ext, left.ext and so on (see template). ext is the extension the pictures have (with dot). """ #TODO: accept all supported image file extensions without the need for an # extra argument # remove the old sky first when loading a new one # TODO: get this working... #oldsky = render.find("*sky*") #print oldsky #for child in render.getChildren(): # child.remove() sky = NodePath().attachNewNode("sky") sides = { "right": ( 1, 0, 0, -90, 0, 0), "left": (-1, 0, 0, 90, 0, 0), "top": ( 0, 0, 1, 0, 90, 0), "bottom": ( 0, 0, -1, 180, -90, 0), "front": ( 0, 1, 0, 0, 0, 0), "back": ( 0, -1, 0, 180, 0, 0) } for name, poshpr in sides.iteritems(): c = CardMaker(name) c.setFrame(-1, 1, -1, 1) card = c.generate() cardnode = sky.attachNewNode(card) cardnode.setPosHpr(*poshpr) tex = loader.loadTexture("skyboxes/" + directory + "/" + name + ext) tex.setWrapV(tex.WMClamp) tex.setMagfilter(tex.FTNearestMipmapNearest) tex.setMinfilter(tex.FTNearestMipmapNearest) cardnode.setTexture(tex) sky.flattenStrong() sky.setScale(10, 10, 10) sky.setCompass() sky.setBin('background', 0) sky.setDepthTest(False) sky.setDepthWrite(False) sky.setLightOff() sky.reparentTo(camera) geom = sky.getChild(0).node() geom.setName("cube")
def renderQuadInto(self, mul=1, div=1, align=1, depthtex=None, colortex=None, auxtex0=None, auxtex1=None): """ Creates an offscreen buffer for an intermediate computation. Installs a quad into the buffer. Returns the fullscreen quad. The size of the buffer is initially equal to the size of the main window. The parameters 'mul', 'div', and 'align' can be used to adjust that size. """ texgroup = (depthtex, colortex, auxtex0, auxtex1) winx, winy = self.getScaledSize(mul, div, align) depthbits = bool(depthtex != None) buffer = self.createBuffer("filter-stage", winx, winy, texgroup, depthbits) if (buffer == None): return None cm = CardMaker("filter-stage-quad") cm.setFrameFullscreenQuad() quad = NodePath(cm.generate()) quad.setDepthTest(0) quad.setDepthWrite(0) quad.setColor(Vec4(1, 0.5, 0.5, 1)) quadcamnode = Camera("filter-quad-cam") lens = OrthographicLens() lens.setFilmSize(2, 2) lens.setFilmOffset(0, 0) lens.setNearFar(-1000, 1000) quadcamnode.setLens(lens) quadcam = quad.attachNewNode(quadcamnode) buffer.getDisplayRegion(0).setCamera(quadcam) buffer.getDisplayRegion(0).setActive(1) self.buffers.append(buffer) self.sizes.append((mul, div, align)) return quad
def renderQuadInto(self, mul=1, div=1, align=1, depthtex=None, colortex=None, auxtex0=None, auxtex1=None): """ Creates an offscreen buffer for an intermediate computation. Installs a quad into the buffer. Returns the fullscreen quad. The size of the buffer is initially equal to the size of the main window. The parameters 'mul', 'div', and 'align' can be used to adjust that size. """ texgroup = (depthtex, colortex, auxtex0, auxtex1) winx, winy = self.getScaledSize(mul, div, align) depthbits = bool(depthtex != None) buffer = self.createBuffer("filter-stage", winx, winy, texgroup, depthbits) if (buffer == None): return None cm = CardMaker("filter-stage-quad") cm.setFrameFullscreenQuad() quad = NodePath(cm.generate()) quad.setDepthTest(0) quad.setDepthWrite(0) quad.setColor(Vec4(1,0.5,0.5,1)) quadcamnode = Camera("filter-quad-cam") lens = OrthographicLens() lens.setFilmSize(2, 2) lens.setFilmOffset(0, 0) lens.setNearFar(-1000, 1000) quadcamnode.setLens(lens) quadcam = quad.attachNewNode(quadcamnode) buffer.getDisplayRegion(0).setCamera(quadcam) buffer.getDisplayRegion(0).setActive(1) self.buffers.append(buffer) self.sizes.append((mul, div, align)) return quad
def make_layer(self, i, a, b): # get data data = self.subdata[a][b] # set color + alpha of vertex texture def ap(n): alpha = 0 if i == n: alpha = 1.0 return alpha def tp(n): list = [0, 0, 0, 0] if i == n: list = [1, 1, 1, 0.75] return list # set vertex data vdata = GeomVertexData('plane', GeomVertexFormat.getV3n3c4t2(), Geom.UHStatic) vertex = GeomVertexWriter(vdata, 'vertex') normal = GeomVertexWriter(vdata, 'normal') color = GeomVertexWriter(vdata, 'color') uv = GeomVertexWriter(vdata, 'texcoord') # set vertices number = 0 for x in range(0, len(data) - 1): for y in range(0, len(data[x]) - 1): # get vertex data v1 = Vec3(x, y, data[x][y]['h']) c1 = data[x][y]['c'] t1 = data[x][y]['texnum'] v2 = Vec3(x+1, y, data[x+1][y]['h']) c2 = data[x+1][y]['c'] t2 = data[x+1][y]['texnum'] v3 = Vec3(x+1, y+1, data[x+1][y+1]['h']) c3 = data[x+1][y+1]['c'] t3 = data[x+1][y+1]['texnum'] v4 = Vec3(x, y+1, data[x][y+1]['h']) c4 = data[x][y+1]['c'] t4 = data[x][y+1]['texnum'] n=(0, 0, 1) # normal # assign vertex colors + alpha a1, a2, a3, a4 = ap(t1), ap(t2), ap(t3), ap(t4) t1, t2, t3, t4 = tp(t1), tp(t2), tp(t3), tp(t4) if v1[2]==0: t1 = [data[x][y]['c'][0], data[x][y]['c'][1], data[x][y]['c'][2], a1] if v2[2]==0: t2 = [data[x+1][y]['c'][0], data[x+1][y]['c'][1], data[x+1][y]['c'][2], a2] if v3[2]==0: t3 = [data[x+1][y+1]['c'][0], data[x+1][y+1]['c'][1], data[x+1][y+1]['c'][2], a3] if v4[2]==0: t4 = [data[x][y+1]['c'][0], data[x][y+1]['c'][1], data[x][y+1]['c'][2], a4] if a1 == 0 and a2 == 0 and a3 == 0 and a4 == 0: continue # add vertices vertex.addData3f(v1) normal.addData3f(*n) color.addData4f(*t1) uv.addData2f(0,0) vertex.addData3f(v2) normal.addData3f(*n) color.addData4f(*t2) uv.addData2f(1,0) vertex.addData3f(v3) normal.addData3f(*n) color.addData4f(*t3) uv.addData2f(1,1) vertex.addData3f(v1) normal.addData3f(*n) color.addData4f(*t1) uv.addData2f(0,0) vertex.addData3f(v3) normal.addData3f(*n) color.addData4f(*t3) uv.addData2f(1,1) vertex.addData3f(v4) normal.addData3f(*n) color.addData4f(*t4) uv.addData2f(0,1) number = number + 2 # add triangles prim = GeomTriangles(Geom.UHStatic) for n in range(number): prim.addVertices((n * 3) + 2, (n * 3) + 0, (n * 3) + 1) prim.closePrimitive() # make geom geom = Geom(vdata) geom.addPrimitive(prim) # make geom node node = GeomNode("layer" + str(i) + "_" + str(a) + "_" + str(b)) node.addGeom(geom) # make mesh nodePath mesh = NodePath(node) # load and assign texture txfile = self.tiles[i]['tex'] tx = base.loader.loadTexture(txfile) tx.setMinfilter(Texture.FTLinearMipmapLinear) mesh.setDepthTest(DepthTestAttrib.MLessEqual) mesh.setDepthWrite(False) mesh.setTransparency(True) mesh.setTexture(tx) # set render order mesh.setBin("", 1) # locate mesh mesh.setPos(self.divsep * (a * int(len(self.data[a]) / self.div)), self.divsep * (b * int(len(self.data[b]) / self.div)), 0.001) # reparent mesh mesh.reparentTo(self.root) # return mesh return mesh
class World: def __init__(self, actor, state, lvl): #Setzte die Parameter self.CActor = actor #Spieler erstellen self.CGame = state #FSM - Gamestate erstellen self.mission = lvl #Aktuelle Mission self.mMission = None #Grundeinstellen fuer die Welt base.disableMouse() #Mouse ausmachen self.slowdown = 1 #Schnelligkeitsfaktor 1=Normal self.hud = False file, filename, description = imp.find_module("mission" + str(self.mission)) self.mMission = imp.load_module("mission" + str(self.mission), file, filename, description) #SPIELER - Variablen self.oldactorlevel = self.CActor.getLevel() self.CActor.CActorShip.setX( -165) #Setze den Spieler links im Bildschirm self.CActor.CActorShip.setY(0) self.CActor.nActorShip.reparentTo(render) self.CActor.CActorShip.getWeapon().setWeapon( "laserGun") #Standardwaffe setzen self.maxshield = self.CActor.CActorShip.getShield( ) #Schild speichern um Prozent berechnen zu koennen self.hitted = False #Variable um abzufragen ob man getroffen wurde self.dead = False #Spieler lebt self.lbullets = [] #Spielerbullets self.lbulletsspeed = [] self.lcanon = [] #Spielercanonbullets self.lcanonspeed = [] self.cameraeffectx = 0 #X-Wert der Camera um eine Sinuskurve zu implementieren self.cameraeffectamplitude = 5 #Die Amplitude der Sinuswelle - Maxima self.exppercent = (self.CActor.getExperience() * 100 ) / self.CActor.getMaxExperience() #EXP in Prozent self.oldcash = self.CActor.getMoney() self.secweapon = 3 #Resultattexte, wenn die Mission zu ende ist self.txtresultmission = addText(-0.15, 0.35, "") self.txtresultkills = addText(-0.15, 0.25, "") self.txtresultleft = addText(-0.15, 0.20, "") self.txtresultcash = addText(-0.15, 0.15, "") self.txtresultlevel = addText(-0.15, 0.10, "") self.txtresultmessage = addText(-0.15, 0.0, "") #ALLES FUER MOTION BLUR *********************************************************************** #Eine Texture erstellen, welches in das Hauptfenster kopiert wird self.CTex = Texture() self.CTex.setMinfilter(Texture.FTLinear) base.win.addRenderTexture(self.CTex, GraphicsOutput.RTMTriggeredCopyTexture) #Eine andere 2D Kamera erstellen, welches vor der Hauptkamera gerendert wird self.backcam = base.makeCamera2d(base.win, sort=-10) self.background = NodePath("background") self.backcam.reparentTo(self.background) self.background.setDepthTest(0) self.background.setDepthWrite(0) self.backcam.node().getDisplayRegion(0).setClearDepthActive(0) #Zwei Texturekarten ersten. Eins bevor, eins danach self.bcard = base.win.getTextureCard() self.bcard.reparentTo(self.background) self.bcard.setTransparency(1) self.fcard = base.win.getTextureCard() self.fcard.reparentTo(render2d) self.fcard.setTransparency(1) #********************************************************************************************** #Drops als Liste self.ldrop = [] #Explosionen - oder besser gesagt Splittereffekt als Liste self.lexplosions = [] #Soundklasse erstellen um Zugriff auf die Sound zu haben self.CSound = SoundMng() self.CSound.sndFlyAmbience.play() #GEGNER - Variablen self.destroyedenemy = 0 self.lostenemy = 0 self.lenemys = [] #Gegnerspeicher self.lbulletsenemy = [] #Gegnerbullets self.newwave = False #Boolean,welches eine neue Gegnerwelle angibt #Effekte self.CEffects = Effects() #Effektklasse erstellen #self.CEffects.createSpaceStars("particle/background.ptf") #Hintergrundeffekt erstellen #Die Game-Loop Voreinstellungen self.gameTask = taskMgr.add(self.gameLoop, "gameLoop") self.gameTask.last = 0 self.gameTask.nextbullet = 0 #Timer wann geschossen werden darf, vom Spieler self.gameTask.gotHit = 0 self.gameTask.lnextenemybullet = [ ] #Timer wann geschossen werden darf, unabhaengig von welche Gegner self.gameTask.resultkills = 0 #Timer fuer die Kills, im Resultat self.gameTask.resultleft = 0 #Timer fuer die geflohenen Gegner, im Resultat self.gameTask.introduction = 0 self.gameTask.introdelete = 0 self.gameTask.won = 0 self.resultcounter = 0 #Zeahler der die Nummern der Kills im Result aktualisiert self.resultcounterleft = 0 #Zeahler der die Nummern der geflohenen Gegner im Result aktualisiert self.introcounter = 0 self.ldata = [] self.readytospawn = False self.musicplayed = False self.musicplayed2 = False self.resultplayed = False #2D Kamera erstellen lens = OrthographicLens() lens.setFilmSize(350, 250) base.cam.node().setLens(lens) def gameLoop(self, task): #Clock fuer FPS unabhaengige Bewegung elapsed = globalClock.getDt() if task.time > task.introduction: if (self.mMission.getIntroduction(self.introcounter) == True): self.introcounter += 1 task.introduction = task.time + 0.1 else: task.introdelete = task.introduction + 3 if task.time > task.introdelete: if self.musicplayed == False: self.CSound.sndMusic.play() self.musicplayed = True self.toogleHud() self.mMission.removeIntroduction() if self.mMission.getSituation(task.time) == True: for i in range(3): self.ldata.append(self.mMission.getEnemies(i)) self.createEnemys(self.ldata[len(self.ldata) - 3], self.ldata[len(self.ldata) - 1]) self.spawnEnemys(200, self.ldata[len(self.ldata) - 2]) #Die Position der Gegner aktualisieren for obj in self.lenemys: self.updatePosEnemy(obj, elapsed) if obj.nEnemyShip.isEmpty() == 0: if obj.CEnemyShip.getX() < -180: obj.nEnemyShip.removeNode() self.lostenemy += 1 if obj.CEnemyShip.getX() > 170: obj.nEnemyShip.detachNode() if obj.CEnemyShip.getX() < 170 and obj.CEnemyShip.getX( ) > -150: obj.nEnemyShip.reparentTo(render) if self.destroyedenemy + self.lostenemy == self.mMission.MAX_ENEMYS: if task.won == 0: task.won = task.time + 3 if task.won < task.time and self.musicplayed2 == False: self.CSound.sndMusic.stop() self.musicplayed2 = True task.won = task.time + 3 if task.won < task.time: if self.resultplayed == False: self.CSound.sndResult.play() self.CSound.sndFlyAmbience.stop() self.resultplayed = True for drop in self.ldrop: drop.remove() self.txthp.destroy() self.txtshield.destroy() self.txtlvl.destroy() self.imgHud.destroy() self.imgExp.destroy() self.txtresultmission.setText("Mission: " + str(self.mission) + " Complete") if task.time > task.resultkills: if self.resultcounter < self.destroyedenemy: self.resultcounter += 1 self.txtresultkills.setText("Killed Enemies: " + str(self.resultcounter)) self.CSound.sndTipp.play() task.resultkills = task.time + 0.1 if self.resultcounter == self.destroyedenemy: if task.time > task.resultleft: if self.resultcounterleft < self.lostenemy: self.resultcounterleft += 1 self.txtresultleft.setText( "Left Enemies: " + str(self.resultcounterleft)) task.resultleft = task.time + 0.1 self.CSound.sndTipp.play() if self.resultcounterleft == self.lostenemy: self.txtresultcash.setText( "Geldstand: " + str(self.CActor.getMoney()) + "$ (+" + str(self.CActor.getMoney() - self.oldcash) + "$)") self.txtresultlevel.setText( "Dein Level: " + str(self.CActor.getLevel()) + " (+" + str(self.CActor.getLevel() - self.oldactorlevel) + ")") self.txtresultmessage.setText( "Druecke Enter um fortzufahren") if self.CActor.keyMap["entr"] != 0: self.CActor.CActorShip.setShield( self.maxshield) self.CActor.setHP(self.CActor.getMaxHP()) taskMgr.remove('gameLoop') self.CGame.request("GameMenue", self.CActor, self.CGame) if self.dead == True: render.node().removeAllChildren() taskMgr.remove("gameLoop") self.CGame.request("MainMenue", self.CGame) #Falls nextEnemyBullet-Timer NULL ist, so erstelle fuer jeden Gegner einen eigenen Timer if (self.newwave == True): for i in range(len(self.lenemys)): task.lnextenemybullet.append(i) self.newwave = False #Gegnerfeuer erstellen und mit einem Zufallsalgorythmus schiessen lassen for i in range(len(self.lenemys)): posEnemyX = self.lenemys[i].CEnemyShip.getX() #Erst schiessen lassen, wenn sie im Spielbereich sind if posEnemyX < 170 and posEnemyX > -180 and self.lenemys[ i].nEnemyShip.hasParent() == True: if task.time > task.lnextenemybullet[i]: task.lnextenemybullet[i] = task.time + choice( range(4, 7) + range(4, 7)) self.enemyShot(self.lenemys[i]) self.lenemys[i].CEnemyShip.getWeapon().sndGun.setVolume( 0.5) self.lenemys[i].CEnemyShip.getWeapon().sndGun.play() #Nachdem der Spieler die Schiesstaste gedrueckt hat, wird ein Timer aktiviert der nach eine Zeit #immer wieder aktualisiert wird, damit der Spieler den naechsten Schuss abfeuern kann if (self.CActor.keyMap["arr_up"] != 0 and task.time > task.nextbullet): if self.dead == False: task.nextbullet = task.time + 1.25**(-1.5 * self.CActor.getAgility()) self.playerShot("laserGun") self.CActor.CActorShip.getWeapon().sndGun.play() #Nachdem der Spieler die Schiesstaste gedrueckt hat, wird ein Timer aktiviert der nach eine Zeit #immer wieder aktualisiert wird, damit der Spieler den naechsten Schuss abfeuern kann if (self.CActor.keyMap["arr_right"] != 0 and task.time > task.nextbullet): if self.dead == False: task.nextbullet = task.time + 1 + 1.25**( -1.5 * self.CActor.getAgility()) self.playerShot("canonGun") self.CActor.CActorShip.getWeapon().sndGun.play() #Ein Array, um abgeschossen Patronen festzuhalten: vom Spieler lnewbullet = [] #Funktion um die Bullets zu aktualsieren for i in range(len(self.lbullets)): self.updateBulletPlayer(self.lbullets[i], self.lbulletsspeed[i], elapsed) if self.lbullets[i].isEmpty() == 0: if (self.lbullets[i].getX() < 180): lnewbullet.append(self.lbullets[i]) else: self.lbullets[i].remove() self.lbullets = lnewbullet lnewcanon = [] #Funktion um die Bullets zu aktualsieren for i in range(len(self.lcanon)): self.updateBulletPlayer(self.lcanon[i], self.lcanonspeed[i], elapsed) if self.lcanon[i].isEmpty() == 0: if (self.lcanon[i].getX() < 180): lnewcanon.append(self.lcanon[i]) else: self.lcanon[i].remove() self.lcanon = lnewcanon #Ein Array, um abgeschossen Patronen festzuhalten: vom Gegner lnewenemybullet = [] #Funktion um die Bullets der Gegner zu aktualsieren for obj in self.lbulletsenemy: self.updateBulletEnemy(obj, elapsed) if obj.isEmpty() == 0: if (obj.getX() > -180): lnewenemybullet.append(obj) else: obj.remove() self.lbulletsenemy = lnewenemybullet #Funktion fuer die Kollision mit dem Gegner for obj in self.lbullets: self.enemyHit(obj) for obj in self.lcanon: self.enemyHit(obj) #Funktion fuer die Kollision mit dem Spieler if self.playerHit() == True: self.hitted = True #Funktion fuer die Kollision mit dem Schiff if self.getShipHit() == True: self.hitted = True self.dropHit() #Falls Spieler getroffen wird, so mache ein Cameraeffekt if self.hitted == True: if self.CActor.CActorShip.getShield() > 0: self.cameraeffectamplitude = 5 base.camera.setZ(base.camera.getZ() + self.cameraeffectamplitude * math.sin(self.cameraeffectx)) self.cameraeffectx = self.cameraeffectx + 1 if self.cameraeffectx == 20: self.hitted = False self.cameraeffectx = 0 base.camera.setZ(0) else: if (self.dead == False): self.cameraeffectamplitude = 2 base.camera.setZ(base.camera.getZ() + self.cameraeffectamplitude * math.sin(self.cameraeffectx)) self.cameraeffectx = self.cameraeffectx + 1 else: self.hitted = False for obj in self.ldrop: if obj != None: if obj.isEmpty() == 0: obj.setHpr(obj.getH() - 1, 0, 0) for obj in self.lexplosions: if obj != None: if obj.isEmpty() == 0: posy = obj.getZ() self.updateExplosion( obj, elapsed, -3, choice(range(-11, 11) + range(-11, 11))) if obj.getX() < -180: obj.remove() return Task.cont def updateExplosion(self, obj, dt, x, y): if obj.isEmpty() == 0: newposx = obj.getX() + (self.slowdown * dt * 35 * 3) * x newposy = obj.getZ() + (self.slowdown * dt * 35 * 3) * y obj.setX(newposx) obj.setZ(newposy) def updateBulletPlayer(self, obj, spe, dt): if obj.isEmpty() == 0: newpos = obj.getX() + (self.slowdown * dt * 35 * spe) obj.setX(newpos) def updateBulletEnemy(self, obj, dt): if obj.isEmpty() == 0: newpos = obj.getX() - ( self.slowdown * dt * 35 * self.CEnemy.CEnemyShip.getWeapon().getWeaponSpeed()) obj.setX(newpos) def updatePosEnemy(self, obj, dt): if obj.nEnemyShip.isEmpty() == 0: obj.CEnemyShip.setX(obj.CEnemyShip.getX() - self.slowdown * dt * 15 * obj.CEnemyShip.getSpeed()) obj.CEnemyShip.setY(obj.CEnemyShip.getY() + self.slowdown * dt * 15 * (math.sin(0.1 * obj.CEnemyShip.getX()))) def playerShot(self, gun): bullet = self.CActor.CActorShip.getWeapon().setWeapon(gun) if bullet.isEmpty() == 0: if self.secweapon == 3: bullet.setPos(self.CActor.CActorShip.getX() + 10, 500, self.CActor.CActorShip.getY() + self.secweapon) self.secweapon = -4 else: bullet.setPos(self.CActor.CActorShip.getX() + 10, 500, self.CActor.CActorShip.getY() + self.secweapon) self.secweapon = 3 print self.CActor.CActorShip.getWeapon().getWeapon() if self.CActor.CActorShip.getWeapon().getWeapon() == "laserGun": self.lbullets.append(bullet) self.lbulletsspeed.append( self.CActor.CActorShip.getWeapon().getWeaponSpeed()) elif self.CActor.CActorShip.getWeapon().getWeapon() == "canonGun": self.lcanon.append(bullet) self.lcanonspeed.append( self.CActor.CActorShip.getWeapon().getWeaponSpeed()) del bullet def enemyShot(self, obj): bullet = obj.CEnemyShip.getWeapon().setWeapon("laserGun") if obj.nEnemyShip.isEmpty() == 0: bullet.setPos(obj.nEnemyShip.getPos()) self.lbulletsenemy.append(bullet) del bullet def addDrop(self, pos): drp = self.CEffects.getDrop("models/heal", 19, pos) if (drp == None): return False else: self.ldrop.append(drp) return True def explode(self, pos): expl = self.CEffects.getExplosion(pos) self.lexplosions.append(expl) def enemyHit(self, bullet): for enmy in self.lenemys: if enmy.nEnemyShip.isEmpty() == 0 and bullet.isEmpty() == 0: #Falls Gegner getroffen wird if (bullet.getPos() - enmy.nEnemyShip.getPos()).lengthSquared() < 85: #Bullet loesche bullet.remove() self.explode(enmy.nEnemyShip.getPos()) enmy.CEnemyShip.setShield( enmy.CEnemyShip.getShield() - self.CActor.CActorShip.getWeapon().getWeaponStrength()) self.CSound.sndHit.play() #Falls kein Schild mehr vorhanden -> Loeschen if enmy.CEnemyShip.getShield() <= 0: self.addDrop(enmy.nEnemyShip.getPos()) for i in range(5): self.explode(enmy.nEnemyShip.getPos()) enmy.nEnemyShip.removeNode() self.CSound.sndExplosion.play() self.destroyedenemy += 1 self.CActor.setExperience(self.CActor.getExperience() + (enmy.getExpDrop())) self.exppercent = (self.CActor.getExperience() * 100 ) / self.CActor.getMaxExperience() if self.imgExp.isEmpty() == 0: self.imgExp.setScale( 0.01, 0.2, ((2.0 * self.exppercent) / 100.0)) self.CActor.setMoney(self.CActor.getMoney() + enmy.getCashDrop()) if self.CActor.getLevelUp() == True: self.txtlvl.setText(str(self.CActor.getLevel())) self.CActor.setExperience(self.CActor.getExperience() + (enmy.getExpDrop() / 2)) self.exppercent = (self.CActor.getExperience() * 100 ) / self.CActor.getMaxExperience() self.imgExp.setScale(0.01, 0.2, 0.002) def playerHit(self): for bullet in self.lbulletsenemy: if self.CActor.nActorShip.isEmpty() == 0 and bullet.isEmpty() == 0: #Falls Spieler getroffen wird if ((bullet.getPos() - self.CActor.nActorShip.getPos()).lengthSquared() < 85): #Bullet loeschen bullet.remove() #Funktion aufrufen - Parameter: Schaden if self.actorHurt(self.CEnemy.CEnemyShip.getWeapon( ).getWeaponStrength() + self.CEnemy.getStrength()) == True: return True def getShipHit(self): for enmy in self.lenemys: if enmy.nEnemyShip.isEmpty( ) == 0 and self.CActor.nActorShip.isEmpty() == 0: #Falls das Spielerschiff einen Gegnerschiff trifft if ((enmy.nEnemyShip.getPos() - self.CActor.nActorShip.getPos()).lengthSquared() < 85): for i in range(5): self.explode(enmy.nEnemyShip.getPos()) enmy.nEnemyShip.removeNode() #self.CSound.sndExplosion.play() self.destroyedenemy += 1 self.CActor.setExperience(self.CActor.getExperience() + (enmy.getExpDrop() / 2)) self.exppercent = (self.CActor.getExperience() * 100) / self.CActor.getMaxExperience() if self.CActor.getLevelUp() == True: self.txtlvl.setText(str(self.CActor.getLevel())) self.CActor.setExperience(self.CActor.getExperience() + (enmy.getExpDrop() / 2)) self.exppercent = (self.CActor.getExperience() * 100 ) / self.CActor.getMaxExperience() #Schaden ist gleich der Staerke vom gegnerischen Schiff if self.actorHurt(enmy.getStrength()) == True: return True def createEnemys(self, amount, kind): for i in range(amount): #Gegner erstellen self.CEnemy = Enemy(kind) self.lenemys.append(self.CEnemy) def spawnEnemys(self, start, width): for obj in self.lenemys: if obj.CEnemyShip.getY() > 101 and obj.nEnemyShip.isEmpty() == 0: obj.CEnemyShip.setX( choice(range(start, width) + range(start, width))) obj.CEnemyShip.setY(choice(range(-100, 0) + range(0, 100))) self.newwave = True def dropHit(self): for obj in self.ldrop: if obj.isEmpty() == 0 and self.CActor.nActorShip.isEmpty() == 0: if ((obj.getPos() - self.CActor.nActorShip.getPos()).lengthSquared() < 86): obj.remove() if self.CActor.getHP() < self.CActor.getMaxHP(): self.CActor.setHP(self.CActor.getHP() + 20) self.txthp.setText( str((self.CActor.getHP() * 100) / self.CActor.getMaxHP())) def actorHurt(self, dmg): if (self.CActor.CActorShip.getShield() <= 0): self.txtshield.setText("0") self.CActor.CActorShip.setShield(0) self.CActor.setHP(self.CActor.getHP() - dmg * 20) self.CSound.sndCrit.play() if (self.CActor.getHP() <= 0): #Der Spieler ist tot und hat verloren self.txthp.setText("0") self.dead = True #self.CFilters.setBloom(blend=(0,0,0,1), desat=-0.5, intensity=5.0, size="small") self.slowdown = 1 self.CActor.slowdown = self.slowdown taskMgr.remove("takeSnapShot") self.clickrate = 0 self.fcard.hide() for i in range(5): self.explode(self.CActor.nActorShip.getPos()) self.CActor.nActorShip.detachNode() return True if (self.CActor.getHP() <= 50): self.CSound.sndExplosion.setPlayRate(0.5) self.CSound.sndMusic.setPlayRate(0.5) self.CSound.sndFlyAmbience.setPlayRate(0.5) self.CSound.sndHit.setPlayRate(0.5) self.CActor.CActorShip.getWeapon().sndGun.setPlayRate(0.5) taskMgr.add(self.takeSnapShot, "takeSnapShot") self.chooseEffectGhost() self.slowdown = 0.5 self.CActor.setSlowDown(self.slowdown) #self.CFilters.delBloom() self.explode(self.CActor.nActorShip.getPos()) self.txthp.setText( str((self.CActor.getHP() * 100) / self.CActor.getMaxHP())) return True else: self.CActor.CActorShip.setShield( self.CActor.CActorShip.getShield() - dmg) self.txtshield.setText( str((self.CActor.CActorShip.getShield() * 100) / self.maxshield)) self.explode(self.CActor.nActorShip.getPos()) return True #Screenshots erstellen um MotionBlur Effekt zu erreichen def takeSnapShot(self, task): if (task.time > self.nextclick): self.nextclick += 1.0 / self.clickrate if (self.nextclick < task.time): self.nextclick = task.time base.win.triggerCopy() return Task.cont #MotionBlur Effekt def chooseEffectGhost(self): base.setBackgroundColor(0, 0, 0, 1) self.bcard.hide() self.fcard.show() self.fcard.setColor(1.0, 1.0, 1.0, 0.99) self.fcard.setScale(1.00) self.fcard.setPos(0, 0, 0) self.fcard.setR(0) self.clickrate = 100 self.nextclick = 0 def toogleHud(self): if self.hud == False: #Hudeinstellung ******************************************************************************* self.imgHud = OnscreenImage(image='images/hud.png', pos=(-1.09, 0, -0.01), scale=(0.185, 0.5, 1)) self.imgHud.reparentTo(aspect2d) self.imgHud.setTransparency(TransparencyAttrib.MAlpha) #EXP Leiste self.imgExp = OnscreenImage(image='images/exp.png', pos=(-1.2645, 0, -1), scale=(0.01, 0.2, 0.001)) self.imgExp.reparentTo(aspect2d) #Texte der HUD self.txthp = addText( -1.03, 0.966, str((self.CActor.getHP() * 100) / self.CActor.getMaxHP())) self.txtshield = addText( -1.03, 0.9151, str((self.CActor.CActorShip.getShield() * 100) / self.maxshield)) self.txtlvl = addText(-1.19, 0.80, str(self.CActor.getLevel())) self.hud = True
def renderSceneInto(self, depthtex=None, colortex=None, auxtex=None, auxbits=0, textures=None): """ Causes the scene to be rendered into the supplied textures instead of into the original window. Puts a fullscreen quad into the original window to show the render-to-texture results. Returns the quad. Normally, the caller would then apply a shader to the quad. To elaborate on how this all works: * An offscreen buffer is created. It is set up to mimic the original display region - it is the same size, uses the same clear colors, and contains a DisplayRegion that uses the original camera. * A fullscreen quad and an orthographic camera to render that quad are both created. The original camera is removed from the original window, and in its place, the orthographic quad-camera is installed. * The fullscreen quad is textured with the data from the offscreen buffer. A shader is applied that tints the results pink. * Automatic shader generation NOT enabled. If you have a filter that depends on a render target from the auto-shader, you either need to set an auto-shader attrib on the main camera or scene, or, you need to provide these outputs in your own shader. * All clears are disabled on the original display region. If the display region fills the whole window, then clears are disabled on the original window as well. It is assumed that rendering the full-screen quad eliminates the need to do clears. Hence, the original window which used to contain the actual scene, now contains a pink-tinted quad with a texture of the scene. It is assumed that the user will replace the shader on the quad with a more interesting filter. """ if (textures): colortex = textures.get("color", None) depthtex = textures.get("depth", None) auxtex = textures.get("aux", None) if (colortex == None): colortex = Texture("filter-base-color") colortex.setWrapU(Texture.WMClamp) colortex.setWrapV(Texture.WMClamp) texgroup = (depthtex, colortex, auxtex, None) # Choose the size of the offscreen buffer. (winx, winy) = self.getScaledSize(1,1,1) buffer = self.createBuffer("filter-base", winx, winy, texgroup) if (buffer == None): return None cm = CardMaker("filter-base-quad") cm.setFrameFullscreenQuad() quad = NodePath(cm.generate()) quad.setDepthTest(0) quad.setDepthWrite(0) quad.setTexture(colortex) quad.setColor(Vec4(1,0.5,0.5,1)) cs = NodePath("dummy") cs.setState(self.camstate) # Do we really need to turn on the Shader Generator? #cs.setShaderAuto() if (auxbits): cs.setAttrib(AuxBitplaneAttrib.make(auxbits)) self.camera.node().setInitialState(cs.getState()) quadcamnode = Camera("filter-quad-cam") lens = OrthographicLens() lens.setFilmSize(2, 2) lens.setFilmOffset(0, 0) lens.setNearFar(-1000, 1000) quadcamnode.setLens(lens) quadcam = quad.attachNewNode(quadcamnode) self.region.setCamera(quadcam) dr = buffer.getDisplayRegion(0) self.setStackedClears(dr, self.rclears, self.wclears) if (auxtex): dr.setClearActive(GraphicsOutput.RTPAuxRgba0, 1) dr.setClearValue(GraphicsOutput.RTPAuxRgba0, Vec4(0.5,0.5,1.0,0.0)) self.region.disableClears() if (self.isFullscreen()): self.win.disableClears() dr.setCamera(self.camera) dr.setActive(1) self.buffers.append(buffer) self.sizes.append((1, 1, 1)) return quad
class FishLure(NodePath): def __init__(self, gameObject, type): NodePath.__init__(self, "FishingLure_%s" % type) self.gameObject = gameObject self.type = type self.initLureModel() if FishingGlobals.wantDebugCollisionVisuals: self.initCollision() self.initLureHelpText() self.setLightOff() def initLureModel(self): self.lureModel = NodePath("lure") self.currentLureType = "regular" self.lureAttractRadius = FishingGlobals.lureTypeToAttractRadius[self.currentLureType] self.lureModel = loader.loadModel(FishingGlobals.lureTypeToModel[self.currentLureType]) self.lureModel.setScale(2.0) self.lureModel.reparentTo(self) self.lureModel.setDepthWrite(False) self.lureModel.setDepthTest(True) self.lureModel.setBin("ground", 25) self.mainGui = loader.loadModel("models/gui/gui_main") def initCollision(self): self.lureCollisionVisual = loader.loadModel("models/ammunition/cannonball") self.lureCollisionVisual.setTransparency(1) self.lureCollisionVisual.setColor(0.0, 0.0, 1.0, 0.29999999999999999) self.lureCollisionVisual.setScale(self.lureAttractRadius) self.lureCollisionVisual.reparentTo(self) self.lureCollisionVisual.hide() def initLureHelpText(self): self.helpTextNode = TextNode("fishBitingIcon") self.helpTextNodePath = NodePath(self.helpTextNode) self.helpTextNodePath.setPos(0.0, 0.0, 0.69999999999999996) self.helpTextNode.setText(" ") self.helpTextNode.setAlign(TextNode.ACenter) self.helpTextNode.setFont(PiratesGlobals.getPirateFont()) self.helpTextNode.setTextColor(1.0, 1.0, 1.0, 1.0) self.helpTextNodePath.reparentTo(self) self.helpTextNodePath.setBillboardPointEye() self.helpTextNodePath.setBin("fishingGame", 10) self.helpTextNodePath.hide() def enableLureGlow(self, glowType): self.lureGlow = LureGlow.getEffect() if self.lureGlow: if self.gameObject.fishManager.activeFish is not None: self.lureGlow.reparentTo(self.gameObject.fishManager.activeFish.mouthJoint) else: self.lureGlow.reparentTo(self) self.lureGlow.effectColor = _glowColors[glowType] self.lureGlow.setShaderOff() self.lureGlow.setBin("fishingGame", 5) self.lureGlow.play() def showHelpText(self, textToShow): taskMgr.remove(self.gameObject.distributedFishingSpot.uniqueName("ClearLureText")) if textToShow is None: self.helpTextNode.setText(" ") self.helpTextNodePath.hide() elif self.gameObject.fishManager.activeFish is not None: self.helpTextNodePath.setScale( FishingGlobals.fishSizeToHelpTextScale[self.gameObject.fishManager.activeFish.myData["size"]] ) else: self.helpTextNodePath.setScale(1.0) self.helpTextNode.setText(textToShow) self.helpTextNodePath.show() taskMgr.doMethodLater( FishingGlobals.lureHelpTextDuration, self.showHelpText, name=self.gameObject.distributedFishingSpot.uniqueName("ClearLureText"), extraArgs=[None], ) def setLureType(self, type): self.currentLureType = type if type == None: self.lureModel.hide() self.gameObject.gui.setTackleBoxPulse(True) elif type == "regular": self.gameObject.gui.setTackleBoxPulse(False) self.currentLureType = type self.lureModel.removeNode() self.lureAttractRadius = FishingGlobals.lureTypeToAttractRadius[type] self.lureModel = loader.loadModel(FishingGlobals.lureTypeToModel[type]) self.lureModel.setScale(2.0) self.lureModel.reparentTo(self) self.lureModel.setDepthWrite(False) self.lureModel.setDepthTest(True) self.lureModel.setBin("ground", 25) elif type == "legendary": self.gameObject.gui.setTackleBoxPulse(False) self.currentLureType = type self.lureModel.removeNode() self.lureAttractRadius = FishingGlobals.lureTypeToAttractRadius[type] self.lureModel = loader.loadModel(FishingGlobals.lureTypeToModel[type]) self.lureModel.setScale(2.0) self.lureModel.reparentTo(self) self.lureModel.setDepthWrite(False) self.lureModel.setDepthTest(True) self.lureModel.setBin("ground", 25) def showCollisionVisuals(self): if FishingGlobals.wantDebugCollisionVisuals: self.lureCollisionVisual.show() def hideCollisionVisuals(self): if FishingGlobals.wantDebugCollisionVisuals: self.lureCollisionVisual.hide() def requestPitch(self, fish): offset = fish.getPos() - self.getPos() if fish.getX() < self.getX(): return math.degrees(math.atan2(offset.getZ(), -offset.getX())) else: return math.degrees(math.atan2(-offset.getZ(), offset.getX())) def resetLureModel(self): self.lureModel.reparentTo(self) self.lureModel.show() self.lureModel.setPosHpr(0, 0, 0, 0, 0, 0.0) if self.currentLureType == None: self.lureModel.hide() self.gameObject.gui.setTackleBoxPulse(True) else: self.gameObject.gui.setTackleBoxPulse(False) def destroy(self): self.lureModel.removeNode() self.removeNode()
def renderSceneInto(self, depthtex=None, colortex=None, auxtex=None, auxbits=0, textures=None): """ Causes the scene to be rendered into the supplied textures instead of into the original window. Puts a fullscreen quad into the original window to show the render-to-texture results. Returns the quad. Normally, the caller would then apply a shader to the quad. To elaborate on how this all works: * An offscreen buffer is created. It is set up to mimic the original display region - it is the same size, uses the same clear colors, and contains a DisplayRegion that uses the original camera. * A fullscreen quad and an orthographic camera to render that quad are both created. The original camera is removed from the original window, and in its place, the orthographic quad-camera is installed. * The fullscreen quad is textured with the data from the offscreen buffer. A shader is applied that tints the results pink. * Automatic shader generation NOT enabled. If you have a filter that depends on a render target from the auto-shader, you either need to set an auto-shader attrib on the main camera or scene, or, you need to provide these outputs in your own shader. * All clears are disabled on the original display region. If the display region fills the whole window, then clears are disabled on the original window as well. It is assumed that rendering the full-screen quad eliminates the need to do clears. Hence, the original window which used to contain the actual scene, now contains a pink-tinted quad with a texture of the scene. It is assumed that the user will replace the shader on the quad with a more interesting filter. """ if (textures): colortex = textures.get("color", None) depthtex = textures.get("depth", None) auxtex = textures.get("aux", None) auxtex0 = textures.get("aux0", auxtex) auxtex1 = textures.get("aux1", None) else: auxtex0 = auxtex auxtex1 = None if (colortex == None): colortex = Texture("filter-base-color") colortex.setWrapU(Texture.WMClamp) colortex.setWrapV(Texture.WMClamp) texgroup = (depthtex, colortex, auxtex0, auxtex1) # Choose the size of the offscreen buffer. (winx, winy) = self.getScaledSize(1,1,1) buffer = self.createBuffer("filter-base", winx, winy, texgroup) if (buffer == None): return None cm = CardMaker("filter-base-quad") cm.setFrameFullscreenQuad() quad = NodePath(cm.generate()) quad.setDepthTest(0) quad.setDepthWrite(0) quad.setTexture(colortex) quad.setColor(Vec4(1,0.5,0.5,1)) cs = NodePath("dummy") cs.setState(self.camstate) # Do we really need to turn on the Shader Generator? #cs.setShaderAuto() if (auxbits): cs.setAttrib(AuxBitplaneAttrib.make(auxbits)) self.camera.node().setInitialState(cs.getState()) quadcamnode = Camera("filter-quad-cam") lens = OrthographicLens() lens.setFilmSize(2, 2) lens.setFilmOffset(0, 0) lens.setNearFar(-1000, 1000) quadcamnode.setLens(lens) quadcam = quad.attachNewNode(quadcamnode) self.region.setCamera(quadcam) self.setStackedClears(buffer, self.rclears, self.wclears) if (auxtex0): buffer.setClearActive(GraphicsOutput.RTPAuxRgba0, 1) buffer.setClearValue(GraphicsOutput.RTPAuxRgba0, Vec4(0.5, 0.5, 1.0, 0.0)) if (auxtex1): buffer.setClearActive(GraphicsOutput.RTPAuxRgba1, 1) self.region.disableClears() if (self.isFullscreen()): self.win.disableClears() dr = buffer.makeDisplayRegion() dr.disableClears() dr.setCamera(self.camera) dr.setActive(1) self.buffers.append(buffer) self.sizes.append((1, 1, 1)) return quad
class FishLure(NodePath): def __init__(self, gameObject, type): NodePath.__init__(self, 'FishingLure_%s' % type) self.gameObject = gameObject self.type = type self.initLureModel() if FishingGlobals.wantDebugCollisionVisuals: self.initCollision() self.initLureHelpText() self.setLightOff() def initLureModel(self): self.lureModel = NodePath('lure') self.currentLureType = 'regular' self.lureAttractRadius = FishingGlobals.lureTypeToAttractRadius[ self.currentLureType] self.lureModel = loader.loadModel( FishingGlobals.lureTypeToModel[self.currentLureType]) self.lureModel.setScale(2.0) self.lureModel.reparentTo(self) self.lureModel.setDepthWrite(False) self.lureModel.setDepthTest(True) self.lureModel.setBin('ground', 25) self.mainGui = loader.loadModel('models/gui/gui_main') def initCollision(self): self.lureCollisionVisual = loader.loadModel( 'models/ammunition/cannonball') self.lureCollisionVisual.setTransparency(1) self.lureCollisionVisual.setColor(0.0, 0.0, 1.0, 0.29999999999999999) self.lureCollisionVisual.setScale(self.lureAttractRadius) self.lureCollisionVisual.reparentTo(self) self.lureCollisionVisual.hide() def initLureHelpText(self): self.helpTextNode = TextNode('fishBitingIcon') self.helpTextNodePath = NodePath(self.helpTextNode) self.helpTextNodePath.setPos(0.0, 0.0, 0.69999999999999996) self.helpTextNode.setText(' ') self.helpTextNode.setAlign(TextNode.ACenter) self.helpTextNode.setFont(PiratesGlobals.getPirateFont()) self.helpTextNode.setTextColor(1.0, 1.0, 1.0, 1.0) self.helpTextNodePath.reparentTo(self) self.helpTextNodePath.setBillboardPointEye() self.helpTextNodePath.setBin('fishingGame', 10) self.helpTextNodePath.hide() def enableLureGlow(self, glowType): self.lureGlow = LureGlow.getEffect() if self.lureGlow: if self.gameObject.fishManager.activeFish is not None: self.lureGlow.reparentTo( self.gameObject.fishManager.activeFish.mouthJoint) else: self.lureGlow.reparentTo(self) self.lureGlow.effectColor = _glowColors[glowType] self.lureGlow.setShaderOff() self.lureGlow.setBin('fishingGame', 5) self.lureGlow.play() def showHelpText(self, textToShow): taskMgr.remove( self.gameObject.distributedFishingSpot.uniqueName('ClearLureText')) if textToShow is None: self.helpTextNode.setText(' ') self.helpTextNodePath.hide() elif self.gameObject.fishManager.activeFish is not None: self.helpTextNodePath.setScale( FishingGlobals.fishSizeToHelpTextScale[ self.gameObject.fishManager.activeFish.myData['size']]) else: self.helpTextNodePath.setScale(1.0) self.helpTextNode.setText(textToShow) self.helpTextNodePath.show() taskMgr.doMethodLater( FishingGlobals.lureHelpTextDuration, self.showHelpText, name=self.gameObject.distributedFishingSpot.uniqueName( 'ClearLureText'), extraArgs=[None]) def setLureType(self, type): self.currentLureType = type if type == None: self.lureModel.hide() self.gameObject.gui.setTackleBoxPulse(True) elif type == 'regular': self.gameObject.gui.setTackleBoxPulse(False) self.currentLureType = type self.lureModel.removeNode() self.lureAttractRadius = FishingGlobals.lureTypeToAttractRadius[ type] self.lureModel = loader.loadModel( FishingGlobals.lureTypeToModel[type]) self.lureModel.setScale(2.0) self.lureModel.reparentTo(self) self.lureModel.setDepthWrite(False) self.lureModel.setDepthTest(True) self.lureModel.setBin('ground', 25) elif type == 'legendary': self.gameObject.gui.setTackleBoxPulse(False) self.currentLureType = type self.lureModel.removeNode() self.lureAttractRadius = FishingGlobals.lureTypeToAttractRadius[ type] self.lureModel = loader.loadModel( FishingGlobals.lureTypeToModel[type]) self.lureModel.setScale(2.0) self.lureModel.reparentTo(self) self.lureModel.setDepthWrite(False) self.lureModel.setDepthTest(True) self.lureModel.setBin('ground', 25) def showCollisionVisuals(self): if FishingGlobals.wantDebugCollisionVisuals: self.lureCollisionVisual.show() def hideCollisionVisuals(self): if FishingGlobals.wantDebugCollisionVisuals: self.lureCollisionVisual.hide() def requestPitch(self, fish): offset = fish.getPos() - self.getPos() if fish.getX() < self.getX(): return math.degrees(math.atan2(offset.getZ(), -offset.getX())) else: return math.degrees(math.atan2(-offset.getZ(), offset.getX())) def resetLureModel(self): self.lureModel.reparentTo(self) self.lureModel.show() self.lureModel.setPosHpr(0, 0, 0, 0, 0, 0.0) if self.currentLureType == None: self.lureModel.hide() self.gameObject.gui.setTackleBoxPulse(True) else: self.gameObject.gui.setTackleBoxPulse(False) def destroy(self): self.lureModel.removeNode() self.removeNode()