public static MinorAsteroid CreateSmallAsteroid(SceneMgr mgr, Vector direction, Vector center, int rot, int textureId, int radius, float speed, double rotation) { MinorAsteroid asteroid = new MinorAsteroid(mgr, IdMgr.GetNewId(mgr.GetCurrentPlayer().GetId())); asteroid.AsteroidType = AsteroidType.SPAWNED; asteroid.Rotation = rot; asteroid.Direction = direction.Rotate(rotation); asteroid.Radius = radius; asteroid.Position = center; asteroid.Gold = radius * 2; asteroid.TextureId = textureId; asteroid.Enabled = true; asteroid.SetGeometry(SceneGeometryFactory.CreateAsteroidImage(asteroid)); SphereCollisionShape cs = new SphereCollisionShape(); cs.Center = asteroid.Center; cs.Radius = asteroid.Radius; asteroid.CollisionShape = cs; NewtonianMovementControl nmc = new NewtonianMovementControl(); nmc.Speed = speed; asteroid.AddControl(nmc); LinearRotationControl lrc = new LinearRotationControl(); lrc.RotationSpeed = mgr.GetRandomGenerator().Next(SharedDef.MIN_ASTEROID_ROTATION_SPEED, SharedDef.MAX_ASTEROID_ROTATION_SPEED) / 10.0f; asteroid.AddControl(lrc); asteroid.AddControl(new MinorAsteroidCollisionReactionControl()); asteroid.AddControl(new StickySphereCollisionShapeControl()); return(asteroid); }
private void Slow(Asteroid ast, bool exact) { IMovementControl c = ast.GetControlOfType <IMovementControl>(); LinearRotationControl c1 = ast.GetControlOfType <LinearRotationControl>(); if (c == null || c1 == null) { return; } float time = exact ? 1.5f * exactBonus : 1.5f; List <IControl> controls = new List <IControl>(); controls.Add(c); controls.Add(c1); AsteroidFreezeControl removal = new AsteroidFreezeControl(); removal.SetControlsForDisable(controls); removal.Time = time; ast.AddControl(removal); // led je posunut o pulku radiusu doleva Vector p = new Vector(ast.Position.X - (ast.Radius / 2), ast.Position.Y - (ast.Radius / 2)); // potom jeho sirka musi byt prumer + 2 * posunuti (vlevo a vpravo) => r * (2 + 0.5 + 0.5) IceSquare s = SceneObjectFactory.CreateIceSquare(SceneMgr, p, new Size(ast.Radius * 3, ast.Radius * 3)); s.AddControl(new LimitedLifeControl(time)); SceneMgr.DelayedAttachToScene(s); }
private static Asteroid CreateAsteroidControls(ServerMgr mgr, Asteroid s) { NewtonianMovementControl nmc = new NewtonianMovementControl(); nmc.Speed = mgr.GetRandomGenerator().Next(SharedDef.MIN_ASTEROID_SPEED * 10, SharedDef.MAX_ASTEROID_SPEED * 10) / 10.0f; s.AddControl(nmc); LinearRotationControl lrc = new LinearRotationControl(); lrc.RotationSpeed = mgr.GetRandomGenerator().Next(SharedDef.MIN_ASTEROID_ROTATION_SPEED, SharedDef.MAX_ASTEROID_ROTATION_SPEED) / 10.0f; s.AddControl(lrc); s.AddControl(new StickySphereCollisionShapeControl()); return(s); }
public static MiningModule CreateMiningModule(SceneMgr mgr, Vector position, Player owner) { MiningModule module = new MiningModule(mgr, IdMgr.GetNewId(mgr.GetCurrentPlayer().GetId()), owner); module.Position = position; module.Radius = 10; module.Color = Colors.Crimson; ModuleDamageControl mc = new ModuleDamageControl(); mc.MaxHp = SharedDef.SPECTATOR_MAX_HP; module.AddControl(mc); SphereCollisionShape cs = new SphereCollisionShape(); cs.Center = module.Center; cs.Radius = module.Radius; module.CollisionShape = cs; ControlableDeviceControl dc = new ControlableMiningModuleControl(); module.AddControl(dc); LinearRotationControl rc = new LinearRotationControl(); rc.RotationSpeed = SharedDef.SPECTATOR_MODULE_ROTATION_SPEED; module.AddControl(rc); HpRegenControl hc = new HpRegenControl(); hc.MaxRegenTime = SharedDef.SPECTATOR_HP_REGEN_CD; hc.RegenTimer = SharedDef.SPECTATOR_HP_REGEN_CD; hc.RegenSpeed = SharedDef.SPECTATOR_REGEN_SPEED; module.AddControl(hc); module.AddControl(new RespawningObjectControl()); module.AddControl(new StickySphereCollisionShapeControl()); module.SetGeometry(SceneGeometryFactory.CrateMiningModule(module)); return(module); }
public static SingularityMine CreateDroppingSingularityMine(SceneMgr mgr, Point point, Player plr) { SingularityMine mine = new SingularityMine(mgr, IdMgr.GetNewId(mgr.GetCurrentPlayer().GetId())); mine.Position = new Vector(point.X, 0); mine.Owner = plr; mine.Radius = 12; mine.Direction = new Vector(0, 1); mine.Color = Colors.BlueViolet; SphereCollisionShape cs = new SphereCollisionShape(); cs.Center = mine.Center; cs.Radius = mine.Radius; mine.CollisionShape = cs; DroppingSingularityControl sc = new DroppingSingularityControl(); sc.Speed = plr.Data.MineGrowthSpeed; sc.Strength = plr.Data.MineStrength; mine.AddControl(sc); LinearMovementControl lmc = new LinearMovementControl(); lmc.Speed = plr.Data.MineFallingSpeed; mine.AddControl(lmc); LinearRotationControl lrc = new LinearRotationControl(); lrc.RotationSpeed = (float)FastMath.LinearInterpolate(0, Math.PI, mgr.GetRandomGenerator().NextDouble()); mine.AddControl(lrc); mine.AddControl(new StickySphereCollisionShapeControl()); mine.SetGeometry(SceneGeometryFactory.CreateMineImage(mine)); return(mine); }
public static StatPowerUp CreateStatPowerUp(ServerMgr mgr, DeviceType type) { Random randomGenerator = mgr.GetRandomGenerator(); StatPowerUp s = new StatPowerUp(null, IdMgr.GetNewId(0)); s.Size = new Size(20, 20); bool headingRight = randomGenerator.Next(10) > 5 ? true : false; s.Position = GetPositionOnEdgeOfLowerOrbitArea(randomGenerator, headingRight, (int)s.Size.Width / 2); s.Direction = headingRight ? new Vector(1, 0) : new Vector(-1, 0); s.Rotation = mgr.GetRandomGenerator().Next(360); s.PowerUpType = type; SquareCollisionShape cs = new SquareCollisionShape(); cs.Position = s.Position; cs.Size = s.Size; cs.Rotation = s.Rotation; s.CollisionShape = cs; NewtonianMovementControl nmc = new NewtonianMovementControl(); nmc.Speed = mgr.GetRandomGenerator().Next(SharedDef.MIN_POWERUP_SPEED * 10, SharedDef.MAX_POWERUP_SPEED * 10) / 10.0f; s.AddControl(nmc); LinearRotationControl lrc = new LinearRotationControl(); lrc.RotationSpeed = mgr.GetRandomGenerator().Next(SharedDef.MIN_ASTEROID_ROTATION_SPEED, SharedDef.MAX_ASTEROID_ROTATION_SPEED) / 10.0f; s.AddControl(lrc); s.AddControl(new StickySquareCollisionShapeControl()); s.AddControl(new StatPowerUpCollisionReactionControl()); return(s); }
public static void ReadObjectLinearRotationControl(this NetIncomingMessage msg, LinearRotationControl c) { msg.ReadControl(c); c.RotationSpeed = msg.ReadFloat(); }
public static void WriteObjectLinearRotationControl(this NetOutgoingMessage msg, LinearRotationControl c) { msg.WriteControl(c); msg.Write(c.RotationSpeed); }
public static IList <IControl> ReadControls(this NetIncomingMessage msg) { int controlCount = msg.ReadInt32(); IList <IControl> controls = new List <IControl>(controlCount); for (int i = 0; i < controlCount; ++i) { int hash = msg.ReadInt32(); if (hash == typeof(BaseCollisionControl).GUID.GetHashCode()) { BaseCollisionControl c = new BaseCollisionControl(); msg.ReadControl(c); controls.Add(c); } else if (hash == typeof(BouncingSingularityBulletControl).GUID.GetHashCode()) { BouncingSingularityBulletControl c = new BouncingSingularityBulletControl(); msg.ReadObjectExplodingSingularityBulletControl(c); controls.Add(c); } else if (hash == typeof(DroppingSingularityControl).GUID.GetHashCode()) { DroppingSingularityControl c = new DroppingSingularityControl(); msg.ReadObjectDroppingSingularityControl(c); controls.Add(c); } else if (hash == typeof(AsteroidDroppingSingularityControl).GUID.GetHashCode()) { AsteroidDroppingSingularityControl c = new AsteroidDroppingSingularityControl(); msg.ReadObjectDroppingSingularityControl(c); controls.Add(c); } else if (hash == typeof(NewtonianMovementControl).GUID.GetHashCode()) { NewtonianMovementControl c = new NewtonianMovementControl(); msg.ReadObjectNewtonianMovementControl(c); controls.Add(c); } else if (hash == typeof(LinearMovementControl).GUID.GetHashCode()) { LinearMovementControl c = new LinearMovementControl(); msg.ReadObjectLinearMovementControl(c); controls.Add(c); } else if (hash == typeof(LinearRotationControl).GUID.GetHashCode()) { LinearRotationControl c = new LinearRotationControl(); msg.ReadObjectLinearRotationControl(c); controls.Add(c); } else if (hash == typeof(PowerHookControl).GUID.GetHashCode()) { PowerHookControl c = new PowerHookControl(); msg.ReadObjectHookControl(c); controls.Add(c); } else if (hash == typeof(HookControl).GUID.GetHashCode()) { HookControl c = new HookControl(); msg.ReadObjectHookControl(c); controls.Add(c); } else if (hash == typeof(ExplodingSingularityBulletControl).GUID.GetHashCode()) { ExplodingSingularityBulletControl c = new ExplodingSingularityBulletControl(); msg.ReadObjectExplodingSingularityBulletControl(c); controls.Add(c); } else if (hash == typeof(ExcludingExplodingSingularityBulletControl).GUID.GetHashCode()) { ExcludingExplodingSingularityBulletControl c = new ExcludingExplodingSingularityBulletControl(); msg.ReadObjectExcludingExplodingSingularityBulletControl(c); controls.Add(c); } else if (hash == typeof(MinorAsteroidCollisionReactionControl).GUID.GetHashCode()) { MinorAsteroidCollisionReactionControl c = new MinorAsteroidCollisionReactionControl(); msg.ReadControl(c); controls.Add(c); } else if (hash == typeof(SingularityBulletCollisionReactionControl).GUID.GetHashCode()) { SingularityBulletCollisionReactionControl c = new SingularityBulletCollisionReactionControl(); msg.ReadControl(c); controls.Add(c); } else if (hash == typeof(StatPowerUpCollisionReactionControl).GUID.GetHashCode()) { StatPowerUpCollisionReactionControl c = new StatPowerUpCollisionReactionControl(); msg.ReadControl(c); controls.Add(c); } else if (hash == typeof(StickyPointCollisionShapeControl).GUID.GetHashCode()) { StickyPointCollisionShapeControl c = new StickyPointCollisionShapeControl(); msg.ReadControl(c); controls.Add(c); } else if (hash == typeof(StickySphereCollisionShapeControl).GUID.GetHashCode()) { StickySphereCollisionShapeControl c = new StickySphereCollisionShapeControl(); msg.ReadControl(c); controls.Add(c); } else if (hash == typeof(StickySquareCollisionShapeControl).GUID.GetHashCode()) { StickySquareCollisionShapeControl c = new StickySquareCollisionShapeControl(); msg.ReadControl(c); controls.Add(c); } else if (hash == typeof(BaseHealthControl).GUID.GetHashCode()) { BaseHealthControl c = new BaseHealthControl(); msg.ReadHealthControl(c); controls.Add(c); } else if (hash == typeof(DestroyHpControl).GUID.GetHashCode()) { DestroyHpControl c = new DestroyHpControl(); msg.ReadHealthControl(c); controls.Add(c); } else if (hash == typeof(HpRegenControl).GUID.GetHashCode()) { HpRegenControl c = new HpRegenControl(); msg.ReadHealthRegenControl(c); controls.Add(c); } else if (hash == typeof(ModuleDamageControl).GUID.GetHashCode()) { ModuleDamageControl c = new ModuleDamageControl(); msg.ReadModuleDamageControl(c); controls.Add(c); } else if (hash == typeof(HighlightingControl).GUID.GetHashCode()) { // skip } else { Logger.Error("Received unsupported control (" + hash + ")!"); } } return(controls); }