def OnLogicUpdate(self, UpdateEvent): Parent = self.Owner.Parent Position = self.Owner.Transform.WorldTranslation Child1 = self.Owner.FindChildByName("LookPoint3") Child1Pos = Child1.Transform.WorldTranslation Ray = VectorMath.Ray() Ray.Start = Vector3(Position.x, Position.y, 0) #Start Ray.Direction = Vector3(Child1Pos.x - Position.x, Child1Pos.y - Position.y, 0) #End MaxRayCastDistance = 1.0 #RayColor = Color.Orange CastResultsRange = self.Space.PhysicsSpace.CastRayResults( Ray, 1) # Number Of Objects LastCastResult = None #Limit #print(Parent.GunManStatus.CanShoot) for CastResult in CastResultsRange: if (CastResult.Distance >= MaxRayCastDistance): break if (CastResult.ObjectHit.Name == "Tung" or CastResult.ObjectHit.Name == "Austin" or CastResult.ObjectHit.Name == "Trey" or CastResult.ObjectHit.Name == "Peyton" or CastResult.ObjectHit.Name == "Sedrick" or CastResult.ObjectHit.Name == "Julio"): Parent.GunManStatus.CanShoot = True Parent.GunManStatus.RayCast3 = True else: Parent.GunManStatus.RayCast3 = False if (Parent.GunManStatus.RayCast1 is False and Parent.GunManStatus.RayCast2 is False and Parent.GunManStatus.RayCast3 is False and Parent.GunManStatus.RayCast4 is False and Parent.GunManStatus.RayCast5 is False and Parent.GunManStatus.RayCast6 is False and Parent.GunManStatus.RayCast7 is False and Parent.GunManStatus.RayCast8 is False and Parent.GunManStatus.RayCast9 is False): Parent.GunManStatus.CanShoot = False LastCastResult = CastResult #Limit if (not LastCastResult): #Limit EndPosition = Ray.Start + Ray.Direction * MaxRayCastDistance #self.DrawArrow(Ray.Start, EndPosition, RayColor) else: EndPosition = Ray.Start + Ray.Direction * LastCastResult.Distance
def CastRayGrapple(self): #creating a ray ray = VectorMath.Ray() #Testing if grapple has hit anything if(self.grappleHit == 0): direction = self.grappleDirection #if yes setting direction to where grapple is and player else: direction = self.grapplePoint - VectorMath.Vec3(self.Owner.Transform.Translation.x + (math.cos(self.PointDirection) * .37*self.Owner.Transform.Scale.x), self.Owner.Transform.Translation.y + (math.sin(self.PointDirection) * .4*self.Owner.Transform.Scale.y) + .15, 0) #Calculating vector for grapple direction.normalize() ray.Direction = direction ray.Direction.normalize() direction = math.atan2(direction.y, direction.x) #Setting starting point at player (can adjust if needed) ray.Start = VectorMath.Vec3(self.Owner.Transform.Translation.x + (math.cos(self.PointDirection) * .37*self.Owner.Transform.Scale.x), self.Owner.Transform.Translation.y + (math.sin(self.PointDirection) * .4*self.Owner.Transform.Scale.y) + .15, 0) #Increase grapple length if nothing has been hit if(self.grappleHit == 0): #Grapple speed (can be adjusted if needed) self.grappleDistance += self.DeltaTime * 25 else: #distance formula self.grappleDistance = math.sqrt(math.pow((ray.Start.x - self.grapplePoint.x), 2) + math.pow((ray.Start.y - self.grapplePoint.y), 2)) #setting player to kinematic so player can move with grapple self.Owner.RigidBody.Kinematic = True #stop grapple when the distance between hook and player is 1 #fixes stuck in the ceiling bug if(self.grappleDistance < 1): self.StopGrapple() #---------------------------------------------------------- #Pendulum Swing Related #if not swinging at the time if(not self.Swing): #if mouse is being held down if(self.MouseDown == True): #move speed for player to hook on grapple self.Owner.Transform.Translation += ray.Direction * (self.DeltaTime * 18) #if mouse is release else: #save the current height self.rayY = self.Owner.Transform.Translation.y #begin to swing self.Swing = True #swing right if(ray.Direction.x > 0): self.swingRight = True self.swingDown = True self.swingPlayer(ray.Direction) #swing left else: self.swingRight = False self.swingDown = True self.swingPlayer(ray.Direction) #keep swinging else: self.swingPlayer(ray.Direction) #---------------------------------------------------------- #Adds color to the 'Rope' rayColor = VectorMath.Vec4(0.45, 0.15, 0, 1) #Finds the range of the first thing grapple collides with castResultRange = self.Space.PhysicsSpace.CastRayResults(ray, 50) #checking if the grapple hit anything if (self.grappleHit == 0): endPosition = ray.Start + ray.Direction * self.grappleDistance else: #sets position to grapple hit endPosition = self.grapplePoint for castResult in castResultRange: #asking if the it hit a certain named object #objects with name floor are able to be grappled to if(castResult.ObjectHit.Name == "Floor"): #attach to this object if(castResult.Distance >= self.grappleDistance): break #setting endPosition to where it hit endPosition = castResult.WorldPosition #has it hit anything yet if (self.grappleHit == 0): #change it to one if it hit something self.grappleHit = 1 #sets grapplePoint to end position so where it hit something self.grapplePoint = endPosition self.Space.SoundSpace.PlayCue("hooked") #Prevents grapple from hitting player, key (+ AOE region), gate AOE region, and gold elif(castResult.ObjectHit.Name != "Player" and castResult.ObjectHit.Name != "Pit" and castResult.ObjectHit.Name != "Key" and castResult.ObjectHit.Name != "AOE" and castResult.ObjectHit.Name != "GateAOE" and castResult.ObjectHit.Name != "Gold"): if(castResult.Distance < self.grappleDistance): self.StopGrapple() else: pass #Scales, Rotates, adds Color, and sets Starting Point of Rope 'Rope' self.Grapple.Transform.Scale = Vec3(0.2, (math.sqrt(math.pow((ray.Start.x - endPosition.x), 2) + math.pow((ray.Start.y - endPosition.y), 2)) * 2), 1) self.Grapple.Transform.Rotation = VectorMath.Quat(0,0,direction + math.radians(-90)) self.Grapple.Transform.Translation = ray.Start self.Grapple.Sprite.Color = rayColor #Setting a 'Hook' at end of the grapple self.hook.Transform.Translation = ray.Start + ray.Direction * self.grappleDistance self.hook.Transform.Rotation = VectorMath.Quat(0,0,direction + math.radians(-90)) #fixed collisions: whenever grapple is running run this script as well self.CastRayStopGrapple()
def CastRayStopGrapple(self): #setting variable for changeability later xvalue = .1 if(self.grappleHit == 1): #Collider 1 ray = VectorMath.Ray() direction = Vec3(xvalue, -0.5,0) direction = math.atan2(direction.y, direction.x) ray.Start = self.Owner.Transform.Translation ray.Direction = Vec3(xvalue*self.Owner.Transform.Scale.x, -0.5*self.Owner.Transform.Scale.y, 0) ray.Direction.normalize() maxRayCastDistance = .75 castResultRange = self.Space.PhysicsSpace.CastRayResults(ray, 1) endPosition = ray.Start + ray.Direction * maxRayCastDistance for castResult in castResultRange: if(castResult.Distance >= maxRayCastDistance): break endPosition = castResult.WorldPosition if (castResult.ObjectHit.Name == "Floor"): self.StopGrapple() #Collider 2 ray2 = VectorMath.Ray() direction = Vec3(xvalue, 0.5,0) direction = math.atan2(direction.y, direction.x) ray2.Start = self.Owner.Transform.Translation ray2.Direction = Vec3(xvalue*self.Owner.Transform.Scale.x, 0.5*self.Owner.Transform.Scale.y, 0) ray2.Direction.normalize() maxRayCastDistance = .75 castResultRange = self.Space.PhysicsSpace.CastRayResults(ray2, 1) endPosition = ray2.Start + ray2.Direction * maxRayCastDistance for castResult in castResultRange: if(castResult.Distance >= maxRayCastDistance): break endPosition = castResult.WorldPosition if (castResult.ObjectHit.Name == "Floor"): self.StopGrapple() #Collider 3 ray3 = VectorMath.Ray() direction = Vec3(-xvalue, 0.5,0) direction = math.atan2(direction.y, direction.x) ray3.Start = self.Owner.Transform.Translation ray3.Direction = Vec3(-xvalue*self.Owner.Transform.Scale.x, 0.5*self.Owner.Transform.Scale.y, 0) ray3.Direction.normalize() maxRayCastDistance = .75 castResultRange = self.Space.PhysicsSpace.CastRayResults(ray3, 1) endPosition = ray3.Start + ray3.Direction * maxRayCastDistance for castResult in castResultRange: if(castResult.Distance >= maxRayCastDistance): break endPosition = castResult.WorldPosition if (castResult.ObjectHit.Name == "Floor"): self.StopGrapple() #Collider 4 ray4 = VectorMath.Ray() direction = Vec3(-xvalue, -0.5,0) direction = math.atan2(direction.y, direction.x) ray4.Start = self.Owner.Transform.Translation ray4.Direction = Vec3(-xvalue*self.Owner.Transform.Scale.x, -0.5*self.Owner.Transform.Scale.y, 0) ray4.Direction.normalize() maxRayCastDistance = .75 castResultRange = self.Space.PhysicsSpace.CastRayResults(ray4, 1) endPosition = ray4.Start + ray4.Direction * maxRayCastDistance for castResult in castResultRange: if(castResult.Distance >= maxRayCastDistance): break endPosition = castResult.WorldPosition if (castResult.ObjectHit.Name == "Floor"): self.StopGrapple()
def OnLogicUpdate(self, UpdateEvent): ObjectPostitionZ = self.GlobalZ DeltaTime = UpdateEvent.Dt self.timer += DeltaTime Parent = self.Owner.Parent if(self.start is True): self.RandomAngle = random.uniform(-5, 5) self.start = False if(Zero.Mouse.IsButtonDown(Zero.MouseButtons.Left)): self.CanAnimateIdle = True WorldPosition = self.Owner.Transform.WorldTranslation if(self.timer > self.Delay): self.CanAnimateIdle2 = True self.timer2 += DeltaTime Position = self.Owner.Transform.WorldTranslation Child1 = self.Owner.FindChildByName("MeleeChild1") Child1Pos = Child1.Transform.WorldTranslation Ray = VectorMath.Ray() Ray.Start = Vector3(Position.x, Position.y, 0) #Start Ray.Direction = Vector3(Child1Pos.x - Position.x, Child1Pos.y - Position.y, Child1Pos.z - Position.z) #End MaxRayCastDistance = 1.0 #RayColor = Color.Orange CastResultsRange = self.Space.PhysicsSpace.CastRayResults(Ray, 10) # Number Of Objects LastCastResult = None #Limit for CastResult in CastResultsRange: if(CastResult.Distance >= MaxRayCastDistance): break if(CastResult.ObjectHit.Name == "Grass1"): CastResult.ObjectHit.Grass.CurrentHealth -= 5 elif(CastResult.ObjectHit.Name == "Dirt1"): CastResult.ObjectHit.Dirt.CurrentHealth -= 5 elif(CastResult.ObjectHit.Name == "Wall1"): CastResult.ObjectHit.Wall1.CurrentHealth -= 5 elif(CastResult.ObjectHit.Name == "Crate"): CastResult.ObjectHit.SmallCrate.CurrentHealth -= 5 elif(CastResult.ObjectHit.Name == "Barrel"): CastResult.ObjectHit.Barrel.CurrentHealth -= 5 elif(CastResult.ObjectHit.Name == "FireBarrel"): CastResult.ObjectHit.FireBarrel.CurrentHealth -= 5 elif(CastResult.ObjectHit.Name == "BridgeBottom"): CastResult.ObjectHit.Bridge.CurrentHealth -= 5 elif(CastResult.ObjectHit.Name == "GunMan"): CastResult.ObjectHit.GunManHealth.CurrentHealth -= 5 elif(CastResult.ObjectHit.Name == "HeavyGunMan"): CastResult.ObjectHit.HeavyGunManHealth.CurrentHealth -= 5 LastCastResult = CastResult #Limit if(not LastCastResult): #Limit EndPosition = Ray.Start + Ray.Direction * MaxRayCastDistance #self.DrawArrow(Ray.Start, EndPosition, RayColor) else: EndPosition = Ray.Start + Ray.Direction * LastCastResult.Distance #self.DrawArrow(Ray.Start, EndPosition, RayColor) if(self.CanAnimate is True): self.CanShoot = True self.CanAnimate = False if(self.timer2 > 0.2): self.CanManSound = True self.timer2 = 0 self.start = True self.timer = 0 else: if(self.CanAnimateIdle2 is True and Parent.Sprite.CurrentFrame >= 2): self.CanIdle = True self.CanManSound = True self.CanAnimateIdle2 = False self.CanAnimate = True else: if(self.CanAnimateIdle is True): self.CanIdle = True self.CanAnimate = True self.CanAnimateIdle = False if(self.CanShoot is True): Parent.Sprite.SpriteSource = "JulioBodyShoot" self.CanShoot = False elif(self.CanIdle is True): Parent.Sprite.SpriteSource = "JulioBody" self.CanIdle = False if(self.CanManSound is True): self.Owner.SoundEmitter.PlayCue("JulioShoot") self.CanManSound = False