本文整理汇总了C#中System.Point.Sub方法的典型用法代码示例。如果您正苦于以下问题:C# Point.Sub方法的具体用法?C# Point.Sub怎么用?C# Point.Sub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Point
的用法示例。
在下文中一共展示了Point.Sub方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NewGame
public override void NewGame()
{
_playerPos = new Point(0.5f, GamesParams.MarginY1).Clamp(GamesParams.Margin0.Add(_padSize.Half()),
GamesParams.Margin1.Sub(_padSize.Half()));
_ballPos = _playerPos.Sub(new Point(0, 0.1f));
_blockPos = new Point[BlocksCountX, BlocksCountY];
for (var y = 0; y < BlocksCountY; ++y)
{
for (var x = 0; x < BlocksCountX; x++)
{
var xx = GamesParams.MarginX0 + (GamesParams.MarginX1 - GamesParams.MarginX0) / (BlocksCountX + 1) * (x + 1);
var yy = GamesParams.MarginY0 + (GamesParams.MarginY1 - BottomLinesOfBlocks ) / (BlocksCountY + 1) * (y + 1);
_blockPos[x, y] = new Point(xx, yy).Clamp(GamesParams.Margin0.Add(_blockSize.Half()),
GamesParams.Margin1.Sub(_blockSize.Half()));
}
}
_playerSpd = 0.8f;
_ballSpd = 0.3f;
_playerDir = new Point(0.0f, 0.0f);
_ballDir = new Point(0.0f, -1.0f).AddNoise().Normalise();
base.NewGame();
}
示例2: Update
public override void Update(DeviceContext context, TargetBase target, DeviceManager deviceManager, Point screenSize, float dt, float elapsedTime)
{
if (AfterStartFreeze)
{
// Player moving
_playerPos =
_playerPos.Add(_playerDir.Mul(_playerSpd).Mul(dt)).Clamp(GamesParams.Margin0.Add(_padSize.Half()),
GamesParams.Margin1.Sub(_padSize.Half()));
// Ball moving
_ballPos = _ballPos.Add(_ballDir.Mul(_ballSpd).Mul(dt));
// Ball collision with borders
if (!_ballPos.IsInside(GamesParams.Margin0.Add(_ballSize.Half()),
GamesParams.Margin1.Sub(_ballSize.Half())))
{
_ballDir.Y = -_ballDir.Y;
if (_ballPos.X < GamesParams.MarginX0 + 0.001f)
{
NewGame();
_gameManager.Die();
return;
}
if (_ballPos.X > GamesParams.MarginX1 - 0.001f)
{
_gameManager.Win(500);
_ballPos = new Point(0.5f, 0.5f);
_ballDir = new Point(1.0f, 0.0f).AddNoise().Normalise();
return;
}
}
_ballPos = _ballPos.Clamp(GamesParams.Margin0.Add(_ballSize.Half()),
GamesParams.Margin1.Sub(_ballSize.Half()));
// Ball collision with player pad
if (_ballPos.IsInside(_playerPos.Sub(_padSize.Half()).Sub(_ballSize.Half()),
_playerPos.Add(_padSize.Half()).Add(_ballSize.Half())))
{
_ballDir.X = 1;
_ballDir.Y = _ballPos.Sub(_playerPos).Y/_padSize.Half().Y;
_ballDir = _ballDir.Normalise();
_ballSpd += _ballSpdInc;
_gameManager.AddPoints(75);
}
// Ball collision with enemy pad
if (_ballPos.IsInside(_enemyPos.Sub(_padSize.Half()).Sub(_ballSize.Half()),
_enemyPos.Add(_padSize.Half()).Add(_ballSize.Half())))
{
_ballDir.X = -1;
_ballDir.Y = _ballPos.Sub(_enemyPos).Y/_padSize.Half().Y;
_ballDir = _ballDir.Normalise();
_ballSpd += _ballSpdInc;
}
// Enemy moving
if (Math.Abs(_ballPos.Y - _enemyPos.Y) < _padSize.Div(3).Y)
{
_enemyDir.Y = 0;
}
else
{
if (_ballPos.Y > _enemyPos.Y)
_enemyDir.Y = 1;
else
_enemyDir.Y = -1;
_enemyPos =
_enemyPos.Add(_enemyDir.Mul(_enemySpd).Mul(dt)).Clamp(GamesParams.Margin0.Add(_padSize.Half()),
GamesParams.Margin1.Sub(_padSize.Half()));
}
}
// Drawing
var playerBox = _playerPos.ToBox(_padSize);
var enemyBox = _enemyPos.ToBox(_padSize);
var ballBox = _ballPos.ToBox(_ballSize);
context.FillRectangle(screenSize.ApplyTo(playerBox), GamesParams.PlayerColor);
context.FillRectangle(screenSize.ApplyTo(enemyBox), GamesParams.EnemyColor);
context.FillRectangle(screenSize.ApplyTo(ballBox), GamesParams.AdditionalColor);
base.Update(context, target, deviceManager, screenSize, dt, elapsedTime);
}
示例3: Update
public override void Update(DeviceContext context, TargetBase target, DeviceManager deviceManager, Point screenSize, float dt, float elapsedTime)
{
if (AfterStartFreeze)
{
// Player moving
_playerPos =
_playerPos.Add(_playerDir.Mul(_playerSpd).Mul(dt)).Clamp(GamesParams.Margin0.Add(_padSize.Half()),
GamesParams.Margin1.Sub(_padSize.Half()));
// Ball moving
var oldBallPos = _ballPos;
_ballPos = _ballPos.Add(_ballDir.Mul(_ballSpd).Mul(dt));
// Ball collision with borders
if (!_ballPos.IsInside(GamesParams.Margin0.Add(_ballSize.Half()),
GamesParams.Margin1.Sub(_ballSize.Half())))
{
if (_ballPos.X - GamesParams.MarginX0 < _ballPos.Y - GamesParams.MarginY0 ||
GamesParams.MarginX1 - _ballPos.X < _ballPos.Y - GamesParams.MarginY0)
_ballDir.X = -_ballDir.X;
else
_ballDir.Y = -_ballDir.Y;
if (_ballPos.Y > GamesParams.MarginY1 - 0.01f)
{
_playerPos =
new Point(0.5f, GamesParams.MarginY1).Clamp(GamesParams.Margin0.Add(_padSize.Half()),
GamesParams.Margin1.Sub(_padSize.Half()));
_ballPos = _playerPos.Sub(new Point(0, 0.1f));
_ballDir = new Point(0.0f, -1.0f).AddNoise().Normalise();
_gameManager.Die();
return;
}
}
_ballPos = _ballPos.Clamp(GamesParams.Margin0.Add(_ballSize.Half()),
GamesParams.Margin1.Sub(_ballSize.Half()));
// Ball collision with player pad
if (_ballPos.IsInside(_playerPos.Sub(_padSize.Half()).Sub(_ballSize.Half()),
_playerPos.Add(_padSize.Half()).Add(_ballSize.Half())))
{
_ballDir.Y = -1;
_ballDir.X = _ballPos.Sub(_playerPos).X/_padSize.Half().X;
_ballDir = _ballDir.Normalise();
_ballSpd += _ballSpdInc;
}
// Ball collision with player pad
foreach (var block in _blockPos)
{
if (_ballPos.IsInside(block.Sub(_blockSize.Half()).Sub(_ballSize.Half()),
block.Add(_blockSize.Half()).Add(_ballSize.Half())))
{
if (oldBallPos.X < block.Sub(_blockSize.Half()).Sub(_ballSize.Half()).X ||
oldBallPos.X > block.Add(_blockSize.Half()).Add(_ballSize.Half()).X)
_ballDir.X = -_ballDir.X;
else
_ballDir.Y = -_ballDir.Y;
block.X = -100;
block.Y = -100;
_gameManager.AddPoints(100);
}
}
}
// Drawing
var anyBlock = false;
foreach (var block in _blockPos)
{
if (block.X < 0)
continue;
anyBlock = true;
var box = block.ToBox(_blockSize);
context.FillRectangle(screenSize.ApplyTo(box), GamesParams.EnemyColor);
}
if (!anyBlock)
{
NewGame();
_gameManager.Win(3000);
return;
}
var playerBox = _playerPos.ToBox(_padSize);
var ballBox = _ballPos.ToBox(_ballSize);
context.FillRectangle(screenSize.ApplyTo(playerBox), GamesParams.PlayerColor);
context.FillRectangle(screenSize.ApplyTo(ballBox), GamesParams.AdditionalColor);
base.Update(context, target, deviceManager, screenSize, dt, elapsedTime);
}
示例4: Update
public override void Update(DeviceContext context, TargetBase target, DeviceManager deviceManager, Point screenSize, float dt, float elapsedTime)
{
if (AfterStartFreeze)
{
_timeToNextPossibleShoot -= dt;
if (_isShootButtonPressed && _timeToNextPossibleShoot <= 0)
{
var p = _playerPos.Sub(new Point(0, 0.01f));
_bulletPos.Add(p);
_timeToNextPossibleShoot = ShootInterval;
}
// Player moving
_playerPos =
_playerPos.Add(_playerDir.Mul(PlayerSpd).Mul(dt)).Clamp(GamesParams.Margin0.Add(_playerSize.Half()),
GamesParams.Margin1.Sub(_playerSize.Half()));
// Enemies
for (var e = 0; e < _enemyPos.Count; ++e)
{
var enemyPos = _enemyPos[e];
// Enemy reach bottom line
_enemyPos[e] = enemyPos.Add(_enemyDir.Mul(EnemySpd).Mul(dt));
enemyPos = _enemyPos[e];
if (enemyPos.IsInside(GamesParams.Margin0.Sub(_enemySize.Half()).Add(new Point(0, 1)),
GamesParams.Margin1.Add(_enemySize.Half()).Add(new Point(0, 1))))
{
AddEnemy(e);
AddEnemy();
AddEnemy();
}
// Enemy collision with player
if (enemyPos.IsInside(_playerPos.Sub(_playerSize.Half()).Sub(_playerSize.Half()),
_playerPos.Add(_playerSize.Half()).Add(_playerSize.Half())))
{
NewGame();
_gameManager.Die();
return;
}
}
// Bullet moving
for (var i = 0; i < _bulletPos.Count; ++i)
{
var bulletPos = _bulletPos[i];
_bulletPos[i] = bulletPos.Add(_bulletDir.Mul(BulletSpd).Mul(dt));
bulletPos = _bulletPos[i];
// Bullet collision with borders
if (!bulletPos.IsInside(GamesParams.Margin0.Sub(_bulletSize.Half()),
GamesParams.Margin1.Add(_bulletSize.Half())))
{
_bulletPos.RemoveAt(i);
}
// Bullet collision with enemies
for (var e = 0; e < _enemyPos.Count; ++e)
{
var enemyPos = _enemyPos[e];
if (bulletPos.IsInside(enemyPos.Sub(_enemySize.Half()).Sub(_bulletSize.Half()),
enemyPos.Add(_enemySize.Half()).Add(_bulletSize.Half())))
{
_bulletPos.RemoveAt(i);
AddEnemy(e);
AddEnemy();
_gameManager.AddPoints(50);
break;
}
}
}
}
// Drawing
foreach (var bullet in _bulletPos)
{
var ballBox = bullet.ToBox(_bulletSize);
context.FillRectangle(screenSize.ApplyTo(ballBox), GamesParams.AdditionalColor);
}
foreach (var enemy in _enemyPos)
{
var box = enemy.ToBox(_enemySize);
if (box.Left > GamesParams.MarginX1 || box.Right < GamesParams.MarginX0 || box.Bottom < GamesParams.MarginY0 || box.Top > GamesParams.MarginY1)
continue;
if (box.Left < GamesParams.MarginX0)
box.Left = GamesParams.MarginX0;
if (box.Right > GamesParams.MarginX1)
box.Right = GamesParams.MarginX1;
if (box.Top < GamesParams.MarginY0)
box.Top = GamesParams.MarginY0;
if (box.Bottom > GamesParams.MarginY1)
box.Bottom = GamesParams.MarginY1;
context.FillRectangle(screenSize.ApplyTo(box), GamesParams.EnemyColor);
}
//.........这里部分代码省略.........