Represents a camera to manage viewing information Should be attached to a GameObject --- Incomplete --- 1. Make it work for both perspective and orthographic cameras 2. Use other methods (off-center cameras)
Inheritance: GameEngine.Component
Ejemplo n.º 1
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            GameObject terrainObject = new GameObject();
            terrainObject.Transform.LocalScale *= new Vector3(1, 5, 1);
            terrain = terrainObject.Add<TerrainRenderer>();
            terrain.Initialize(
                Content.Load<Texture2D>("Textures/Heightmap"),
                Vector2.One * 100, Vector2.One * 200);
            terrain.NormalMap = Content.Load<Texture2D>("Textures/Normalmap");
            effect = Content.Load<Effect>("Effects/TerrainShader");

            GameObject cameraObject = new GameObject();
            cameraObject.Transform.LocalPosition = Vector3.Backward * 5 + Vector3.Right * 5 + Vector3.Up * 5;
            camera = cameraObject.Add<Camera>();
        }
Ejemplo n.º 2
0
 protected override void LoadContent()
 {
     spriteBatch = new SpriteBatch(GraphicsDevice);
     // Let's load our model
     model = Content.Load<Model>("Models/Torus");
     // Ask our model to do "default" lighting"
     foreach (ModelMesh mesh in model.Meshes)
         foreach (BasicEffect effect in mesh.Effects)
         {
             effect.EnableDefaultLighting();
             effect.Alpha = 1;
         }
     parentObject = new GameObject();
     childObject = new GameObject();
     childObject.Transform.Parent = parentObject.Transform;
     childObject.Transform.LocalPosition = Vector3.Right * 10;
     cameraObject = new GameObject();
     cameraObject.Transform.LocalPosition = Vector3.Backward * 50;
     camera = cameraObject.Add<Camera>();
 }
Ejemplo n.º 3
0
        public void Redraw(Camera drawCamera, Size levelSize)
        {
            var gfx = Graphics.FromImage(drawCamera.CameraScreen);

            var parallaxOffset = new DecimalPoint();

            int xOffset = 0;

            foreach(var bgnd in BackgroundList)
            {
                if (drawCamera.CameraStyle == CameraType.Left3D)
                    xOffset += bgnd.ZLevel;
                else if (drawCamera.CameraStyle == CameraType.Right3D)
                    xOffset -= bgnd.ZLevel;
                else
                    xOffset = 0;

                if (levelSize.Width - drawCamera.CameraScreen.Width == 0)
                    parallaxOffset.X = 0;
                else
                    parallaxOffset.X = Convert.ToDecimal(bgnd.ImageSize.Width - drawCamera.CameraScreen.Width) /
                                       Convert.ToDecimal(levelSize.Width - drawCamera.CameraScreen.Width);

                if (levelSize.Height - drawCamera.CameraScreen.Height == 0)
                    parallaxOffset.Y = 0;
                else
                    parallaxOffset.Y = Convert.ToDecimal(bgnd.ImageSize.Height - drawCamera.CameraScreen.Height) /
                                      Convert.ToDecimal(levelSize.Height - drawCamera.CameraScreen.Height);

                var rec = new Rectangle(Convert.ToInt32(parallaxOffset.X * drawCamera.Offset.X) + xOffset,
                          Convert.ToInt32(parallaxOffset.Y * drawCamera.Offset.Y),
                          drawCamera.CameraScreen.Width,
                          drawCamera.CameraScreen.Height);

                bgnd.Draw(rec, ref drawCamera.CameraScreen);
            }
        }
