Exemplo n.º 1
0
        public PlayingState(StateManager stateManager,
                            ISoundEngine soundEngine,
                            Renderer renderer,
                            ResourceManager resourceManager) : base(stateManager)
        {
            physics  = new Physics();
            contacts = new List <Physics.Contact>();

            physics.Collision += (sender, contact) =>
            {
                if (contact.collider == Collider.Paddle)
                {
                    soundEngine.Play2D(ResourceManager.MediaPath + "puckHitPaddle.wav");
                    contacts.Add(contact);
                }
                if (contact.collider == Collider.Table)
                {
                    soundEngine.Play2D(ResourceManager.MediaPath + "puckHitWall.wav");
                    contacts.Add(contact);
                }
            };


            tableGraphicsObject = new Visual(
                GeometryFactory.CreateBox(
                    new Box2(-Constants.tableWidth * 0.5f, Constants.tableHeight * 0.5f,
                             Constants.tableWidth * 0.5f, -Constants.tableHeight * 0.5f)),
                new TextureEffect("table.png"));
            puckGraphicsObject = new Visual(
                GeometryFactory.CreateCircle(Constants.puckRadius, new Color4(1, 0, 0, 1)),
                new VertexColorEffect());
            paddleGraphicsObjects    = new Visual[2];
            paddleGraphicsObjects[0] = new Visual(
                GeometryFactory.CreateCircle(Constants.paddleRadius, new Color4(1, 1, 1, 1)),
                new VertexColorEffect());
            paddleGraphicsObjects[1] = new Visual(
                GeometryFactory.CreateCircle(Constants.paddleRadius, new Color4(1, 1, 1, 1)),
                new VertexColorEffect());

            gameFrame = new GameFrame();
            ai        = new AIPlayer();
        }
Exemplo n.º 2
0
 public Button(Effect effect, OpenTK.Box2 b)
 {
     this.graphicsObject = new Visual(GeometryFactory.CreateBox(b), effect);
     box     = b;
     pressed = false;
 }
Exemplo n.º 3
0
        protected override void OnLoad(EventArgs e)
        {
            AnimationState beginPlayState, winnerState, loserState, newGameState;
            StartMenuState startMenuState;
            GameOverState  gameOverState;
            PlayingState   playingState;

            Animation readyGoAnimation;
            Animation newGameAnimation;
            Animation winAnimation;
            Animation loseAnimation;

            OpenTK.Box2 box = new OpenTK.Box2(
                new OpenTK.Vector2(-Constants.tableWidth * 0.5f, Constants.tableHeight * 0.5f),
                new OpenTK.Vector2(Constants.tableWidth * 0.5f, -Constants.tableHeight * 0.5f));
            Geometry boxGeometry = GeometryFactory.CreateBox(box);

            readyGoAnimation = new Animation();
            readyGoAnimation.AddFrame(new Visual(boxGeometry,
                                                 new TextureEffect("ready.png")), 0.3f, box);

            readyGoAnimation.AddFrame(new Visual(boxGeometry,
                                                 new TextureEffect("go.png")), 0.2f, box);

            newGameAnimation = new Animation();
            newGameAnimation.AddFrame(new Visual(boxGeometry,
                                                 new TextureEffect("newGame.png")), 0.1f, box);
            newGameAnimation.AddFrame(new Visual(boxGeometry,
                                                 new TextureEffect("countDown3.png")), 0.1f, box);
            newGameAnimation.AddFrame(new Visual(boxGeometry,
                                                 new TextureEffect("countDown2.png")), 0.1f, box);
            newGameAnimation.AddFrame(new Visual(boxGeometry,
                                                 new TextureEffect("countDown1.png")), 0.1f, box);

            winAnimation = new Animation();
            winAnimation.AddFrame(new Visual(boxGeometry,
                                             new TextureEffect("winner.png")), 2.0f, box);

            loseAnimation = new Animation();
            loseAnimation.AddFrame(new Visual(boxGeometry,
                                              new TextureEffect("loser.png")), 2.0f, box);

            beginPlayState = new AnimationState(stateManager, soundEngine, readyGoAnimation, "", StateId.Pop);
            winnerState    = new AnimationState(stateManager, soundEngine, winAnimation, "", StateId.GameOver);
            loserState     = new AnimationState(stateManager, soundEngine, loseAnimation, "", StateId.GameOver);
            newGameState   = new AnimationState(stateManager, soundEngine, newGameAnimation, ResourceManager.MediaPath + "countdown.wav",
                                                StateId.BeginPlay);
            startMenuState = new StartMenuState(stateManager, resourceManager);
            playingState   = new PlayingState(stateManager, soundEngine, renderer, resourceManager);
            gameOverState  = new GameOverState(stateManager, resourceManager);

            stateManager.Add(StateId.Menu, startMenuState);
            stateManager.Add(StateId.Playing, playingState);
            stateManager.Add(StateId.Winner, winnerState);
            stateManager.Add(StateId.Loser, loserState);
            stateManager.Add(StateId.BeginPlay, beginPlayState);
            stateManager.Add(StateId.GameOver, gameOverState);
            stateManager.Add(StateId.NewGame, newGameState);



            stateManager.Change(StateId.Menu);
        }