private void CollisionChecker(GameObject _other, bool _isBlock) { Collision collWithBlockInfo = collider.GetCollisionInfo(_other.collider); if (collWithBlockInfo.normal.y < 0) { _moveSpeedY = -Mathf.Abs(_moveSpeedY); } else if (collWithBlockInfo.normal.x < 0) { _moveSpeedX = -Mathf.Abs(_moveSpeedX); } else if (collWithBlockInfo.normal.y > 0) { _moveSpeedY = Mathf.Abs(_moveSpeedY); } else if (collWithBlockInfo.normal.x > 0) { _moveSpeedX = Mathf.Abs(_moveSpeedX); } if (_isBlock) { Block blockHit = (Block)_other; blockHit.GotHit(); } if (!_isBlock) { PlayerArkanoid playerHit = (PlayerArkanoid)_other; playerHit.GotHit(); } }
public Lives(PlayerArkanoid _playerInst, TiledObject _obj) : base(200, 50) { SetOrigin(this.width / 2, this.height / 2); SetXY(_obj.X, _obj.Y); _font = new Font("Arial", 20, FontStyle.Regular); _stringFormatCenter = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; _player = _playerInst; }
// Constructor that needs an instance of type Block, a TiledObject instance and a Level instance. // Again this is used so I can call certain methods from those classes and get property information of Ball from Tiled. public Ball(TiledObject _obj, PlayerArkanoid _playerInst) : base("ArkanoidSprites/ball.png", addCollider: true) { // Scales the sprite of Ball to 25% of its original width and height. this.scale = 0.25f; // Sets the X and Y pos of ball to X and Y values defined in Tiled. xPos = _obj.X; yPos = _obj.Y; SetXY(xPos, yPos); _moveSpeedX = 0; _moveSpeedY = 0; _ballSpeedX = -_obj.GetIntProperty("speedX"); _ballSpeedY = -_obj.GetIntProperty("speedY"); _player = _playerInst; }
// Checks which object is being loaded from Tiled and creates the appropriate instance for it. private void ObjectCheck(ObjectGroup objectGroup) { foreach (TiledObject obj in objectGroup.Objects) { switch (obj.Name) { case "Player": // Creating the player _player = new PlayerArkanoid(obj, this, _game); //Console.WriteLine(_player); AddChild(_player); break; case "Block": _block = new Block(this, obj); _blocks.Add(_block); AddChild(_block); break; case "Ball": // Creating the ball _ball = new Ball(obj, _player); AddChild(_ball); _overlay = new Overlay(); AddChild(_overlay); break; case "Score": // Creating the HUD element: Score Score score = new Score(_player, obj); AddChild(score); break; case "Lives": // Creating the HUD element: Lives Lives playerLives = new Lives(_player, obj); AddChild(playerLives); break; } } }