Example #1
0
        private void GameLoop(object sender, EventArgs e)
        {
            HighScore += ScoreForTick;
            if (Enemies.Any(enemy => CollisionDetector.AreCollided(Batwing, enemy)))
            {
                timer.Stop();
                renderer.ShowEndGameScreen(HighScore);
                return;
            }

            renderer.Clear();
            renderer.Draw(Batwing);

            if (rand.Next(100) < SpawnEnemyChange)
            {
                var enemy = enemiesFactory.Get(renderer.ScreenWidth, rand.Next(renderer.ScreenHeight));
                Enemies.Add(enemy);
                GameObjects.Add(enemy);
            }

            KillEnemiesIfColliding();

            HighScore += Enemies.Count(enemy => !enemy.IsAlive) * ScoreForKill;
            RemoveNotAliveGameObjects();
            UpdateObjectsPositions();
            DrawGameObjects();
        }
Example #2
0
 /// <summary>
 /// Add an object to the room
 /// </summary>
 /// <param name="gameObject">The object to add</param>
 public void Add(GameObject gameObject)
 {
     if (gameObject != null)
     {
         GameObjects.Add(gameObject);
     }
 }
Example #3
0
        protected void AddRink()
        {
            if (GameObjects.Count(x => x.Model.IsGameWorld) > 0)
            {
                return;
            }

            GameObject _rink = new GameObject();

            _rink.ApplyPhysics      = false;
            _rink.Model.ModelFile   = "rink.3ds";
            _rink.Scale             = new Vector3D(30, 30, 30);
            _rink.Position          = new Vector3D(15, 50, -1);
            _rink.Model.IsGameWorld = true;

            ModelMaterial ice = new ModelMaterial();

            ice.TextureFile   = "rink.3ds.png";
            ice.MeshIndex     = 0;
            ice.SpecularPower = 15000;
            ice.SpecularColor = Color.FromRgb(255, 255, 255);

            ModelMaterial glass = new ModelMaterial();

            glass.Opacity   = .12;
            glass.MeshIndex = 2;

            _rink.Model.Materials.Add(glass);
            _rink.Model.Materials.Add(ice);

            GameObjects.Add(_rink);
        }
Example #4
0
        public static void Main()
        {
            var rng = new Random();

            for (int i = 0; i < 1; i++)
            {
                GameObjects.Add(new Andrzej(new Vector2(rng.Next(1, 49), rng.Next(1, 49)), '%', Color4.Red));
            }

            while ((GameWindow.Window.GetKey() != Key.Escape) && GameWindow.Window.WindowUpdate())
            {
                Map.PrintMap();

                Player.Draw();
                KeyboardMovement();

                foreach (var gameObject in GameObjects)
                {
                    gameObject.Draw();
                    if (Player.DidMove)
                    {
                        (gameObject as IMovable)?.Move(Player);
                    }
                }

                GameWindow.Window.Write(50, 50, Player.LivingComponent.Health.ToString(), Color4.Crimson);

                Player.DidMove = false;
            }
        }
Example #5
0
        /// <summary>
        /// When <see cref="AIMSteeringBehaviour.PrepareEvaluation"/> is called, this method is used in order to
        /// transfer the data from <see cref="Target"/> or <see cref="TargetPosition"/> to <see
        /// cref="AIMPerceptBehaviour{T}.GameObjects"/>.
        /// </summary>
        public override void PrepareEvaluation()
        {
            if (FilteredEnvironments.Count != 0)
            {
                FilteredEnvironments.Clear();
            }

            if (GameObjects.Count == 1)
            {
                GameObjects[0] = Target;
            }
            else
            {
                GameObjects.Clear();
                GameObjects.Add(Target);
            }

            base.PrepareEvaluation();

            if (Target == null)
            {
                PerceptBehaviour.Percepts[0].Position     = TargetPosition;
                PerceptBehaviour.Percepts[0].Active       = true;
                PerceptBehaviour.Percepts[0].Significance = 1f;
            }
        }
