public static void Initialize() {
		LevelManager = new LevelManager();
		PlayerManager = new PlayerManager();
		EnemyManager = new EnemyManager();
 		ResourceCache = (new GameObject()).AddComponent<ResourceCache>();
		EntityTemplateManager = new EntityTemplateManager();
		SoundManager = new SoundManager();
		StatsManager = new StatsManager();
	}
Exemplo n.º 2
0
        private static void MakeExplosions()
        {
            EntityTemplateManager.AddTemplate(
                new EntityTemplate(
                    "Explosion",
                    new Placement()
            {
                Layer   = 4,
                Visible = true,
            },
                    new Aspect()
            {
                ModelNameId = "Explosion".CRC32Hash(),
                Tint        = Color.White,
                Size        = new Vector2(1.7f),
            },
                    new Explosion()
            {
                Countdown            = GameConstants.ExplosionDuration,
                PropagationCountDown = GameConstants.PropagationTime,
            },
                    new FrameAnimation()
            {
                FrameRate = GameConstants.ExplosionFrameRate,
            }
                    )
                );

            EntityTemplateManager.AddTemplate(
                new EntityTemplate(
                    "ExplosionBlue",
                    new Placement()
            {
                Layer   = 4,
                Visible = true,
            },
                    new Aspect()
            {
                ModelNameId = "ExplosionBlue".CRC32Hash(),
                Tint        = Color.White,
                Size        = new Vector2(1.7f),
            },
                    new Explosion()
            {
                Countdown            = GameConstants.ExplosionDuration,
                PropagationCountDown = GameConstants.PropagationTime,
            },
                    new FrameAnimation()
            {
                FrameRate = GameConstants.ExplosionFrameRate,
            }
                    )
                );
        }
Exemplo n.º 3
0
 private static void MakeCharacter(string name, Color tint, int number, InputMap inputMap)
 {
     EntityTemplateManager.AddTemplate(
         new EntityTemplate(
             name,
             new Placement()
     {
         Layer   = 3,
         Visible = true,
     },
             new Aspect()
     {
         ModelNameId = "Man".CRC32Hash(),
         Tint        = tint,
         Size        = new Vector2(1.1f),
     },
             new Physics()
     {
         BoundingVolumeType = BoundingVolumeType.Circle,
         IsDynamic          = true,
         Size = 0.95f,
         CollisionCategories = CollisionCategory.AllPlayers,
         CollidesWidth       = CollisionCategory.Bricks | CollisionCategory.Bombs,
     },
             inputMap,
             new ExplosionImpact()
     {
         Barrier           = ExplosionBarrier.None,
         ShouldSendMessage = true,
     },
             new InputHandlers("DropBomb", "MovePlayer")
     {
     },
             // TODO: Update with a better handler that does animations, etc...
             new MessageHandler(new MessageAndHandler(Messages.InExplosion, "KillPlayer".CRC32Hash()),
                                new MessageAndHandler(Messages.DirectKill, "KillPlayer".CRC32Hash()))
     {
     },
             new PlayerInfo()
     {
         MaxSpeed = GameConstants.PlayerDefaultSpeed,
         PermittedSimultaneousBombs = 1,
         BombState = new BombState()
         {
             PropagationDirection = PropagationDirection.NESW,
             Range = 1,
         },
         PlayerNumber = number,
     }
             )
         );
 }
Exemplo n.º 4
0
 private static void MakeGame()
 {
     EntityTemplateManager.AddTemplate(
         new EntityTemplate(
             "MainGame",
             new GameState()
     {
         TimeRemaining = GameConstants.GameLength
     },
             new InputMap(
                 new KeyValuePair <Keys, int>[]
     {
         new KeyValuePair <Keys, int>(Keys.Space, InputActions.RestartGame),
     }
                 )
     {
     }
             // We'll add the RestartGame action handler dynamically after
             )
         );
 }
Exemplo n.º 5
0
        public void Prospect(EntityGraph entityGraph, TextArticle article)
        {
            AssertUtils.AssertParamNotNull(article, "article");

            _CurrentArticle = article;

            IEntityList <IEntity> entities = ConvertEachTBlockToEntity(article);

            entityGraph.ConditionalRuleRelationships.OnAdd += new Knowledge.Prospector.Common.SetEvent <Knowledge.Prospector.Data.Relationships.ConditionalRuleRelationship>(ConditionalRuleRelationships_OnAdd);

            //Buiding Graph
            ILanguage           language           = LanguageManager.GetInstance().DeterminateLanguage(article);
            IEntityGraphBuilder entityGraphBuilder = new EntityGraphBuilder(entityGraph, entities);

            //Applying rules
            EntityTemplateManager.GetInstance().ApplyTemplates(entityGraphBuilder, language);
            //	EntityGraphBuilderRules.UseEntitiesRule(entityGraphBuilder);
            //	EntityGraphBuilderRules.UseConvertRelationshipEntityToRelationshipRule(entityGraphBuilder);

            _CurrentArticle = null;
            entityGraph.ConditionalRuleRelationships.OnAdd -= ConditionalRuleRelationships_OnAdd;
        }
