Exemplo n.º 1
0
    protected override void OnConstruct()
    {
        waypoint       = new Vector2(-1, -1);
        queuedWaypoint = new Vector2(-1, -1);
        stateMachine   = new EntityStateMachine <HeroState, Hero>(this);
        stateMachine.RegisterInitialState(HeroState.Standing, new StandingState());
        stateMachine.RegisterState(HeroState.Running, new RunningState());

        boxCollider = this.GetComponentStrict <BoxCollider2D>();
        OrbBehavior = this.GetComponentStrict <OrbBehavior>();
        buffs       = new Buffable <HeroBuffs, Hero, IHero>(this);

        collisionFilter = new ContactFilter2D();
        var layerMask = new LayerMask();

        layerMask.value |= 1 << 8;
        collisionFilter.SetLayerMask(layerMask);

        this.stats.Initialize();

        regenTimer        = new Timer(1);
        isSpellOnCooldown = true;

        this.paddle = AddChild(Game.Resources.LoadPrefab <Paddle>("Heroes/Paddle"), resetPosition: true);
        audioSource = this.GetComponentStrict <AudioSource>();

        this.spell         = AddChild(Game.Objects.CreatePrefab(this.spell));
        spellCooldownTimer = new Timer(this.spell.cooldown);
    }
Exemplo n.º 2
0
    // void Start()
    void Awake()
    {
        Debug.Log($"SceneController.Awake: entered, paddle.GetType={paddleGameObject.GetType()}");
        // var sphericalPaddle_go = GameObject.Find("spherical_paddle_proto");
        // var sphericalPaddle_go = GameObject.Find("SphericalPaddle");
        // SphericalPdl = sphericalPaddle_go.GetComponent<SphericalPaddleProto>();
        // SphericalPdl = sphericalPaddle_go.GetComponent<SphericalPaddle>();
        // SphericalPaddle = GameObject.FindWithTag("SphericalPaddle").GetComponent<SphericalPaddle>();
        if (paddleGameObject.GetComponent <SphericalPaddle>() != null)
        {
            SphericalPaddle = paddleGameObject.GetComponent <SphericalPaddle>();
            paddle          = (IPaddle)SphericalPaddle;
        }
        if (paddleGameObject.GetComponent <PlanarPaddle>() != null)
        {
            PlanarPaddle = paddleGameObject.GetComponent <PlanarPaddle>();
            // paddle = (IPaddle) PlanarPaddle;
            paddle = (IPaddle)PlanarPaddle;
            // Debug.Log($"SceneController: paddle.DoIt={paddle.DoIt()}");
            // Debug.Log($"SceneController: paddle.DoIt={PlanarPaddle.DoIt()}");
        }

        Ball = GameObject.Find("Ball").GetComponent <Ball>();

        var brickPlaneGo = GameObject.FindWithTag("BrickPlane");

        if (brickPlaneGo != null)
        {
            BrickPlane = brickPlaneGo.GetComponent <BrickPlane>();
        }

        // Debug.Log($"SceneController.Awake: entered, SphericalPaddle.GetType()={SphericalPaddle.GetType()}");
    }
Exemplo n.º 3
0
 public Paddle(ContentManager content)
 {
     paddletext = content.Load<Texture2D>(@"images/Game/padle");
      paddleRect = new Rectangle(1250, 318, 18, 90);
      _content = content;
      this.state = new PaddleNoMovement(this);
 }
Exemplo n.º 4
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        ContactPoint2D contactPoint2D     = collision.GetContact(0);
        Vector2        reflectedDirection = Vector2.Reflect(movementDirection, contactPoint2D.normal);
        IPaddle        paddle             = collision.collider.GetComponent <IPaddle>();

        if (paddle != null)
        {
            if (paddle.Velocity.y > 0)
            {
                reflectedDirection     = new Vector2(-movementDirection.x, 1);
                startingMovementSpeed += 0.5f;
            }
            else if (paddle.Velocity.y < 0)
            {
                reflectedDirection     = new Vector2(-movementDirection.x, -1);
                startingMovementSpeed += 0.5f;
            }
            else
            {
                startingMovementSpeed -= 0.5f;
            }
            startingMovementSpeed = Mathf.Max(startingMovementSpeed, currentMoveSpeed);
        }

        movementDirection    = reflectedDirection;
        myRigidBody.velocity = movementDirection * startingMovementSpeed;
    }
Exemplo n.º 5
0
        private void CheckForBallCollisionWithPaddle(IBall ball, IPaddle paddle)
        {
            if (!ball.Boundings.Intersects(paddle.Boundings))
            {
                return;
            }

            var collisionPenetration = CollisionPenetration(paddle.Boundings, ball.Boundings,
                                                            ball.BoundingsLastFrame);

            ball.Position -= collisionPenetration.Depth;
            switch (collisionPenetration.From)
            {
            case Direction.Left:
            case Direction.Right:
                ball.Velocity *= new Vector2(-1, 1);
                break;

            case Direction.Top:
            case Direction.Bottom:
                ball.Velocity *= new Vector2(1, -1);
                break;
            }

            _eventAggregator.Publish(new BallCollidedWithPaddle()
            {
                Ball   = ball,
                Paddle = paddle
            });
        }
Exemplo n.º 6
0
 public Level(IEventAggregator eventAggregator, IEnumerable <IWall> walls, IEnumerable <IBlock> blocks,
              IPaddle paddle, IBall ball)
 {
     _eventAggregator = eventAggregator;
     Walls            = walls;
     Blocks           = blocks.ToList();
     Paddle           = paddle;
     Ball             = ball;
 }
Exemplo n.º 7
0
 public void Render(IPaddle paddle)
 {
     Primitives.DrawRectangle(
         paddle.Position.X - 10,
         paddle.Position.Y - 50,
         paddle.Position.X + 10,
         paddle.Position.Y + 50,
         paddle.Color, 1);
 }
Exemplo n.º 8
0
 public void Render(IPaddle paddle)
 {
     Primitives.DrawRectangle(
         paddle.Position.X - 10,
         paddle.Position.Y - 50,
         paddle.Position.X + 10,
         paddle.Position.Y + 50,
         paddle.Color, 1);
 }
 public PaddleBlockCollisionHandler(CollisionData collision)
 {
     this.collision = collision;
     collisionSide = (ICollisionSide)collision.CollisionSide;
     if (collision.GameObjectA is IPaddle)
     {
         paddle = (IPaddle)collision.GameObjectA;
     }
     else
     {
         paddle = (IPaddle)collision.GameObjectB;
         collisionSide = collisionSide.FlipSide();
     }
 }
Exemplo n.º 10
0
        public void Update(GameTime gt)
        {
            kState = Keyboard.GetState();
            this.state.Update(gt);

                if (kState.IsKeyDown(Keys.Up))
                {
                    this.state = new PaddleUp(this);
                }
                else if (!kState.IsKeyDown(Keys.Down))
                {
                    this.state = new PaddleNoMovement(this);
                }

                if (kState.IsKeyDown(Keys.Down))
                {
                    this.state = new PaddleDown(this);
                }
                else if (!kState.IsKeyDown(Keys.Up))
                {
                    this.state = new PaddleNoMovement(this);
                }
        }
Exemplo n.º 11
0
 public void BrickHit(IPaddle paddle, Collider other)
 {
     // transform.position = new Vector3(transform.position.x, transform.position.y, -transform.position.z);
     transform.forward = new Vector3(transform.forward.x, transform.forward.y, -transform.forward.z);
 }
Exemplo n.º 12
0
 protected override void OnParented(IGameEntity parent)
 {
     paddle = (IPaddle)parent;
 }