Exemplo n.º 1
0
 public void ExecuteBulletEvent()
 {
     BulletFired?.Invoke();
 }
Exemplo n.º 2
0
        public override void Update(GameTime aGameTime)
        {
            base.Update(aGameTime);

            if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                AccessDirection = -1.0f;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                AccessDirection = 1.0f;
            }
            else
            {
                AccessDirection = 0.0f;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                //The else statement below will make this into a "one time trigger"
                if (mySpacePressed == false)
                {
                    mySpacePressed = true;
                    SinkBombElement sinkBomb = mySinkBombList.FirstOrDefault();
                    if (sinkBomb != null)
                    {
                        AccessSinkBombReleased?.Invoke(sinkBomb);
                        mySinkBombList.Remove(sinkBomb);
                    }
                }
            }
            else
            {
                //Force to unpress space before it is allowed to drop next sink bomb, "one time trigger"
                mySpacePressed = false;
            }

            if (myLevel > 5 && AccessDirection > 0.0f && Keyboard.GetState().IsKeyDown(Keys.Enter))
            {
                //The else statement below will make this into a "one time trigger"
                if (myEnterPressed == false)
                {
                    myEnterPressed = true;
                    //TODO! Add proper values
                    Vector2 bulletOrigin = new Vector2(AccessPosition.X + (AccessSize.Width * AccessScale), AccessPosition.Y);
                    float   bulletSpeed  = 120.0f;
                    float   bulletAngle  = 50.2f;
                    Bullet  bullet       = new Bullet(myBulletTexture, bulletOrigin, bulletSpeed, bulletAngle);
                    if (bullet != null)
                    {
                        BulletFired?.Invoke(bullet);
                    }
                }
            }
            else
            {
                //Force to unpress enter before it is allowed to shoot next bullet, "one time trigger"
                myEnterPressed = false;
            }

            //Keep the boat within screens left and right edge
            if (AccessPosition.X <= myLeftEdge && AccessDirection < 0.0f)
            {
                AccessDirection = 0.0f;
            }
            else if (AccessPosition.X > (myRightEdge) && AccessDirection > 0.0f)
            {
                AccessDirection = 0.0f;
            }

            CalcHorizontalMovement(AccessSpeed);
            AccessWhereIsTheBoat?.Invoke(new Rectangle(AccessPosition.ToPoint(), AccessSize.Size), aGameTime);

            foreach (SinkBombElement sinkBomb in mySinkBombList)
            {
                //Make all not dropped sinkbombs follow the boat
                sinkBomb.AccessPosition = new Vector2(AccessPosition.X + AccessSize.Center.X, AccessPosition.Y + AccessSize.Center.Y);
            }
        }