Example #6
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            Globals.Graphics.LoadAllGraphics(this.Content);

            Director dir = new Director(new BaseBuilder());

            gameObjects.Add(dir.Construct(new Vector2(20)));

            dir = new Director(new EnemyBaseBuilder());
            gameObjects.Add(dir.Construct(new Vector2(1350, 20)));

            dir = new Director(new GoldMineBuilder());
            gameObjects.Add(dir.Construct(new Vector2(20, 370)));

            dir = new Director(new MinerBuilder());
            gameObjects.Add(dir.Construct(new Vector2(20, 150)));


            dir = new Director(new InfoBuilder());
            GameObjects.Add(dir.Construct(Vector2.Zero));

            foreach (GameObject obj in gameObjects)
            {
                obj.LoadContent(this.Content);
            }
        }
Example #7
0
 public void Explosion(int x, int y)
 {
     for (int i = 0; i < Globals.Randomizer.Next(10, 15); i++)
     {
         GameObjects.Add(new Piece(new Vector2(Tiles[x][y].Position.X + Globals.Randomizer.Next(-20, 20), Tiles[x][y].Position.Y + Globals.Randomizer.Next(-20, 20)), Tiles[x][y].Texture, 60, 1));
     }
 }
Example #8
0
        public static void Update()
        {
            changeSceneTimer--;
            if (changeSceneTimer <= 0)
            {
                CurrentScene = changeTo;
            }

            // Stars
            if (Globals.Randomizer.Next(0, 101) < Options.StarChance)
            {
                GameObjects.Add(new Star(new Vector2(-5, Globals.Randomizer.Next(5, Globals.ScreenSize.Y * 2 + 50))));
            }

            foreach (GameObject gameObject in GameObjects)
            {
                gameObject.Update();
            }

            for (int i = GameObjects.Count - 1; i >= 0; i--)
            {
                if (GameObjects[i].Dead)
                {
                    GameObjects.RemoveAt(i);
                }
            }
        }
        public GameField(int width, int height)
        {
            Width  = width;
            Height = height;
            Tiles  = new TerrainTile[width, height];
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    GameObjects.Add(
                        Tiles[x, y] =
                            new TerrainTile(new Point(x * CellSize, y * CellSize), GetTypeForCoords(x, y)));
                }
            }
            GameObjects.Add(
                Player = new Player(this, new CellLocation(width / 2, height / 2), Facing.East));

            for (var c = 0; c < 10;)
            {
                var x = Random.Next(Width - 1);
                var y = Random.Next(Height - 1);
                if (!Tiles[x, y].IsPassable)
                {
                    continue;
                }
                c++;
                GameObjects.Add(new Tank(this, new CellLocation(x, y), (Facing)Random.Next(4),
                                         Random.NextDouble() * 4 + 1));
            }
        }
Example #10
0
 public BasicGameLoop(uint width, uint height, string windowTitle, float targetFps) : base(width, height, windowTitle, targetFps)
 {
     text            = new TextObject("test object", "Hello, world!", "raleway.ttf", 25);
     text.Position   = new Vector2f(50, 50);
     Window.Resized += Window_Resized;
     GameObjects.Add(text);
 }
Example #11
0
        //-------------------------------------------------------------------------------------
        // Game functions


        /// <summary>
        /// Reset the game to its initial state
        /// </summary>
        private void ResetGame()
        {
            string rockTextureName;

            // Remove any existing objects
            GameObjects.Clear();

            // Add some stars
            for (int i = 0; i < 50; i++)
            {
                GameObjects.Add(new StarObject(this, Textures["Star"]));
            }

            // Add some space rocks
            for (int i = 0; i < 5; i++)
            {
                rockTextureName = "Rock" + GameHelper.RandomNext(1, 4).ToString();
                GameObjects.Add(new RockObject(this, Textures[rockTextureName], 2, 0.5f, 2.0f));
            }

            // Add the player ship
            _playerShip = new SpaceshipObject(this, Textures["Spaceship"], new Vector2(GraphicsDevice.Viewport.Bounds.Width / 2, GraphicsDevice.Viewport.Bounds.Height / 2));
            GameObjects.Add(_playerShip);

            // Add a benchmark object
            //GameObjects.Add(new BenchmarkObject(this, Fonts["Miramonte"], new Vector2(0, 40), Color.White));

            // Look for pinch and drag textures
            TouchPanel.EnabledGestures = GestureType.Pinch;
        }
