def makeping(self, rname, rnd): tank = self.tanks[rname] body = tank.turret segmentLength = 65.0 blocalpos = box2d.b2Vec2(1.12, 0) segment = box2d.b2Segment() laserStart = (1.12, 0) laserDir = (segmentLength, 0.0) segment.p1 = body.GetWorldPoint(laserStart) segment.p2 = body.GetWorldVector(laserDir) segment.p2+=segment.p1 lambda_, normal, shape = self.w.RaycastOne(segment, False, None) hitp = (1 - lambda_) * segment.p1 + lambda_ * segment.p2 angle = tank.get_turretangle() dist = box2d.b2Distance(segment.p1, hitp) if shape is not None: hitbody = shape.GetBody() kind = hitbody.userData['kind'] if kind == 'tank': actor = hitbody.userData['actor'] if actor._pinged != rnd - 1: actor._pinged = rnd return kind, angle, dist else: return 'w', angle, 0
def makeping(self, rname, rnd): robot = self.robots[rname] body = robot.turret segmentLength = 65.0 blocalpos = box2d.b2Vec2(1.12, 0) segment = box2d.b2Segment() laserStart = (1.12, 0) laserDir = (segmentLength, 0.0) segment.p1 = body.GetWorldPoint(laserStart) segment.p2 = body.GetWorldVector(laserDir) segment.p2 += segment.p1 lambda_, normal, shape = self.w.RaycastOne(segment, False, None) hitp = (1 - lambda_) * segment.p1 + lambda_ * segment.p2 angle = robot.get_turretangle() dist = box2d.b2Distance(segment.p1, hitp) if shape is not None: hitbody = shape.GetBody() kind = hitbody.userData['kind'] if kind == 'robot': actor = hitbody.userData['actor'] if actor._pinged != rnd - 1: actor._pinged = rnd return kind, angle, dist else: # Not sure why shape returns None here. Seems to be when the # robot is pressed right up against a wall, though. return 'w', angle, 0
def makeping(self, rname, rnd): robot = self.robots[rname] body = robot.turret segmentLength = 65.0 blocalpos = box2d.b2Vec2(1.12, 0) segment = box2d.b2Segment() laserStart = (1.12, 0) laserDir = (segmentLength, 0.0) segment.p1 = body.GetWorldPoint(laserStart) segment.p2 = body.GetWorldVector(laserDir) segment.p2+=segment.p1 lambda_, normal, shape = self.w.RaycastOne(segment, False, None) hitp = (1 - lambda_) * segment.p1 + lambda_ * segment.p2 angle = robot.get_turretangle() dist = box2d.b2Distance(segment.p1, hitp) if shape is not None: hitbody = shape.GetBody() kind = hitbody.userData['kind'] if kind == 'robot': actor = hitbody.userData['actor'] if actor._pinged != rnd - 1: actor._pinged = rnd return kind, angle, dist else: # Not sure why shape returns None here. Seems to be when the # robot is pressed right up against a wall, though. return 'w', angle, 0
def Push(self): power = ((globals.game_view.mode.power_box.power_level)** 2) * self.push_strength globals.game_view.mode.power_box.Disable() self.push_start = None if not self.IsGrabbed(): return obj = self.other_obj self.Ungrab() #Push on another object. Equal and opposite forces and what not #Fire a ray from my player to the object. Where it meets is where the force should be applied centre = self.body.GetWorldPoint([0, self.midpoint[1] * 1.01]) front = self.body.GetWorldPoint([0, self.midpoint[1] * 100]) cast_segment = box2d.b2Segment() cast_segment.p1 = centre cast_segment.p2 = front #This is a hack. My contact filtering messes up with rays, so turn it off for the duration of the ray cast self.physics.contact_filter.collide = True try: lam, normal, shape = self.physics.world.RaycastOne( cast_segment, True, None) finally: self.physics.contact_filter.collide = False if shape == self.shapeI: return if shape != obj.shapeI: return if abs(normal[0]) < 0.5 and abs(normal[1]) < 0.5: #print 'updating normal!',normal normal = Point(*(centre - front)) normal /= normal.length() normal = normal.to_vec() #self.physics.contact_filter.pushed = (self,obj,globals.time+500) self.body.ApplyForce(normal * power, centre) intersection_point = self.body.GetWorldPoint((front - centre) * lam) shape.userData.body.ApplyForce(-normal * power, intersection_point)