Ejemplo n.º 1
0
        public void KeyPress(string key)
        {
            switch (key)
            {
            case "KEY_SPACE":
                playerShots.AddDynamicEntity(
                    new DynamicShape(player.Entity.Shape.Position + new Vec2F(0.046f, 0.09f),
                                     new Vec2F(0.008f, 0.027f), new Vec2F(0.0f, 0.01f)),
                    shotStride);
                break;

            case "KEY_RIGHT":
                player.MoveRight();
                break;

            case "KEY_LEFT":
                player.MoveLeft();
                break;

            case "KEY_ESCAPE":
                GalagaBus.GetBus().RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.GameStateEvent,
                        this,
                        "CHANGE_STATE",
                        "GAME_PAUSED", ""));
                break;
            }
        }
Ejemplo n.º 2
0
        public void KeyPress(string key)
        {
            switch (key)
            {
            case "KEY_ESCAPE":
                eventBus.RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.WindowEvent, this, "CLOSE_WINDOW", "", ""));
                break;

            case "KEY_SPACE":
                playerShots.AddDynamicEntity(
                    new DynamicShape(player.Entity.Shape.Position + new Vec2F(0.046f, 0.09f),
                                     new Vec2F(0.008f, 0.027f), new Vec2F(0.0f, 0.01f)),
                    shotStride);
                break;

            case "KEY_RIGHT":
                player.MoveRight();
                break;

            case "KEY_LEFT":
                player.MoveLeft();
                break;
            }
        }
Ejemplo n.º 3
0
        private void UpdateShots()
        {
            EntityContainer <PlayerShot> newPlayerShots = new EntityContainer <PlayerShot>();

            playerShots.Iterate(delegate(PlayerShot shot) {
                if (!shot.IsDeleted())
                {
                    shot.Move();
                    newPlayerShots.AddDynamicEntity(shot);
                }

                foreach (ISquadron squadron in Enemies)
                {
                    foreach (Enemy enemy in squadron.Enemies)
                    {
                        CollisionData collision =
                            CollisionDetection.Aabb(
                                shot.Shape.AsDynamicShape(),
                                enemy.Shape.AsDynamicShape());
                        if (collision.Collision && !shot.IsDeleted())
                        {
                            shot.DeleteEntity();
                            enemy.Hit();
                            AddExplosion(enemy.Shape.Position.X, enemy.Shape.Position.Y,
                                         enemy.Shape.Extent.X, enemy.Shape.Extent.Y);
                        }
                    }
                }
            });

            playerShots = newPlayerShots;
        }
Ejemplo n.º 4
0
 public void AddEnemies()
 {
     for (int i = 1; i < 9; i++)
     {
         var shape = new DynamicShape(new Vec2F(i * 0.1f, 0.9f), new Vec2F(0.1f, 0.1f));
         enemies.AddDynamicEntity(shape, new ImageStride(80, enemyStrides));
     }
 }
Ejemplo n.º 5
0
        public void AddProjectiles()
        {
            var laser = new DynamicShape(
                new Vec2F(player.GetPos.X + 0.0425f, player.GetPos.Y + 0.1f),
                new Vec2F(0.008f, 0.027f));

            projectiles.AddDynamicEntity(laser, laserImage);
        }
Ejemplo n.º 6
0
        public void AddShot()
        {
            PlayerShot shot = new PlayerShot(
                new DynamicShape(
                    player.GetCannonPoint(),
                    new Vec2F(0.008F, 0.027F)));

            playerShots.AddDynamicEntity(shot);
        }
        public void KeyPress(string key)
        {
            switch (key)
            {
            case "KEY_ESCAPE":
                eventBus.RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.WindowEvent, this, "CLOSE_WINDOW", "", ""));
                break;

            case "KEY_A":
                if (!EntityOutOfBounds(player.Entity, "EDGE_LEFT"))
                {
                    player.Entity.Shape.MoveX(-player.defaultSpeed);
                }
                break;

            case "KEY_D":
                if (!EntityOutOfBounds(player.Entity, "EDGE_RIGHT"))
                {
                    player.Entity.Shape.MoveX(player.defaultSpeed);
                }

                break;

            /*
             * case "KEY_W":
             *  if (!EntityOutOfBounds(player.Entity, "EDGE_TOP")) {
             *      player.Entity.Shape.MoveY(0.010f);
             *  }
             *
             *  break;
             *
             * case "KEY_S":
             *  if (!EntityOutOfBounds(player.Entity, "EDGE_BOTTOM")) {
             *      player.Entity.Shape.MoveY(-0.010f);
             *  }
             *
             *  break;
             */


            case "KEY_SPACE":

                DynamicShape shape = new DynamicShape(new Vec2F(
                                                          player.Entity.Shape.Position.X + (player.Entity.Shape.Extent.X / 2.0f),
                                                          player.Entity.Shape.Position.Y + player.Entity.Shape.Extent.Y),
                                                      new Vec2F(0.008f, 0.027f), new Vec2F(0.0f, 0.01f));

                playerShots.AddDynamicEntity(
                    shape,
                    imageShot);


                break;
            }
        }
