public Ball(PhysicsBody physicsBody) { m_physicsBody = physicsBody; this.TextureInfo = new TextureInfo(new Texture2D("Application/images/ball.png", false)); this.Scale = this.TextureInfo.TextureSizef; this.Pivot = new Sce.PlayStation.Core.Vector2(0.5f, 0.5f); this.Position = new Sce.PlayStation.Core.Vector2( Director.Instance.GL.Context.GetViewport().Width / 2 - Scale.X / 2, Director.Instance.GL.Context.GetViewport().Height / 2 - Scale.Y / 2); //Right angles are exceedingly boring, so make sure we dont start on one //So if our Random angle is between 90 +- 25 degrees or 270 +- 25 degrees //we add 25 degree to value, ie, making 90 into 115 instead System.Random rand = new System.Random(); float angle = (float)rand.Next(0, 360); if ((angle % 90) <= 25) { angle += 25.0f; } this.m_physicsBody.Velocity = new Vector2(0.0f, BALL_VELOCITY).Rotate(PhysicsUtility.GetRadian(angle)); Scheduler.Instance.ScheduleUpdateForTarget(this, 0, false); }
private void ResetBall() { //Move ball to screen center and release in a random directory m_physics.SceneBodies[(int)PongPhysics.BODIES.Ball].Position = new Vector2(Director.Instance.GL.Context.GetViewport().Width / 2.0f, Director.Instance.GL.Context.GetViewport().Height / 2.0f) / PongPhysics.PtoM; System.Random rand = new System.Random(); float angle = (float)rand.Next(0, 360); if ((angle % 90) <= 15) { angle += 15.0f; } m_physics.SceneBodies[(int)PongPhysics.BODIES.Ball].Velocity = new Vector2(0.0f, 5.0f).Rotate(PhysicsUtility.GetRadian(angle)); }