Пример #1
0
        // Matrix? parentTransform = null
        public override void Draw(GameTime gameTime, Camera camera, Matrix parentTransform)
        {
            //Matrix matrix = (parentTransform == null) ? Matrix.Identity : (Matrix)parentTransform;

            Matrix[] transforms = new Matrix[Model.Bones.Count];
            Model.CopyAbsoluteBoneTransformsTo(transforms);
            foreach (ModelMesh mesh in Model.Meshes)
            {
                foreach (
                    BasicEffect effect in mesh.Effects)
                {
                    if (Texture != null)
                    {
                        effect.TextureEnabled = true;
                        effect.Texture = Texture;
                    }
                    /*else
                    {
                        effect.DiffuseColor = DiffuseColor.ToVector3();
                    } //*/
                    effect.EnableDefaultLighting();
                    effect.DiffuseColor = DiffuseColor.ToVector3();
                    effect.World = /*transforms[mesh.ParentBone.Index] */ World * parentTransform; // matrix
                    effect.View = camera.View;
                    effect.Projection = camera.Projection;
                }
                mesh.Draw();
            }

            //base.Draw(gameTime, camera, parentTransform);
            foreach (Transform transform in Children)
            {
                transform.Draw(gameTime, camera, World * parentTransform);//matrix);
            }
        }
Пример #2
0
        public ModelObject playerObject; // player

        #endregion Fields

        #region Constructors

        // constructor number 2
        public PlayerController(ModelObject model, float aspectRatio)
        {
            playerObject = model;

            // set up cameras
            cameras = new Camera[2];
            cameras[0] = new Camera();
            cameras[1] = new Camera();

            cameras[0].Position = new Vector3(0, 1.0f, 0);
            cameras[0].AspectRatio = aspectRatio;

            cameras[1].Position = new Vector3(0, 1.0f, 0);
            cameras[1].AspectRatio = aspectRatio;
            cameras[1].RotateX = -MathHelper.PiOver2; // look down, or alternatively:
            //cameras[1].Rotation = Quaternion.CreateFromAxisAngle(cameras[0].Right, MathHelper.PiOver2); // look down
        }
Пример #3
0
        public override void Draw(GameTime gameTime, Camera camera, Matrix parentTransform)
        {
            BasicEffect.World = World;
            BasicEffect.View = camera.View;
            BasicEffect.Projection = camera.Projection;
            BasicEffect.EnableDefaultLighting();

            foreach (EffectPass pass in BasicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                BasicEffect.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(
                        PrimitiveType.TriangleList, // primitive type
                        Vertices, // vertex data
                        0, Vertices.Length, // indices offset
                        Indices, // number of vertices
                        0, // index data
                        Indices.Length / 3); // number of primitives(in this case: triangles)
            }

            base.Draw(gameTime, camera, parentTransform);
        }
Пример #4
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            bombTexture = Content.Load<Texture2D>("Textures/Bomb");      // Load the texture
            textFont = Content.Load<SpriteFont>("Fonts/SegoeUI");    // Load the font
            torus = new ModelObject();
            torus.Model = Content.Load<Model>("Models/Cube");
            torus.Texture = Content.Load<Texture2D>("Textures/Stripes");
            torus.Scale *= 5;

            mercury = new Planet();
            mercury.Parent = torus;
            mercury.RevolutionRate = MathHelper.PiOver2;
            mercury.Radius = 10;
            mercury.Scale *= 2;
            mercury.Model = torus.Model;
            mercury.Texture = torus.Texture;

            // TODO: use this.Content to load your game content here
            camera = new Camera();
            camera.Position = new Vector3(0, 0, -20);
            camera.AspectRatio = GraphicsDevice.Viewport.AspectRatio;

            plane = new Common.Plane(99);
            plane.Texture = Content.Load<Texture2D>("Textures/Jellyfish");
            plane.Scale *= 50;
            //plane.RotateX = 0.50f;
            plane.Position = new Vector3(0, -5, 0);

            UIElement background = new UIElement(Content.Load<Texture2D>("Textures/Jellyfish"),
                                    GraphicsDevice.Viewport.Bounds);
            ButtonGroup group = new ButtonGroup();
            group.Children.Add(new Button(Content.Load<Texture2D>("Textures/Stripes"),
                                new Rectangle(40,40,200,25),
                                Content.Load<Texture2D>("Textures/Bomb"),
                                "Play",textFont));

            group.Children.Add(new Button(Content.Load<Texture2D>("Textures/Stripes"),
                                new Rectangle(40,80,200,25),
                                Content.Load<Texture2D>("Textures/Bomb"),
                                "Information",textFont));

            group.Children.Add(new Button(Content.Load<Texture2D>("Textures/Stripes"),
                                new Rectangle(40,120,200,25),
                                Content.Load<Texture2D>("Textures/Bomb"),
                                "Credits",textFont));

            group.Children.Add(new Button(null,
                                new Rectangle(40,160,200,25),
                                Content.Load<Texture2D>("Textures/Bomb"),
                                "Quit",textFont));
            group.Children[0].Clicked += StartNewGame;
            group.Children[3].Clicked += EndGame;
            background.Children.Add(group);

            elements[GameState.Start] = background;
            elements[GameState.Play] = new UIElement();
            elements[GameState.Pause] = background;

            effect = new BasicEffect(GraphicsDevice);
        }
