public PlayerMissile AddMissile(PlayerMissile missile) { _missiles.Add(missile); missile.Owner = this; ClearCache(); return(missile); }
public static void Main() { var LeftJoystick = new AnalogJoystick(Pins.GPIO_PIN_A0, Pins.GPIO_PIN_A1); var RightJoystick = new AnalogJoystick(Pins.GPIO_PIN_A2, Pins.GPIO_PIN_A3); var matrix = new Max72197221(chipSelect: Pins.GPIO_PIN_D8); matrix.Shutdown(Max72197221.ShutdownRegister.NormalOperation); matrix.SetDecodeMode(Max72197221.DecodeModeRegister.NoDecodeMode); matrix.SetDigitScanLimit(7); matrix.SetIntensity(8); var comp = new Composition(new byte[8], 8, 8); var leftBall = new PlayerMissile("leftBall", 0, 0); var rightBall = new PlayerMissile("rightBall", 0, 0); comp.AddMissile(leftBall); comp.AddMissile(rightBall); while (true) { leftBall.X = LeftJoystick.X / 128; leftBall.Y = LeftJoystick.Y / 128; rightBall.X = RightJoystick.X / 128; rightBall.Y = RightJoystick.Y / 128; Debug.Print("X=" + LeftJoystick.X.ToString() + " (" + LeftJoystick.XDirection.ToString() + ")" + ", Y=" + LeftJoystick.Y.ToString() + " (" + LeftJoystick.YDirection.ToString() + ")"); matrix.Display(comp.GetFrame(0, 0)); Thread.Sleep(80); } }
public PlayerMissile AddMissile(PlayerMissile missile) { if (missile == null) throw new ArgumentNullException("missile"); _missiles.Add(missile); if (missile.Owner != this) missile.Owner = this; ClearCache(); return missile; }
public Paddle(Side side, GameOfPaddles game) { _side = side; _game = game; _world = game.World; _ball = _world["ball"]; _pixels = new PlayerMissile[Size]; for(var i = 0; i < Size; i++) { _pixels[i] = new PlayerMissile( "paddle" + (_side == Side.Right ? 'R' : 'L') + i, _side == Side.Right ? 7 : 0, i, _world); } _world.Coinc += (s, a) => { if (_ball.X == 0 && _side == Side.Left) { _game.BallGoingRight = true; } if (_ball.X == 7 && _side == Side.Right) { _game.BallGoingRight = false; } }; }
protected virtual bool OnCoinc(object sender, PlayerMissile missile1, PlayerMissile missile2) { if (Coinc != null) { Coinc(this, missile1, missile2); } return(false); }
public PlayerMissile AddMissile( string name, int x = 0, int y = 0) { var missile = new PlayerMissile(name, x, y, this); _missiles.Add(missile); ClearCache(); return missile; }
public PlayerMissile AddMissile( string name, int x = 0, int y = 0) { var missile = new PlayerMissile(name, x, y, this); _missiles.Add(missile); ClearCache(); return(missile); }
public Meteor(GameOfMeteors game, int index) { Owner = game; Index = index; for (var i = 0; i < 3; i++) { _rocks[i] = new PlayerMissile { Name = "Meteor" + index + ":" + i, IsVisible = false, Owner = game.World, IsEnemy = true }; } }
public PlayerMissile AddMissile(PlayerMissile missile) { if (missile == null) { throw new ArgumentNullException("missile"); } _missiles.Add(missile); if (missile.Owner != this) { missile.Owner = this; } ClearCache(); return(missile); }
public Paddle(Side side, GameOfPaddles game) { _side = side; var world = game.World; _pixels = new PlayerMissile[Size]; for(var i = 0; i < Size; i++) { _pixels[i] = new PlayerMissile( "paddle" + (_side == Side.Right ? 'R' : 'L') + i, _side == Side.Right ? 7 : 0, i, world); } }
protected override void OnGameStart() { base.OnGameStart(); _ship = new PlayerMissile() { Name = "ship", IsEnemy = false, X = 3, IsVisible = true, VerticalSpeed = 0, }; ScrollMessage(" 6T4Racer!"); }
public GameOfPaddles(ConsoleHardwareConfig config) : base(config) { Hardware.LeftButton.Input.DisableInterrupt(); Hardware.RightButton.Input.DisableInterrupt(); Hardware.LeftButton.Input.OnInterrupt += OnLeftButtonClick; Hardware.RightButton.Input.OnInterrupt += OnRightButtonClick; Hardware.LeftButton.Input.EnableInterrupt(); Hardware.RightButton.Input.EnableInterrupt(); DisplaySplashScreen(); World = new Composition(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }, ScreenSize, ScreenSize); Ball = new PlayerMissile("ball", 0, 0, World); LeftPaddle = new Paddle(Side.Left, this); RightPaddle = new Paddle(Side.Right, this); ResetBall(true); }
public static void Main() { using (var matrix = new Max72197221(chipSelect: Pins.GPIO_PIN_D8, speedKHz: 10000)) { matrix.Shutdown(Max72197221.ShutdownRegister.NormalOperation); matrix.SetDecodeMode(Max72197221.DecodeModeRegister.NoDecodeMode); matrix.SetDigitScanLimit(7); matrix.SetIntensity(8); var comp = new Composition(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xC0, 0x07, 0xE0, 0x0F, 0xF0, 0x0F, 0xF0, 0x0F, 0xF0, 0x0F, 0xF0, 0x07, 0xE0, 0x03, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }, 16, 16); var player = new PlayerMissile("player", 0, 0); var missile = new PlayerMissile("missile", 0, 0); comp.AddMissile(player); comp.AddMissile(missile); while (true) { for (var angle = 0; angle < 360; angle++) { player.X = 8 + Math.Sin(angle * 2)/160; player.Y = 8 + Math.Cos(angle * 2)/160; missile.X = 8 + Math.Sin(angle) / 160; missile.Y = 8 + Math.Cos(angle) / 160; var frame = comp.GetFrame(Math.Sin(angle*20)/250 + 4, Math.Cos(angle*20)/250 + 4); matrix.Display(frame); Thread.Sleep(25); } } } }
public GameOfPaddles(ConsoleHardwareConfig config) : base(config) { World = new Composition(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }, ScreenSize, ScreenSize); Ball = new PlayerMissile { Name = "ball", Owner = World, IsEnemy = true }; LeftPaddle = new Paddle(Side.Left, this); RightPaddle = new Paddle(Side.Right, this); World.Coinc += (s, a, b) => { Ball.HorizontalSpeed = -Ball.HorizontalSpeed; return false; }; ResetBall(true); }
public Meteor(GameOfMeteors game, int index, int x, int y) { _rnd = new Random(); var speed = GetRandomSpeed(); var j = 0; var skip = _rnd.Next(4); for (var i = 0; i < 4; i++) { if (i == skip) continue; _rockXOffsets[j] = _rockOffsets[i*2]; _rockYOffsets[j] = _rockOffsets[i*2 + 1]; _rocks[j] = new PlayerMissile { Name = "Meteor" + index + ":" + j, X = x + _rockXOffsets[j], Y = y + _rockYOffsets[j], HorizontalSpeed = speed.X, VerticalSpeed = speed.Y, Owner = game.World }; j++; } }
public GameOfMeteors(ConsoleHardwareConfig config) : base(config) { World = new Composition(new byte[WorldSize * WorldSize / 8], WorldSize, WorldSize); World.Coinc += WorldCoinc; Ship = new PlayerMissile("ship", WorldSize / 2, WorldSize / 2, World); Ship.X = WorldSize / 2; Ship.Y = WorldSize / 2; Pruneau = new PlayerMissile { Name = "Pruneau", Owner = World, IsVisible = false }; Meteors = new Meteor[NumberOfMeteors]; for (var i = 0; i < NumberOfMeteors; i++) { Meteors[i] = new Meteor(this, i, new[] {0, WorldSize - 2, 0, WorldSize - 2} [i], new[] {0, 0, WorldSize - 2, WorldSize - 2} [i]); } DisplayDelay = 0; }
public static void Main() { #if NETDUINO || NETDUINO_PLUS var LeftJoystick = new AnalogJoystick(Pins.GPIO_PIN_A0, Pins.GPIO_PIN_A1); var RightJoystick = new AnalogJoystick(Pins.GPIO_PIN_A2, Pins.GPIO_PIN_A3); var matrix = new Max72197221(chipSelect: Pins.GPIO_PIN_D8); #endif #if NETDUINO_MINI var LeftJoystick = new AnalogJoystick(Pins.GPIO_PIN_5, Pins.GPIO_PIN_6, minYRange: 1023, maxYRange: 0, centerDeadZoneRadius: 30); var RightJoystick = new AnalogJoystick(Pins.GPIO_PIN_7, Pins.GPIO_PIN_8, minYRange: 1023, maxYRange: 0, centerDeadZoneRadius: 30); var matrix = new Max72197221(chipSelect: Pins.GPIO_PIN_17); #endif matrix.Shutdown(Max72197221.ShutdownRegister.NormalOperation); matrix.SetDecodeMode(Max72197221.DecodeModeRegister.NoDecodeMode); matrix.SetDigitScanLimit(7); matrix.SetIntensity(4); var comp = new Composition(new byte[8], 8, 8); var leftBall = new PlayerMissile("leftBall", 0, 0); var rightBall = new PlayerMissile("rightBall", 0, 0); comp.AddMissile(leftBall); comp.AddMissile(rightBall); while (true) { leftBall.X = LeftJoystick.X / 128; leftBall.Y = LeftJoystick.Y / 128; rightBall.X = RightJoystick.X / 128; rightBall.Y = RightJoystick.Y / 128; Debug.Print("LEFT: (X=" + LeftJoystick.X + " (" + LeftJoystick.XDirection + ")" + ", Y=" + LeftJoystick.Y + " (" + LeftJoystick.YDirection + "), RIGHT: (X=" + RightJoystick.X + " (" + RightJoystick.XDirection + ")" + ", Y=" + RightJoystick.Y + " (" + RightJoystick.YDirection + ")"); matrix.Display(comp.GetFrame(0, 0)); Thread.Sleep(80); } }
public GameOfMeteors(ConsoleHardwareConfig config) : base(config) { World = new Composition(new byte[WorldSize * WorldSize / 8], WorldSize, WorldSize); World.Coinc += WorldCoinc; Ship = new PlayerMissile { Name = "Ship", Owner = World, X = WorldSize/2, Y = WorldSize/2 }; Pruneau = new PlayerMissile { Name = "Pruneau", Owner = World, IsVisible = false }; Meteors = new Meteor[WinningNumberOfMeteors]; for (var i = 0; i < Meteors.Length; i++) { Meteors[i] = new Meteor(this, i); } NumberOfMeteors = StartingNumberOfMeteors; SpawnMeteors(); DisplayDelay = 0; }
bool WorldCoinc(object sender, PlayerMissile missile1, PlayerMissile missile2) { if (missile1 == Pruneau || missile2 == Pruneau) { // Explode rock or meteor var rock = missile1 == Pruneau ? missile2 : missile1; var meteor = GetOwner(rock); // Does this rock belong to a meteor? if (meteor != null) { if (meteor.IsExploded) { rock.IsVisible = false; RemainingRocks--; if (RemainingRocks == 0) { Hardware.Matrix.Display(SmallChars.ToBitmap(-1, NumberOfMeteors)); Thread.Sleep(1000); NumberOfMeteors++; if (NumberOfMeteors >= WinningNumberOfMeteors) { Stop(); } else { SpawnMeteors(); Pruneau.IsVisible = false; return true; } } } else { meteor.Explode(); MakeExplosionSound(); } Pruneau.IsVisible = false; return false; } } else if (missile1 == Ship || missile2 == Ship) { MakeExplosionSound(); Stop(); } return false; }
private Meteor GetOwner(PlayerMissile rock) { foreach (var meteor in Meteors) { if (meteor.Has(rock)) return meteor; } return null; }
public CoincEventArgs(PlayerMissile missile1, PlayerMissile missile2) { Missile1 = missile1; Missile2 = missile2; }
public bool Has(PlayerMissile someRock) { foreach (var rock in _rocks) { if (rock == someRock && rock.IsVisible) return true; } return false; }
protected virtual bool OnCoinc(object sender, PlayerMissile missile1, PlayerMissile missile2) { if (Coinc != null) { Coinc(this, missile1, missile2); } return false; }
public static void ApplyToreGeometry(PlayerMissile missile) { if (missile.ExactX < 0) missile.ExactX += WorldSize; if (missile.ExactY < 0) missile.ExactY += WorldSize; if (missile.ExactX >= WorldSize) missile.ExactX -= WorldSize; if (missile.ExactY >= WorldSize) missile.ExactY -= WorldSize; }
public PlayerMissile AddMissile(PlayerMissile missile) { _missiles.Add(missile); if (missile.Owner != this) missile.Owner = this; ClearCache(); return missile; }