protected override void Initialize() { spriteBatch = new SpriteBatch(GraphicsDevice); //Ball texture spriteTexture = Content.Load<Texture2D>("ball1.png"); //Bar(player) textures topBorderTexture = Content.Load<Texture2D>("bar.png"); leftBorderTexture = Content.Load<Texture2D>("bar.png"); rightBorderTexture = Content.Load<Texture2D>("bar.png"); bottomBorderTexture = Content.Load<Texture2D>("bar.png"); //Font texture font = Content.Load<SpriteFont>("font"); base.Window.AllowUserResizing = false; //initialize bar controls topBarKeys[0] = Keys.T; //LEFT topBarKeys[1] = Keys.U; //RIGHT topBarKeys[2] = Keys.Y; //BOOST bottomBarKeys[0] = Keys.V; //LEFT bottomBarKeys[1] = Keys.N; //RIGHT bottomBarKeys[2] = Keys.B; //BOOST leftBarKeys[0] = Keys.A; //UP leftBarKeys[1] = Keys.D; //DOWN leftBarKeys[2] = Keys.S; //BOOST rightBarKeys[0] = Keys.L; //UP rightBarKeys[1] = Keys.J; //DOWN rightBarKeys[2] = Keys.K; //BOOST //initialize bar properties topBarSpeed = barSpeed; bottomBarSpeed = barSpeed; leftBarSpeed = barSpeed; rightBarSpeed = barSpeed; topBarLength = barLength; bottomBarLength = barLength; leftBarLength = barLength; rightBarLength= barLength; //initialize ball ballSize = 16; ballSpeed = 500.0f; ballSpeedInc = 20.0f; ballSpeedLimit = 800f; ballXVelocity = -300.0f; ballYVelocity = 0.0f; collision = false; ballStartPos = (fieldSize - ballSize) / 2; ball = new Rectangle(ballStartPos, ballStartPos, ballSize, ballSize); //initialize bars int barStartPos = (fieldSize - barLength) / 2; topBar = new Rectangle(barStartPos, barToBorderDist, barLength, barWidth); bottomBar = new Rectangle(barStartPos, fieldSize-barToBorderDist-barWidth, barLength, barWidth); leftBar = new Rectangle(barToBorderDist, barStartPos, barWidth, barLength); rightBar = new Rectangle(fieldSize - barToBorderDist - barWidth, barStartPos, barWidth, barLength); //initialize borders topBorder = new Rectangle(0, 0, fieldSize, borderWidth); bottomBorder = new Rectangle(0, fieldSize - borderWidth, fieldSize, borderWidth); leftBorder = new Rectangle(0, 0, borderWidth, fieldSize); rightBorder = new Rectangle(fieldSize - borderWidth, 0, borderWidth, fieldSize); //initialize player lives topPlayerLives = bottomPlayerLives = leftPlayerLives = rightPlayerLives = lives; //powerup powerup = new Powerup[3]; powerupCount = 0; for(int i=0;i<powerup.Length;i++) powerup[i] = new Powerup(spriteBatch, spriteTexture, GraphicsDevice,i); gameTime = 0; base.Initialize(); }
protected override void Initialize() { spriteBatch = new SpriteBatch(GraphicsDevice); bleepHigh = Content.Load<SoundEffect>("bleep-high"); bleepLow = Content.Load<SoundEffect>("bleep-low"); //Ball texture spriteTexture = Content.Load<Texture2D>("ball1.png"); //Border textures borderTexture = Content.Load<Texture2D>("bar.png"); //Player Textures barTexture = Content.Load<Texture2D>("ball1.png"); //Font texture font = Content.Load<SpriteFont>("font"); test = new Rectangle(400, 400, 64, 64); base.Window.AllowUserResizing = false; //initialize bar controls topBarKeys[0] = Keys.T; //LEFT topBarKeys[1] = Keys.U; //RIGHT topBarKeys[2] = Keys.Y; //BOOST bottomBarKeys[0] = Keys.V; //LEFT bottomBarKeys[1] = Keys.N; //RIGHT bottomBarKeys[2] = Keys.B; //BOOST leftBarKeys[0] = Keys.A; //UP leftBarKeys[1] = Keys.D; //DOWN leftBarKeys[2] = Keys.S; //BOOST rightBarKeys[0] = Keys.L; //UP rightBarKeys[1] = Keys.J; //DOWN rightBarKeys[2] = Keys.K; //BOOST controls[0, 0] = topBarKeys[0]; controls[0, 1] = topBarKeys[1]; controls[0, 2] = topBarKeys[2]; controls[1, 0] = bottomBarKeys[0]; controls[1, 1] = bottomBarKeys[1]; controls[1, 2] = bottomBarKeys[2]; controls[2, 0] = leftBarKeys[0]; controls[2, 1] = leftBarKeys[1]; controls[2, 2] = leftBarKeys[2]; controls[3, 0] = rightBarKeys[0]; controls[3, 1] = rightBarKeys[1]; controls[3, 2] = rightBarKeys[2]; //initialize ball balls = new List<Ball>(); balls.Insert(0, new Ball(fieldSize, ballSize, ballSpeed, ballSpeedLimit, ballSpeedInc, bounceCorrection, false, spriteBatch, spriteTexture)); firstCycle = true; //initialize bars //barKeys = new Keys[][]{ topBarKeys, bottomBarKeys, leftBarKeys, rightBarKeys }; //put all the inputs in 1 array int barStartPos = (fieldSize - barLength) / 2; //initialize player lives playerLives = new int[4] {lives,lives,lives,lives}; //powerup powerup = new Powerup[3]; powerupCount = 0; for(int i=0;i<powerup.Length;i++) powerup[i] = new Powerup(spriteBatch, spriteTexture, GraphicsDevice,i); //Inititialize borders borders = new Border[4]; borders[0] = new Border(spriteBatch, borderTexture, 0, 0, "Lying");//Top border borders[1] = new Border(spriteBatch, borderTexture, 0, (fieldSize - borderWidth), "Lying");//Bottom border borders[2] = new Border(spriteBatch, borderTexture, 0, 0, "Standing");//Left border borders[3] = new Border(spriteBatch, borderTexture, (fieldSize - borderWidth), 0, "Standing");//Right border //initialize players playerBars = new Bar[4]; playerBars[0] = new Bar(borders, spriteBatch, barTexture, barStartPos, barToBorderDist, topBarKeys, "Lying");//Topp bar playerBars[1] = new Bar(borders, spriteBatch, barTexture, barStartPos, fieldSize - barToBorderDist - barWidth, bottomBarKeys, "Lying");//Bottom bar playerBars[2] = new Bar(borders, spriteBatch, barTexture, barToBorderDist, barStartPos, leftBarKeys ,"Standing");//Left bar playerBars[3] = new Bar(borders, spriteBatch, barTexture, fieldSize - barToBorderDist - barWidth, barStartPos, rightBarKeys ,"Standing");//Right bar input = new KeyboardController(controls); gameTime = 0; setPlayersAmount(); base.Initialize(); }