Пример #5
0
 // Matrix? parentTransform = null // this was nullable before
 // 3D Draw which calls children's draw methods.
 // Has three arguments: GameTime, Camera, and parentTransform Matrix
 public virtual void Draw(GameTime gameTime, Camera camera, Matrix parentTransform)
 {
     //Matrix matrix = (parentTransform == null) ? Matrix.Identity : (Matrix)parentTransform;
     foreach (Transform transform in Children)
     {
         transform.Draw(gameTime, camera, World * parentTransform);
     }
 }
Пример #6
0
 // 3D Draw. Has two arguments: GameTime and Camera
 public virtual void Draw(GameTime gameTime, Camera camera)
 {
     Draw(gameTime, camera, Matrix.Identity);
 }
Пример #7
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            textFont = Content.Load<SpriteFont>("Fonts/SegoeUI");    // Load the font
            sphereModel = Content.Load<Model>("Models/Sphere");
            sphereTexture = Content.Load<Texture2D>("Textures/Stripes");

            // TODO: use this.Content to load your game content here
            camera = new Camera();
            camera.Position = new Vector3(0, 0, -20);
            camera.AspectRatio = GraphicsDevice.Viewport.AspectRatio;

            plane = new Common.HeightMap(Content.Load<Texture2D>("Textures/HeightMap"));
            plane.Texture = Content.Load<Texture2D>("Textures/Jellyfish");
            plane.Scale *= 50;
            plane.Position = new Vector3(0, -15, 0);

            effect = new BasicEffect(GraphicsDevice);
            simpleEffect = Content.Load<Effect>("Effects/SimpleEffect");

            AddSphere();
            AddSphere();
            AddSphere();

            ChooseRandomLights();
        }
Пример #8
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            bombTexture = Content.Load<Texture2D>("Textures/Bomb");      // Load the texture
            textFont = Content.Load<SpriteFont>("Fonts/SegoeUI");    // Load the font

            // TODO: use this.Content to load your game content here
            camera = new Camera();
            camera.Position = new Vector3(0, 0, -20);

            camera.AspectRatio = GraphicsDevice.Viewport.AspectRatio;

            plane = new Common.Plane(99);
            plane.Texture = Content.Load<Texture2D>("Textures/Jellyfish");
            plane.Scale *= 50;
            //plane.RotateX = 0.50f;
            plane.Position = new Vector3(0, -5, 0);

            cube = new AnimatedObject();
            cube.Model = Content.Load<Model>("Models/Dude/Dude");
            cube.Scale *= 0.25f;

            applause = Content.Load<SoundEffect>("Sounds/applause");
            currentSound = applause.CreateInstance();

            cube.StartAnimation("Take 001");
            effect = new BasicEffect(GraphicsDevice);
        }
