def updateLockOn(cont): ''' own = cont.owner if 'versiKa2' in own: print('versi ka dua') else: print('versi pertama') sen = cont.sensors['Radar2'] print(sen.positive) ids = [] for i in sen.hitObjectList: ids.append(id(i)) cek = [sen.positive, ids, sen.hitObjectList, id(var.player)] print(cek) if sen.positive == False: print('yeah sensor is negatif') print('---------------------------------------') ''' try: if cont.owner.scene.name == 'inGame': if hasattr(cont.owner, 'updateLockTarget'): cont.owner.updateLockTarget(cont) except: checker.getInfo() bge.logic.endGame()
def getKills(cont): own = cont.owner try: if var.userTotalScore != False: own.text = str(var.userTotalScore['kill']) except: print("error ref : " + str(var.userTotalScore)) checker.getInfo() bge.logic.endGame()
def addKill(killer, victim): try: if hasattr(killer, 'score'): if killer.team == victim.team: killer.score.teamkill += 1 else: killer.score.kill += 1 return True else: return False except: checker.getInfo() bge.logic.endGame()
def __init__(self, old_owner): self.name = str(old_owner) self.nick = str(old_owner) self.score = None self.invalid = False #lockedAudioFile = bge.logic.expandPath("//") + 'audio' try: lockedAudioFile = bge.logic.expandPath("//") + 'audio' #lockedAudioFile = bge.logic.expandPath("//") factory = aud.Factory(lockedAudioFile + "//locked.ogg") self.factory_buffered = aud.Factory.buffer(factory) #cek = lockedAudioFile #print("USER class state = " + str(cek)) except: checker.getInfo() bge.logic.endGame() ''' ''' pass
def deklarasi(cont): kamus = var.globalDict own = cont.owner scene = own.scene world = scene.world #world.backgroundColor = [0.0, 0.0, 0.0] if var.PCO == None: nikLok = bge.logic.expandPath('//') + 'cfg/id.txt' f = open(nikLok) n = f.readline() var.PCO = USER(n) print('id user is ' + str(var.PCO)) f.close() getUserScore(cont) if var.player == None: var.player = gameobjects.simpleObject() if 'objek' not in var.scene: var.scene['objek'] = {} #var.player = simpleObject() ''' if 'aiobject' not in kamus: kamus['aiobject'] = {} if 'object_target' not in kamus: kamus['object_target'] = {} if 'lookAtObject' not in var.scene: var.scene['lookAtObject'] = None ''' if 'lookAtRange' not in var.scene: var.scene['lookAtRange'] = None if 'rangeOfUse' not in kamus: kamus['rangeOfUse'] = 1.5 if 'inGame' not in var.scene: var.scene['inGame'] = None #custom script section import customScript try: customScript.main() except: checker.getInfo() bge.logic.endGame()
def run(self): try: (dataRaw, addr) = self.shock.recvfrom(var.buf) #data = loads(data) data = dataRaw.decode() l = simpleDecoder(data) cmd = l[0] try: if cmd == "addBlock": self.addBlock(float(l[2]), float(l[1])) if cmd == "setNScale": var.xScale = float(l[1]) for block in self.blocks: block.refresh() self.x_adder.refresh() if cmd == "setValueScale": var.yScale = float(l[1]) for block in self.blocks: block.refresh() self.y_adder.refresh() if cmd == "restart": bge.logic.restartGame() if cmd == "resetCamPos": self.cam.reset() if cmd == "setNDesc": self.nDeskripsi.text = l[1] if cmd == "setValueDesc": self.valueDeskripsi.text = l[1] print("Received message from {0}: ".format(str(addr)) + data) if cmd == "exit": print("exiting command from " + str(addr)) bge.logic.endGame() except: checker.getInfo() except: #for now I'll have to bypass it :'v pass
def run(self): #tahap spawn if self.gameObject == None: self.hasGameObjectUpdated = False hasil = spawnTuBot(self) if hasil == True: if var.waymesh != None: if self.waymesh == None: self.waymesh = gameobjects.KX_WayMesh2(var.waymesh, self) self.wayPoints = self.waymesh.rebuildTrackList(self.gameObject, self.destinedByCommander[0]) else: if self.gameObject.invalid == True: self.hasGameObjectUpdated = False self.target = None spawnTuBot(self) #print("bot need to spawn reference " + str(var.isFirstSpawn)) #self.ticks = 0 else: if self.hasGameObjectUpdated == False: #initializing scrpit for bot gameObject self.updateGameObjectData() pass self.hasGameObjectUpdated = True # -------- Note -------- #mungkin nanti stw qt mo perlu pake tuh botAirPlaneSensingObject for bot awarness # ---------------------- if 'evadingStats' not in self: self['evadingStats'] = "id {0} dari team {1} ialah {2}".format(str(id(self)), str(self.team), self.evadingStats) self.addDebugProperty('evadingStats') else: self['evadingStats'] = "id {0} dari team {1} ialah {2}".format(str(id(self)), str(self.team), self.evadingStats) if self.gameObject.tipe == "airplane": #bot for jetplane ------------ #willCollide = self.planeCollidiongPrediction() tooLow = self.altitudeAwareness() (willCollide, evadeTo, asal, evadeList, crashTime) = self.gameObject.getImpactWarning() #if var.ngecek == True: if 'a' == 'a': status = 'status of ' + self.nick + " of team " + str(self.team) if status not in self: self[status] = self.flightStats self.addDebugProperty(status) else: self[status] = self.flightStats if self.flightStats == 'needToTakeOff': self.gameObject.maju = 2 self.gameObject.runJetEngine() #tooLow = self.altitudeAwareness() #if self.sensSekitar() == False: # self.trackTo(self.gameObject.position + self.gameObject.worldOrientation * Vector((0, 45, 20))) self.trackTo(self.gameObject.position + self.gameObject.worldOrientation * Vector((0, 45, 20))) if self.gameObject.tiks > self.gameObject.botTimeToFlight: self.flightStats = "askingOrder" self.restPosition = Vector(self.gameObject.position) elif self.flightStats == "askingOrder": if self.gameObject.localLinearVelocity.y < self.speedWhenNoOrder: self.gameObject.maju = 2 self.gameObject.runJetEngine() self.trackTo(self.restPosition) #print("rest position on " + str(self.restPosition)) self.tujuan = self.destinedByCommander[0] if self.isFirstMove == True: if self.destinedByCommander != []: #self.isFirstMove = False self.flightStats = "doingOrder" #setWayPoints if var.waymesh != None: if self.waymesh != None: self.wayPoints = self.waymesh.rebuildTrackList(self.gameObject, self.destinedByCommander[0]) else: if self.destinedByCommander != self.lastQuestByCommander: self.flightStats = "doingOrder" #setWayPoints if var.waymesh != None: if self.waymesh != None: self.wayPoints = self.waymesh.rebuildTrackList(self.gameObject, self.destinedByCommander[0]) #print("let's rebuild it again") elif self.flightStats == "doingOrder": if self.destinedByCommander[1] == "goto": if willCollide == True and asal == 'depan': self.gameObject.maju = 0 self.gameObject.mundur = 2 else: self.gameObject.maju = 2 self.gameObject.mundur = 0 self.gameObject.runJetEngine() tujuan = self.destinedByCommander[0] #cek = tooLow, self.altitudeAwareness() #print("status toolownya ialah " + str(cek)) if tooLow == True: if self.waymesh != None: if self.isDirectTrackToTujuan == False: pa = len(self.wayPoints) #print("way count is " + str(pa)) if pa > 0: try: node = self.wayPoints[self.wayIndex].position except: checker.getInfo() bge.logic.endGame() #sdt = self.gameObject.worldOrientation.to_euler().z #ma = Matrix.Rotation(sdt, 3, 'Z') #va = Vector((0, 50, 0)) * ma + Vector((0, 0, 40)) #vt = va + self.gameObject.worldPosition z = hypot(node.x - self.gameObject.position.x, node.y - self.gameObject.position.y) vv = Vector((0, 0, z)).length vvt = Vector((node.x, node.y, self.gameObject.position.z + vv)) self.trackTo(vvt) self.evadingStats = "altitude warning using waymesh to evade" #self.trackTo(node) bge.render.drawLine(self.gameObject.position, vvt, [1.0, 0.0, 0.0]) #if self.gameObject.getDistanceTo(node) < 100.0: if self.gameObject.getDistanceTo(node) < self.waymesh.distToChangeNode: if self.wayIndex < pa - 1: self.wayIndex += 1 else: self.isDirectTrackToTujuan = True else: print("error!!!!!!!!!!, pa is zero") bge.logic.endGame() else: sdt = self.gameObject.worldOrientation.to_euler().z ma = Matrix.Rotation(sdt, 3, 'Z') va = Vector((0, 50, 0)) * ma + Vector((0, 0, 40)) self.trackTo(va + self.gameObject.worldPosition) self.evadingStats == "altitude warning without navigation" #print("tooLow is True, now this tracking to " + str(va + self.gameObject.worldPosition)) else: if self.waymesh != None: if self.isDirectTrackToTujuan == False: pa = len(self.wayPoints) #print("way count is " + str(pa)) if pa > 0: try: node = self.wayPoints[self.wayIndex].position except: checker.getInfo() bge.logic.endGame() nodeSpeed = -self.gameObject.worldLinearVelocity nodePos = node + nodeSpeed if willCollide == True and crashTime[asal] < self.gameObject.impactTimeWarning / 2: evadePos = evadeTo + self.gameObject.worldPosition self.trackTo(evadePos) bge.render.drawLine(self.gameObject.position, evadePos, [0.0, 1.0, 0.0]) #if self.team == 2: # print("not low evade dengan asal " + asal) else: self.trackTo(nodePos) #if self.team == 2: # print("not low node") self.evadingStats = "using navmesh, not evading" bge.render.drawLine(self.gameObject.position, node, [1.0, 0.0, 0.0]) #if self.gameObject.getDistanceTo(node) < 100.0: if self.gameObject.getDistanceTo(node) < self.waymesh.distToChangeNode: if self.wayIndex < pa - 1: self.wayIndex += 1 else: self.isDirectTrackToTujuan = True else: print("error!!!!!!!!!!! pa is zero") bge.logic.endGame() else: #if self.sensSekitar(tujuan.position) == False: # self.trackTo(tujuan) self.trackTo(tujuan) self.evadingStats = "not evading" if var.ngecek == True: self['trakKepada'] = str(tujuan) self.addDebugProperty('trakKepada') elif self.flightStats == "fighting": self.gameObject.maju = 2 self.gameObject.runJetEngine() if self.target != None: if self.target.invalid == False: if self.gameObject.rayCastTo(self.target) != self.target: self.target = None self.targetDiketahui = False self.flightStats = 'doingOrder' else: if self.gameObject.getDistanceTo(self.target) < self.senseRadius or self.targetDiketahui == True: if self.lenOfArms > 1: #algoritma untuk pergantian senjata bagi bot pass #print(self.gameObject.currentWeapon) if self.gameObject.currentWeapon != None or self.gameObject.primaryWeapon != None: shotAble = False if self.gameObject.primaryWeapon != None: icept = vektorkan(interceptPrediction(self.gameObject, self.gameObject.primaryWeapon, self.target)) ak = self.gameObject.getVectTo(icept) #ak = self.gameObject.getVectTo(self.target) if tooLow == False: #print(ak[2][1]) if willCollide == False: if ak[2][1] < 0: #print("target {0} is behind {1}".format(id(self.target), id(self))) (xl, yl, zl) = self.trackTo((icept.x, icept.y, self.gameObject.position.z - var.mapKonfigurasi['gravity'] + 2)) ''' if ak[2][0] != 0: vrot = self.worldPosition + Vector((ak[2][0] * ak[0], 0.0, 0.0)) * self.worldOrientation (xl, yl, zl) = self.trackTo((vrot.x, vrot.y, self.gameObject.position.z - var.mapKonfigurasi['gravity'] + 2)) else: (xl, yl, zl) = self.trackTo((icept.x, icept.y, self.gameObject.position.z - var.mapKonfigurasi['gravity'] + 2)) ''' #print('yes') else: shotAble = True (xl, yl, zl) = self.trackTo(icept) else: shotAble = False (xl, yl, zl) = self.trackTo(evadeTo) else: ''' if ak[2][1] < 0: print("target {0} is behind {1}".format(id(self.target), id(self))) (xl, yl, zl) = self.trackTo((icept.x, icept.y, self.gameObject.position.z - var.mapKonfigurasi['gravity'] + 2)) else: pass ''' #print(self.gameObject.worldPosition.z) #print("tooLow is " + str(tooLow)) #(xl, yl, zl) = self.trackTo((icept.x + 20, icept.y + 20, self.gameObject.worldPosition.z + 20)) shotAble = False tinggi = hypot(icept.x - self.gameObject.worldPosition.x, icept.y - self.gameObject.worldPosition.y) (xl, yl, zl) = self.trackTo((icept.x, icept.y, self.gameObject.worldPosition.z + tinggi/2)) self.evadingStats = "tooLow while fighting" #print(tinggi/2) agl = self.gameObject.primaryWeapon.angleToShot else: self.evadingStats = "not evading" (xl, yl, zl) = self.trackTo(interceptPrediction(self.gameObject, self.gameObject.currentWeapon, self.target)) agl = self.gameObject.currentWeapon.angleToShot if var.ngecek == True: if 'dleft' not in self: self['dleft'] = str([xl, zl]) self.addDebugProperty('dleft') else: self['dleft'] = str([xl, zl]) #print(shotAble) if shotAble == True: if xl < agl and zl < agl: if self.gameObject.primaryWeapon != None: self.gameObject.primaryWeapon.checkFire(2) if self.gameObject.currentWeapon != None: if self.gameObject.currentWeapon.tipe == "heatSeekingMissile": if self.gameObject.currentWeapon.lockOnStatus == 'locked': self.gameObject.currentWeapon.checkFire(2) else: self.gameObject.currentWeapon.checkFire(2) pass #print("bot is trying to fire") else: if self.gameObject.primaryWeapon != None: self.gameObject.primaryWeapon.checkFire(0) if self.gameObject.currentWeapon != None: self.gameObject.currentWeapon.checkFire(0) else: self.trackTo(self.target) else: self.flightStats = "doingOrder" else: self.flightStats = "doingOrder" if self.waymesh != None: self.wayPoints = self.waymesh.rebuildTrackList(self.gameObject, self.destinedByCommander[0]) self.wayIndex = 0 else: self.flightStats = "doingOrder" self.lastQuestByCommander = self.destinedByCommander if self.gameObject.tipe == "soldier": if self.enemy != None: self.chaseTheEnemy() self.ticks += 1 #self.gameObject.tiks += 1 self.gameObject.run()
def spawnBotControllerObject(cont): print("assigning team for bots... with object " + cont.owner.name) botAssigning = var.mapKonfigurasi['botAssigning'] scene = bge.logic.getCurrentScene() f = open(var.thisLok + 'cfg//bot names.txt') d = f.read() f.close() dl = d.split('\n') #randomize bot name #dl = random.choice(dl) nickYgTergunakan = [] print("result from spliting bot names is " + str(dl)) a = botAssigning[0] b = botAssigning[1] print("there's {0} bot/bots in team A".format(a)) print("there's {0} bot/bots in team B".format(b)) nameIndex = 0 for i in range(botAssigning[0]): bot = scene.addObject('botControllerObject') bot = ai.KX_BotVehicleController(bot) var.scene['bots'].append(bot) bot.team = 1 var.NPCList[1].append(bot) ''' if nameIndex < len(dl) - 1: bot.nick = dl[nameIndex] nameIndex += 1 ''' nick = random.choice(dl) tlahAda = nickYgTergunakan.count(nick) if tlahAda == 0: bot.nick = nick nickYgTergunakan.append(nick) else: bot.nick = nick + str(tlahAda) nickYgTergunakan.append(nick) if bot.nick == None: nick = gameobjects.KX_ScoreObject(str(id(bot))) var.players[bot.team].append(nick) bot.score = nick nick.team = bot.team else: nick = gameobjects.KX_ScoreObject(bot.nick) var.players[bot.team].append(nick) bot.score = nick nick.team = bot.team for i in range(botAssigning[1]): bot = scene.addObject('botControllerObject') bot = ai.KX_BotVehicleController(bot) var.scene['bots'].append(bot) bot.team = 2 var.NPCList[2].append(bot) ''' if nameIndex < len(dl) - 1: bot.nick = dl[nameIndex] nameIndex += 1 ''' nick = random.choice(dl) tlahAda = nickYgTergunakan.count(nick) if tlahAda == 0: bot.nick = nick nickYgTergunakan.append(nick) else: bot.nick = nick + str(tlahAda) nickYgTergunakan.append(nick) if bot.nick == None: nick = gameobjects.KX_ScoreObject(str(id(bot))) var.players[bot.team].append(nick) bot.score = nick nick.team = bot.team else: nick = gameobjects.KX_ScoreObject(bot.nick) var.players[bot.team].append(nick) bot.score = nick nick.team = bot.team try: db.checkPalyerForScore() except: checker.getInfo() bge.logic.endGame()
''' if psn != ">>>masuk<<<": if psn == ">>>RequestingTermination<<<": if addr in clientsByAddress: cdata = encode(["server", ">>>exit<<<"]) clientsByAddress[addr].sendall(cdata.encode("utf-8")) clientsByAddress[addr].close() del clients[clients.index(clientsByAddress[addr])] del clientsAddr[clientsAddr.index(addr)] del clientsByAddress[addr] else: print("alamat {0} meminta keluar".format(str(addr))) else: for i in clients: if i.getpeername() != addr: ldata = decode(data) cdata = encode([ldata[0], ldata[2]]) i.sendall(cdata.encode("utf-8")) except socket.timeout: print("server is timeout") timeoutCount += 1 if timeoutCount > 5: for i in clients: cdata = encode(["server", "exit"]) i.sendall(cdata.encode("utf-8")) s.close() break except: checker.getInfo() s.close() break
def run(self): #cek = self.listBlock[0] - atas, self.listBlock[0], atas #print(cek) #return False try: if self.curBlock == None: #print("wew") pass #bge.logic.endGame() #return False#kalo nga pake ini dia bole mo bypass to error yang akan dilaksanakan script yg ada dibawah #print(self.curBlock) if self.curBlock != None: self.step += 1 print( " ---------------------------- step {0} ---------------------------- " .format(str(self.step))) ''' - cek antrian - ''' ant = [] for i in self.antrian: ant.append(i.v) print("antriannya ialah " + str(ant)) ''' --------------- ''' print("currentBlocknya ialah " + str(self.curBlock.v)) ada = False isUjung = False if self.langkah > 0: print("arahnya ialah " + str(self.arah)) teredit = False if self.arah[0] > scale: self.arah[0] = int(scale) teredit = True if self.arah[0] < -scale: self.arah[0] = int(-scale) teredit = True if self.arah[1] > scale: self.arah[1] = int(scale) teredit = True if self.arah[1] < -scale: self.arah = int(-scale) teredit = True if teredit: print("fix arahnya ialah " + str(self.arah)) x, y = self.arah if abs(x) == abs(y): print("there's some bug on arah. Rewrite it...") jalur = [] for block in self.curBlock.jalur: temp = block.v in self.listBlock cek = temp, block.v print("hasilnya keberadaan = " + str(cek)) if block.v not in self.listBlock: jalur.append(block) ada = True if ada: acakResult = floor(random() * len(jalur)) cek = acakResult, len( jalur), jalur, self.curBlock.jalur print(cek) v = jalur[acakResult].v if jalur[acakResult].object.sebelumnya == None: #jalur[acakResult].object.sebelumnya = self.curBlock jalur[acakResult].object.setSebelumnya( self.curBlock) self.curBlock = jalur[acakResult] self.usedBlock.append(jalur[acakResult]) #point = KX_RedBlock(self.scene.addObject('red_cube', jalur[acakResult])) self.arah = v - self.curBlock.v print("result of self.arah = " + str(self.arah)) else: pass #self.antrian.append(self.curBlock) else: next = self.curBlock.v + self.arah print("next block ialah " + str(next)) ada = next in self.listBlock print("next ada di listBlock ialah " + str(ada)) for i in self.listBlock: if i == next: ada = True if i.object.sebelumnya == None: #i.object.sebelumnya = self.curBlock i.object.setSebelumnya(self.curBlock) self.curBlock = i.object self.usedBlock.append(i.object) #point = KX_RedBlock(self.scene.addObject('red_cube', i.object)) #point.sebelumnya = self.lastRedblock #self.lastRedblock = point i.object.visible = False #print(len(self.listBlock)) break if ada == False: self.langkah = 0 self.antrian.append(self.curBlock) self.isUjung = True else: self.langkah -= 1 else: belok = intClose(random()) #belok = 0 if belok == 1: jalur = [] for i in self.curBlock.jalur: if i not in self.usedBlock: ada = True jalur.append(i) if ada: jml = len(jalur) terpilih = jalur[floor(random() * jml)] #print(">>> " + str(terpilih)) try: ar = terpilih.v - self.curBlock.v #self.arah = Vec([ar[0], ar[1]])#kemungkinan nilainya ba hang/miss cukup tinggi self.arah = ar #kemungkinan nilainya ba hang/miss cukup tinggi self.antrian.append(terpilih) self.usedBlock.append(terpilih) if terpilih.sebelumnya == None: #terpilih.sebelumnya = self.curBlock terpilih.setSebelumnya(self.curBlock) #point = KX_RedBlock(self.scene.addObject('red_cube', terpilih)) except: cek = terpilih, self.curBlock print("error di sini ref : " + str(cek)) checker.getInfo() bge.logic.endGame() return False else: for i in self.curBlock.jalur: if i not in self.usedBlock: ada = True ar = i.position - self.position self.arah = Vec( [ar.x, ar.y] ) #kemungkinan nilainya ba hang/miss cukup tinggi self.antrian.append(i) self.usedBlock.append(i) if i.sebelumnya == None: #i.sebelumnya = self.curBlock i.setSebelumnya(self.curBlock) #point = KX_RedBlock(self.scene.addObject('red_cube', i)) #let it pass so it can acak lagi self.antrian nya pa = len(self.antrian) if pa > 0: pass #acak lagi jalur yang kan dipilih print("generating new step or langkah") terpilih = floor(random() * pa) self.curBlock = self.antrian[terpilih] self.curBlock.visible = False #point.sebelumnya = self.lastRedblock #self.lastRedblock = point del self.antrian[terpilih] self.langkah = acakLangkah() print("langkah yang diambil ialah = " + str(self.langkah)) pa = len(self.antrian) if ada == False and pa == 0 and isUjung == False: print("kosong") print("done generating maze") self.curBlock = None else: pass #memulai tahap selanjutnya if self.generateStats == "way": print("relating between nodes being") self.generateStats = "wayNodes" self.wayIndex = 0 elif self.generateStats == "wayNodes": ''' curNode = self.listBlock[self.wayIndex].object print("mendata " + str(curNode)) if curNode.sebelumnya != None: curNode.sebelumnya.next.append(curNode) self.wayIndex += 1 if self.wayIndex >= len(self.listBlock): self.generateStats = "collectingTheEdge" print("collecting the edge of nodes...") self.wayIndex = 0 self.nodeEdge = [] ''' ''' Let's just pass this for curVec in self.listBlock: curNode = curVec.object if curNode.sebelumnya != None: #curNode.sebelumnya.next.append(curNode) curNode.sebelumnya.appendNext(curNode) ''' self.generateStats = "collectingTheEdge" print("collecting the edge of nodes...") self.wayIndex = 0 self.nodeEdge = [] elif self.generateStats == "collectingTheEdge": for curVec in self.listBlock: curNode = curVec.object if len(curNode.next ) == 0 and curNode.sebelumnya != None: print("adding edge " + str(curNode)) self.nodeEdge.append(curNode) print("inserting start point...") self.tempEdge = list(self.nodeEdge) terpilih = floor(random() * len(self.tempEdge)) self.startPoint = self.tempEdge[terpilih] del self.tempEdge[terpilih] print("{0} has been choosen as the start point".format( str(self.startPoint))) added = self.scene.addObject('input', self.startPoint) print("inserting end point...") terpilih = floor(random() * len(self.tempEdge)) self.endPoint = self.tempEdge[terpilih] del self.tempEdge[terpilih] print("{0} has been choosen as the end point".format( self.endPoint)) added = self.scene.addObject('output', self.endPoint) self.generateStats = "insertingRoom" print("inserting room...") self.wayIndex = 0 self.roomCount = 0 elif self.generateStats == "insertingRoom": if len(self.tempEdge) > 0: terpilih = floor(random() * len(self.tempEdge)) edge = self.tempEdge[terpilih] if self.roomCount < maxRoom: #memasukan ruangan print("{0} has been choosen as the room".format( str(edge))) #added = self.scene.addObject('Room', edge) #added.actuators['track'].object = edge.sebelumnya edge.replaceWithRoom() self.roomCount += 1 else: pass #cuma jalan noh ini #print("passing the " + str(edge)) del self.tempEdge[terpilih] else: self.generateStats = "done" print("done generating maze") print("total room is " + str(self.roomCount)) except: checker.getInfo() bge.logic.endGame() return False
def TrajectoryAngle(own, interceptPoint, velocity): try: scene = bge.logic.getCurrentScene() if 'calculate' not in own: own['calculate'] = True if 'trajectoryAngle' not in own: own['trajectoryAngle'] = '' else: try: gravity = scene.gravity.z own['reachable'] = True vec = interceptPoint.getVectTo(own) px = hypot(vec[1].x, vec[1].y) * vec[0] pz = vec[1].z * vec[0] #rumus pertama menggunakan plus berfungsi untuk rumus mortar #rad = atan((velocity**2 + sqrt(velocity**4-gravity*(gravity*px**2 + 2*pz*velocity**2))) / (gravity*px)) #rumus kedua menggunakan minus rad = atan((velocity**2 - sqrt(velocity**4 - gravity * (gravity * px**2 + 2 * pz * velocity**2))) / (gravity * px)) #rad = asin(jarak * gravity / velocity**2) / 2 sRad = sin(rad) cRad = cos(rad) y = cRad * velocity z = sRad * velocity own['cosine'] = str([sRad, cRad]) own['travelTime'] = px / y own['vy'] = y own['vz'] = z own['angle'] = degrees(rad) if own.parent == None: Eul = Euler((rad, 0, 0), 'XYZ') else: parent = own.parent pR = parent.worldOrientation pE = pR.to_euler() Eul = Euler((-rad, pE.y, pE.z), 'XYZ') own.worldOrientation = Eul.to_matrix() own['reachable'] = True own['calculate'] = True except ValueError: own['reachable'] = False if own['calculate'] == True: print("calculate error") own['calculate'] = False except ZeroDivisionError: print('float division by zero') except: checker.getInfo() bge.logic.endGame()