private static void AddObjectToScene(RoomScene room, short gridX, short gridY, byte objectId, byte subType = 0, Dictionary <string, short> paramList = null) { // Adjust for World Gaps gridX += (byte)TilemapEnum.GapLeft; gridY += (byte)TilemapEnum.GapUp; // Prepare Position FVector pos = FVector.Create( Snap.GridToPos((short)TilemapEnum.TileWidth, gridX), Snap.GridToPos((short)TilemapEnum.TileHeight, gridY) ); GameMapper mapper = Systems.mapper; // Identify Object Class Type Type classType; bool hasType = mapper.ObjectTypeDict.TryGetValue(objectId, out classType); if (!hasType || classType == null) { return; } // Create Object GameObject gameObj = (GameObject)Activator.CreateInstance(classType, new object[] { room, (byte)subType, (FVector)pos, (Dictionary <string, short>)paramList }); // Add the Object to the Scene if (gameObj is GameObject) { room.AddToScene((GameObject)gameObj, true); } }
private int endFrame; // The frame that a movement style ends on. public GrenadeProjectile() : base(null, 0, FVector.Create(0, 0), FVector.Create(0, 0)) { this.Damage = DamageStrength.None; this.CollisionType = ProjectileCollisionType.DestroyOnCollide; this.physics.SetGravity(FInt.Create(0.4)); this.SetSpriteName("Projectiles/Grenade"); }
public GloveProjectile() : base(null, 0, FVector.Create(0, 0), FVector.Create(0, 0)) { this.CollisionType = ProjectileCollisionType.IgnoreWallsSurvive; this.Damage = DamageStrength.Standard; this.physics.SetGravity(FInt.Create(0)); this.spinRate = 0f; }
public override void Launch(GameObject actor, int startX, int startY, sbyte velX) { var projectile = GloveProjectile.Create(actor.room, this.projSubType, FVector.Create(startX, startY), FVector.Create(velX, 0)); projectile.SetActorID(actor); projectile.SetEndLife(Systems.timer.Frame + this.duration); }
public HammerProjectile() : base(null, 0, FVector.Create(0, 0), FVector.Create(0, 0)) { this.Damage = DamageStrength.Major; this.CollisionType = ProjectileCollisionType.IgnoreWallsSurvive; this.physics.SetGravity(FInt.Create(0.45)); this.SetSpriteName("Weapon/Hammer"); }
public ProjectileEarth() : base(null, 0, FVector.Create(0, 0), FVector.Create(0, 0)) { this.SetCollisionType(ProjectileCollisionType.DestroyOnCollide); this.SetSpriteName("Projectiles/Earth1"); this.SetDamage(DamageStrength.Lethal); this.SetSafelyJumpOnTop(true); this.physics.SetGravity(FInt.Create(0.1)); }
public SpearProjectile() : base(null, 0, FVector.Create(0, 0), FVector.Create(0, 0)) { this.CollisionType = ProjectileCollisionType.IgnoreWallsSurvive; this.Damage = DamageStrength.Standard; this.physics.SetGravity(FInt.Create(0)); this.spinRate = 0f; this.SetSpriteName("Weapon/Spear"); this.AssignBoundsByAtlas(2, 2, -2, -2); }
private void TryUpdateBehavior(int midX, int midY) { // If there is no character in sight, check for a new one: if (this.charBeingChased is Character == false) { int objectId = this.WatchForCharacter(midX, midY); if (objectId > 0) { this.charBeingChased = (Character)this.actor.room.objects[(byte)LoadOrder.Character][objectId]; } } // Prepare Values int frame = Systems.timer.Frame; // Get distance from Character, if applicable. int destX = this.charBeingChased is Character ? this.charBeingChased.posX + this.charBeingChased.bounds.MidX : midX; int destY = this.charBeingChased is Character ? this.charBeingChased.posY + this.charBeingChased.bounds.MidY : midY; int distance = FPTrigCalc.GetDistance(FVector.Create(midX, midY), FVector.Create(destX, destY)).RoundInt; // Assign New Chase Action (When Action Time Expires). // Flee if (this.flee > 0 && distance < this.flee) { this.quickAct = ChaseAction.Flee; } // Chase else if (this.chase > 0 && distance <= this.chase) { this.quickAct = ChaseAction.Chase; } // Return to Start Position else if (this.returns) { if (this.quickAct == ChaseAction.Return || (this.quickAct == ChaseAction.Wait && this.waitEndFrame < frame)) { this.quickAct = ChaseAction.Return; } else { this.quickAct = ChaseAction.Wait; this.waitEndFrame = this.waitEndFrame < frame ? frame + this.retDelay : this.waitEndFrame; } } // Standard: Do Nothing else { this.quickAct = ChaseAction.Standard; } }
public void CollisionDetection() { Character ch = this.character; Physics phys = ch.physics; // Setup Character phys.StopX(); phys.StopY(); // Reset the Character's Velocity phys.MoveToPos(600, 300); // Reset the Character's Position phys.SetGravity(FInt.Create(0)); phys.intend = FVector.Create(3, 3); // Setup Shroom Shroom shroom = new Shroom(this.roomScene, (byte)ShroomSubType.Black, FVector.Create(700, 300), null); shroom.physics.intend = FVector.Create(-1, -1); // Confirm that Physics Alignments, IsOverlapping, GetOverlapX, GetOverlapY are working correctly: shroom.physics.AlignRight(ch); Debug.Assert(CollideDetect.IsOverlapping(ch, shroom) == false); shroom.physics.MoveToPosX(shroom.posX - 1); Debug.Assert(CollideDetect.IsOverlapping(ch, shroom) == true); Debug.Assert(CollideDetect.GetOverlapX(ch, shroom, true) == 1); shroom.physics.AlignLeft(ch); Debug.Assert(CollideDetect.IsOverlapping(ch, shroom) == false); shroom.physics.MoveToPosX(shroom.posX + 1); Debug.Assert(CollideDetect.IsOverlapping(ch, shroom) == true); Debug.Assert(CollideDetect.GetOverlapX(shroom, ch, true) == 1); shroom.physics.AlignUp(ch); Debug.Assert(CollideDetect.IsOverlapping(ch, shroom) == false); shroom.physics.MoveToPosY(shroom.posY + 1); Debug.Assert(CollideDetect.IsOverlapping(ch, shroom) == true); Debug.Assert(CollideDetect.GetOverlapY(shroom, ch, true) == 1); shroom.physics.AlignDown(ch); Debug.Assert(CollideDetect.IsOverlapping(ch, shroom) == false); shroom.physics.MoveToPosY(shroom.posY - 1); Debug.Assert(CollideDetect.IsOverlapping(ch, shroom) == true); Debug.Assert(CollideDetect.GetOverlapY(ch, shroom, true) == 1); // Move Away (no longer overlapping, off by 2) shroom.physics.MoveToPosY(shroom.posY + 3); Debug.Assert(CollideDetect.GetOverlapY(ch, shroom, true) == -2); }
public Physics(GameObject actor) { this.actor = actor; this.physPos = FVector.Create(this.actor.posX, this.actor.posY); this.lastPosX = this.actor.posX; this.lastPosY = this.actor.posY; this.velocity = new FVector(); this.extraMovement = new FVector(); this.gravity = new FInt(); this.hasExtraMovement = false; this.touch = new Touch(); }
public override bool Die(DeathResult deathType) { // Knockouts and TNT can still occur, but squishing will cause other behaviors. if (deathType == DeathResult.Knockout) { return(base.Die(deathType)); } this.Destroy(); // Create Shell In Turtle's Place Shell shell = new Shell(this.room, (byte)ShellSubType.Red, FVector.Create(this.posX, this.posY), null); room.AddToScene(shell, true); return(true); }
public override bool GetJumpedOn(Character character, sbyte bounceStrength = 0) { this.Destroy(); // Can automatically destroy Boom, since it gets replaced with an item. this.room.PlaySound(Systems.sounds.thudWhop, 1f, this.posX + 16, this.posY + 16); // Create Bomb in Boom's Place Bomb bomb = new Bomb(this.room, (byte)BombSubType.Bomb, FVector.Create(this.posX, this.posY), new Dictionary <string, short>() { { "on", 1 } }); room.AddToScene(bomb, true); ActionMap.Jump.StartAction(character, 0, 0, 2, true, false); return(true); }
public void SolidTileCollision() { Character ch = this.character; Physics phys = ch.physics; // Create Tiles in diamond pattern. this.tilemap.SetMainTile(10, 8, (byte)TileEnum.Brick, 0); // Position at 480, 384 this.tilemap.SetMainTile(9, 9, (byte)TileEnum.Brick, 0); // Position at 432, 432 this.tilemap.SetMainTile(10, 10, (byte)TileEnum.Brick, 0); // Position at 480, 480 this.tilemap.SetMainTile(11, 9, (byte)TileEnum.Brick, 0); // Position at 528, 432 // --- Simultaneous Up AND Right Tile Collisions; not corner --- // phys.SetGravity(FInt.Create(0)); // End Gravity phys.MoveToPos(480 - ch.bounds.Right - 3, 480); phys.velocity = FVector.Create(6, -4); // Character moving up-right. this.VerifyGridPos(ch, 9, 10, 9, 10); phys.RunPhysicsTick(); ch.RunTick(); CollideTile.RunTileCollision(ch); Debug.Assert(ch.posX + ch.bounds.Right == 480, "Character posX should be 480."); Debug.Assert(ch.posY + ch.bounds.Top == 480, "Character posY should be 480."); // --- Simultaneous Down AND Left Tile Collisions; not corner --- // phys.MoveToPos(528 - ch.bounds.Left + 2, 432 - ch.bounds.Bottom - 2); phys.velocity = FVector.Create(-5, 7); // Character moving down-left. this.VerifyGridPos(ch, 11, 8, 11, 8); phys.RunPhysicsTick(); ch.RunTick(); CollideTile.RunTileCollision(ch); Debug.Assert(ch.posX + ch.bounds.Left == 528, "Character posX should be 528."); Debug.Assert(ch.posY + ch.bounds.Bottom == 432, "Character posY should be 432."); // Delete Tiles this.tilemap.ClearMainLayer(10, 8); this.tilemap.ClearMainLayer(9, 9); this.tilemap.ClearMainLayer(10, 10); this.tilemap.ClearMainLayer(11, 9); }
public override void RunTick() { base.RunTick(); // Get Center Bounds int midX = this.posX + this.bounds.MidX; int midY = this.posY + this.bounds.MidY; // Only change behaviors every 16 frames. if (Systems.timer.frame16Modulus == 15) { this.WatchForCharacter(midX, midY); } // Check for any attack to make this round. if (this.charWatched is Character && this.attack.AttackThisFrame()) { // Get distance from Character, if applicable. int destX = this.charWatched is Character ? this.charWatched.posX + this.charWatched.bounds.MidX - 10 : midX; int destY = this.charWatched is Character ? this.charWatched.posY + this.charWatched.bounds.MidY - 10 : midY; int distance = FPTrigCalc.GetDistance(FVector.Create(midX, midY), FVector.Create(destX, destY)).RoundInt; if (distance < ViewDistance) { FInt rotation = FPRadians.GetRadiansBetweenCoords(midX, midY, destX, destY); this.rotation = (float)rotation.ToDouble(); if (this.attCount != 2) { this.ShootBolt(rotation, midX, midY); } if (this.attCount > 1) { this.ShootBolt(rotation + attSpread, midX, midY); this.ShootBolt(rotation - attSpread, midX, midY); } this.room.PlaySound(Systems.sounds.bolt, 0.6f, this.posX + 16, this.posY + 16); } } }
public override void ActivateCannon(RoomScene room, byte subType, short gridX, short gridY, byte cannonSpeed) { FVector pos = FVector.Create(gridX * (byte)TilemapEnum.TileWidth + Cannon.xOffset, gridY * (byte)TilemapEnum.TileHeight + Cannon.xOffset); FInt angleSpeed = FInt.Create(cannonSpeed * 0.707); // Left if (subType == (byte)CannonHorSubType.Left) { pos.X -= 30; ProjectileBullet.Create(room, (byte)0, pos, FVector.Create(0 - angleSpeed, FInt.Create(0))); } // Right else { pos.X += 30; ProjectileBullet.Create(room, (byte)0, pos, FVector.Create(angleSpeed, FInt.Create(0))); } room.PlaySound(Systems.sounds.cannonFire, 1f, gridX * (byte)TilemapEnum.TileWidth, gridY * (byte)TilemapEnum.TileHeight); }
public override void ActivateCannon(RoomScene room, byte subType, short gridX, short gridY, byte cannonSpeed) { FVector pos = FVector.Create(gridX * (byte)TilemapEnum.TileWidth + Cannon.xOffset, gridY * (byte)TilemapEnum.TileHeight + Cannon.xOffset); FInt angleSpeed = FInt.Create(cannonSpeed * 0.707); // Up Right if (subType == (byte)CannonDiagSubType.UpRight) { pos.X += 18; pos.Y -= 18; ProjectileBullet.Create(room, (byte)0, pos, FVector.Create(angleSpeed, 0 - angleSpeed)); } // Down Right else if (subType == (byte)CannonDiagSubType.DownRight) { pos.X += 16; pos.Y += 19; ProjectileBullet.Create(room, (byte)0, pos, FVector.Create(angleSpeed, angleSpeed)); } // Down Left else if (subType == (byte)CannonDiagSubType.DownLeft) { pos.X -= 17; pos.Y += 19; ProjectileBullet.Create(room, (byte)0, pos, FVector.Create(0 - angleSpeed, angleSpeed)); } // Up Left else { pos.X -= 17; pos.Y -= 20; ProjectileBullet.Create(room, (byte)0, pos, FVector.Create(0 - angleSpeed, 0 - angleSpeed)); } room.PlaySound(Systems.sounds.cannonFire, 1f, gridX * (byte)TilemapEnum.TileWidth, gridY * (byte)TilemapEnum.TileHeight); }
public void ResetMagiBall(MagiShield magiShield, GameObject actor, byte subType, byte numberOfBalls, byte ballNumber, byte radius, short regenFrames = 0) { this.ResetProjectile(actor.room, subType, FVector.Create(0, 0), FVector.Create(0, 0)); this.magiShield = magiShield; this.actor = actor; this.ByCharacterId = actor.id; this.regenFrames = regenFrames; this.regenEnergy = regenFrames; this.regenAlpha = 1; this.radius = radius; this.isAlive = true; this.SetSafelyJumpOnTop(false); this.SetDamage(DamageStrength.Standard); this.AssignSubType(subType); this.AssignBoundsByAtlas(2, 2, -2, -2); this.SetOffset(numberOfBalls, ballNumber); this.SetEndLife(Systems.timer.Frame + (60 * 60 * 10)); // Ten minute lifespan. // Add the Projectile to Scene actor.room.AddToScene(this, true); }
public override void RunTick() { base.RunTick(); // Check if an attack needs to be made: if (this.attack.AttackThisFrame()) { ProjectileEarth projectile = ProjectileEarth.Create(room, (byte)ProjectileEarthSubType.Earth, FVector.Create(this.posX + this.bounds.MidX - 10, this.posY + this.bounds.Bottom - 10), FVector.Create(0, this.attSpeed)); this.room.PlaySound(Systems.sounds.rock, 0.4f, this.posX + 16, this.posY + 16); } }
public override void Launch(int posX, int posY, FInt velX, FInt velY) { var projectile = HammerProjectile.Create(this.character.room, this.projSubType, FVector.Create(posX, posY), FVector.Create(velX, velY)); projectile.SetActorID(this.character); }
public override void RunTick() { // Update the rotation to move toward. int midX = this.actor.posX + this.actor.bounds.MidX; int midY = this.actor.posY + this.actor.bounds.MidY; // Only change behaviors every 16 frames. if (Systems.timer.frame16Modulus == 7) { this.TryUpdateBehavior(midX, midY); } // Get distance from Character, if applicable. int destX = this.charBeingChased is Character ? this.charBeingChased.posX + this.charBeingChased.bounds.MidX : midX; int destY = this.charBeingChased is Character ? this.charBeingChased.posY + this.charBeingChased.bounds.MidY : midY; int distance = FPTrigCalc.GetDistance(FVector.Create(midX, midY), FVector.Create(destX, destY)).RoundInt; // Stall if (this.stall > 0 && distance < this.stall) { if (this.physics.velocity.X != 0) { this.physics.velocity.X *= FInt.Create(0.85); } if (this.physics.velocity.Y != 0) { this.physics.velocity.Y *= FInt.Create(0.85); } return; } // Stop Chasing if (this.quickAct == ChaseAction.Standard || this.quickAct == ChaseAction.Wait) { if (this.physics.velocity.X != 0) { this.physics.velocity.X *= FInt.Create(0.9); } if (this.physics.velocity.Y != 0) { this.physics.velocity.Y *= FInt.Create(0.9); } return; } // Return to Starting Position if (this.quickAct == ChaseAction.Return) { destX = (int)this.startPos.X; destY = (int)this.startPos.Y; } FInt newVelX = FInt.Create(0); FInt newVelY = FInt.Create(0); // Chase or Flee if (this.axis == (byte)FlightChaseAxis.Both) { if (Math.Abs(midX - destX) < 2 && Math.Abs(midY - destY) <= 2) { this.physics.velocity.X *= FInt.Create(0.90); this.physics.velocity.Y *= FInt.Create(0.90); return; } FInt rotRadian = FPRadians.GetRadiansBetweenCoords(midX, midY, destX, destY); newVelX = FPRadians.GetXFromRotation(rotRadian, this.speed); newVelY = FPRadians.GetYFromRotation(rotRadian, this.speed); } // Vertical Movement Only else if (this.axis == (byte)FlightChaseAxis.Vertical) { if (Math.Abs(midY - destY) <= 2) { this.physics.velocity.Y *= FInt.Create(0.90); return; } FInt rotRadian = FPRadians.GetRadiansBetweenCoords(0, midY, 0, destY); newVelY = FPRadians.GetYFromRotation(rotRadian, this.speed); } // Horizontal Movement Only else { if (Math.Abs(midX - destX) <= 2) { this.physics.velocity.X *= FInt.Create(0.90); return; } FInt rotRadian = FPRadians.GetRadiansBetweenCoords(midX, 0, destX, 0); newVelX = FPRadians.GetXFromRotation(rotRadian, this.speed); } // Flee if (this.quickAct == ChaseAction.Flee) { newVelX = newVelX.Inverse; newVelY = newVelY.Inverse; } FInt accel = this.speed * FInt.Create(0.02); if (this.physics.velocity.X > newVelX) { this.physics.velocity.X -= accel; } else if (this.physics.velocity.X < newVelX) { this.physics.velocity.X += accel; } if (this.physics.velocity.Y > newVelY) { this.physics.velocity.Y -= accel; } else if (this.physics.velocity.Y < newVelY) { this.physics.velocity.Y += accel; } }
public ProjectileBullet() : base(null, 0, FVector.Create(0, 0), FVector.Create(0, 0)) { this.SetCollide(CollideEnum.NoTileCollide); this.SetCollisionType(ProjectileCollisionType.IgnoreWallsDestroy); this.SetSpriteName("Projectiles/Bullet"); }
private int gravFrame; // The frame that a movement style ends on. public ShurikenProjectile() : base(null, 0, FVector.Create(0, 0), FVector.Create(0, 0)) { this.Damage = DamageStrength.Standard; this.CollisionType = ProjectileCollisionType.DestroyOnCollide; }
public override void Launch(int posX, int posY, FInt velX, FInt velY) { if (velX < 0) { posX -= 8; } var projectile = ProjectileBall.Create(this.character.room, this.projSubType, FVector.Create(posX, posY), FVector.Create(velX, velY)); projectile.SetActorID(this.character); }
public virtual void Launch(int posX, int posY, FInt velX, FInt velY) { ProjectileBall projectile = ProjectileBall.Create(this.character.room, this.projSubType, FVector.Create(posX, posY), FVector.Create(velX.RoundInt, velY.RoundInt)); projectile.SetActorID(this.character); }
public AxeProjectile() : base(null, 0, FVector.Create(0, 0), FVector.Create(0, 0)) { this.Damage = DamageStrength.Lethal; this.physics.SetGravity(FInt.Create(0.45)); this.CollisionType = ProjectileCollisionType.IgnoreWallsSurvive; }
public ProjectileBolt() : base(null, 0, FVector.Create(0, 0), FVector.Create(0, 0)) { }
public override void RunTick() { base.RunTick(); // Check if an attack needs to be made: if (this.attack.AttackThisFrame()) { ProjectileEnemy projectile = ProjectileEnemy.Create(room, (byte)ProjectileEnemySubType.Electric, FVector.Create(this.posX + this.bounds.MidX - 10, this.posY + this.bounds.MidY + 4), FVector.Create(this.FaceRight ? this.attSpeed : -this.attSpeed, -5)); projectile.physics.SetGravity(this.gravity); this.room.PlaySound(Systems.sounds.flame, 0.6f, this.posX + 16, this.posY + 16); } }
private void ShootBolt(FInt rotation, int midX, int midY) { FInt r = FPRadians.Normalize(rotation); FInt velX = FInt.Create(Radians.GetXFromRotation((float)r.ToDouble(), (float)this.attSpeed.ToDouble())); FInt velY = FInt.Create(Radians.GetYFromRotation((float)r.ToDouble(), (float)this.attSpeed.ToDouble())); ProjectileEnemy projectile = ProjectileEnemy.Create(room, (byte)ProjectileEnemySubType.BoltBlue, FVector.Create(midX - 10, midY + 4), FVector.Create(velX, velY)); projectile.physics.SetGravity(FInt.Create(0)); projectile.rotation = (float)r.ToDouble(); }
public override void Launch(GameObject actor, int posX, int posY, FInt velX, FInt velY) { // Green Bolts have random direction casting: Random rand = new Random((int)Systems.timer.Frame); FInt modY = FInt.Create(rand.Next(-20, 20) * 0.1); var projectile = ProjectileBolt.Create(actor.room, (byte)ProjectileBoltSubType.Green, FVector.Create(posX, posY), FVector.Create(velX, velY + modY)); projectile.SetActorID(actor); }
public ThrustProjectile() : base(null, 0, FVector.Create(0, 0), FVector.Create(0, 0)) { }