Пример #9
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            segoeFont = Content.Load<SpriteFont>("Fonts/Segoe");

            gameClock = new Clock(Content.Load<Texture2D>("Textures/sprite0_0"), Content.Load<Texture2D>("Textures/Triangle"));
            gameClock.Position = new Vector3(30, 30, -1);
            gameClock.Parent = states[GameState.Play];
            gameClock.TimeUpEvent += GameOver;

            #region Sound Intialization

            // play background music (using the system SoundPlayer which only plays waves...)
            player.SoundLocation = Content.RootDirectory + "\\Sounds\\Acid_Swamps.wav";
            player.PlayLooping();

            click = Content.Load<SoundEffect>("Sounds/click_tiny");
            cannonShot = Content.Load<SoundEffect>("Sounds/cannon");
            woodHit = Content.Load<SoundEffect>("Sounds/wood2");
            rockHit = Content.Load<SoundEffect>("Sounds/crunchy");
            glassHit = Content.Load<SoundEffect>("Sounds/breaking");

            #endregion

            #region Camera Initialization
            cameras = new Camera[3];
            cameras[0] = new Camera();
            cameras[0].Position = new Vector3(0, 0, 10);
            cameras[0].AspectRatio = GraphicsDevice.Viewport.AspectRatio;
            cameras[1] = new Camera();
            cameras[1].RotateX = -MathHelper.PiOver2; // to look down
            cameras[1].Position = new Vector3(0,10,0);
            cameras[1].AspectRatio = GraphicsDevice.Viewport.AspectRatio;
            cameras[2] = new Camera();
            cameras[2].Position = new Vector3(0, 0, 5);
            cameras[2].AspectRatio = GraphicsDevice.Viewport.AspectRatio;

            curCamera = 0; // 0 = behind the cannon
            // 1 = top-down view
            // 2 = first person
            #endregion

            #region Game Objects Initialization
            generator = new TextureGenerator(GraphicsDevice, 256, 256);

            // load ground
            ground = new ModelObject(Content.Load<Model>("Models/Plane"), Vector3.Zero);
            ground.Position = new Vector3(0, -1, 0);
            ground.Scale *= 10.0f;
            ground.Parent = states[GameState.Play];
            ground.Texture = generator.makeGroundTexture();

            // load cannon
            cannon = new Cannon(Content.Load<Model>("Models/Torus"), Content.Load<Texture2D>("Textures/Stripes"), generator.makeBlank(), new Vector3(0,0,5));
            cannon.Parent = states[GameState.Play];
            cannon.FireEvent += FireCannon;
            ball = Content.Load<Model>("Models/Sphere");

            // create the blocks
            cube = Content.Load<Model>("Models/Cube");

            //SkyBox stuff
            skyCube = Content.Load<Model>("Models/Cube");
            skyboxTexture = Content.Load<TextureCube>("Skyboxes/SunnySkybox");
            skyboxEffect = Content.Load<Effect>("Skyboxes/Skybox");
            skybox = new Skybox(skyCube,skyboxTexture,skyboxEffect);
            #endregion

            #region GUI Intialization

            pausePanel = new GUIElement(Content.Load<Texture2D>("Textures/Square"), 200, 200);
            pausePanel.Position = new Vector3(0,20,-1);
            pausePanel.Parent = states[GameState.Pause];

            infoPanel = new GUIElement(Content.Load<Texture2D>("Textures/Square"), 200, 200);
            infoPanel.Position = new Vector3(0, 0, -2);
            infoPanel.Parent = states[GameState.Info];

            mainMenuPanel = new GUIElement(Content.Load<Texture2D>("Textures/Square"), 200, 120);
            mainMenuPanel.Position = new Vector3(0, 0, -2);
            mainMenuPanel.Parent = states[GameState.Menu];

            howToPanel = new GUIElement(Content.Load<Texture2D>("Textures/Square"), 500, 200);
            howToPanel.Position = new Vector3(200, 60, -1);
            howToPanel.eleColor = Color.Yellow;
            howToPanel.Parent = states[GameState.Info];

            playPanel = new GUIElement(Content.Load<Texture2D>("Textures/Square"), 270, 70);
            playPanel.Position = new Vector3(180, 0, -1);
            playPanel.eleColor = Color.SeaShell;
            playPanel.Parent = states[GameState.Play];

            playButton = new Button(40, 50, 50, 25, Content.Load<Texture2D>("Textures/Square"), segoeFont);
            playButton.MouseDown += PlayGame;
            playButton.TextColor = Color.Black;
            playButton.HoverColor = Color.YellowGreen;
            playButton.Text = "Play";

            infoButton = new Button(40, 75, 50, 25, Content.Load<Texture2D>("Textures/Square"), segoeFont);
            infoButton.MouseDown += InfoMenu;
            infoButton.TextColor = Color.Black;
            infoButton.HoverColor = Color.YellowGreen;
            infoButton.Text = "Info";

            quitButton = new Button(40, 75, 50, 25, Content.Load<Texture2D>("Textures/Square"), segoeFont);
            quitButton.MouseDown += QuitGame;
            quitButton.TextColor = Color.Black;
            quitButton.HoverColor = Color.YellowGreen;
            quitButton.Text = "Quit";

            menuButton = new Button(40, 100, 50, 25, Content.Load<Texture2D>("Textures/Square"), segoeFont);
            menuButton.MouseDown += ToMenu;
            menuButton.TextColor = Color.Black;
            menuButton.HoverColor = Color.YellowGreen;
            menuButton.Text = "Main Menu";

            mainMenuButtons = new ButtonGroup(Color.YellowGreen, click);
            mainMenuButtons.addButton(playButton);
            mainMenuButtons.addButton(quitButton);
            mainMenuButtons.Parent = states[GameState.Menu];

            pauseMenuButtons = new ButtonGroup(Color.YellowGreen, click);
            pauseMenuButtons.addButton(playButton);
            pauseMenuButtons.addButton(infoButton);
            pauseMenuButtons.addButton(menuButton);
            pauseMenuButtons.Parent = states[GameState.Pause];

            infoMenuButtons = new ButtonGroup(Color.YellowGreen, click);
            infoMenuButtons.addButton(playButton);
            infoMenuButtons.addButton(menuButton);
            infoMenuButtons.Parent = states[GameState.Info];

            gameOverMenuButtons = new ButtonGroup(Color.YellowGreen, click);
            gameOverMenuButtons.addButton(menuButton);
            gameOverMenuButtons.addButton(quitButton);
            gameOverMenuButtons.Parent = states[GameState.End];
            #endregion GUI Intialization
        }