Exemplo n.º 6
0
        private static void MakePowerUp(PowerUpType type, string name, string model, string sound, Color tint)
        {
            ScriptContainer scriptContainer = new ScriptContainer("Wiggle".CRC32Hash())
            {
            };

            Scripts.Scripts.Wiggle_Init(scriptContainer, period: GameConstants.PowerUpWigglePeriod, extent: GameConstants.PowerUpWiggleExtent);

            EntityTemplateManager.AddTemplate(
                new EntityTemplate(
                    name,
                    new Placement()
            {
                Layer   = 2,
                Visible = true,
            },
                    new Aspect()
            {
                ModelNameId = model.CRC32Hash(),
                Tint        = tint,
                Size        = new Vector2(1.12f),
            },
                    new PowerUp()
            {
                Type    = type,
                SoundId = sound.CRC32Hash()
            },
                    new ExplosionImpact()
            {
                Barrier           = ExplosionBarrier.None,
                ShouldSendMessage = true,
            },
                    scriptContainer
                    )
                );
        }
Exemplo n.º 7
0
        private void PropagateExplosions(List <int> templateIds, List <Explosion> propagateList, List <Placement> propagateListPlacement)
        {
            for (int explosionIndex = 0; explosionIndex < propagateList.Count; explosionIndex++)
            {
                Explosion explosion       = propagateList[explosionIndex];
                Placement placement       = propagateListPlacement[explosionIndex];
                Vector3   currentPosition = placement.Position;

                // Consider all directions
                for (int considerIndex = 0; considerIndex < propagationOffsets.Length; considerIndex++)
                {
                    PropagationDirection consideredDirection = (PropagationDirection)(0x1 << considerIndex);
                    if ((explosion.State.PropagationDirection & consideredDirection) == consideredDirection)
                    {
                        Point   offset      = propagationOffsets[considerIndex];
                        Vector3 newPosition = new Vector3(currentPosition.X + offset.X, currentPosition.Y + offset.Y, 0f);

                        // We need to check that there aren't any hard barriers here. Explosions shouldn't go there (unless we have hard pass-through)
                        ExplosionBarrier barrier      = GetBarrierAtLocation(newPosition.ToInteger());
                        bool             shouldGoHere = (barrier != ExplosionBarrier.Hard) || explosion.State.IsHardPassThrough;
                        if (shouldGoHere)
                        {
                            // When creating the new wexplosion, use the same template as the previous.
                            Entity    newEntity    = EntityManager.AllocateForGeneratedContent(EntityTemplateManager.GetTemplateById(templateIds[explosionIndex]), Universe.TopLevelGroupUniqueIdBase);
                            Explosion newExplosion = (Explosion)EntityManager.GetComponent(newEntity, ComponentTypeIds.Explosion);
                            newExplosion.State = explosion.State;
                            newExplosion.State.Range--; // Reduce the range of course...
                            // If we explode into a soft block, we don't propagate (unless we're passthrough)
                            if (!ShouldExplosionPropagateThroughBarrier(barrier, explosion))
                            {
                                newExplosion.State.Range = 0;
                            }
                            newExplosion.State.PropagationDirection = inheritedPropagationDirections[considerIndex];

                            // Assign its position
                            Placement newPlacement = (Placement)EntityManager.GetComponent(newEntity, ComponentTypeIds.Placement);
                            newPlacement.Position         = newPosition;
                            newPlacement.OrientationAngle = (float)(random.NextDouble() * 360.0);
                        }
                    }
                }
                explosion.State.PropagationDirection = PropagationDirection.None; // Mark this explosion so it doesn't propagate anymore!
            }
        }