Ejemplo n.º 8
0
        public static void MainFunction()
        {
            var win = new Window("hej", 500, AspectRatio.R1X1);

            win.SetClearColor(System.Drawing.Color.Brown);

            Image img1 = new Image("Taxi.png");
            Image img2 = new Image("Taxi2.png");

            var entities = new EntityContainer(10);

            for (int i = 0; i < 10; i++)
            {
                var shape = new DynamicShape(new Vec2F(i * 0.1f, 0.9f), new Vec2F(0.1f, 0.1f));
                entities.AddDynamicEntity(shape, new ImageStride(250, img1, img2));
                //entities.AddDynamicEntity(shape, img1);
            }

            win.AddKeyPressEventHandler(delegate(KeyboardKeyEventArgs keyArgs) {
                if (keyArgs.Key == Key.Left)
                {
                    entities.Iterate(delegate(Entity entity) {
                        entity.Shape.MoveX(-0.05f);
                    });
                }
                if (keyArgs.Key == Key.Right)
                {
                    entities.Iterate(delegate(Entity entity) {
                        entity.Shape.MoveX(0.05f);
                    });
                }
                if (keyArgs.Key == Key.Up)
                {
                    entities.Iterate(delegate(Entity entity) {
                        entity.Shape.MoveY(0.05f);
                    });
                }
                if (keyArgs.Key == Key.Down)
                {
                    entities.Iterate(delegate(Entity entity) {
                        entity.Shape.MoveY(-0.05f);
                    });
                }
            });

            while (win.IsRunning())
            {
                win.PollEvents();
                win.Clear();

                entities.RenderEntities();

                win.SwapBuffers();
            }
            Console.WriteLine("window closed now");
        }
Ejemplo n.º 9
0
 private void AddEnemies()
 {
     for (int j = 0; j < 3; j++)
     {
         for (int i = 0; i < 8; i++)
         {
             enemies.AddDynamicEntity(
                 (new DynamicShape(0.1f + i / 10.0f, 0.9f - j / 10.0f, 0.1f, 0.1f)), enemyStrides);
         }
     }
 }
Ejemplo n.º 10
0
        public void UpdateEnemyList()
        {
            EntityContainer <Enemy> newEnemies = new EntityContainer <Enemy>();

            foreach (Enemy enemy in enemies)
            {
                if (!enemy.IsDeleted())
                {
                    newEnemies.AddDynamicEntity(enemy);
                }
            }

            enemies = newEnemies;
        }
Ejemplo n.º 11
0
        public void IterateShots()
        {
            foreach (PlayerShot shot in playerShots)
            {
                shot.Shape.Move();
                if (shot.Shape.Position.Y > 1.0f)
                {
                    shot.DeleteEntity();
                }

                foreach (Enemy e in enemies)
                {
                    if (CollisionDetection.Aabb(shot.Shape.AsDynamicShape(), e.Shape).Collision)
                    {
                        e.DeleteEntity();
                        shot.DeleteEntity();
                        AddExplosion(e.Shape.Position.X - 0.05f,
                                     e.Shape.Position.Y - 0.05f, 0.2f, 0.2f);
                        score.AddPoint();
                    }
                }
            }

            EntityContainer <Enemy> newEnemies = new EntityContainer <Enemy>();

            foreach (Enemy e in enemies)
            {
                if (!e.IsDeleted())
                {
                    newEnemies.AddDynamicEntity(e);
                }
            }

            enemies = newEnemies;

            EntityContainer <PlayerShot> newPlayerShots = new EntityContainer <PlayerShot>();

            foreach (PlayerShot shot in playerShots)
            {
                if (!shot.IsDeleted())
                {
                    newPlayerShots.AddDynamicEntity(shot);
                }
            }

            playerShots = newPlayerShots;
        }
        private void AddEnemies()
        {
            // hint: y = ax+b
            int numberOfEnemies = 9;

            for (int i = 0; i < numberOfEnemies; i++)
            {
                enemies.AddDynamicEntity(new DynamicShape(new Vec2F((0.10f * (float)i) + 0.03f, .9f), new Vec2F(0.1f, 0.1f)), new ImageStride(80, enemyStrides));
            }

            /*
             * enemies.AddDynamicEntity(new DynamicShape(new Vec2F(0.10f, 0.1f), new Vec2F(0.1f, 0.1f)), new ImageStride(80, enemyStrides));
             * enemies.AddDynamicEntity(new DynamicShape(new Vec2F(0.30f, 0.2f), new Vec2F(0.1f, 0.1f)), new ImageStride(80, enemyStrides));
             * enemies.AddDynamicEntity(new DynamicShape(new Vec2F(0.90f, 0.3f), new Vec2F(0.1f, 0.1f)), new ImageStride(80, enemyStrides));
             * enemies.AddDynamicEntity(new DynamicShape(new Vec2F(0.05f, 0.6f), new Vec2F(0.1f, 0.1f)), new ImageStride(80, enemyStrides));
             */
        }
Ejemplo n.º 13
0
        public bool CleanEnemies()
        {
            EntityContainer <Enemy> newEnemies = new EntityContainer <Enemy>();

            foreach (Enemy enemy in Enemies)
            {
                if (enemy.IsDestroyed())
                {
                    Score.GetInstance().AddPoint(enemy.Points);
                    enemy.DeleteEntity();
                }

                if (!enemy.IsDeleted())
                {
                    newEnemies.AddDynamicEntity(enemy);
                }
            }

            Enemies = newEnemies;

            // returns false if squadron is empty
            return(newEnemies.CountEntities() > 0);
        }