Example #12
0
        public override void RegisterEvents()
        {
            CampaignEvents.OnSessionLaunchedEvent.AddNonSerializedListener(this, OnSessionLaunched);
            CampaignEvents.DailyTickEvent.AddNonSerializedListener(this, OnDailyTick);
            CampaignEvents.TickEvent.AddNonSerializedListener(this, OnTick);

            CampaignEvents.KingdomCreatedEvent.AddNonSerializedListener(this, kingdom =>
            {
                GameObjects.Add(new GameObject
                {
                    GameObjectType = GameObjectType.Kingdom,
                    StringId       = kingdom.StringId
                });
            });

            CampaignEvents.KingdomDestroyedEvent.AddNonSerializedListener(this, kingdom =>
            {
                GameObjects.RemoveAll(g => g.GameObjectType == GameObjectType.Kingdom && g.StringId == kingdom.StringId);
                KingdomHelper.RemoveKingdom(kingdom);
            });

            CampaignEvents.OnClanDestroyedEvent.AddNonSerializedListener(this, clan =>
            {
                GameObjects.RemoveAll(g => g.GameObjectType == GameObjectType.Clan && g.StringId == clan.StringId);
            });
        }
Example #13
0
        /// <summary>
        /// Reset the game to its default state
        /// </summary>
        private void ResetGame()
        {
            BiplaneObject biplane;
            CloudObject   cloud;

            // Add the biplane
            biplane            = new BiplaneObject(this, Textures["Biplane"]);
            biplane.Position   = new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);
            biplane.LayerDepth = 0.5f;
            GameObjects.Add(biplane);

            // Add some clouds
            for (int i = 1; i < 15; i++)
            {
                cloud            = new CloudObject(this, Textures["Cloud"]);
                cloud.Position   = new Vector2(GameHelper.RandomNext(GraphicsDevice.Viewport.Width), GameHelper.RandomNext(GraphicsDevice.Viewport.Height));
                cloud.LayerDepth = (GameHelper.RandomNext(1.0f));
                cloud.Scale      = new Vector2(2, 1) * (1.2f - cloud.LayerDepth);
                GameObjects.Add(cloud);
            }

            // Reset the player data
            Lives = 3;
            Score = 0;
        }
        private void ResetGame()
        {
            // Create a single text object
            GameObjects.Clear();

            GameObjects.Add(new TextObject(this, Fonts["Kootenay"], new Vector2(20, 100), "No name entered, click or tap the screen..."));
        }
 private void CreatePlanet(PlanetCreationRequest request)
 {
     lock (GameObjectsLock)
     {
         var item = new Planet(Bus);
         GameObjects.Add(item);
         for (int x = 0; x < request.PlanetSize; ++x)
         {
             for (int y = 0; y < request.PlanetSize; ++y)
             {
                 for (int z = 0; z < request.PlanetSize; ++z)
                 {
                     if ((Math.Pow(x - (request.PlanetSize - 1) / 2.0, 2) + Math.Pow(y - (request.PlanetSize - 1) / 2.0, 2) + Math.Pow(z - (request.PlanetSize - 1) / 2.0, 2) - Math.Pow(request.PlanetSize / 2.0, 2)) <= 0)
                     {
                         var child = new VoxelGreen(_idTally++, Bus)
                         {
                             Position = new Vect3(x, y, z)
                         };
                         GameObjects.Add(child);
                         item.AddChild(child);
                     }
                 }
             }
         }
     }
 }
Example #16
0
 private void AddMenu()
 {
     AddMenuItem = new MenuItem("button-add", "button-add-move")
     {
         Tag = "Add", IsActive = true
     };
     AddLineMenuItem = new MenuItem("button-line", "button-line-move")
     {
         Tag = "AddLine"
     };
     MoveMenuItem = new MenuItem("button-move", "button-move-move")
     {
         Tag = "Move"
     };
     RemoveMenuItem = new MenuItem("button-remove", "button-remove-move")
     {
         Tag = "Remove"
     };
     Menu.AddMenuItem(AddMenuItem);
     Menu.AddMenuItem(AddLineMenuItem);
     Menu.AddMenuItem(MoveMenuItem);
     Menu.AddMenuItem(RemoveMenuItem);
     Menu.Position = Vector2.Zero;
     Menu.Show();
     GameObjects.Add(Menu);
 }