Ejemplo n.º 4
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            gunSound = Content.Load<SoundEffect>("Sounds/Gun");
            cube = Content.Load<Model>("Models/Cube");
            sphere = Content.Load<Model>("Models/Sphere");

            GameObject gameObject;
            gameObject = new GameObject();
            gameObject.Transform.LocalPosition = new Vector3(1, 0, 0);
            objects.Add(gameObject);
            BoxCollider boxCollider = gameObject.Add<BoxCollider>();
            boxCollider.Size = 1;
            colliders.Add(boxCollider);

            gameObject = new GameObject();
            gameObject.Transform.LocalPosition = new Vector3(-1, 0, 0);
            objects.Add(gameObject);
            SphereCollider sphereCollider = gameObject.Add<SphereCollider>();
            sphereCollider.Radius = 1;
            colliders.Add(sphereCollider);

            // Front Camera
            gameObject = new GameObject();
            gameObject.Transform.LocalPosition = Vector3.Backward * 5;
            camera = gameObject.Add<Camera>();
            camera.Position = new Vector2(0f, 0f);
            camera.Size = new Vector2(0.5f, 1f);
            camera.AspectRatio = camera.Viewport.AspectRatio;
            cameras.Add(camera);
            // Top Down Camera
            gameObject = new GameObject();
            gameObject.Transform.LocalPosition = Vector3.Up * 10;
            gameObject.Transform.Rotate(Vector3.Right, -MathHelper.PiOver2);
            camera = gameObject.Add<Camera>();
            camera.Position = new Vector2(0.5f, 0f);
            camera.Size = new Vector2(0.5f, 1f);
            camera.AspectRatio = camera.Viewport.AspectRatio;
            cameras.Add(camera);

            camera = cameras[0];
        }
Ejemplo n.º 5
0
        public void Redraw(Camera cam, ref Hashtable graphicLibrary, ref Hashtable graphicObjects)
        {
            int xOffset = 0;

            var currentObject = graphicObjects[CurrentObject] as GraphicObject;

            if (MaxFrame == 0)
            {
                MaxFrame = currentObject.NumberOfFrames;

                if (ObjectSize.Width == -1 || AutoSizeWithAnimation)
                {
                    ObjectSize = currentObject.FrameSize;
                }
            }

            if (cam.CameraStyle == CameraType.Left3D)
                xOffset += Location.Z;
            else if (cam.CameraStyle == CameraType.Right3D)
                xOffset -= Location.Z;
            else
                xOffset = 0;

            var location = new Point3D(Location.X - cam.Offset.X + xOffset, Location.Y - cam.Offset.Y, Location.Z);
            currentObject.DrawGraphic(ref graphicLibrary, CurrentFrame, location, ObjectSize, ref cam.CameraScreen);
        }