Exemplo n.º 8
0
        private static void MakeBricks()
        {
            // Hard blocks are permanent.
            EntityTemplateManager.AddTemplate(
                new EntityTemplate(
                    "HardBlock",
                    new Placement()
            {
                Layer   = 1,
                Visible = true,
            },
                    new Aspect()
            {
                ModelNameId = "Brick".CRC32Hash(),
                Tint        = new Color(196, 196, 196, 255),
                Size        = new Vector2(1.12f),
            },
                    new ExplosionImpact()
            {
                Barrier = ExplosionBarrier.Hard,
            },
                    new Physics()
            {
                BoundingVolumeType = BoundingVolumeType.Box,
                IsDynamic          = false,
                Size = 1f,
                CollisionCategories = CollisionCategory.Bricks,
                CollidesWidth       = CollisionCategory.AllPlayers,
            }
                    )
                );

            // Soft blocks disintegrate when hit by an explosion.
            EntityTemplateManager.AddTemplate(
                new EntityTemplate(
                    "SoftBlock",
                    new Placement()
            {
                Layer   = 1,
                Visible = true,
            },
                    new Aspect()
            {
                ModelNameId = "SoftBrick".CRC32Hash(),
                Tint        = new Color(128, 128, 128, 255),
                Size        = new Vector2(1.12f),
            },
                    new ExplosionImpact()
            {
                Barrier           = ExplosionBarrier.Soft,
                ShouldSendMessage = true,
            },
                    new Physics()
            {
                BoundingVolumeType = BoundingVolumeType.Box,
                IsDynamic          = false,
                Size = 1f,
                CollisionCategories = CollisionCategory.Bricks,
                CollidesWidth       = CollisionCategory.AllPlayers,
            },
                    new MessageHandler(
                        new MessageAndHandler(Messages.HitByInitialExplosion, "DestroyOnExplosionAndRevealPowerUp".CRC32Hash())
                        )
            {
            }
                    )
                );

            // Death blocks fall from the sky at the end.
            EntityTemplateManager.AddTemplate(
                new EntityTemplate(
                    "DeathBlock",
                    new Placement()
            {
                Layer   = 5,
                Visible = true,
            },
                    new Aspect()
            {
                ModelNameId = "EndBrick".CRC32Hash(),
                Tint        = new Color(196, 196, 196, 255),
                Size        = new Vector2(1.12f),
            },
                    new ExplosionImpact()
            {
                Barrier = ExplosionBarrier.Hard,
            },
                    new Physics()
            {
                BoundingVolumeType = BoundingVolumeType.Box,
                IsDynamic          = false,
                Size = 1f,
                CollisionCategories = CollisionCategory.Bricks,
                CollidesWidth       = CollisionCategory.AllPlayers,
            }
                    )
                );
        }
