Beispiel #1
0
        public Game()
        {
            Window = new RenderWindow(new VideoMode(1280, 720), "DigitalBattle", Styles.Close);
            Window.SetFramerateLimit(60);
            Window.SetVerticalSyncEnabled(true);
            Window.SetKeyRepeatEnabled(false);
            MainView = new View(new Vector2f(640, 360), new Vector2f(1280, 720));
            Window.SetView(MainView);
            Resurses.Load();

            Tank          = new Tank(new Vector2f(-250, -250));
            TimeOneFrame  = new Clock();
            AllBullets    = new List <Bullet>();
            DeleteBullets = new List <Bullet>();
            Enemies       = new List <Enemies>();
            DeleteEnemies = new List <Enemies>();
            situation     = new Parametres();

            GameInterface = new GameInterface(Tank.Health);

            TMXMap = new TMX();
            TMXMap.Load(LevelName[0], SpawnNewBullet);

            DeathSound  = new Sound();
            SplashSound = new Sound();
            Rnd         = new Random();

            Window.Closed               += WindowClosed;
            Window.KeyPressed           += KeyPress;
            Window.KeyPressed           += Tank.KeyPress;
            Window.KeyReleased          += Tank.KeyReleas;
            Window.MouseButtonPressed   += Tank.Tower.Shot;
            Window.MouseButtonPressed   += ChoseBottomForGame;
            TankMoveEvent               += Tank.Move;
            Tank.Tower.BulletSpawnEvent += SpawnNewBullet;
            TankSpawnEvent              += Tank.Spawn;
            TankSubstractHealthEvent    += Tank.SubstractHealth;
            TowerRotateEvent            += Tank.Tower.Rotation;
            TMXMap.SpawnEnemyEvent      += SpawnEnemy;
            CoolDownShotEvent           += Tank.Tower.CD;
            SetNewInterfaceEvent        += GameInterface.SetInterface;

            Resurses.Musics[0].Loop = true;
            Resurses.Musics[0].Play();

            while (Window.IsOpen)
            {
                Window.DispatchEvents();
                Window.Clear();

                GamePlay();
                Draw();

                TimeOneFrame.Restart();
                Window.Display();
            }
        }
Beispiel #2
0
        private bool SomeInterspect(Parametres param)
        {
            double firstVec = Vector.CrossProduct(new Vector(param.X4 - param.X3, param.Y4 - param.Y3), new Vector(param.X1 - param.X3, param.Y1 - param.Y3));
            double secodVec = Vector.CrossProduct(new Vector(param.X4 - param.X3, param.Y4 - param.Y3), new Vector(param.X2 - param.X3, param.Y2 - param.Y3));
            double third    = Vector.CrossProduct(new Vector(param.X2 - param.X1, param.Y2 - param.Y1), new Vector(param.X3 - param.X1, param.Y3 - param.Y1));
            double fourth   = Vector.CrossProduct(new Vector(param.X2 - param.X1, param.Y2 - param.Y1), new Vector(param.X4 - param.X1, param.Y4 - param.Y1));

            return(Math.Sign(firstVec) != Math.Sign(secodVec) && Math.Sign(third) != Math.Sign(fourth));
        }