public override void RunTick() { if (this.behavior is Behavior) { this.behavior.RunTick(); } // Standard Physics this.physics.RunPhysicsTick(); // Animations, if applicable. if (this.animate is Animate) { this.animate.RunAnimationTick(Systems.timer); } // Check if the enemy is about to run off of a cliff: if (Systems.timer.IsTickFrame && this.physics.touch.toFloor) { if (this.FaceRight) { if (!CollideTile.IsBlockingCoord(this.room.tilemap, this.posX + this.bounds.Right + 8, this.posY + this.bounds.Bottom + 10, DirCardinal.Down)) { this.SetDirection(false); } } else { if (!CollideTile.IsBlockingCoord(this.room.tilemap, this.posX + this.bounds.Left - 8, this.posY + this.bounds.Bottom + 10, DirCardinal.Down)) { this.SetDirection(true); } } } }
private void DoTeleport() { CharacterStatus status = this.character.status; // End the Teleport Action (to prevent re-teleportation) this.character.status.action.EndAction(this.character); // Get X, Y Coordinates from Distance and Radian float trueRotation = Radians.Normalize(status.actionFloat1); int xCoord = (int)Radians.GetXFromRotation(trueRotation, status.actionNum1) + character.posX + character.bounds.MidX; int yCoord = (int)Radians.GetYFromRotation(trueRotation, status.actionNum1) + character.posY + character.bounds.MidY; // Make sure teleportation is within world bounds. if (yCoord < (byte)TilemapEnum.GapUpPixel || yCoord > this.character.room.Height + (byte)TilemapEnum.GapUpPixel || xCoord < (byte)TilemapEnum.GapLeftPixel || xCoord > this.character.room.Width + (byte)TilemapEnum.GapRightPixel) { this.character.room.PlaySound(Systems.sounds.disableCollectable, 0.5f, this.character.posX + 16, this.character.posY + 16); return; } TilemapLevel tilemap = character.room.tilemap; // Make sure teleportation is to a valid open area. Blocking tiles will prevent teleportation. int xMid = xCoord - this.character.bounds.MidX; int yMid = yCoord - this.character.bounds.MidY; bool upLeft = CollideTile.IsBlockingCoord(tilemap, xMid + character.bounds.Left, yMid + character.bounds.Top - 1, DirCardinal.None); bool upRight = CollideTile.IsBlockingCoord(tilemap, xMid + character.bounds.Right, yMid + character.bounds.Bottom - 1, DirCardinal.None); bool downLeft = CollideTile.IsBlockingCoord(tilemap, xMid + character.bounds.Left, yMid + character.bounds.Top - 1, DirCardinal.None); bool downRight = CollideTile.IsBlockingCoord(tilemap, xMid + character.bounds.Right, yMid + character.bounds.Bottom - 1, DirCardinal.None); // If all positions are blocked, prevent teleport. if (upLeft && upRight && downLeft && downRight) { this.character.room.PlaySound(Systems.sounds.disableCollectable, 0.5f, this.character.posX + 16, this.character.posY + 16); return; } // If some positions are blocked, adjust position: if (upLeft && downLeft) { xMid += 12; } if (upRight && downRight) { xMid -= 12; } if (upLeft && upRight) { yMid += 12; } if (downLeft && downRight) { yMid -= 12; } this.character.room.PlaySound(Systems.sounds.pop, 1f, this.character.posX + 16, this.character.posY + 16); // Teleport Character this.character.physics.MoveToPos(xMid, yMid); }
public override bool Activate() { // Make sure the power can be activated if (!this.CanActivate()) { return(false); } // References Character character = this.character; // Determine Starting Position of Projectile relative to Character int posX = character.posX + character.bounds.MidX + (character.FaceRight ? 10 : -30); int posY = character.posY + character.bounds.Top + 5; // Play Sound character.room.PlaySound(this.sound, 1f, posX, posY); // Check if the tile placement is blocked: TilemapLevel tilemap = this.character.room.tilemap; bool isBlocked = CollideTile.IsBlockingCoord(tilemap, posX + 10 + (character.FaceRight ? 6 : -6), posY + 10, character.FaceRight ? DirCardinal.Right : DirCardinal.Left); // Prevent Throw if (isBlocked) { return(false); } // Prepare Velocity FInt velX = character.FaceRight ? this.xVel : this.xVel.Inverse; FInt velY = this.yVel; // Affect the Y-Velocity of the projectile if holding UP or DOWN this.AffectByInput(ref velX, ref velY); // Apply Character's Momentum (if applicable) if (this.multMomentum > 0) { velX += character.physics.velocity.X * this.multMomentum; velY += character.physics.velocity.Y * this.multMomentum * FInt.Create(0.5); } // Launch Projectile this.Launch(posX, posY, velX, velY); return(true); }
public override bool Activate() { // Make sure the power can be activated if (!this.CanActivate()) { return(false); } // References Character character = this.character; // Determine Starting Position of Projectile relative to Character int posX = character.posX + character.bounds.MidX + (character.FaceRight ? 6 : -30); int posY = character.posY + character.bounds.Top + 5; // Play Sound character.room.PlaySound(this.sound, 1f, posX, posY); // Check if the tile placement is blocked (only applies to bolts that collide with tiles). if (this is BoltBlue) { TilemapLevel tilemap = this.character.room.tilemap; bool isBlocked = CollideTile.IsBlockingCoord(tilemap, posX + (character.FaceRight ? 10 : 4), posY, character.FaceRight ? DirCardinal.Right : DirCardinal.Left); // Prevent Throw if (isBlocked) { return(false); } } // Prepare Velocity FInt velX = character.FaceRight ? FInt.Create(this.xVel) : FInt.Create(-this.xVel); FInt velY = FInt.Create(this.yVel); // Affect the Y-Velocity of the projectile if holding UP or DOWN this.AffectByInput(ref velX, ref velY); // Launch Projectile this.Launch(character, posX, posY, velX, velY); return(true); }