Example #17
0
 /// <summary>
 /// Add a new GameObject to the list of objects to be handled.
 /// </summary>
 /// <param name="gameObject">The new object to handle.</param>
 public void AddObject(GameObject gameObject)
 {
     if (!GameObjects.Contains(gameObject))
     {
         GameObjects.Add(gameObject);
     }
 }
Example #18
0
        private void ResetGame()
        {
            GameObjects.Clear();

            _borderBlocks = new EnemyObject[17];

            for (int i = 0; i < 17; ++i)
            {
                _borderBlocks[i] = new EnemyObject(this, Textures["_borderBlocksGraphics"], 62 * i + 800, _copter, _speed);
                GameObjects.Add(_borderBlocks[i]);
            }

            _midBlock  = new MidEnemyObject(this, Textures["_midBlocksGraphics"], 850, _copter, _speed);
            _midBlock2 = new MidEnemyObject(this, Textures["_midBlocksGraphics"], 850 + 600, _copter, _speed);
            GameObjects.Add(_midBlock);
            GameObjects.Add(_midBlock2);

            _copter = new CopterObject(this, Textures["_copterGraphics"], _borderBlocks, _midBlock, _midBlock2);
            GameObjects.Add(_copter);

            _smoke = new SmokeObject[20];
            for (int i = 0; i < 20; ++i)
            {
                _smoke[i] = new SmokeObject(this, Textures["_smokeGraphics"], _copter, -195 + i * 10, _speed);
                GameObjects.Add(_smoke[i]);
            }

            _wings = new WingsObject(this, Textures["_wingsGraphics1"], _copter);
            GameObjects.Add(_wings);
        }
Example #19
0
 // This method initializes when the object already has a player.
 public void InitializeWithShipCreated()
 {
     GameObjects.Add(Player);
     Timer          = new DispatcherTimer();
     Timer.Interval = new TimeSpan(0, 0, 0, 0, 20);
     Timer.Start();
     Timer.Tick += Timer_Tick;
 }
Example #20
0
        /// <summary>
        /// Set the game objects collection to display the high score table
        /// </summary>
        /// <param name="highlightEntry">If a new score has been added, pass its entry here and it will be highlighted</param>
        private void ResetHighscoreTableDisplay(HighScoreEntry highlightEntry)
        {
            // Add the title
            GameObjects.Add(new TextObject(_game, _game.Fonts["WascoSans"], new Vector2(10, 10), "High Scores"));

            // Add the score objects
            _game.HighScores.CreateTextObjectsForTable("Normal", _game.Fonts["WascoSans"], 0.7f, 80, 45, Color.White, Color.Blue, highlightEntry, Color.Yellow);
        }
        /// <summary>
        /// Reset the game ready to play
        /// </summary>
        private void ResetGame()
        {
            AddPlanets_Interleaved();
            //AddPlanets_InBlocks();

            // Add the benchmark object
            GameObjects.Add(new BenchmarkObject(this, Fonts["Kootenay"], new Vector2(50, 50), Color.White));
        }
Example #22
0
        /// <summary>
        /// Reset the game
        /// </summary>
        private void ResetGame()
        {
            // Clear any existing objects
            GameObjects.Clear();

            // Add a cube
            GameObjects.Add(new CubeObject(this));
        }
Example #23
0
        /// <summary>
        /// Reset the game
        /// </summary>
        private void ResetGame()
        {
            // Clear any existing objects
            GameObjects.Clear();

            // Add an object
            GameObjects.Add(new SquareObject(this, Vector3.Zero, Textures["Ground"], Textures["Lights"]));
            //GameObjects.Add(new SquareObject(this, Vector3.Zero, Textures["MoireTexture1"], Textures["MoireTexture2"]));
        }
Example #24
0
        void addCoinToLevel(Vector2 position)
        {
            var coin = new Coin();

            coin.Load(_loader);
            coin.Props.Position = position;
            GameObjects.Add(coin);
            chunkMap.UpdateEntity(coin);
        }