Exemplo n.º 9
0
        public void BuildKnowledges()
        {
            #region UI
            this.Cursor       = Cursors.WaitCursor;
            StatusLabel1.Text = Messages.InitializingDictionaries;
            #endregion

            if (!IsInited)
            {
                //Need to implement IsInited in new option handlers!
                ShortcutManager.Instance.Init(ConfigurationManager.GetSection("shortcutManager"));
                ClauseHolderManager.Instance.Init(ConfigurationManager.GetSection("clauseHolderManager"));
                WordHolderManager.Instance.Init(ConfigurationManager.GetSection("wordHolderManager"));
                EntityTemplateManager.GetInstance().Init(ConfigurationManager.GetSection("entityTemplateManager"));

                //Init dictionaries
                if (!DictionaryManager.GetInstance().IsInited)
                {
                    DictionaryManager.GetInstance().Init((DictionaryManagerOptions)ConfigurationManager.GetSection("dictionaryManager"));
                }
                IsInited = true;
            }

            #region UI
            DateTime startDT = DateTime.Now;
            #endregion

            //Reading file
            #region UI
            StatusLabel1.Text = Messages.ReadingSource;
            #endregion

            Provider <IDocumentProvider> documentProviderProvider = _DocumentProviderConfig[cbDocumentProviderProvider.Text];
            IDocumentProvider            documentProvider         = documentProviderProvider.CreateProvidedClassInstance();
            documentProvider.Init(txtDocumentsProviderSettings.Text);

            //Graph
            EntityGraph entityGraph;

            if (cbLoadFromDump.Checked)
            {
                try
                {
                    entityGraph = EntityGraph.LoadDump(txtLoadFromDumpFileName.Text);
                }
                catch
                {
                    if (DialogResult.OK == MessageBox.Show("Ignore?", "Cannot load dump", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                    {
                        entityGraph = new EntityGraph();
                    }
                    else
                    {
                        return;
                    }
                }
            }
            else
            {
                entityGraph = new EntityGraph();
            }

            foreach (IDocument document in documentProvider)
            {
                foreach (IArticle article in document)
                {
                    //Prospecting
                    #region UI
                    StatusLabel1.Text = Messages.Translating;
                    #endregion
                    IProspector prospector = ProspectorManager.Instance.GetProspector(article);
                    prospector.Prospect(entityGraph, article);
                }

                document.Close();
            }
            documentProvider.Close();

            //Optimizing the graph
            #region UI
            StatusLabel1.Text = Messages.OptimizingGraph;
            #endregion
            EntityGraphOptimizer entityGraphOptimizer = new EntityGraphOptimizer(entityGraph);
            entityGraphOptimizer.OptimizeSubclassRelationship();
            entityGraphOptimizer.OptimizePropertyRelationships();

            //Saving Graph to file
            #region UI
            StatusLabel1.Text = Messages.SavingGraph;
            #endregion

            Provider <IOntology> outputOntologyProvider = _OnologyConfig[cbOutputOntologyProvider.Text];
            IOntology            outputOntology         = outputOntologyProvider.CreateProvidedClassInstance();
            outputOntology.SaveGraph(entityGraph, txtOutputFileName.Text);

            if (cbAddToDump.Checked)
            {
                entityGraph.Dump(txtAddToDumpFileName.Text);
            }

            #region UI
            DateTime stopDT = DateTime.Now;
            TimeSpan ts     = stopDT - startDT;
            StatusLabel1.Text          = string.Format(Messages.BuildingCompliteFormat, ts.TotalMilliseconds);
            StatusProgressBar1.Visible = false;
            this.Cursor = Cursors.Default;
            MessageBox.Show(string.Format("Done by {0} milliseconds", ts.TotalMilliseconds), "Knowledge Prospector", MessageBoxButtons.OK, MessageBoxIcon.Information);
            #endregion

            GC.Collect();
        }
Exemplo n.º 10
0
        private static void MakeBombs()
        {
            ScriptContainer scriptContainer1 = new ScriptContainer("Pulsate".CRC32Hash())
            {
            };

            Scripts.Scripts.Pulsate_Init(scriptContainer1, period: GameConstants.PulsationPeriod);

            EntityTemplateManager.AddTemplate(
                new EntityTemplate(
                    "BasicBomb",
                    new Placement()
            {
                Layer   = 2,
                Visible = true,
            },
                    new Aspect()
            {
                ModelNameId = "Bomb".CRC32Hash(),                    // Possibly Over-ridden when we create the bomb.
                Tint        = Color.White,
                Size        = new Vector2(1.12f),
            },
                    new ExplosionImpact()
            {
                Barrier           = ExplosionBarrier.None,
                ShouldSendMessage = true,
            },
                    new MessageHandler(
                        new MessageAndHandler(Messages.HitByInitialExplosion, "TriggerOnExplosion".CRC32Hash())
                        )
            {
            },
                    new Bomb()
            {
                Countdown = GameConstants.BombSecondsToExplode,
                // Other things are filled in when we create the bomb.
            },
                    scriptContainer1,
                    new Physics()
            {
                IsSensor           = true,
                BoundingVolumeType = BoundingVolumeType.Box,
                Size                = 1f,
                IsDynamic           = false, // REVIEW: We'll need to modify this in the case of throwing bombs.
                CollisionCategories = CollisionCategory.Bombs,
                CollidesWidth       = CollisionCategory.AllPlayers,
            }
                    )
                );

            // Land mines are different enough that we'll use a different prefab
            ScriptContainer scriptContainer2 = new ScriptContainer("LandMineRiseFall".CRC32Hash())
            {
            };

            Scripts.Scripts.LandMineRiseFall_Init(scriptContainer2, GameConstants.LandMineFuseTime);

            EntityTemplateManager.AddTemplate(
                new EntityTemplate(
                    "LandMineBomb",
                    new Placement()
            {
                Layer   = 2,
                Visible = true,
            },
                    new Aspect()
            {
                ModelNameId = "LandMine".CRC32Hash(),                    // Possibly Over-ridden when we create the bomb.
                Tint        = new Color(196, 196, 196, 255),
                Size        = new Vector2(1.12f),
            },
                    new ExplosionImpact()
            {
                Barrier           = ExplosionBarrier.None,
                ShouldSendMessage = true,
            },
                    new MessageHandler(
                        new MessageAndHandler(Messages.HitByInitialExplosion, "TriggerOnExplosion".CRC32Hash())
                        )
            {
            },
                    new Bomb()
            {
                Countdown = GameConstants.BombSecondsToExplode,
                // Other things are filled in when we create the bomb.
            },
                    scriptContainer2
                    // No physics for land mines, since we can walk over them.
                    )
                );
        }