Example #1
0
        float time = 3.0f; // three seconds to hit target

        #endregion Fields

        #region Constructors

        // ignore this constructor, used it for the lab
        public Cannonball(Model ball, Vector3 position, ModelObject target)
            : base(ball, position)
        {
            this.target = target;

            // using Velocity ONLY
            // sphereObject.Velocity = Vector3.Normalize(cubeObject.Position - sphereObject.Position) * 2;

            Vector3 bulletDistance = target.Position - Position;
            Acceleration = new Vector3(0.0f, -9.81f, 0.0f); // gravity
            Velocity = (bulletDistance - 0.5f * Acceleration * time * time) / time;
        }
        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
        }
Example #3
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);
        }
Example #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);
            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
        }
Example #5
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);
        }