public MainPage()
        {
            //don't touch this method. microsoft created
            InitializeComponent();

            //this method initializes the Device
            DeviceManager.CreateDevice(panel1.Handle, panel1.Width, panel1.Height);

            _camera = new Camera();

            _renderer = new Renderer();
            Init();

            DeviceManager.LocalDevice.SetRenderState(RenderState.Lighting, _renderer.IsGlobalLightOn);
            DeviceManager.LocalDevice.SetRenderState(RenderState.CullMode, Cull.Counterclockwise);
            DeviceManager.LocalDevice.SetRenderState(RenderState.ZEnable, ZBufferType.UseZBuffer);
            DeviceManager.LocalDevice.SetRenderState(RenderState.NormalizeNormals, true);
            DeviceManager.LocalDevice.SetRenderState(RenderState.Ambient, Color.Gray.ToArgb());
            DeviceManager.LocalDevice.SetRenderState(RenderState.SpecularEnable, false);

            //set GUI control attributes
            SetGui();

            panel1.MouseWheel += panel1_MouseWheel;
        }
Ejemplo n.º 2
0
 public SpecificVehiclePresenter(Renderer renderer, SpriteTemplate st)
 {
     _renderer = renderer;
     _sprite = new Sprite(st, Drawable.Flags.Colorize, Priority.Vehicle);
     _sprite.Clear();
     Console.WriteLine("new svp...");
 }
Ejemplo n.º 3
0
 public MonitoringHeader(Game game, Renderer renderer)
     : base(game, renderer, 0, false, true)
 {
     _cpuUsageCounter = new CpuUsageCounter();
     _fpsCounter = new FpsCounter();
     _text = renderer.TextManager.Create("Courrier", 14, 80, new Vector4(1,1,1,0.5f));
     _text.Position = new Vector2I(3,0);
     _videoCardInfo = renderer.DirectX.VideoCardName + " ("+renderer.DirectX.VideoCardMemorySize+" MB)";
     _overlay = new Rectangle(renderer, renderer.ScreenSize, new Vector2I(0,0), new Vector2I(485,16), new Vector4(1,0,0,0.2f));
 }
Ejemplo n.º 4
0
 public Airplane(World world, State state, Game game, Renderer renderer, bool isPlayer, Airplane playerPlane, String name, String modelName)
     : base(game, renderer, isPlayer ? -1000 : 0)
 {
     IsPlayer = isPlayer;
     World = world;
     CurrentState = state;
     Name = name;
     ModelName = modelName;
     if (isPlayer)
         Commands = new PlayerAirplaneCommands(game.Input);
     else
         Commands = new ComputerAirplaneCommands();
     PhysicalModel = new AirplanePhysicalModel(this, Commands);
     Model = new ObjModel(renderer.DirectX.Device, "Airplane.obj", Renderer.TextureManager.Create("Metal.png"));
     if(!isPlayer && ConfigurationManager.Config.DisplayOverlay)
         game.Register(new AirplaneOverlay(game, renderer, this, playerPlane));
 }