Ejemplo n.º 6
0
 protected override void LoadContent()
 {
     spriteBatch = new SpriteBatch(GraphicsDevice);
     // Let's load our model
     model = Content.Load<Model>("Models/Torus");
     parentObject = new GameObject();
     childObject = new GameObject();
     childObject.Transform.Parent = parentObject.Transform;
     childObject.Transform.LocalPosition = Vector3.Right * 10;
     cameraObject = new GameObject();
     cameraObject.Transform.LocalPosition = Vector3.Backward * 50;
     camera = cameraObject.Add<Camera>();
     texture = Content.Load<Texture2D>("Textures/Square");
     effect = Content.Load<Effect>("Effects/SimpleShading");
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Load the level file into the game world
        /// </summary>
        /// <param name="levelFile"></param>
        public void LoadLevel(string levelFile)
        {
            using (var sr = new StreamReader(levelFile))
            {
                string line = sr.ReadLine();

                string[] levelSizeItems = line.Split(new char[] { ',' });

                //size of the level

                LevelSize.Width = Convert.ToInt32(levelSizeItems[0]);
                LevelSize.Height = Convert.ToInt32(levelSizeItems[1]);
                LevelDepth = Convert.ToInt32(levelSizeItems[0]);

                Bitmap temp;
                Color transparentColour;

                line = sr.ReadLine();
                while (line != ENDGRAPHICS)
                {
                    levelSizeItems = line.Split(new char[] { ',' });

                    temp = new Bitmap("images\\" + levelSizeItems[1]);

                    int r = Convert.ToInt32(levelSizeItems[2]);
                    int g = Convert.ToInt32(levelSizeItems[3]);
                    int b = Convert.ToInt32(levelSizeItems[4]);
                    transparentColour = Color.FromArgb(r, g, b);

                    temp.MakeTransparent(transparentColour);

                    //image name name, bitmap
                    GraphicLibrary.Add(levelSizeItems[0], temp);

                    line = sr.ReadLine();
                }

                bool vertical = false;
                line = sr.ReadLine();
                while (line != ENDANIMATIONS)
                {
                    levelSizeItems = line.Split(new char[] { ',' });

                    vertical = levelSizeItems[7] == "Y";

                    var oname = levelSizeItems[0];
                    var image = levelSizeItems[1];
                    var local = new Point(Convert.ToInt32(levelSizeItems[2]), Convert.ToInt32(levelSizeItems[3]));
                    var size = new Size(Convert.ToInt32(levelSizeItems[4]), Convert.ToInt32(levelSizeItems[5]));
                    int numFrames = Convert.ToInt32(levelSizeItems[6]);

                    var go = new GraphicObject(image, size, local, numFrames, vertical);

                    GraphicObjects.Add(oname, go);

                    line = sr.ReadLine();
                }

                Background tmpBgnd;
                line = sr.ReadLine();
                while (line != ENDBACKGROUNDS)
                {
                    string map = sr.ReadLine();

                    tmpBgnd = new Background(line, map);

                    Background.AddParallax(tmpBgnd);

                    line = sr.ReadLine();
                }

                // Next the bump map
                line = sr.ReadLine();

                levelSizeItems = line.Split(new char[] { ',' });

                BumpMapSize.X = Convert.ToInt32(levelSizeItems[0]);
                BumpMapSize.Y = Convert.ToInt32(levelSizeItems[1]);

                int width = LevelSize.Width / BumpMapSize.X;
                int height = LevelSize.Height / BumpMapSize.Y;
                BumpMap = new int[width, height];

                var gridTransfer = new Point(width, height);
                var gridPosition = new Point(0, 0);

                int bump = 0;
                while (gridPosition.Y < gridTransfer.Y) // intuitivo
                {
                    while (gridPosition.X < gridTransfer.X)
                    {
                        if (levelSizeItems[2][bump] == '0')
                            BumpMap[gridPosition.X, gridPosition.Y] = 0;
                        else
                            BumpMap[gridPosition.X, gridPosition.Y] = 1;

                        bump++;
                        gridPosition.X++;
                    }

                    gridPosition.X = 0;
                    gridPosition.Y++;
                }

                // Next the objects
                line = sr.ReadLine();

                while (line != ENDOBJECTS)
                {
                    levelSizeItems = line.Split(new char[] { ',' });

                    if (levelSizeItems.Length == 17)
                    {
                        var objType = levelSizeItems[0];

                        var animTopLeft = levelSizeItems[1];
                        var animTop = levelSizeItems[2];
                        var animTopRight = levelSizeItems[3];
                        var animLeft = levelSizeItems[4];
                        var animStay = levelSizeItems[5];
                        var animRight = levelSizeItems[6];

                        var animBottomLeft = levelSizeItems[7];
                        var animBottom = levelSizeItems[8];
                        var animBottomRight = levelSizeItems[9];

                        var x = levelSizeItems[10];
                        var y = levelSizeItems[11];
                        var z = levelSizeItems[12];
                        var spx = levelSizeItems[13];
                        var spy = levelSizeItems[14];
                        var spz = levelSizeItems[15];
                        var ghost = levelSizeItems[16];

                        var go = new GameObject(objType, animTopLeft, animTop, animTopRight, animLeft, animStay, animRight, animBottomLeft, animBottom, animBottomRight, x, y, z, spx, spy, spz, ghost);
                        WorldObjects.Add(go);
                    }
                    else
                    {
                        var objType = levelSizeItems[0];

                        var animStay = levelSizeItems[1];

                        var x = levelSizeItems[2];
                        var y = levelSizeItems[3];
                        var z = levelSizeItems[4];
                        var spx = levelSizeItems[5];
                        var spy = levelSizeItems[6];
                        var spz = levelSizeItems[7];
                        var ghost = levelSizeItems[8];

                        var go = new GameObject(objType, animStay, x, y, z, spx, spy, spz, ghost);
                        WorldObjects.Add(go);
                    }

                    line = sr.ReadLine();
                }

                // CAMERAS
                line = sr.ReadLine();
                while (line != ENDCAMERAS)
                {
                    levelSizeItems = line.Split(new char[] { ',' });

                    var camType = CameraType.Standard;

                    if (levelSizeItems[6] == "L")
                        camType = CameraType.Left3D;
                    else if (levelSizeItems[6] == "R")
                        camType = CameraType.Right3D;

                    var resolution = new Size(Convert.ToInt32(levelSizeItems[0]), Convert.ToInt32(levelSizeItems[1]));
                    var drawLocation = new Rectangle(Convert.ToInt32(levelSizeItems[2]), Convert.ToInt32(levelSizeItems[3]), Convert.ToInt32(levelSizeItems[4]), Convert.ToInt32(levelSizeItems[5]));

                    var camera = new Camera(resolution, drawLocation, camType);

                    WorldCameras.Add(camera);
                }
            }
        }