Beispiel #1
0
        protected override void Initialize()
        {
            this.Window.Title = "Tank Diggity";

            uiManager = new UIManager(this);
            Components.Add(uiManager);

            screenManager = new ScreenManager(this);
            Components.Add(screenManager);

            soundManager = new SoundManager(this);
            Components.Add(soundManager);
            
            tankPos = new Vector2(60, 785);
            turretPos = new Vector2(tankPos.X + 45, tankPos.Y + 25);
            player1Tank = new Tank(this, tankPos,(float)Math.PI / 2);
            Components.Add(player1Tank);

            tankPos2 = new Vector2(2048 - 140, 785);
            turretPos2 = new Vector2(tankPos2.X + 45, tankPos.Y + 10);
            player2Tank = new Tank(this, tankPos2,-(float)Math.PI / 2);
            Components.Add(player2Tank);

            currentTank = player1Tank;

            camera = new Camera2d(graphics.GraphicsDevice);

            background = new Background(this);
            Components.Add(background);          

            powerUpManager = new PowerUpManager(this);
            Components.Add(powerUpManager);

            power = 0;

            chargingShot = false;
            chargingShot2 = false;
            shotFired = false;
            shotCollided = false;
            turnOver = false;
            gameRunning = false;
            rightSwap = false;
            leftSwap = false;
            debugGame = false;

            controller = GamePad.GetState(PlayerIndex.One);

            base.Initialize();
        }
Beispiel #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            rand = new Random();
            base.Initialize();

            this.background = new Background(this.backgroundTexture, Vector2.Zero);
            this.ship = new Ship(this.shipTexture, new Vector2(350, 260));
            this.explosions = new List<Explosion>();
            createEnemies();

            MediaPlayer.Play(this.music);
            MediaPlayer.IsRepeating = true;
        }
Beispiel #3
0
        async void CreateScene()
        {
            scene = new Scene();
            scene.CreateComponent <Octree>();

            var physics = scene.CreateComponent <PhysicsWorld>();

            physics.SetGravity(new Vector3(0, 0, 0));

            // Camera
            var cameraNode = scene.CreateChild();

            cameraNode.Position = (new Vector3(0.0f, 0.0f, -10.0f));
            cameraNode.CreateComponent <Camera>();
            Viewport = new Viewport(Context, scene, cameraNode.GetComponent <Camera>(), null);

            if (Platform != Platforms.Android && Platform != Platforms.iOS)
            {
                RenderPath effectRenderPath = Viewport.RenderPath.Clone();
                var        fxaaRp           = ResourceCache.GetXmlFile(Assets.PostProcess.FXAA3);
                effectRenderPath.Append(fxaaRp);
                Viewport.RenderPath = effectRenderPath;
            }
            Renderer.SetViewport(0, Viewport);

            var zoneNode = scene.CreateChild();
            var zone     = zoneNode.CreateComponent <Zone>();

            zone.SetBoundingBox(new BoundingBox(-300.0f, 300.0f));
            zone.AmbientColor = new Color(1f, 1f, 1f);

            // UI
            coinsText = new Text();
            coinsText.HorizontalAlignment = HorizontalAlignment.Right;
            coinsText.SetFont(ResourceCache.GetFont(Assets.Fonts.Font), Graphics.Width / 20);
            UI.Root.AddChild(coinsText);
            Input.SetMouseVisible(true, false);

            // Background
            var background = new Background();

            scene.AddComponent(background);
            background.Start();

            // Lights:
            var lightNode = scene.CreateChild();

            lightNode.Position = new Vector3(0, -5, -40);
            lightNode.AddComponent(new Light {
                Range = 120, Brightness = 0.8f
            });

            // Game logic cycle
            bool firstCycle = true;

            while (true)
            {
                var startMenu = scene.CreateComponent <StartMenu>();
                await startMenu.ShowStartMenu(!firstCycle); //wait for "start"

                startMenu.Remove();
                await StartGame();

                firstCycle = false;
            }
        }