Example #25
0
        /// <summary>
        /// Reset the game
        /// </summary>
        private void ResetGame()
        {
            // Clear any existing objects
            GameObjects.Clear();

            // Add an object
            GameObjects.Add(new CubeObject(this, new Vector3(0, 0.75f, 0), Textures["Marble"], 0.3f, 0.3f));
            GameObjects.Add(new CylinderObject(this, new Vector3(0, -0.75f, 0), null, 1.0f, 0.0f));
        }
Example #26
0
        public override void Load(IContentLoader loader)
        {
            _loader = loader;

            var defaultFont = loader.Load <SpriteFont>(ContentPaths.FONT_UI_GENERAL);

            varShowLootTip = new GameVariable <bool>();
            varShowLootTip.Load(loader);
            GameObjects.Add(varShowLootTip);

            // Player
            player = new Player(eventBus, varShowLootTip);
            player.Load(loader);
            GameObjects.Add(player);

            // Bot
            bot = new Bot(eventBus, Camera);
            bot.Load(loader);
            GameObjects.Add(bot);

            // Message manager
            textPopupManager = new TextPopupManager(ContentPaths.FONT_UI_GENERAL, StackingMethod.Parallel);
            textPopupManager.Load(loader);
            GameObjects.Add(textPopupManager);

            // Physics
            phys = new MapPhysics(chunkMap, physSettings);
            GameObjects.Add(chunkMap);

            // Camera
            GameObjects.Add(Camera);

            // Services
            setupKeyListeners();

            // Event listeners
            eventBusSubscriptionIds.AddRange(new[] {
                eventBus.Subscribe(Events.PlayerPickedUpCoin, (p) => Debug.WriteLine("picked up coin!")),
                eventBus.Subscribe(Events.PlayerDied, (p) => playerDied()),
                eventBus.Subscribe(Events.CreateProjectile, (p) => playerCreatedProjectile(p as Projectile)),
            });

            // Game variables
            var tipLootBoxOpen = "Press <E> to open loot box";

            txtDisplayTipLootBoxOpen = new TextElement <string>(tipLootBoxOpen, defaultFont, new TextElementSettings())
            {
                Position           = new Vector2(10, 10),
                IsAttachedToCamera = true,
                IsHidden           = true,
            };
            txtDisplayTipLootBoxOpen.Load(loader);
            GameObjects.Add(txtDisplayTipLootBoxOpen);

            // Map
            loadMap();
        }
        private void ResetGame()
        {
            // Create a stringbuilder to write out gamepad details to
            _padStateDetails = new System.Text.StringBuilder();

            // Create a text object to display the details on the screen
            _padStateDetailsObject = new TextObject(this, Fonts["Miramonte"], new Vector2(10, 10));
            GameObjects.Add(_padStateDetailsObject);
        }
Example #28
0
        /// <summary>
        /// Reset the game
        /// </summary>
        private void ResetGame()
        {
            // Clear any existing objects
            GameObjects.Clear();

            // Add some new game objects
            GameObjects.Add(new TexturedSquareObject(this, new Vector3(0, 0.6f, 0), Textures["Grapes"], 2.0f));
            GameObjects.Add(new TexturedSquareObject(this, new Vector3(0, -0.6f, 0), Textures["Strawberry"], 2.0f));
        }
Example #29
0
        public void Add(GameObject gameObject)
        {
            var count = GetPointCount(gameObject.X, gameObject.Y);

            if (gameObject.Z != -1)
            {
                GameObjects.Add(gameObject);
            }
        }
Example #30
0
        /// <summary>
        /// Reset the game
        /// </summary>
        private void ResetGame()
        {
            // Clear any existing objects
            GameObjects.Clear();

            // Add a cube using each of the new rendering techniques
            GameObjects.Add(new VertexBufferCubeObject(this, new Vector3(0, 1.5f, 0)));
            GameObjects.Add(new IndexedCubeObject(this, new Vector3(0, 0, 0)));
            GameObjects.Add(new VertexAndIndexBufferCubeObject(this, new Vector3(0, -1.5f, 0)));
        }