public static void brick_applyReflectPower(Ball ball, Brick brick) { currentHit = brick.brick_Level; if (currentHit != prevHit) // if the same brick was previously hit, don't increase ball velocity { if (currentHit > prevHit) // if a higher point brick is struck, apply that brick's reflective force { apply_Level++; apply_ForceLevel(ball); prevHit = currentHit; } else //if a lower point brick is struck, use 2 levels lower reflective force { apply_Level = prevHit - 2; apply_ForceLevel(ball); prevHit = currentHit; } } else if (currentHit != apply_Level) // in normal success scenario, both levels should be the same { // if not, then each hit of the same brick will use the next upper level of force. apply_Level++; apply_ForceLevel(ball); } }
public void check_Collisions(Ball ball, bool killable) { for (int r = 0; r < rows; r++) { for (int u = 0; u < bricks_per_row; u++) { Collisions.Check_Sprite_colision(ball, brick_layout[r,u], killable); } } }
public void Rebound_from_Paddle(Ball ball) { if (this.box.Intersects(ball.box)) { deviation = (box.Min.X + mSpriteTexture.Width / 2) -(ball.box.Min.X + ball.get_Texture().Width / 2); if (ball.Direction.X > 0) { ball.Speed.X -= ball.Old_deviation; ball.Speed.X += (deviation * -1 * DEV_MAGNITUDE); ball.Old_deviation = (deviation * -1 * DEV_MAGNITUDE); } else { ball.Speed.X -= ball.Old_deviation; ball.Speed.X += (deviation * DEV_MAGNITUDE); ball.Old_deviation = (deviation * DEV_MAGNITUDE); } } }
protected override void Initialize() { height = graphics.GraphicsDevice.Viewport; height.Height = 800; graphics.GraphicsDevice.Viewport = height; this.graphics.PreferredBackBufferHeight = 800; this.graphics.ApplyChanges(); ball_1 = new Ball(new Vector2(400, 400), // init Position 2, // Speed multi, multiplies final speed vector // after all other modifications in the game lifetime new Vector2(1, 1)); // init Direction ball_2 = new Ball(new Vector2(400, 400), 2, new Vector2(1, 1)); paddle = new Paddle(this.graphics); theBrick_Manager = new Brick_Manager(this.graphics); theScore_Manager = new Score_Manager(this.graphics); theMenu_Manager = new Menu_Manager(this.graphics); // Initializing audio objects theAudioEngine = new AudioEngine("Content\\Audio\\Breakout_Audio.xgs"); theWaveBank = new WaveBank(theAudioEngine, "Content\\Audio\\Wave Bank.xwb"); theSoundBank = new SoundBank(theAudioEngine, "Content\\Audio\\Sound Bank.xsb"); theMusic_Manager = new Music_Manager(); gameover = false; base.Initialize(); }
private static void apply_ForceLevel(Ball ball) { ball.Speed.X -= applied_oldForce; ball.Speed.Y -= applied_oldForce; switch (apply_Level) { case 0: applied_oldForce = 0; ball.Speed.X += 0; ball.Speed.Y += 0; break; case 1: ball.Speed.X += yellow_reflectForce; ball.Speed.Y += yellow_reflectForce; applied_oldForce = yellow_reflectForce; break; case 2: ball.Speed.X += red_reflectForce; ball.Speed.Y += red_reflectForce; applied_oldForce = red_reflectForce; break; case 3: ball.Speed.X += green_reflectForce; ball.Speed.Y += green_reflectForce; applied_oldForce = green_reflectForce; break; case 4: ball.Speed.X += blue_reflectForce; ball.Speed.Y += blue_reflectForce; applied_oldForce = blue_reflectForce; break; default: break; } }
/// <summary> /// Determines if ball hit top wall and shrinks the paddle by 1/3. /// </summary> /// <param name="graphics"></param> /// <param name="ball"></param> /// <param name="paddle"></param> public static void upperWallHit_shrink(GraphicsDeviceManager graphics, Ball ball, Paddle paddle) { if (paddle.isNotShrunk) { if (ball.Prev_Pos_min.Y < 0) // Top border check { paddle.set_Scale(new Vector2(paddle.get_Scale().X * 0.333f, 1)); // 0.333f = 1/3 scale paddle.isNotShrunk = false; // Shrinking only happens once, subsequent top wall colisions will no shrink it further } } }