Пример #10
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            bombTexture = Content.Load<Texture2D>("Textures/Bomb");      // Load the texture
            textFont = Content.Load<SpriteFont>("Fonts/SegoeUI");    // Load the font
            torus = new ModelObject();
            torus.Model = Content.Load<Model>("Models/Cube");
            torus.Texture = Content.Load<Texture2D>("Textures/Stripes");
            torus.Scale *= 5;

            mercury = new Planet();
            mercury.Parent = torus;
            mercury.RevolutionRate = MathHelper.PiOver2;
            mercury.Radius = 10;
            mercury.Scale *= 2;
            mercury.Model = torus.Model;
            mercury.Texture = torus.Texture;

            // TODO: use this.Content to load your game content here
            camera = new Camera();
            camera.Position = new Vector3(0, 0, -20);
            camera.AspectRatio = GraphicsDevice.Viewport.AspectRatio;

            plane = new Common.Plane(99);
            plane.Texture = Content.Load<Texture2D>("Textures/Jellyfish");
            plane.Scale *= 50;
            //plane.RotateX = 0.50f;
            plane.Position = new Vector3(0, -5, 0);

            effect = new BasicEffect(GraphicsDevice);
        }
Пример #11
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()
 {
     this.IsMouseVisible = true;
     ground = GraphicsDevice.Viewport.TitleSafeArea.Height - 40;
     camera = new Camera(viewport);
     contentManager = eContentManager.getInstance(this.Content);
     Globals.contentManager = eContentManager.getInstance();
     Globals.viewport = viewport;
     Globals.font = contentManager.getSpriteFont("myFont");
     //level = new Level(Content.RootDirectory + "/Maps/serializeTest.xml");
     inputManager = new InputHandler.InputManager();
     mainMenu = new MainMenu(LevelManager.LevelManager.LEVEL_DIR);
     base.Initialize();
 }