Example #1
0
        protected override void Initialize()
        {
            uint version = 0;
            FMOD.RESULT result;

            result = FMOD.Factory.System_Create(ref SoundSystem);
            ERRCHECK(result);

            result = SoundSystem.getVersion(ref version);
            ERRCHECK(result);

            if (version < FMOD.VERSION.number) {
                System.Diagnostics.Debug.WriteLine("Error!  You are using an old version of FMOD " + version.ToString("X") + ".  This program requires " + FMOD.VERSION.number.ToString("X") + ".");
            }

            result = SoundSystem.init(32, FMOD.INITFLAG.NORMAL, (IntPtr)null);
            ERRCHECK(result);

            VectorRenderer = new VectorRenderComponent(this,
                               Content,
                               "Content\\Effects\\VectorLineEffect");
            this.Components.Add(VectorRenderer);

            sprite = new SpriteBatch(Graphics.GraphicsDevice);
            font = Content.Load<SpriteFont>("Content\\Tahoma");
            fontBold = Content.Load<SpriteFont>("Content\\TahomaBold");

            gamepad = Content.Load<Texture2D>("Content\\Textures\\Controls_Gamepad");
            keyboard = Content.Load<Texture2D>("Content\\Textures\\Controls_Keyboard");
            mouse = Content.Load<Texture2D>("Content\\Textures\\Controls_Mouse");

            ////////////////////
            // register groups
            BehaviorGroup camera = Scene.Coordinator.Register("Camera");
            camera.Associate(new LookAtCamera());//new Camera());
            camera.Associate(new CameraController());

            BehaviorGroup field = Scene.Coordinator.Register("Playing Field");
            field.Associate(new PlayingField(20, 0.25f, 10));
            field.Associate(new PlayingFieldVisual());

            BehaviorGroup player1 = Scene.Coordinator.Register("Player");
            player1.Associate(new SpringSkeleton());
            player1.Associate(new PlayerController(PlayerIndex.One, ControlScheme.Gamepad));
            player1.Associate(new PlayerVisual());
            player1.Associate(new PlayerTailRepresentation());

            BehaviorGroup player2 = Scene.Coordinator.Register("Player");
            player2.Associate(new SpringSkeleton());
            player2.Associate(new PlayerController(PlayerIndex.Two, ControlScheme.Mouse));
            player2.Associate(new PlayerVisual());
            player2.Associate(new PlayerTailRepresentation());

            BehaviorGroup ball = Scene.Coordinator.Register("Ball");
            ball.Associate(new BallVisual());
            ball.Associate(new BallController());
            ball.Associate(new BallRepresentation());

            BehaviorGroup player1Score = Scene.Coordinator.Register("Score Counter");
            player1Score.Associate(new ScoreCount());
            player1Score.Associate(new ScoreVisual());

            BehaviorGroup goal1 = Scene.Coordinator.Register("Goal");
            goal1.Associate(new GoalRepresentation(PlayerIndex.One));
            goal1.Associate(new GoalVisual());

            BehaviorGroup goal2 = Scene.Coordinator.Register("Goal");
            goal2.Associate(new GoalRepresentation(PlayerIndex.Two));
            goal2.Associate(new GoalVisual());

            BehaviorGroup advertisement1 = Scene.Coordinator.Register("Commercial");
            advertisement1.Associate(new BarrierVisual());
            BehaviorGroup advertisement2 = Scene.Coordinator.Register("Commercial");
            advertisement2.Associate(new BarrierVisual());

            BehaviorGroup collisionChecks = Scene.Coordinator.Register("Collision Check");
            collisionChecks.Associate(new CollisionCheck());

            ////////////////////
            // set defaults
            camera.Get<Transform>().Position = new Vector3(0, 12.5f, 14);

            collisionChecks.Get<CollisionCheck>().OwnGoal += new EventHandler<OwnGoalEventArgs>(Collision_OwnGoal);

            advertisement1.Get<Transform>().Position = new Vector3(-(field.Get<PlayingField>().Width / 4), 0.75f, -(field.Get<PlayingField>().Depth / 2));
            advertisement1.Get<Transform>().Scale = new Vector3((field.Get<PlayingField>().Width / 2) - 0.5f, 1, 1);
            advertisement1.Get<Transform>().Rotation = Matrix.CreateRotationX(MathHelper.ToRadians(-35));
            advertisement1.Get<BarrierVisual>().Advertisement = Content.Load<Texture2D>("Content\\Textures\\Groov");

            advertisement2.Get<Transform>().Position = new Vector3((field.Get<PlayingField>().Width / 4), 0.75f, -(field.Get<PlayingField>().Depth / 2));
            advertisement2.Get<Transform>().Scale = new Vector3((field.Get<PlayingField>().Width / 2) - 0.5f, 1, 1);
            advertisement2.Get<Transform>().Rotation = Matrix.CreateRotationX(MathHelper.ToRadians(-35));
            advertisement2.Get<BarrierVisual>().Advertisement = Content.Load<Texture2D>("Content\\Textures\\Midget");

            goal1.Get<Transform>().Position = new Vector3(-(field.Get<PlayingField>().Width / 2) - (goal1.Get<GoalRepresentation>().Extents.X / 2) + 0.5f, goal1.Get<GoalRepresentation>().Extents.Y / 2, 0);
            goal2.Get<Transform>().Position = new Vector3((field.Get<PlayingField>().Width / 2) + (goal2.Get<GoalRepresentation>().Extents.X / 2) - 0.5f, goal2.Get<GoalRepresentation>().Extents.Y / 2, 0);

            // player1
            SpringSkeleton skeleton = player1.Get<SpringSkeleton>();

            skeleton.Coefficient = 0.3f;
            skeleton.Elasticity = 0.01f;
            skeleton.EnergyLoss = 0.86f;

            skeleton.Enabled = true;

            SpringHelper.CreateChain(skeleton, 5, 0.35f, new Vector3(-1, 0, 0), false);

            skeleton.Nodes[skeleton.Nodes.Count - 1].Mass = 2;

            player1.Get<PlayerController>().Head = skeleton.Nodes[0];
            player1.Get<PlayerController>().Tail = skeleton.Nodes[skeleton.Nodes.Count - 1];

            // player2
            SpringSkeleton skeleton2 = player2.Get<SpringSkeleton>();

            skeleton2.Coefficient = 0.3f;
            skeleton2.Elasticity = 0.01f;
            skeleton2.EnergyLoss = 0.86f;

            skeleton2.Enabled = true;

            SpringHelper.CreateChain(skeleton2, 5, 0.35f, new Vector3(1, 0, 0), true);

            skeleton2.Nodes[skeleton2.Nodes.Count - 1].Mass = 2;

            player2.Get<PlayerController>().Head = skeleton2.Nodes[0];
            player2.Get<PlayerController>().Tail = skeleton2.Nodes[skeleton2.Nodes.Count - 1];

            base.Initialize();

            Scene.Start();

            // hack - this is because the dependency to the PlayingField behavior has not been injected before Scene.Start()
            ball.Get<BallController>().Reset();
        }
