def testShotHit(shot): x, y, z = shot.pos.Pos() lx, ly, lz = shot.lpos.Pos() sp = Vex(x, y) lsp = Vex(lx, ly) dmg = shot.damage / 100.0 for p in Planets.pl: d = p.pos.dist2D(sp) if d < p.atmos: shln = Line(lsp - p.pos, sp - p.pos) for lines2 in p.edges: if lines2[1] != 1: lines = Line(p.surfPoints[lines2[0][0]], p.surfPoints[lines2[0][1]]) li = shln.find_intersection(lines) if li: minR = 5 ParticleEngine.Emitter(li + p.pos, shot.angle_rad, 2) if lines.seg[0].length() > p.rad - minR: a1 = math.atan2(lines.seg[0].Y(), lines.seg[0].X()) d1 = ZERO.dist2D(lines.seg[0]) - dmg lines.seg[0].set2D(math.cos(a1) * d1, math.sin(a1) * d1) if lines.seg[1].length() > p.rad - minR: a2 = math.atan2(lines.seg[1].Y(), lines.seg[1].X()) d2 = ZERO.dist2D(lines.seg[1]) - dmg lines.seg[1].set2D(math.cos(a2) * d2, math.sin(a2) * d2) return True if d <= p.coreRad: ParticleEngine.Emitter(Vex(x, y), shot.angle_rad, 2) p.corHealth -= dmg * 10 if p.corHealth <= 0: # do explody stuff pass return True return False
def testRadiusCollision(ent, cp, np, rad): ent.inatmosphere = False for p in Planets.pl: d = (cp + np).dist2D(p.pos) if d <= p.atmos: edit = False if d > p.coreRad - 6: ent.inatmosphere = True v = (cp + np) out = Vex(0, 0) delta = v - p.pos # new position relative to planet position delta0 = cp - p.pos for lines2 in p.edges: lines = (Line(p.surfPoints[lines2[0][0]], p.surfPoints[lines2[0][1]]), lines2[1]) if lines[1] == 0 or (lines[1] == 1 and ent.inship): ds = lines[0].ClosestPointOnLine(delta0) cpol = delta.dist2D(ds) if cpol <= rad: # print (lines[0]) a = -(lines[0].angle()) + math.pi v = Vex(math.sin(a) * rad, math.cos(a) * rad) + ds + p.pos ParticleEngine.Emitter(v, a, 3) ParticleEngine.Emitter(ds + p.pos, a, 2) out.assign(v) edit = True break if not edit: for segs in p.entryPs: ln = [] ln += [Line(p.surfPoints[segs[0]], p.sancPoints[segs[0]])] ln += [Line(p.sancPoints[segs[1]], p.surfPoints[segs[1]])] for i in range(0, 2): lines = ln[i] ds = lines.ClosestPointOnLine(delta) cpol = delta.dist2D(ds) if cpol <= rad: a = -(lines.angle()) + math.pi v = Vex(math.sin(a) * rad, math.cos(a) * rad) + ds + p.pos ParticleEngine.Emitter(ds + p.pos, a, 2) out.assign(v) edit = True # if d < p.rad: # if not edit: # for lines2 in p.edges: # lines = (Line(p.sancPoints[lines2[0][1]], p.sancPoints[lines2[0][0]]), lines2[1]) # if lines[1] == 0 or (lines[1] == 1 and ent.inship): # ds = lines[0].ClosestPointOnLine(delta) # cpol = delta.dist2D(ds) # if cpol <= rad: # a = -(lines[0].angle()) + math.pi # v = Vex(math.sin(a) * rad, math.cos(a) * rad) + ds + p.pos # ParticleEngine.Emitter(ds + p.pos, a, 2) # out.assign(v) # edit = True if edit: return out return None
def testShotHit(shot): x,y,z = shot.pos.Pos() #def testShotHit(x, y, z, dmg, ant): out = False for self in reversed(Mind.Minds): v = Vex(x, y, z) if v.dist2D(self.pos)<=2: tdmg = 0 if not self.inship: tdmg = int(shot.damage - self.creature.stats.getDEX()*(self.creature.stats.doLUK()*10)) else: tdmg = int(shot.damage - self.ship.stats.getDEX()*(self.ship.stats.doLUK()*10)) out = True if tdmg>0: DrawINFO.DrawINFO(x, y, z, tdmg, Color.RED) ParticleEngine.Emitter(Vex(x, y, z), shot.angle_rad, 0) self.ship.stats.hpDMG(tdmg) if shot.source.isAlive(): if shot.source not in self.target: self.target.extend([shot.source]) else: DrawINFO.DrawINFO(x, y, z, "MISS", Color.ORANGE) if self.inship: if self.ship.stats.isDead(): if shot.source.ship.stats.updateXP(random.randint(self.ship.stats.getLVL(),2*self.ship.stats.getLVL() )): DrawINFO.DrawINFO(x, y, z, "LEVEL UP", Color.RED) ParticleEngine.Emitter(Vex(x, y, z), shot.angle_rad, 1) Mind.Minds.remove(self) else: if self.creature.stats.isDead(): if shot.source.stats.updateXP(random.randint(1*self.creature.stats.getLVL(),10*self.creature.stats.getLVL() )): DrawINFO.DrawINFO(x, y, z, "LEVEL UP", Color.RED) ParticleEngine.Emitter(Vex(x, y, z), shot.angle_rad, 1) Mind.Minds.remove(self) return out
def testShotHit(shot): p = Environment.Environment.sun x, y, z = shot.pos.Pos() sp = Vex(x, y) dmg = shot.damage / 100.0 d = p.pos.dist2D(sp) if d <= Sun.minRad: ParticleEngine.Emitter(Vex(x, y), shot.angle_rad, 2) p.corHealth -= dmg * 10 if p.corHealth <= 0: # destroy sun, destroy planets, generate random asteroids pass return True return False
def testShotHit(shot): x, y, z = shot.pos.Pos() lx, ly, lz = shot.lpos.Pos() sp = Vex(x, y) # lsp = Vex(lx, ly) dmg = shot.damage for p in Asteroid.asteroids: d = p.pos.dist2D(sp) if d < 2: ParticleEngine.Emitter(p.pos, shot.angle_rad, 2, 50, Vex(0, 0), False, 25) p.corHealth -= dmg if p.corHealth <= 0: ParticleEngine.Emitter(p.pos, shot.angle_rad, 1, 50, Vex(0, 0), False, 50) p.corHealth = 150 d = p.pos.dist2D(p.parent.pos) delt = p.parent.pos - p.pos a1 = math.degrees(math.atan2(delt.y(), delt.x())) ra = math.radians(-a1 + 90 + p.speed + 180) dp = Vex(math.sin(ra) * d, math.cos(ra) * d) np = p.parent.pos - dp p.pos.assign(np) return True for p in Asteroid.tempAsteroids: d = p.pos.dist2D(sp) if d < 2: ParticleEngine.Emitter(p.pos, shot.angle_rad, 2) p.corHealth -= dmg if p.corHealth <= 0: ParticleEngine.Emitter(p.pos, shot.angle_rad, 1, 10, Vex(0, 0), False, 1) Asteroid.tempAsteroids.remove(p) return True return False