public Paddle(PaddleType type, PhysicsBody physicsBody) { this._type = type; this._physicsBody = physicsBody; this.TextureInfo = new TextureInfo(new Texture2D("/Application/images/paddle.png", false)); this.Scale = TextureInfo.TextureSizef; this.Pivot = new Vector2(0.5f, 0.5f); if(_type == PaddleType.AI) { this.Position = new Vector2( Director.Instance.GL.Context.GetViewport().Width / 2 - this.Scale.X / 2, this.Scale.Y / 2 + 10); } else { this.Position = new Vector2( Director.Instance.GL.Context.GetViewport().Width / 2 - this.Scale.X / 2, Director.Instance.GL.Context.GetViewport().Height - this.Scale.Y / 2 - 10); } // cache the vertical position so we can reset after physics _fixedY = _physicsBody.Position.Y; // start with a minor amount of movement _physicsBody.Force = new Vector2(-10.0f, 0); Scheduler.Instance.ScheduleUpdateForTarget(this, 0, false); }
public Paddle(PaddleType type, PhysicsBody physicsBody) { _physicsBody = physicsBody; _type = type; this.TextureInfo = new TextureInfo(new Texture2D("Application/images/Paddle.png",false)); this.Scale = this.TextureInfo.TextureSizef; this.Pivot = new Sce.PlayStation.Core.Vector2(0.5f,0.5f); if(_type== PaddleType.AI) { this.Position = new Sce.PlayStation.Core.Vector2( Director.Instance.GL.Context.GetViewport().Width/2 - this.Scale.X/2, 10 + this.Scale.Y/2); } else { this.Position = new Sce.PlayStation.Core.Vector2( Director.Instance.GL.Context.GetViewport().Width/2 - this.Scale.X/2, Director.Instance.GL.Context.GetViewport().Height - this.Scale.Y/2 - 10); } // Cache the starting Y position, so we can reset and prevent any vertical movement from the Physics Engien _fixedY = _physicsBody.Position.Y; // Start with a minor amount of movement _physicsBody.Force = new Vector2(-10.0f,0); Scheduler.Instance.ScheduleUpdateForTarget(this,0,false); }
public Paddle(PaddleType type, PhysicsBody physicsBody) { m_physicsBody = physicsBody; m_type = type; this.TextureInfo = new TextureInfo(new Texture2D("Application/images/Paddle.png", false)); this.Scale = this.TextureInfo.TextureSizef; this.Pivot = new Sce.PlayStation.Core.Vector2(0.5f, 0.5f); if (m_type == PaddleType.AI || m_type == PaddleType.PLAYER2) { this.Position = new Sce.PlayStation.Core.Vector2( Director.Instance.GL.Context.GetViewport().Width / 2 - this.Scale.X / 2, 10 + this.Scale.Y / 2); } else { this.Position = new Sce.PlayStation.Core.Vector2( Director.Instance.GL.Context.GetViewport().Width / 2 - this.Scale.X / 2, Director.Instance.GL.Context.GetViewport().Height - this.Scale.Y / 2 - 10); } // Cache the starting Y position, so we can reset and prevent any vertical movement from the Physics Engien m_fixedY = m_physicsBody.Position.Y; // Start with a minor amount of movement m_physicsBody.Force = new Vector2(-10.0f, 0); Scheduler.Instance.ScheduleUpdateForTarget(this, 0, false); }
public void InitLogic(Dictionary <byte, NetworkPlayer> players) { PlayerCount = players.Count; Mediator = MainForm.Instance.Mediator; DoAfterGameLoop = new List <Action>(); PlayerPaddles = new Dictionary <byte, Paddle>(); ArenaBalls = new Dictionary <byte, IBall>(); ArenaObjects = new Dictionary <byte, ArenaObject>(); float deltaAngle = SharedUtilities.PI * 2 / PlayerCount; float angle = (-SharedUtilities.PI + deltaAngle) / 2f; foreach (var player in players.Values) { PaddleType pType = player.PaddleType; Paddle paddle = PaddleFactory.CreatePaddle(pType, player.Id); paddle.SetPosition(SharedUtilities.RadToDeg(angle)); PlayerPaddles.Add(player.Id, paddle); player.SetLife(paddle.Life); if (Mediator.GetBool("IdMatches", player.Id)) { LocalPaddle = paddle; } paddle.AddClampAngles(SharedUtilities.RadToDeg(angle - deltaAngle / 2), SharedUtilities.RadToDeg(angle + deltaAngle / 2)); angle += deltaAngle; } AlivePaddleCount = PlayerPaddles.Count; StartingAlivePaddleCount = AlivePaddleCount; UpdatableRoot = new UpdateComposite(); UpdatableRoot.Add(LocalPaddle.Id, LocalPaddle); UpdateComponent spawnerBranch = new UpdateComposite(); spawnerBranch.Add(spawnerBranch.GetNextId(), new ObstacleSpawner(GameData.ObstacleSpawnerParams, ArenaObjectFactories.Values.ToArray())); spawnerBranch.Add(spawnerBranch.GetNextId(), new PowerUpSpawner(GameData.PowerUpSpawnerParams, ArenaObjectFactories.Values.ToArray())); UpdatableRoot.Add(UpdatableRoot.GetNextId(), spawnerBranch); UpdateComponent objectBranch = new UpdateComposite(); ObjectBranchId = UpdatableRoot.GetNextId(); UpdatableRoot.Add(ObjectBranchId, objectBranch); UpdateComponent ballBranch = new UpdateComposite(); BallBranchId = UpdatableRoot.GetNextId(); UpdatableRoot.Add(BallBranchId, ballBranch); BallType bType = RoomSettings.Instance.BallType; Ball ball = Ball.CreateBall(0, bType, ArenaDimensions.Center, GameData.DefaultBallSpeed, Vector2.RandomInUnitCircle(), GameData.DefaultBallSize); ArenaBalls.Add(0, ball); ballBranch.Add(0, ball); IsInitted = true; PauseGame(false); }
public Paddle(PaddleType type) : base(ContentLoader.Texure_Paddle) { this.type = type; canFire = true; SetSize(Constants.PADDLE_WIDTH, Constants.PADDLE_HEIGHT); bullets = new List <Bullet>(); }
private GameObject GetPrefab(PaddleType type) { switch (type) { case PaddleType.Normal: return normal; case PaddleType.Small: return small; case PaddleType.Extended: return extended; case PaddleType.Laser: return laser; case PaddleType.Magnet: return magnet; default: return null; } }
public IPaddleController GetController(PaddleType paddleType, bool isBottom) { switch (paddleType) { case PaddleType.AI: return(new AIController(_ball)); case PaddleType.Player: return(new PlayerController(isBottom, _gameCamera)); case PaddleType.Remote: return(new RemoteController()); } return(null); }
public static void StartLocalGame() { byte[] playerIds = new byte[] { 0 }; PaddleType[] paddleTypes = new PaddleType[] { //(PaddleType)RandomNumber.RandomNumb((int)PaddleType.Normal, (int)PaddleType.Short + 1) PaddleType.Normal }; BallType ballType = BallType.Normal; RoomSettings.Instance.SetRoomSettings(playerIds, paddleTypes, ballType, playerIds[0]); Instance.SetGameState(GameState.InGame); }
public void AddPoint(PaddleType type, int num) { if (type == PaddleType.Left) { _leftPaddle.score += num; } if (type == PaddleType.Right) { _rightPaddle.score += num; } }
public static PaddleSettings GetPaddleData(PaddleType type) { PaddleSettings settings = null; if (types.ContainsKey(type)) { settings = types[type]; } else { switch (type) { case PaddleType.Normal: settings = new PaddleSettings() { Size = 20, Speed = 1.5f, Thickness = 10, Life = 3, PaddleColor = new PaddleColorBlack(), PType = PaddleType.Normal }; break; case PaddleType.Long: settings = new PaddleSettings() { Size = 35, Speed = .8f, Thickness = 13, Life = 4, PaddleColor = new PaddleColorBlack(), PType = PaddleType.Long }; break; case PaddleType.Short: settings = new PaddleSettings() { Size = 13, Speed = 2.25f, Thickness = 7, Life = 2, PaddleColor = new PaddleColorRed(), PType = PaddleType.Short }; break; default: break; } types.Add(type, settings); } return(settings); }
public void DecodeGameStartMessage(byte[] data, out byte[] playerIds, out PaddleType[] paddleTypes, out BallType ballType, out byte roomMasterId) { int playerCount = data[0]; playerIds = new byte[playerCount]; paddleTypes = new PaddleType[playerCount]; ballType = (BallType)data[1]; roomMasterId = data[2]; for (int i = 0; i < playerCount; i++) { playerIds[i] = data[i + 3]; paddleTypes[i] = (PaddleType)data[i + 3 + playerCount]; } }
private void PaddleManager_OnPaddleChanging(PaddleType newType, GameObject newPaddle, Rigidbody2D newPaddleBody) { if (attachedToPaddle) { if (PaddleManager.Instance.currentType == PaddleType.Magnet && newType != PaddleType.Magnet && AttachedByMagnet) { DetachFromPaddle(); } else { // Change parent to new paddle transform.SetParent(newPaddle.transform); } } }
public static Paddle CreatePaddle(PaddleType type, byte id) { switch (type) { case PaddleType.Normal: return(new NormalPaddle(id, PaddleDataFactory.GetPaddleData(type))); case PaddleType.Long: return(new LongPaddle(id, PaddleDataFactory.GetPaddleData(type))); case PaddleType.Short: return(new ShortPaddle(id, PaddleDataFactory.GetPaddleData(type))); default: return(null); } }
public void ChangePaddle(PaddleType newType) { // Create new paddle GameObject newPaddle = Instantiate(GetPrefab(newType), currentPaddle.transform.position, currentPaddle.transform.rotation); newPaddle.name = "Paddle"; Rigidbody2D newPaddleBody = newPaddle.GetComponent<Rigidbody2D>(); BoxCollider2D newPaddleCollider = newPaddle.GetComponent<BoxCollider2D>(); // Alert subscribed scripts about new paddle OnPaddleChanging?.Invoke(newType, newPaddle, newPaddleBody); // Destroy and replace current paddle Destroy(currentPaddle); currentType = newType; currentPaddle = newPaddle; currentPaddleBody = newPaddleBody; currentPaddleCollider = newPaddleCollider; }
public void Init(PaddleType paddleType) { this.paddleType = paddleType; switch (this.paddleType) { case PaddleType.Right: transform.position = new Vector3(GameManager.topRight.x, 0, 0); transform.position += Vector3.left * transform.localScale.x * 2; transform.name = "PlayerRight"; break; case PaddleType.Left: transform.position = new Vector3(GameManager.bottomLeft.x, 0, 0); transform.position += Vector3.right * transform.localScale.x * 2; transform.name = "PlayerLeft"; break; default: throw new UnityException("Invalid playerType"); } }
public NetworkPlayer(byte id, int life, PaddleType paddleType) { Id = id; PaddleType = paddleType; Life = (byte)life; }