Example #1
0
        public Game1()
        {
            // Window
            graphicsDeviceManager = new GraphicsDeviceManager(this);
            graphicsDeviceManager.PreferredBackBufferWidth  = Wellknown.Default.Width;
            graphicsDeviceManager.PreferredBackBufferHeight = Wellknown.Default.Height;
            graphicsDeviceManager.ApplyChanges();

            // FPS
            base.IsFixedTimeStep   = true;
            base.TargetElapsedTime = TimeSpan.FromSeconds(1d / Wellknown.Default.FPS);

            // Content
            string absolutePath = Path.Combine(Environment.CurrentDirectory, "Content");

            base.Content.RootDirectory = absolutePath;
            Game1.contentManager       = base.Content;

            // others
            base.Window.Title   = "Pong!";
            base.IsMouseVisible = true;

            // Iniciar assets
            jugador   = new Jugador();
            pelota    = new Pelota();
            enemigo   = new Enemigo();
            gameState = GameState.modo_juego;

            SpriteFont _spriteFont = Tools.Font.GenerateFont(texture2D: Tools.Texture.GetTexture(graphicsDeviceManager.GraphicsDevice, contentManager, "MyFont_PNG_260x56"), chars: Wellknown.Font.chars);

            gameOverLabel = new Label(new Rectangle(0, 0, 700, 250), _spriteFont, "GAME OVER!\nPRESS 'P' TO RESTART", Label.TextAlignment.Midle_Center, Color.Green, lineSpacing: 15);

            // Initialize Game
            base.Initialize();
        }
Example #2
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }


            switch (gameState)
            {
            case GameState.modo_juego:
                pelota.Update(enemigo, jugador);
                enemigo.Update(pelota);
                jugador.Update();

                if (pelota.rectangulo.X < jugador.rectangulo.X || pelota.rectangulo.X > enemigo.rectangulo.X)
                {
                    gameState = GameState.game_over;
                }

                break;

            case GameState.game_over:
                if (Keyboard.GetState().IsKeyDown(Keys.P))
                {
                    pelota    = new Pelota();
                    gameState = GameState.modo_juego;
                }
                break;

            case GameState.pausa:
                break;
            }

            base.Update(gameTime);
        }