Ejemplo n.º 5
0
        public PresentationManager(Renderer r, Sim.ObjectDatabase sim)
        {
            _config = new Config();
            _presenters.Add(new BuildablePresenter(r, _config));
            _presenters.Add(new VehiclePresenter(r, _config));

            /*		sim.ObjectAdded += oa => { lock(_addedObjects) { _addedObjects.Enqueue(oa); } };
            sim.ObjectRemoved += or => { lock(_removedObjects) { _removedObjects.Enqueue(or); } };
            */
            sim.Updated += update =>
            {
                lock(_updateLock)
                {
                    _previousUpdate = _currentUpdate;
                    _currentUpdate = update;
                }
            };
        }
        /*public static bool Intersect(Ray a, Content.Model9 b, out object intersection)
        {

            if (b.XMesh != null)
                return Intersect(a, new BoundingMetaMesh
                {
                    Mesh = b.XMesh,
                    Tranformation = b.World
                }, out intersection);
            else if (b.SkinnedMesh != null)
                return Intersect(a, b.SkinnedMesh, out intersection);

            intersection = null;
            return false;
        }*/

        /*public static bool Intersect(Ray a, Content.SkinnedMesh b, out object intersection)
        {
            float minD = float.MaxValue;
            foreach (var v in b.MeshContainers)
            {
                float d;
                if (v.Second.MeshData != null && 
                    v.Second.MeshData.Mesh != null)
                {
                    Matrix invTransformation = Matrix.Invert(v.First.CombinedTransform);
                    var newRay = new Ray(
                        Vector3.TransformCoordinate(a.Position, invTransformation),
                        Vector3.Normalize(Vector3.TransformNormal(a.Direction, invTransformation)));

                    if(v.Second.MeshData.Mesh.Intersects(newRay, out d))
                    {
                        var newPos = Vector3.TransformCoordinate(newRay.Position + newRay.Direction * d,
                            v.First.CombinedTransform);
                        d = (newPos - a.Position).Length();
                        if(d < minD)
                            minD = d;
                    }
                }
            }
            intersection = new Common.RayIntersection { Distance = minD };
            return minD != float.MaxValue;
        }*/


        public static bool Intersect(Ray a, Renderer.Renderer.EntityAnimation b, out object intersection)
        {
            float minD = float.MaxValue;
            foreach (var v in b.StoredFrameMatrices)
            {
                if (v.Key != null)
                {
                    foreach (var m in v.Value)
                    {
                        float d;
                        Matrix invTransformation = Matrix.Invert(m[0]);
                        var newRay = new Ray(
                            Vector3.TransformCoordinate(a.Position, invTransformation),
                            Vector3.Normalize(Vector3.TransformNormal(a.Direction, invTransformation)));

                        if (v.Key.Intersects(newRay, out d))
                        {
                            var newPos = Vector3.TransformCoordinate(newRay.Position + newRay.Direction * d,
                                m[0]);
                            d = (newPos - a.Position).Length();
                            if (d < minD)
                                minD = d;
                        }
                    }
                }
            }
            intersection = new Common.RayIntersection { Distance = minD };
            return minD != float.MaxValue;
        }
