/// <summary> /// Create an explosion /// </summary> /// <param name="center">Center point of the explosion</param> /// <param name="magnitude">How much damage the explosion deals and how large the fireball is</param> /// <param name="delay">Delay in seconds when the explosion should take place, or 0 to explode immediately</param> /// <param name="doDamage">Whether the explosion should deal damage. Default true</param> /// <param name="angles">Angles of the explosion entity</param> /// <param name="owner">Which entity owns this explosion</param> /// <param name="randomRange">If not 0, adds some random x and y distribution to the center point within a box that is 2 * this value in the x and y axes, centered on the given center point</param> public static void CreateExplosion(Vector center, int magnitude, float delay = 0, bool doDamage = true, Vector angles = default, BaseEntity owner = null, float randomRange = 0) { if (randomRange != 0) { center.x += EngineRandom.Float(-randomRange, randomRange); center.y += EngineRandom.Float(-randomRange, randomRange); } var explosion = Engine.EntityRegistry.CreateInstance <EnvExplosion>(); explosion.Origin = center; explosion.Angles = angles; explosion.Owner = owner; explosion.Magnitude = magnitude; if (!doDamage) { explosion.SpawnFlags |= SF.NoDamage; } explosion.Spawn(); if (delay == 0) { //TODO: pass world as both explosion.Use(null, null, UseType.Toggle, 0); } else { Debug.Assert(delay > 0); explosion.SetThink(explosion.SUB_CallUseToggle); explosion.SetNextThink(Engine.Globals.Time + delay); } }
public int LookupActivity(int activity) { //TODO: define 0 Debug.Assert(activity != 0); var model = GetStudioModel(); if (model == null) { return(0); } var sequences = model.Sequences; var weighttotal = 0; var seq = ActivityNotAvailable; for (var i = 0; i < sequences.Count; ++i) { if (sequences[i].Activity == activity) { weighttotal += sequences[i].ActWeight; if (weighttotal == 0 || EngineRandom.Long(0, weighttotal - 1) < sequences[i].ActWeight) { seq = i; } } } return(seq); }
public override void Spawn() { var velocity = EngineRandom.Float(200, 300) * Angles; velocity.x += EngineRandom.Float(-100.0f, 100.0f); velocity.y += EngineRandom.Float(-100.0f, 100.0f); if (velocity.z >= 0) { velocity.z += 200; } else { velocity.z -= 200; } Velocity = velocity; MoveType = MoveType.Bounce; Gravity = 0.5f; SetNextThink(Engine.Globals.Time + 0.1f); Solid = Solid.Not; SetModel("models/grenade.mdl"); // Need a model, just use the grenade, we don't draw it anyway SetSize(WorldConstants.g_vecZero, WorldConstants.g_vecZero); Effects |= EntityEffects.NoDraw; Speed = EngineRandom.Float(0.5f, 1.5f); Angles = WorldConstants.g_vecZero; }
static void CreateEntitiesWhichNotSynchronizedViaNetwork() { //ground { //create materials from the code ShaderBaseMaterial[] materials = new ShaderBaseMaterial[7]; { for (int n = 0; n < materials.Length; n++) { string materialName = HighLevelMaterialManager.Instance.GetUniqueMaterialName( "ExampleOfProceduralMapCreation_Ground"); ShaderBaseMaterial material = (ShaderBaseMaterial)HighLevelMaterialManager.Instance.CreateMaterial( materialName, "ShaderBaseMaterial"); material.Diffuse1Map.Texture = string.Format("Types\\Vegetation\\Trees\\Textures\\Bark{0}A.dds", n + 1); material.NormalMap.Texture = string.Format("Types\\Vegetation\\Trees\\Textures\\Bark{0}A_N.dds", n + 1); material.SpecularColor = new ColorValue(1, 1, 1); material.SpecularMap.Texture = string.Format("Types\\Vegetation\\Trees\\Textures\\Bark{0}A_S.dds", n + 1); material.PostCreate(); materials[n] = material; } } //create objects with collision body EngineRandom random = new EngineRandom(0); for (float y = -35; y < 35; y += 5) { for (float x = -35; x < 35; x += 2.5f) { StaticMesh staticMesh = (StaticMesh)Entities.Instance.Create("StaticMesh", Map.Instance); staticMesh.MeshName = "Base\\Simple Models\\Box.mesh"; ShaderBaseMaterial material = materials[random.Next(0, 6)]; staticMesh.ForceMaterial = material.Name; //"DarkGray"; staticMesh.Position = new Vec3(x, y, -1.0f); staticMesh.Scale = new Vec3(2.5f, 5, 2); staticMesh.CastDynamicShadows = false; staticMesh.PostCreate(); } } } //SkyBox { Entity skyBox = Entities.Instance.Create("SkyBox", Map.Instance); skyBox.PostCreate(); } //Light { Light light = (Light)Entities.Instance.Create("Light", Map.Instance); light.LightType = RenderLightType.Directional; light.SpecularColor = new ColorValue(1, 1, 1); light.Position = new Vec3(0, 0, 10); light.Rotation = new Angles(120, 50, 330).ToQuat(); light.PostCreate(); } }
public override void Use(BaseEntity pActivator, BaseEntity pCaller, UseType useType, float value) { ModelName = null; //invisible Solid = Solid.Not; // intangible var vecSpot = Origin + new Vector(0, 0, 8); // trace starts here! Server.Game.Engine.Trace.Line(vecSpot, vecSpot + new Vector(0, 0, -40), TraceFlags.IgnoreMonsters, Edict(), out var tr); // Pull out of the wall a bit if (tr.Fraction != 1.0) { Origin = tr.EndPos + (tr.PlaneNormal * (Magnitude - 24) * 0.6); } // draw decal if ((SpawnFlags & SF.NoDecal) == 0) { if (EngineRandom.Float(0, 1) < 0.5f) { EntUtils.DecalTrace(tr, Decal.Scorch1); } else { EntUtils.DecalTrace(tr, Decal.Scorch2); } } // draw fireball TempEntity.Explosion(Origin, (short)Globals.g_sModelIndexFireball, (SpawnFlags & SF.NoFireball) == 0 ? SpriteScale : 0, 15); // do damage if ((SpawnFlags & SF.NoDamage) == 0) { RadiusDamage(this, this, Magnitude, EntityClass.None, DamageTypes.Blast); } SetThink(Smoke); SetNextThink(Engine.Globals.Time + 0.3f); // draw sparks if ((SpawnFlags & SF.NoSparks) == 0) { int sparkCount = EngineRandom.Long(0, 3); for (var i = 0; i < sparkCount; ++i) { Create("spark_shower", Origin, tr.PlaneNormal); } } }
void Fire() { if (!Visible) { return; } if (fireworkBulletType == null) { return; } Bullet bullet = (Bullet)Entities.Instance.Create(fireworkBulletType, Map.Instance); bullet.Position = GetInterpolatedPosition() + new Vec3(0, 0, .1f); EngineRandom random = World.Instance.Random; Quat rot = new Angles(random.NextFloatCenter() * 25, 90 + random.NextFloatCenter() * 25, 0).ToQuat(); bullet.Rotation = rot; bullet.PostCreate(); foreach (MapObjectAttachedObject attachedObject in bullet.AttachedObjects) { MapObjectAttachedRibbonTrail attachedRibbonTrail = attachedObject as MapObjectAttachedRibbonTrail; if (attachedRibbonTrail == null) { continue; } ColorValue color; switch (random.Next(4)) { case 0: color = new ColorValue(1, 0, 0); break; case 1: color = new ColorValue(0, 1, 0); break; case 2: color = new ColorValue(0, 0, 1); break; case 3: color = new ColorValue(1, 1, 0); break; default: color = new ColorValue(0, 0, 0); break; } if (attachedRibbonTrail.RibbonTrail != null) { attachedRibbonTrail.RibbonTrail.Chains[0].InitialColor = color; } } }
void ServerOrSingle_CreatePiece(Vec2i index) { JigsawPuzzlePiece piece = (JigsawPuzzlePiece)Entities.Instance.Create( "JigsawPuzzlePiece", Map.Instance); piece.ServerOrSingle_SetIndex(index); //calculate position { Rect area = GetGameArea(); area.Expand(-.5f); Rect exceptArea = GetDestinationArea(); exceptArea.Expand(1); float x = 0; float y = 0; bool free = false; do { free = true; EngineRandom random = World.Instance.Random; x = area.Minimum.X + random.NextFloat() * area.Size.X; y = area.Minimum.Y + random.NextFloat() * area.Size.Y; if (exceptArea.IsContainsPoint(new Vec2(x, y))) { free = false; } Bounds checkBounds = new Bounds( new Vec3(x - .5f, y - .5f, -100), new Vec3(x + .5f, y + .5f, 100)); Map.Instance.GetObjects(checkBounds, delegate(MapObject mapObject) { JigsawPuzzlePiece p = mapObject as JigsawPuzzlePiece; if (p != null) { free = false; } }); } while(!free); piece.Position = new Vec3(x, y, .1f); } piece.PostCreate(); }
public override void Startup(IServiceCollection services) { EngineRandom.SeedRandomNumberGenerator(); services.AddSingleton <IServerInterface, ServerInterface>(); services.AddSingleton <IGameClients, GameClients>(); services.AddSingleton <IEntities, Entities>(); services.AddSingleton <INetworking, Networking>(); services.AddSingleton <IPersistence, Persistence>(); services.AddSingleton <IPlayerPhysics, PlayerPhysics>(); services.AddSingleton <IEntityRegistry, EntityRegistry>(); services.AddSingleton <SentencesSystem>(); services.AddSingleton <MaterialsSystem>(); services.AddSingleton <ISoundSystem, SoundSystem>(); services.AddSingleton <INetworkMessages, NetworkMessages>(); }
/////////////////////////////////////////// protected override void OnAttach() { base.OnAttach(); //disable check for disconnection GameEngineApp.Instance.Client_AllowCheckForDisconnection = false; //register config fields EngineApp.Instance.Config.RegisterClassParameters(GetType()); //create window window = ControlDeclarationManager.Instance.CreateControl( "Gui\\MultiplayerLoginWindow.gui"); Controls.Add(window); MouseCover = true; BackColor = new ColorValue(0, 0, 0, .5f); //initialize controls buttonCreateServer = (EButton)window.Controls["CreateServer"]; buttonCreateServer.Click += CreateServer_Click; buttonConnect = (EButton)window.Controls["Connect"]; buttonConnect.Click += Connect_Click; ((EButton)window.Controls["Exit"]).Click += Exit_Click; //generate user name if (string.IsNullOrEmpty(userName)) { EngineRandom random = new EngineRandom(); userName = "******" + random.Next(1000).ToString("D03"); } editBoxUserName = (EEditBox)window.Controls["UserName"]; editBoxUserName.Text = userName; editBoxUserName.TextChange += editBoxUserName_TextChange; editBoxConnectTo = (EEditBox)window.Controls["ConnectTo"]; editBoxConnectTo.Text = connectToAddress; editBoxConnectTo.TextChange += editBoxConnectTo_TextChange; SetInfo("", false); }
/////////////////////////////////////////// protected override void OnAttach() { base.OnAttach(); //disable check for disconnection GameEngineApp.Instance.Client_AllowCheckForDisconnection = false; //register config fields EngineApp.Instance.Config.RegisterClassParameters( GetType() ); //create window window = ControlDeclarationManager.Instance.CreateControl( "Gui\\MultiplayerLoginWindow.gui" ); Controls.Add( window ); MouseCover = true; BackColor = new ColorValue( 0, 0, 0, .5f ); //initialize controls buttonCreateServer = (EButton)window.Controls[ "CreateServer" ]; buttonCreateServer.Click += CreateServer_Click; buttonConnect = (EButton)window.Controls[ "Connect" ]; buttonConnect.Click += Connect_Click; ( (EButton)window.Controls[ "Exit" ] ).Click += Exit_Click; //generate user name if( string.IsNullOrEmpty( userName ) ) { EngineRandom random = new EngineRandom(); userName = "******" + random.Next( 1000 ).ToString( "D03" ); } editBoxUserName = (EEditBox)window.Controls[ "UserName" ]; editBoxUserName.Text = userName; editBoxUserName.TextChange += editBoxUserName_TextChange; editBoxConnectTo = (EEditBox)window.Controls[ "ConnectTo" ]; editBoxConnectTo.Text = connectToAddress; editBoxConnectTo.TextChange += editBoxConnectTo_TextChange; SetInfo( "", false ); }
public void InitLRU() { for (var i = 0; i < LRU.Count; ++i) { LRU[i] = i; } // randomize array for (var i = 0; i < (LRU.Count * 4); ++i) { var j = EngineRandom.Long(0, LRU.Count - 1); var k = EngineRandom.Long(0, LRU.Count - 1); var temp = LRU[j]; LRU[j] = LRU[k]; LRU[k] = temp; } }
private void DoEffect() { float radius = Type.Radius; float radiusInv = 1.0f / radius; List <MapObject> objects = mapObjectListAllocator.Alloc(); List <DamageItem> damageItems = damageItemListAllocator.Alloc(); //generate objects list Map.Instance.GetObjects(new Sphere(Position, radius), delegate(MapObject obj) { if (Type.IgnoreReasonObject && obj == ReasonObject) { return; } objects.Add(obj); }); //enumerate objects foreach (MapObject obj in objects) { if (obj.IsSetForDeletion) { continue; } if (!obj.Visible) { continue; } PhysicsModel objPhysicsModel = obj.PhysicsModel; float totalObjImpulse = 0; float totalObjDamage = 0; if (Type.Impulse != 0 && objPhysicsModel != null) { float bodyCountInv = 1.0f / objPhysicsModel.Bodies.Length; foreach (Body body in objPhysicsModel.Bodies) { if (body.Static) { continue; } Vec3 dir = body.Position - Position; float distance = dir.Normalize(); if (distance < radius) { float objImpulse = MathFunctions.Cos((distance * radiusInv) * (MathFunctions.PI / 2)) * Type.Impulse * DamageCoefficient; objImpulse *= bodyCountInv; //forcePos for torque Vec3 forcePos; { Vec3 gabarites = body.GetGlobalBounds().GetSize() * .05f; EngineRandom random = World.Instance.Random; forcePos = new Vec3( random.NextFloatCenter() * gabarites.X, random.NextFloatCenter() * gabarites.Y, random.NextFloatCenter() * gabarites.Z); } body.AddForce(ForceType.GlobalAtLocalPos, 0, dir * objImpulse, forcePos); totalObjImpulse += objImpulse; } } } if (Type.Damage != 0) { Dynamic dynamic = obj as Dynamic; if (dynamic != null) { float distance = (dynamic.Position - Position).Length(); if (distance < radius) { float objDamage = MathFunctions.Cos((distance * radiusInv) * (MathFunctions.PI / 2)) * Type.Damage * DamageCoefficient; //add damages to cache and apply after influences (for correct influences work) damageItems.Add(new DamageItem(dynamic, obj.Position, objDamage)); //dynamic.DoDamage( dynamic, obj.Position, objDamage, false ); totalObjDamage += objDamage; } } } //PlayerCharacter contusion if (totalObjDamage > 10 && totalObjImpulse > 500) { PlayerCharacter playerCharacter = obj as PlayerCharacter; if (playerCharacter != null) { playerCharacter.ContusionTimeRemaining += totalObjDamage * .05f; } } //Influence if (Type.InfluenceType != null && (totalObjDamage != 0 || totalObjImpulse != 0)) { Dynamic dynamic = obj as Dynamic; if (dynamic != null) { float coef = 0; if (Type.Damage != 0) { coef = totalObjDamage / Type.Damage; } if (Type.Impulse != 0) { coef = Math.Max(coef, totalObjImpulse / Type.Impulse); } if (coef > 1) { coef = 1; } if (coef != 0) { dynamic.AddInfluence(Type.InfluenceType, Type.InfluenceMaxTime * coef, true); } } } } //Create splash for water CreateWaterPlaneSplash(); //Apply damages foreach (DamageItem item in damageItems) { if (!item.dynamic.IsSetForDeletion) { item.dynamic.DoDamage(this, item.position, null, item.damage, false); } } mapObjectListAllocator.Free(objects); damageItemListAllocator.Free(damageItems); }
/////////////////////////////////////////// protected override void OnAttach() { base.OnAttach(); //disable check for disconnection GameEngineApp.Instance.Client_AllowCheckForDisconnection = false; //register config fields EngineApp.Instance.Config.RegisterClassParameters(GetType()); //create window window = ControlDeclarationManager.Instance.CreateControl( "Gui\\MultiplayerLoginWindow.gui"); Controls.Add(window); //MouseCover = true; //BackColor = new ColorValue( 0, 0, 0, .5f ); //initialize controls buttonConnect = (Button)window.Controls["Connect"]; buttonConnect.Click += Connect_Click; //( (Button)window.Controls[ "Exit" ] ).Click += Exit_Click; //Quit button event handler ((Button)window.Controls["Exit"]).Click += delegate(Button sender) { SetShouldDetach(); //Back(true); }; //positionY = maxout; //generate user name if (string.IsNullOrEmpty(userName)) { EngineRandom random = new EngineRandom(); userName = "******" + random.Next(1000).ToString("D03"); } savePass = (CheckBox)window.Controls["savePass"]; editBoxUserPass = (PasswordBox)window.Controls["password"]; if (!string.IsNullOrEmpty(password)) { editBoxUserPass.Text = password; savePass.Checked = true; } //configure password feature editBoxUserPass.UpdatingTextControl = delegate(EditBox sender, ref string text) { text = new string('*', sender.Text.Length); if (sender.Focused) text += "_"; savePass.Checked = true; }; //editBoxUserPass.TextChange += passwordEditBox_TextChange; savePass.CheckedChange += savePass_CheckedChange; editBoxUserPass.TextChange += editBoxUserPass_TextChange; editBoxUserName = (EditBox)window.Controls["UserName"]; editBoxUserName.Text = userName; editBoxUserName.TextChange += editBoxUserName_TextChange; ((Button)window.Controls["Register"]).Click += Register_Click; SetInfo("", false); }
private static BaseEntity EntDetermineSpawnPoint(BaseEntity pPlayer) { BaseEntity pSpot; // choose a info_player_deathmatch point if (Engine.GameRules.IsCoOp()) { pSpot = EntUtils.FindEntityByClassName(g_pLastSpawn, "info_player_coop"); if (pSpot != null) { return(pSpot); } pSpot = EntUtils.FindEntityByClassName(g_pLastSpawn, "info_player_start"); if (pSpot != null) { return(pSpot); } } else if (Engine.GameRules.IsDeathmatch()) { pSpot = g_pLastSpawn; // Randomize the start spot for (var i = EngineRandom.Long(1, 5); i > 0; i--) { pSpot = EntUtils.FindEntityByClassName(pSpot, "info_player_deathmatch"); } if (pSpot == null) // skip over the null point { pSpot = EntUtils.FindEntityByClassName(pSpot, "info_player_deathmatch"); } var pFirstSpot = pSpot; do { if (pSpot != null) { // check if pSpot is valid if (IsSpawnPointValid(pPlayer, pSpot)) { if (pSpot.Origin == WorldConstants.g_vecZero) { pSpot = EntUtils.FindEntityByClassName(pSpot, "info_player_deathmatch"); continue; } // if so, go to pSpot return(pSpot); } } // increment pSpot pSpot = EntUtils.FindEntityByClassName(pSpot, "info_player_deathmatch"); } while (pSpot != pFirstSpot); // loop if we're not back to the start // we haven't found a place to spawn yet, so kill any guy at the first spawn point and spawn there if (pSpot != null) { for (BaseEntity ent = null; (ent = EntUtils.FindEntityInSphere(ent, pSpot.Origin, 128)) != null;) { // if ent is a client, kill em (unless they are ourselves) if (ent.IsPlayer() && ent != pPlayer) { ent.TakeDamage(World.WorldInstance, World.WorldInstance, 300, DamageTypes.Generic); } } return(pSpot); } } // If startspot is set, (re)spawn there. if (string.IsNullOrEmpty(Engine.Globals.StartSpot)) { pSpot = EntUtils.FindEntityByClassName(null, "info_player_start"); if (pSpot != null) { return(pSpot); } } else { pSpot = EntUtils.FindEntityByTargetName(null, Engine.Globals.StartSpot); if (pSpot != null) { return(pSpot); } } Log.Alert(AlertType.Error, "PutClientInServer: no info_player_start on level"); return(null); }
private void DrawArea_RenderUI(Control sender, GuiRenderer renderer) { Rect rectangle = sender.GetScreenRectangle(); bool clipRectangle = true; ColorValue[] colors = new ColorValue[]{ new ColorValue( 1 ,0, 0 ), new ColorValue( 0, 1, 0 ), new ColorValue( 0, 0, 1 ), new ColorValue( 1, 1, 0 ), new ColorValue( 1, 1, 1 )}; if (clipRectangle) renderer.PushClipRectangle(rectangle); //draw triangles if (GetDrawAreaMode() == DrawAreaModes.Triangles) { float distance = rectangle.GetSize().X / 2; List<GuiRenderer.TriangleVertex> triangles = new List<GuiRenderer.TriangleVertex>(256); Radian angle = -EngineApp.Instance.Time; const int steps = 30; Vec2 lastPosition = Vec2.Zero; for (int step = 0; step < steps + 1; step++) { Vec2 localPos = new Vec2(MathFunctions.Cos(angle), MathFunctions.Sin(angle)) * distance; Vec2 pos = rectangle.GetCenter() + new Vec2(localPos.X, localPos.Y * renderer.AspectRatio); if (step != 0) { ColorValue color = colors[step % colors.Length]; ColorValue color2 = color; color2.Alpha = 0; triangles.Add(new GuiRenderer.TriangleVertex(rectangle.GetCenter(), color)); triangles.Add(new GuiRenderer.TriangleVertex(lastPosition, color2)); triangles.Add(new GuiRenderer.TriangleVertex(pos, color2)); } angle += (MathFunctions.PI * 2) / steps; lastPosition = pos; } renderer.AddTriangles(triangles); } //draw quads if (GetDrawAreaMode() == DrawAreaModes.Quads) { //draw background { Texture texture = TextureManager.Instance.Load("GUI\\Textures\\NeoAxisLogo.png"); renderer.AddQuad(rectangle, new Rect(0, -.3f, 1, 1.4f), texture, new ColorValue(1, 1, 1), true); } //draw bars { float time = EngineApp.Instance.Time; EngineRandom random = new EngineRandom(0); int count = 15; float stepOffset = rectangle.GetSize().X / count; float size = stepOffset * .9f; for (int n = 0; n < count; n++) { float v = MathFunctions.Cos(time * random.NextFloat()); float v2 = (v + 1) / 2; ColorValue color = colors[n % colors.Length]; Rect rect = new Rect( rectangle.Left + stepOffset * n, rectangle.Bottom - rectangle.GetSize().Y * v2, rectangle.Left + stepOffset * n + size, rectangle.Bottom); renderer.AddQuad(rect, color); } } } //draw lines if (GetDrawAreaMode() == DrawAreaModes.Lines) { float maxDistance; { Vec2 s = rectangle.GetSize() / 2; maxDistance = MathFunctions.Sqrt(s.X * s.X + s.Y * s.Y); } int step = 0; float distance = 0; Radian angle = -EngineApp.Instance.Time; Vec2 lastPosition = Vec2.Zero; while (distance < maxDistance) { Vec2 localPos = new Vec2(MathFunctions.Cos(angle), MathFunctions.Sin(angle)) * distance; Vec2 pos = rectangle.GetCenter() + new Vec2(localPos.X, localPos.Y * renderer.AspectRatio); if (step != 0) { ColorValue color = colors[step % colors.Length]; renderer.AddLine(lastPosition, pos, color); } step++; angle += MathFunctions.PI / 10; distance += .001f; lastPosition = pos; } } //draw text if (GetDrawAreaMode() == DrawAreaModes.Text) { string text; //draw text with specified font. text = "Map Editor is a tool to create worlds for your project. The tool is a complex editor to manage " + "objects on the map."; renderer.AddTextWordWrap(drawAreaBigFont, text, rectangle, HorizontalAlign.Left, false, VerticalAlign.Top, 0, new ColorValue(1, 1, 1)); //draw text with word wrap. text = "Deployment Tool is a tool to deploy the final version of your application to specified platforms. " + "This utility is useful to automate the final product's creation."; renderer.AddTextWordWrap(drawAreaSmallFont, text, rectangle, HorizontalAlign.Right, false, VerticalAlign.Bottom, 0, new ColorValue(1, 1, 0)); } if (clipRectangle) renderer.PopClipRectangle(); }
protected virtual void CreateBullet(Mode mode) { Bullet obj = (Bullet)Entities.Instance.Create(mode.typeMode.BulletType, Parent); obj.SourceUnit = GetParentUnitHavingIntellect(); obj.Position = GetFirePosition(mode.typeMode); //Correcting position at a shot in very near object (when the point of a shot inside object). { Vec3 startPos = Position; if (AttachedMapObjectParent != null) { startPos = AttachedMapObjectParent.Position; } Ray ray = new Ray(startPos, obj.Position - startPos); if (ray.Direction != Vec3.Zero) { RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing( ray, (int)ContactGroup.CastOnlyContact); foreach (RayCastResult result in piercingResult) { MapObject mapObject = MapSystemWorld.GetMapObjectByBody(result.Shape.Body); if (mapObject != null) { if (mapObject == this) { continue; } if (mapObject == this.AttachedMapObjectParent) { continue; } } obj.Position = result.Position - ray.Direction * .01f; break; } } } Quat rot = GetFireRotation(mode.typeMode); Radian dispersionAngle = mode.typeMode.DispersionAngle; if (dispersionAngle != 0) { EngineRandom random = World.Instance.Random; Mat3 matrix; matrix = Mat3.FromRotateByX(random.NextFloat() * MathFunctions.PI * 2); matrix *= Mat3.FromRotateByZ(random.NextFloat() * dispersionAngle); rot *= matrix.ToQuat(); } obj.Rotation = rot; obj.PostCreate(); //set damage coefficient float coef = obj.DamageCoefficient; Unit unit = GetParentUnitHavingIntellect(); if (unit != null && unit.BigDamageInfluence != null) { coef *= unit.BigDamageInfluence.Type.Coefficient; } obj.DamageCoefficient = coef; }
/////////////////////////////////////////// protected override void OnAttach() { base.OnAttach(); //disable check for disconnection GameEngineApp.Instance.Client_AllowCheckForDisconnection = false; //register config fields EngineApp.Instance.Config.RegisterClassParameters(GetType()); //create window window = ControlDeclarationManager.Instance.CreateControl( "Gui\\MultiplayerLoginWindow.gui"); Controls.Add(window); //MouseCover = true; //BackColor = new ColorValue( 0, 0, 0, .5f ); //initialize controls buttonConnect = (Button)window.Controls["Connect"]; buttonConnect.Click += Connect_Click; //( (Button)window.Controls[ "Exit" ] ).Click += Exit_Click; //Quit button event handler ((Button)window.Controls["Exit"]).Click += delegate(Button sender) { SetShouldDetach(); //Back(true); }; //positionY = maxout; //generate user name if (string.IsNullOrEmpty(userName)) { EngineRandom random = new EngineRandom(); userName = "******" + random.Next(1000).ToString("D03"); } savePass = (CheckBox)window.Controls["savePass"]; editBoxUserPass = (PasswordBox)window.Controls["password"]; if (!string.IsNullOrEmpty(password)) { editBoxUserPass.Text = password; savePass.Checked = true; } //configure password feature editBoxUserPass.UpdatingTextControl = delegate(EditBox sender, ref string text) { text = new string('*', sender.Text.Length); if (sender.Focused) { text += "_"; } savePass.Checked = true; }; //editBoxUserPass.TextChange += passwordEditBox_TextChange; savePass.CheckedChange += savePass_CheckedChange; editBoxUserPass.TextChange += editBoxUserPass_TextChange; editBoxUserName = (EditBox)window.Controls["UserName"]; editBoxUserName.Text = userName; editBoxUserName.TextChange += editBoxUserName_TextChange; ((Button)window.Controls["Register"]).Click += Register_Click; SetInfo("", false); }
void DrawArea_RenderUI( Control sender, GuiRenderer renderer ) { Rect rectangle = sender.GetScreenRectangle(); bool clipRectangle = true; ColorValue[] colors = new ColorValue[]{ new ColorValue( 1 ,0, 0 ), new ColorValue( 0, 1, 0 ), new ColorValue( 0, 0, 1 ), new ColorValue( 1, 1, 0 ), new ColorValue( 1, 1, 1 )}; if( clipRectangle ) renderer.PushClipRectangle( rectangle ); //draw triangles if( GetDrawAreaMode() == DrawAreaModes.Triangles ) { float distance = rectangle.GetSize().X / 2; List<GuiRenderer.TriangleVertex> triangles = new List<GuiRenderer.TriangleVertex>( 256 ); Radian angle = -EngineApp.Instance.Time; const int steps = 30; Vec2 lastPosition = Vec2.Zero; for( int step = 0; step < steps + 1; step++ ) { Vec2 localPos = new Vec2( MathFunctions.Cos( angle ), MathFunctions.Sin( angle ) ) * distance; Vec2 pos = rectangle.GetCenter() + new Vec2( localPos.X, localPos.Y * renderer.AspectRatio ); if( step != 0 ) { ColorValue color = colors[ step % colors.Length ]; ColorValue color2 = color; color2.Alpha = 0; triangles.Add( new GuiRenderer.TriangleVertex( rectangle.GetCenter(), color ) ); triangles.Add( new GuiRenderer.TriangleVertex( lastPosition, color2 ) ); triangles.Add( new GuiRenderer.TriangleVertex( pos, color2 ) ); } angle += ( MathFunctions.PI * 2 ) / steps; lastPosition = pos; } renderer.AddTriangles( triangles ); } //draw quads if( GetDrawAreaMode() == DrawAreaModes.Quads ) { //draw background { Texture texture = TextureManager.Instance.Load( "Gui\\Various\\Logo.png" ); renderer.AddQuad( rectangle, new Rect( 0, -.3f, 1, 1.4f ), texture, new ColorValue( 1, 1, 1 ), true ); } //draw bars { float time = EngineApp.Instance.Time; EngineRandom random = new EngineRandom( 0 ); int count = 15; float stepOffset = rectangle.GetSize().X / count; float size = stepOffset * .9f; for( int n = 0; n < count; n++ ) { float v = MathFunctions.Cos( time * random.NextFloat() ); float v2 = ( v + 1 ) / 2; ColorValue color = colors[ n % colors.Length ]; Rect rect = new Rect( rectangle.Left + stepOffset * n, rectangle.Bottom - rectangle.GetSize().Y * v2, rectangle.Left + stepOffset * n + size, rectangle.Bottom ); renderer.AddQuad( rect, color ); } } } //draw lines if( GetDrawAreaMode() == DrawAreaModes.Lines ) { float maxDistance; { Vec2 s = rectangle.GetSize() / 2; maxDistance = MathFunctions.Sqrt( s.X * s.X + s.Y * s.Y ); } int step = 0; float distance = 0; Radian angle = -EngineApp.Instance.Time; Vec2 lastPosition = Vec2.Zero; while( distance < maxDistance ) { Vec2 localPos = new Vec2( MathFunctions.Cos( angle ), MathFunctions.Sin( angle ) ) * distance; Vec2 pos = rectangle.GetCenter() + new Vec2( localPos.X, localPos.Y * renderer.AspectRatio ); if( step != 0 ) { ColorValue color = colors[ step % colors.Length ]; renderer.AddLine( lastPosition, pos, color ); } step++; angle += MathFunctions.PI / 10; distance += .001f; lastPosition = pos; } } //draw text if( GetDrawAreaMode() == DrawAreaModes.Text ) { //draw text with specified font. renderer.AddText( drawAreaBigFont, "Big Font Sample", rectangle.LeftTop, HorizontalAlign.Left, VerticalAlign.Top, new ColorValue( 1, 1, 1 ) ); //draw text with word wrap. string text = "Test Test Test.\n\nThe expandable user interface system is a unified system " + "for the creation of end-user controls, menus, dialogues, windows and HUD screens. " + "With the help of this system the end-user exercises control over the application."; renderer.AddTextWordWrap( text, rectangle, HorizontalAlign.Right, false, VerticalAlign.Bottom, 0, new ColorValue( 1, 1, 0 ) ); } if( clipRectangle ) renderer.PopClipRectangle(); }
private void DrawArea_RenderUI(Control sender, GuiRenderer renderer) { Rect rectangle = sender.GetScreenRectangle(); bool clipRectangle = true; ColorValue[] colors = new ColorValue[] { new ColorValue(1, 0, 0), new ColorValue(0, 1, 0), new ColorValue(0, 0, 1), new ColorValue(1, 1, 0), new ColorValue(1, 1, 1) }; if (clipRectangle) { renderer.PushClipRectangle(rectangle); } //draw triangles if (GetDrawAreaMode() == DrawAreaModes.Triangles) { float distance = rectangle.GetSize().X / 2; List <GuiRenderer.TriangleVertex> triangles = new List <GuiRenderer.TriangleVertex>(256); Radian angle = -EngineApp.Instance.Time; const int steps = 30; Vec2 lastPosition = Vec2.Zero; for (int step = 0; step < steps + 1; step++) { Vec2 localPos = new Vec2(MathFunctions.Cos(angle), MathFunctions.Sin(angle)) * distance; Vec2 pos = rectangle.GetCenter() + new Vec2(localPos.X, localPos.Y * renderer.AspectRatio); if (step != 0) { ColorValue color = colors[step % colors.Length]; ColorValue color2 = color; color2.Alpha = 0; triangles.Add(new GuiRenderer.TriangleVertex(rectangle.GetCenter(), color)); triangles.Add(new GuiRenderer.TriangleVertex(lastPosition, color2)); triangles.Add(new GuiRenderer.TriangleVertex(pos, color2)); } angle += (MathFunctions.PI * 2) / steps; lastPosition = pos; } renderer.AddTriangles(triangles); } //draw quads if (GetDrawAreaMode() == DrawAreaModes.Quads) { //draw background { Texture texture = TextureManager.Instance.Load("GUI\\Textures\\NeoAxisLogo.png"); renderer.AddQuad(rectangle, new Rect(0, -.3f, 1, 1.4f), texture, new ColorValue(1, 1, 1), true); } //draw bars { float time = EngineApp.Instance.Time; EngineRandom random = new EngineRandom(0); int count = 15; float stepOffset = rectangle.GetSize().X / count; float size = stepOffset * .9f; for (int n = 0; n < count; n++) { float v = MathFunctions.Cos(time * random.NextFloat()); float v2 = (v + 1) / 2; ColorValue color = colors[n % colors.Length]; Rect rect = new Rect( rectangle.Left + stepOffset * n, rectangle.Bottom - rectangle.GetSize().Y *v2, rectangle.Left + stepOffset * n + size, rectangle.Bottom); renderer.AddQuad(rect, color); } } } //draw lines if (GetDrawAreaMode() == DrawAreaModes.Lines) { float maxDistance; { Vec2 s = rectangle.GetSize() / 2; maxDistance = MathFunctions.Sqrt(s.X * s.X + s.Y * s.Y); } int step = 0; float distance = 0; Radian angle = -EngineApp.Instance.Time; Vec2 lastPosition = Vec2.Zero; while (distance < maxDistance) { Vec2 localPos = new Vec2(MathFunctions.Cos(angle), MathFunctions.Sin(angle)) * distance; Vec2 pos = rectangle.GetCenter() + new Vec2(localPos.X, localPos.Y * renderer.AspectRatio); if (step != 0) { ColorValue color = colors[step % colors.Length]; renderer.AddLine(lastPosition, pos, color); } step++; angle += MathFunctions.PI / 10; distance += .001f; lastPosition = pos; } } //draw text if (GetDrawAreaMode() == DrawAreaModes.Text) { string text; //draw text with specified font. text = "Map Editor is a tool to create worlds for your project. The tool is a complex editor to manage " + "objects on the map."; renderer.AddTextWordWrap(drawAreaBigFont, text, rectangle, HorizontalAlign.Left, false, VerticalAlign.Top, 0, new ColorValue(1, 1, 1)); //draw text with word wrap. text = "Deployment Tool is a tool to deploy the final version of your application to specified platforms. " + "This utility is useful to automate the final product's creation."; renderer.AddTextWordWrap(drawAreaSmallFont, text, rectangle, HorizontalAlign.Right, false, VerticalAlign.Bottom, 0, new ColorValue(1, 1, 0)); } if (clipRectangle) { renderer.PopClipRectangle(); } }
/// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnTick()"/>.</summary> protected override void OnTick() { base.OnTick(); if (force != 0) { foreach (MapObject obj in ObjectsInRegion) { if (obj.IsSetForDeletion) { continue; } //impulse if (impulsePerSecond != 0) { PhysicsModel objPhysicsModel = obj.PhysicsModel; if (objPhysicsModel != null) { foreach (Body body in objPhysicsModel.Bodies) { if (body.Static) { continue; } EngineRandom random = World.Instance.Random; float distanceCoef = GetDistanceCoefficient(body.Position); float randomCoef = 1.0f + random.NextFloatCenter() * .1f; float v = impulsePerSecond * force * distanceCoef * randomCoef * TickDelta; Vec3 point = new Vec3( random.NextFloat() * .1f, random.NextFloat() * .1f, random.NextFloat() * .1f); body.AddForce(ForceType.GlobalAtLocalPos, TickDelta, Rotation * new Vec3(v, 0, 0), point); } } } if (InfluenceType != null || DamagePerSecond != 0) { Dynamic dynamic = obj as Dynamic; if (dynamic != null) { float distanceCoef = GetDistanceCoefficient(obj.Position); if (InfluenceType != null) { dynamic.AddInfluence(InfluenceType, InfluenceTimePerSecond * distanceCoef * TickDelta, true); } if (DamagePerSecond != 0) { dynamic.DoDamage(null, obj.Position, null, DamagePerSecond * distanceCoef * TickDelta, false); } } } } } }
public override void Spawn() { // spread think times SetNextThink(Engine.Globals.Time + EngineRandom.Float(0.0f, 0.5f)); }
private static void CreateEntitiesWhichNotSynchronizedViaNetwork() { //ground { //create materials from the code ShaderBaseMaterial[] materials = new ShaderBaseMaterial[7]; { for (int n = 0; n < materials.Length; n++) { string materialName = HighLevelMaterialManager.Instance.GetUniqueMaterialName( "ExampleOfProceduralMapCreation_Ground"); ShaderBaseMaterial material = (ShaderBaseMaterial)HighLevelMaterialManager.Instance.CreateMaterial( materialName, "ShaderBaseMaterial"); material.Diffuse1Map.Texture = string.Format("Types\\Vegetation\\Trees\\Textures\\Bark{0}A.dds", n + 1); material.NormalMap.Texture = string.Format("Types\\Vegetation\\Trees\\Textures\\Bark{0}A_N.dds", n + 1); material.SpecularColor = new ColorValue(1, 1, 1); material.SpecularMap.Texture = string.Format("Types\\Vegetation\\Trees\\Textures\\Bark{0}A_S.dds", n + 1); material.PostCreate(); materials[n] = material; } } //create objects with collision body EngineRandom random = new EngineRandom(0); for (float y = -35; y < 35; y += 5) { for (float x = -35; x < 35; x += 2.5f) { StaticMesh staticMesh = (StaticMesh)Entities.Instance.Create("StaticMesh", Map.Instance); staticMesh.MeshName = "Base\\Simple Models\\Box.mesh"; ShaderBaseMaterial material = materials[random.Next(0, 6)]; staticMesh.ForceMaterial = material.Name;//"DarkGray"; staticMesh.Position = new Vec3(x, y, -1.0f); staticMesh.Scale = new Vec3(2.5f, 5, 2); staticMesh.CastDynamicShadows = false; staticMesh.PostCreate(); } } } //SkyBox { Entity skyBox = Entities.Instance.Create("SkyBox", Map.Instance); skyBox.PostCreate(); } //Light { Light light = (Light)Entities.Instance.Create("Light", Map.Instance); light.LightType = RenderLightType.Directional; light.SpecularColor = new ColorValue(1, 1, 1); light.Position = new Vec3(0, 0, 10); light.Rotation = new Angles(120, 50, 330).ToQuat(); light.PostCreate(); } }
protected override void CreateBullet(Mode mode) { //only missiles for missilelauncher if (mode.typeMode.BulletType as Missile2Type == null) { return; } Missile2 obj = (Missile2)Entities.Instance.Create(mode.typeMode.BulletType, Parent); obj.SourceUnit = GetParentUnitHavingIntellect(); obj.Position = GetFirePosition(mode.typeMode); //Correcting position at a shot in very near object (when the point of a shot inside object). { Vec3 startPos = Position; if (AttachedMapObjectParent != null) { startPos = AttachedMapObjectParent.Position; } Ray ray = new Ray(startPos, obj.Position - startPos); if (ray.Direction != Vec3.Zero) { RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing( ray, (int)ContactGroup.CastOnlyContact); foreach (RayCastResult result in piercingResult) { MapObject mapObject = MapSystemWorld.GetMapObjectByBody(result.Shape.Body); if (mapObject != null) { if (mapObject == this) { continue; } if (mapObject == this.AttachedMapObjectParent) { continue; } } obj.Position = result.Position - ray.Direction * .01f; break; } } } Quat rot = GetFireRotation(mode.typeMode); Radian dispersionAngle = mode.typeMode.DispersionAngle; if (dispersionAngle != 0) { EngineRandom random = World.Instance.Random; float halfDir; halfDir = random.NextFloatCenter() * dispersionAngle * .5f; rot *= new Quat(new Vec3(0, 0, MathFunctions.Sin(halfDir)), MathFunctions.Cos(halfDir)); halfDir = random.NextFloatCenter() * dispersionAngle * .5f; rot *= new Quat(new Vec3(0, MathFunctions.Sin(halfDir), 0), MathFunctions.Cos(halfDir)); halfDir = random.NextFloatCenter() * dispersionAngle * .5f; rot *= new Quat(new Vec3(MathFunctions.Sin(halfDir), 0, 0), MathFunctions.Cos(halfDir)); } obj.Rotation = rot; obj.PostCreate(); //set damage coefficient float coef = obj.DamageCoefficient; Unit unit = GetParentUnitHavingIntellect(); if (unit != null && unit.BigDamageInfluence != null) { coef *= unit.BigDamageInfluence.Type.Coefficient; } obj.DamageCoefficient = coef; foreach (MapObjectAttachedObject attachedObject in AttachedObjects) { MapObjectAttachedMesh attachedMesh = attachedObject as MapObjectAttachedMesh; if (attachedMesh == null) { continue; } if (attachedMesh.Alias.Equals("Missile")) { if (!attachedMesh.Visible) { continue; } else { attachedMesh.Visible = false; break; } } } }