Example #2
0
        protected override void Initialize()
        {
            uint version = 0;

            FMOD.RESULT result;

            result = FMOD.Factory.System_Create(ref SoundSystem);
            ERRCHECK(result);

            result = SoundSystem.getVersion(ref version);
            ERRCHECK(result);

            if (version < FMOD.VERSION.number)
            {
                System.Diagnostics.Debug.WriteLine("Error!  You are using an old version of FMOD " + version.ToString("X") + ".  This program requires " + FMOD.VERSION.number.ToString("X") + ".");
            }

            result = SoundSystem.init(32, FMOD.INITFLAG.NORMAL, (IntPtr)null);
            ERRCHECK(result);

            VectorRenderer = new VectorRenderComponent(this,
                                                       Content,
                                                       "Content\\Effects\\VectorLineEffect");
            this.Components.Add(VectorRenderer);

            sprite   = new SpriteBatch(Graphics.GraphicsDevice);
            font     = Content.Load <SpriteFont>("Content\\Tahoma");
            fontBold = Content.Load <SpriteFont>("Content\\TahomaBold");

            gamepad  = Content.Load <Texture2D>("Content\\Textures\\Controls_Gamepad");
            keyboard = Content.Load <Texture2D>("Content\\Textures\\Controls_Keyboard");
            mouse    = Content.Load <Texture2D>("Content\\Textures\\Controls_Mouse");

            ////////////////////
            // register groups
            BehaviorGroup camera = Scene.Coordinator.Register("Camera");

            camera.Associate(new LookAtCamera());//new Camera());
            camera.Associate(new CameraController());

            BehaviorGroup field = Scene.Coordinator.Register("Playing Field");

            field.Associate(new PlayingField(20, 0.25f, 10));
            field.Associate(new PlayingFieldVisual());

            BehaviorGroup player1 = Scene.Coordinator.Register("Player");

            player1.Associate(new SpringSkeleton());
            player1.Associate(new PlayerController(PlayerIndex.One, ControlScheme.Gamepad));
            player1.Associate(new PlayerVisual());
            player1.Associate(new PlayerTailRepresentation());

            BehaviorGroup player2 = Scene.Coordinator.Register("Player");

            player2.Associate(new SpringSkeleton());
            player2.Associate(new PlayerController(PlayerIndex.Two, ControlScheme.Mouse));
            player2.Associate(new PlayerVisual());
            player2.Associate(new PlayerTailRepresentation());

            BehaviorGroup ball = Scene.Coordinator.Register("Ball");

            ball.Associate(new BallVisual());
            ball.Associate(new BallController());
            ball.Associate(new BallRepresentation());

            BehaviorGroup player1Score = Scene.Coordinator.Register("Score Counter");

            player1Score.Associate(new ScoreCount());
            player1Score.Associate(new ScoreVisual());

            BehaviorGroup goal1 = Scene.Coordinator.Register("Goal");

            goal1.Associate(new GoalRepresentation(PlayerIndex.One));
            goal1.Associate(new GoalVisual());

            BehaviorGroup goal2 = Scene.Coordinator.Register("Goal");

            goal2.Associate(new GoalRepresentation(PlayerIndex.Two));
            goal2.Associate(new GoalVisual());

            BehaviorGroup advertisement1 = Scene.Coordinator.Register("Commercial");

            advertisement1.Associate(new BarrierVisual());
            BehaviorGroup advertisement2 = Scene.Coordinator.Register("Commercial");

            advertisement2.Associate(new BarrierVisual());

            BehaviorGroup collisionChecks = Scene.Coordinator.Register("Collision Check");

            collisionChecks.Associate(new CollisionCheck());

            ////////////////////
            // set defaults
            camera.Get <Transform>().Position = new Vector3(0, 12.5f, 14);

            collisionChecks.Get <CollisionCheck>().OwnGoal += new EventHandler <OwnGoalEventArgs>(Collision_OwnGoal);

            advertisement1.Get <Transform>().Position          = new Vector3(-(field.Get <PlayingField>().Width / 4), 0.75f, -(field.Get <PlayingField>().Depth / 2));
            advertisement1.Get <Transform>().Scale             = new Vector3((field.Get <PlayingField>().Width / 2) - 0.5f, 1, 1);
            advertisement1.Get <Transform>().Rotation          = Matrix.CreateRotationX(MathHelper.ToRadians(-35));
            advertisement1.Get <BarrierVisual>().Advertisement = Content.Load <Texture2D>("Content\\Textures\\Groov");

            advertisement2.Get <Transform>().Position          = new Vector3((field.Get <PlayingField>().Width / 4), 0.75f, -(field.Get <PlayingField>().Depth / 2));
            advertisement2.Get <Transform>().Scale             = new Vector3((field.Get <PlayingField>().Width / 2) - 0.5f, 1, 1);
            advertisement2.Get <Transform>().Rotation          = Matrix.CreateRotationX(MathHelper.ToRadians(-35));
            advertisement2.Get <BarrierVisual>().Advertisement = Content.Load <Texture2D>("Content\\Textures\\Midget");

            goal1.Get <Transform>().Position = new Vector3(-(field.Get <PlayingField>().Width / 2) - (goal1.Get <GoalRepresentation>().Extents.X / 2) + 0.5f, goal1.Get <GoalRepresentation>().Extents.Y / 2, 0);
            goal2.Get <Transform>().Position = new Vector3((field.Get <PlayingField>().Width / 2) + (goal2.Get <GoalRepresentation>().Extents.X / 2) - 0.5f, goal2.Get <GoalRepresentation>().Extents.Y / 2, 0);

            // player1
            SpringSkeleton skeleton = player1.Get <SpringSkeleton>();

            skeleton.Coefficient = 0.3f;
            skeleton.Elasticity  = 0.01f;
            skeleton.EnergyLoss  = 0.86f;

            skeleton.Enabled = true;

            SpringHelper.CreateChain(skeleton, 5, 0.35f, new Vector3(-1, 0, 0), false);

            skeleton.Nodes[skeleton.Nodes.Count - 1].Mass = 2;

            player1.Get <PlayerController>().Head = skeleton.Nodes[0];
            player1.Get <PlayerController>().Tail = skeleton.Nodes[skeleton.Nodes.Count - 1];

            // player2
            SpringSkeleton skeleton2 = player2.Get <SpringSkeleton>();

            skeleton2.Coefficient = 0.3f;
            skeleton2.Elasticity  = 0.01f;
            skeleton2.EnergyLoss  = 0.86f;

            skeleton2.Enabled = true;

            SpringHelper.CreateChain(skeleton2, 5, 0.35f, new Vector3(1, 0, 0), true);

            skeleton2.Nodes[skeleton2.Nodes.Count - 1].Mass = 2;

            player2.Get <PlayerController>().Head = skeleton2.Nodes[0];
            player2.Get <PlayerController>().Tail = skeleton2.Nodes[skeleton2.Nodes.Count - 1];

            base.Initialize();

            Scene.Start();

            // hack - this is because the dependency to the PlayingField behavior has not been injected before Scene.Start()
            ball.Get <BallController>().Reset();
        }