Ejemplo n.º 7
0
        public PlayerView(GameLogic game)
        {
            this.Game         = game;
            this.EventManager = game.EventManager;

            menuClock = new GameClock();
            menuClock.Start();

            /**
             * Initialize Graphics Subsystem
             **/
            RenderForm                 = new Form();
            RenderForm.ClientSize      = new Size(Game.World.Width, Game.World.Height);
            RenderForm.Text            = "Alien Invasion v1.0";
            RenderForm.BackColor       = Color.Empty;
            RenderForm.KeyPreview      = true;
            RenderForm.FormBorderStyle = FormBorderStyle.FixedSingle; // Disable resizing of window
            RenderForm.MaximizeBox     = false;                       // Disable maximizing
            RenderForm.Leave          += (s, e) => {
                this.RenderForm.Focus();                              // When RenderForm loses focus player input won't be processed correctly
            };

            extractor = new Extractor(game);
            Renderer  = new Graphics.Renderer(RenderForm, extractor);
            Renderer.StartRender();

            rendererLoaders.Add(new TextureLoader(Renderer));
            rendererLoaders.Add(new MeshLoader(Renderer));
            rendererLoaders.Add(new EffectLoader(Renderer));

            foreach (var rendererLoader in rendererLoaders)
            {
                game.ResourceManager.AddLoader(rendererLoader);
            }

            game.ResourceManager.AddLoader(new MaterialLoader(game.ResourceManager));

            /**
             * Initialize Input Subsystem
             **/
            gameController      = new GameController(EventManager, game);
            RenderForm.KeyDown += new KeyEventHandler(gameController.OnKeyDown);
            RenderForm.KeyUp   += new KeyEventHandler(gameController.OnKeyUp);

            /**
             * Initialize Audio Subsystem
             **/
            audioPlayer = new FmodAudioPlayer(@"./data/audio/");
            audioPlayer.LoadFile("audio.fev");
            audioPlayer.IsPaused = false;

            /**
             * Initialize GUI
             **/
            mainMenuControl          = new GameMainMenu(EventManager);
            mainMenuControl.Location = new Point(
                (RenderForm.ClientSize.Width - mainMenuControl.Width) / 2,
                (RenderForm.ClientSize.Height - mainMenuControl.Height) / 2);
            RenderForm.Controls.Add(mainMenuControl);

            highscoreControl          = new HighscoreScreen(EventManager);
            highscoreControl.Location = new Point(
                (RenderForm.ClientSize.Width - highscoreControl.Width) / 2,
                (RenderForm.ClientSize.Height - highscoreControl.Height) / 2);
            RenderForm.Controls.Add(highscoreControl);

            creditsControl          = new Credits(EventManager);
            creditsControl.Location = new Point(
                (RenderForm.ClientSize.Width - creditsControl.Width) / 2,
                (RenderForm.ClientSize.Height - creditsControl.Height) / 2);
            RenderForm.Controls.Add(creditsControl);

            pauseControl          = new PauseScreen();
            pauseControl.Location = new Point(
                (RenderForm.ClientSize.Width - pauseControl.Width) / 2,
                (RenderForm.ClientSize.Height / 2) - pauseControl.Height);
            RenderForm.Controls.Add(pauseControl);

            victoryControl          = new VictoryScreen(EventManager);
            victoryControl.Location = new Point(
                (RenderForm.ClientSize.Width - victoryControl.Width) / 2,
                (RenderForm.ClientSize.Height / 2) - (victoryControl.Height / 2));
            RenderForm.Controls.Add(victoryControl);

            gameOverControl          = new DefeatScreen(EventManager);
            gameOverControl.Location = new Point(
                (RenderForm.ClientSize.Width - gameOverControl.Width) / 2,
                (RenderForm.ClientSize.Height / 2) - (gameOverControl.Height / 2));
            RenderForm.Controls.Add(gameOverControl);

            hud          = new Hud(EventManager);
            hud.Location = new Point(RenderForm.ClientSize.Width - hud.Width, 0);
            RenderForm.Controls.Add(hud);

            numOfGcCollectedObjects = new int[GC.MaxGeneration];

            registerGameEventListeners();
        }
Ejemplo n.º 8
0
        public VehiclePresenter(Renderer renderer, Config config)
        {
            _renderer = renderer;
            _config = config;
            _configuredTypeIds = new HashSet<string>(_config.GetVehicleTypeIds());
            _healthBars = new Sprite(_healthBarTmp, 0, Priority.HealthBar);

            foreach(var typeId in _configuredTypeIds)
            {
                _presenters.Add(typeId, new SpecificVehiclePresenter(_renderer, _config.GetVehicleSpriteTemplate(typeId)));
            }
        }
Ejemplo n.º 9
0
 public BuildablePresenter(Renderer renderer, Config config)
 {
     _renderer = renderer;
     _config = config;
     _configuredTypeIds = new HashSet<string>(_config.GetBuildableTypeIds());
 }
Ejemplo n.º 10
0
 public WallPresenter(Renderer renderer)
 {
     _renderer = renderer;
     _bg = renderer.Backgrounds[1];
     _walls = new bool[_bg.Width,_bg.Height];
     Console.WriteLine("wall presenter+");
 }
Ejemplo n.º 11
0
 public TowerPresenter(Renderer renderer, SpriteTemplate weaponTemplate, SpriteTemplate flashTemplate)
 {
     _renderer = renderer;
     _weaponSprite = new Sprite(weaponTemplate, 0, Priority.TowerWeapon);
     _flashSprite = new Sprite(flashTemplate, 0, Priority.TowerWeaponOverlay);
 }