public PlayerInput(GameState state, Paddle target, PlayerInputType key, float distance) : base(state) { Target = target; Request = key; Distance = Math.Abs(distance); }
public PaddleHit(GameState state, Paddle target, float[] velocity, float[] position) : base(state) { Target = target; Velocity[0] = velocity[0]; Velocity[1] = velocity[1]; Position[0] = position[0]; Position[1] = position[1]; if (target == state.AiPaddle) Type = SparkleType.SPARKLE_AI; else if (target == state.PlayerPaddle) Type = SparkleType.SPARKLE_PLAYER; else Type = SparkleType.SPARKLE_WALL; }
public void Update(Ball b, Paddle p) { float target = 0f; if (b.Velocity [1] > 0) target = b.Position [0]; float distance_to_target = Math.Abs(target - p.Position [0]); if (distance_to_target < p.Speed) { distance_to_target = distance_to_target / 10f; if (distance_to_target < 1f) distance_to_target = 0f; } if (target > p.Position[0]) p.MoveRight(distance_to_target); if (target < p.Position[0]) p.MoveLeft(distance_to_target); }
public void Update(Ball b, Paddle p) { var target = b.Position [0]; float distance_to_target = Math.Abs(target - p.Position [0]); if (distance_to_target < 1f) return; /* Don't jerk */ if ((distance_to_target > 2f) && (distance_to_target < 2.5f)) { distance_to_target = 0.3f; } if (target > p.Position[0]) p.MoveRight(distance_to_target); if (target < p.Position[0]) p.MoveLeft(distance_to_target); }
/** Reset the ball position and start again */ public void NewGame() { PlayerPaddle = new Paddle(this); AiPaddle = new Paddle(this); Ball = new Ball(this); Field = new Field(this, Camera()); Sparkle = new Sparkle(this); RainbowTrail = new RainbowTrail(this); Flare = new Ps.Model.Object.Flare(this); Collectables = new Collectables(this); /* actions */ SetupActions(); _input = new GameInput(this); Game.SoundReset(); // reload /* Set initial paddle positions */ PlayerPaddle.Position[0] = 0f; PlayerPaddle.Position[1] = Field.Bounds[1] + nLayout.DistanceInWorld(14f, nAxis.Y, _camera);; AiPaddle.Position[0] = 0f; AiPaddle.Position[1] = Field.Bounds[3] - AiPaddle.Size[1] - nLayout.DistanceInWorld(7f, nAxis.Y, _camera); var direction = new nGLine() { P1 = new float[2] { 0, 0 }, P2 = new float[2] { nRand.Float(0f, 1f), nRand.Float(1f, 0.3f) } }; var unit = direction.Unit; Ball.Position[0] = 0; Ball.Position[1] = 0; Ball.Velocity[0] = unit[0] * 35f; Ball.Velocity[1] = unit[1] * 35f; /* reset paddles */ AiPaddle.Ai = new EasyAiProfile(); AiPaddle.Speed = AiPaddle.Ai.Speed; PlayerPaddle.Speed = Config.PlayerSpeed; AiPaddle.Position[0] = 0; PlayerPaddle.Position[0] = 0; /* ai */ Activated = false; Camera().Pipe.Drawables.Clear(); Camera().Pipe.Render(); }
private void HandlePaddleHit(Paddle p) { var magic_number = 0.6f; var xdelta = (p.Position[0] - Position[0]) / (p.Size[0]); var factor = xdelta / magic_number; if (factor > 1f) factor = 1f; else if (factor < -1f) factor = -1f; Velocity[1] = -Velocity [1]; Velocity[0] = Velocity[0] - 20f * factor; Velocity[0] += 0.6f * Math.Sign(Velocity[0]); Velocity[1] += 0.6f * Math.Sign(Velocity[1]); }
public void Update(Ball b, Paddle p) { p.Position[0] = b.Position[0]; }