void RecreateBallIfNeed() { const float minHeight = -50; if (ball != null && ball.IsSetForDeletion) { ball = null; } if (ball != null && ball.Position.Z < minHeight) { ball.SetForDeletion(true); return; } if (ball == null) { ball = (MapObject)Entities.Instance.Create("BallGame_Ball", Map.Instance); SpawnPoint spawnPoint = FindSpawnPoint(); if (spawnPoint != null) { ball.Position = spawnPoint.Position; } ball.PostCreate(); } }
static void ServerOrSingle_CreateEntities() { CreateEntitiesWhichNotSynchronizedViaNetwork(); //SpawnPoint (server or single only) { SpawnPoint spawnPoint = (SpawnPoint)Entities.Instance.Create( "SpawnPoint", Map.Instance); spawnPoint.Position = new Vec3(-20, 0, 1); spawnPoint.PostCreate(); } //Boxes (synchronized via network) { for (int n = 0; n < 10; n++) { Vec3 position = new Vec3( World.Instance.Random.NextFloatCenter() * 10, World.Instance.Random.NextFloatCenter() * 10, 40 + (float)n * 1.1f); MapObject mapObject = (MapObject)Entities.Instance.Create("Box", Map.Instance); mapObject.Position = position; mapObject.Rotation = new Angles( World.Instance.Random.NextFloat() * 360, World.Instance.Random.NextFloat() * 360, World.Instance.Random.NextFloat() * 360).ToQuat(); mapObject.PostCreate(); } } }
static void ServerOrSingle_CreateEntities() { CreateEntitiesWhichNotSynchronizedViaNetwork(); //SpawnPoint (server or single only) { SpawnPoint obj = (SpawnPoint)Entities.Instance.Create("SpawnPoint", Map.Instance); obj.Position = new Vec3(-29, 0, 1); obj.PostCreate(); } //weapon if (EntityTypes.Instance.GetByName("SubmachineGunItem") != null) { MapObject obj = (MapObject)Entities.Instance.Create("SubmachineGunItem", Map.Instance); obj.Position = new Vec3(-26, 0, .3f); obj.PostCreate(); } //Boxes (synchronized via network) for (float y = -20; y <= 20; y += 5) { for (float x = -20; x <= 20; x += 5) { for (float z = .5f; z < 10; z += 1) { MapObject mapObject = (MapObject)Entities.Instance.Create("Box", Map.Instance); mapObject.Position = new Vec3(x, y, z); mapObject.Rotation = new Angles(0, 0, World.Instance.Random.NextFloat() * 360).ToQuat(); mapObject.PostCreate(); } } } }
bool CreateEnemy() { //Get need enemy type string typeName = GetCreateEnemyTypeName(); //Get point MapObject point = null; int safeCounter = 1; while (point == null) { point = enemySpawnPoints[World.Instance.Random.Next(enemySpawnPoints.Count)]; safeCounter++; if (safeCounter > 1000) { break; } } if (point == null) { return(false); } //check for free position bool freePoint; { Bounds volume = new Bounds(point.Position); volume.Expand(new Vec3(2, 2, 2)); Body[] bodies = PhysicsWorld.Instance.VolumeCast(volume, (int)ContactGroup.CastOnlyDynamic); freePoint = bodies.Length == 0; } if (!freePoint) { return(false); } //Create object MapObject newObj = (MapObject)Entities.Instance.Create(typeName, Map.Instance); newObj.Position = point.Position + new Vec3(0, 0, 1); if (typeName == "Robot") { newObj.Position += new Vec3(0, 0, 1); } newObj.PostCreate(); if (newObj is Unit) { ((Unit)newObj).ViewRadius = 300; } newObj.Destroying += EnemyUnitDestroying; newObj.Tick += EnemyUnitTick; return(true); }
private void Fire() { Vec3 pos; Quat rot; float speed; GetFireParameters(out pos, out rot, out speed); //create entity MapObject mapObject = (MapObject)Entities.Instance.Create("CatapultGame_CatapultBullet", Map.Instance); mapObject.Position = pos; mapObject.Rotation = rot; mapObject.PostCreate(); //apply force Body body = mapObject.PhysicsModel.Bodies[0]; body.LinearVelocity = mapObject.Rotation.GetForward() * speed; //Vec3 vector = mapObject.Rotation.GetForward() * power * body.Mass; //body.AddForce( ForceType.GlobalAtLocalPos, 0, vector, Vec3.Zero ); }