Beispiel #1
0
        public void CommandConnectionTest()
        {
            Command c = new Command(new Point(35, 75), PsychicNinja.Data.Util.CommandType.LedgeClimb);
            Platform p = new Platform(new Rectangle(35, 75, 40, 80));

            c.ConnectToPlatform(p);

            Assert.Equal(true, c.ConnectedPlatforms.Count > 0);
        }
Beispiel #2
0
        public void CommandValidityTest()
        {
            Command c = new Command(new Point(35, 75), PsychicNinja.Data.Util.CommandType.Jump);
            Platform p = new Platform(new Rectangle(35, 75, 40, 80));

            c.ConnectToPlatform(p);

            Assert.Equal(false, c.ConnectedPlatforms.Count > 0);
        }
Beispiel #3
0
        public void CommandCollisionTest()
        {
            Command c = new Command(new Point(35, 75), PsychicNinja.Data.Util.CommandType.LedgeClimb);
            Platform p = new Platform(new Rectangle(35, 75, 40, 80));

            c.ConnectToPlatform(p);

            Assert.Equal(true, c.CollidesWithConnectedPlatforms(new Platform(new Rectangle(70, 65, 40, 80))) != null);
        }
 public void setData(Command c)
 {
     data = c;
     drawTex = c.drawTex;
 }
Beispiel #5
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// 
        /// DO NOT MODIFY THIS FUNCTION!! - Austin
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            GraphicsDevice.Present();

            // TODO: Add your initialization logic here
            TouchPanel.EnabledGestures = GestureType.Tap |
                                         GestureType.Hold |
                                         GestureType.DoubleTap |
                                         GestureType.FreeDrag |
                                         GestureType.DragComplete |
                                         GestureType.Flick |
                                         GestureType.Pinch;
            //LoadLastLevel();
            titleScreen = new TitleScreen(graphics, _gameData);
            MediaPlayer.IsRepeating = true;

            chosen = null;

            gameRunState = GameState.StateMenu;
        }
Beispiel #6
0
 //used to attach a wall command to a wall durring runtime
 private void livingWallConnect(Command c, LinkedList<Platform> listOfWorldPlatforms)
 {
     foreach (Platform p in listOfWorldPlatforms)
     {
         //if(p.drawRect.Intersects(c.drawRect))
             c.ConnectToPlatform(p);
     }
 }
Beispiel #7
0
 /// <summary>
 /// Update the buttons in this menu.
 /// </summary>
 /// <param name="state">Game state to update with it.</param>
 /// <param name="selectedRef">Ref to the command that is selected. Pass null if no command is selected so the button doesn't show.</param>
 public void Update(GameState state, Command selectedRef)
 {
     switch (state)
     {
         case GameState.StateWorld:
             playGame.hidden = false;
             pauseGame.hidden = false;
             stopGame.hidden = true;
             fastForward.hidden = true;
             break;
         case GameState.StateRunning:
             playGame.hidden = true;
             stopGame.hidden = false;
             pauseGame.hidden = false;
             fastForward.hidden = false;
             break;
     }
 }
Beispiel #8
0
        /// <summary>
        /// Handles the touch gesture. Returns a response based on what we did with the touch.
        /// </summary>
        /// <param name="gesture"></param>
        /// <returns>Whether or not this object handled the touch.</returns>
        public bool ProcessTouch(GestureSample gesture, LinkedList<Platform> listOfWorldPlatforms)
        {
            Point hit = new Point((int)gesture.Position.X, (int)gesture.Position.Y);
            Point worldHit = Spotlight.TranslateScreenPointToWorldPoint(hit);

            #region Menu Touches
            if (drawRect.Contains(hit) && CanRespond())
            {
                if (selectedCommand == CommandType.NumCommands)
                {
                    Point adjustedHit = new Point(hit.X, hit.Y - MenuButtonVerticalOffset);
                    foreach (CommandButton cb in commandButtons)
                    {
                        if (cb.Contains(adjustedHit))
                        {
                            selectedCommand = cb.getData().getCommandType();
                            break;
                        }
                    }
                }

                switch (gesture.GestureType)
                {
                    case GestureType.FreeDrag:
                        OffsetMenuButtons((int)gesture.Delta.Y);
                        BecomeFirstResponder();
                        return true;
                }
                return true; // Eat all touches in this draw frame
            }
            else if (IsFirstResponder())
            {
                switch (gesture.GestureType)
                {
                    case GestureType.FreeDrag:
                        ResignFirstResponder();
                        if (selectedCommand == CommandType.NumCommands || commandlimits[(int)selectedCommand] == 0) return false; // earlier touch wasnt on a button.
                        Command created = new Command(worldHit, selectedCommand);
                        created.ProcessTouch(gesture);
                        Hide();
                        listOfWorldCommands.AddLast(created);
                        if (commandlimits[(int)selectedCommand] != -1)
                            commandlimits[(int)selectedCommand]--;
                        selectedCommand = CommandType.NumCommands;
                        return true;
                    case GestureType.DragComplete:
                        ResignFirstResponder();
                        selectedCommand = CommandType.NumCommands;
                        return false;
                    case GestureType.Flick:
                        if (gesture.Delta.Y > 0)
                        {
                            currentAnimationType = CommandMenuButtonScrollAnimationType.ToTop;
                        }
                        else
                        {
                            currentAnimationType = CommandMenuButtonScrollAnimationType.ToBottom;
                        }
                        ResignFirstResponder();
                        selectedCommand = CommandType.NumCommands;
                        return true;
                }
            }
            #endregion
            #region Toggle Touches
            if (toggle.ProcessTouch(gesture))
            {
                if (show)
                    Hide();
                else
                    Show();

                return true;
            }
            #endregion
            #region Command Touches
            foreach (Command c in listOfWorldCommands)
            {
                if (c.ProcessTouch(gesture, listOfWorldPlatforms))
                {
                    if (gesture.GestureType == GestureType.DragComplete)
                    {
                        if (drawRect.Contains(Spotlight.TranslateWorldPointToScreenPoint(c.drawRect.Location)))
                        {
                            listOfWorldCommands.Remove(c);
                            if (commandlimits[(int)c.getCommandType()] != -1)
                                commandlimits[(int)c.getCommandType()] += 1;
                        }
                        if (c.newlyCreated)
                        {
                            Show();
                            c.newlyCreated = false;
                        }
                    }
                    return true;
                }
            }
            #endregion
            return false;
        }
Beispiel #9
0
        /// <summary>
        /// Makes the ninja slide on a wall associated with the command passed in.
        /// Returns true if wall slide was successful, false otherwise
        /// </summary>
        public bool Action_WallSlide(Command c)
        {
            if (actionState == NinjaActionState.WallSliding)
                return false;
            Platform p = c.CollidesWithConnectedPlatforms(this);
            //Checks to see if the Ninja collides with Command C's list of tagged platforms
            if (p != null)
            {
                if (velocity.X > 0)
                    wallSlideFacingLeft = false;
                else
                    wallSlideFacingLeft = true;

                actionState = NinjaActionState.WallSliding;
                WallSlidePlatform = p;

                //create rectangle for emission based on ninja's direction
                int xvar;
                if (!wallSlideFacingLeft)
                    xvar = drawRect.Right - 10;
                else
                    xvar = drawRect.Left;
                Rectangle b = new Rectangle(xvar, drawRect.Bottom, 10, 10);

                //create the emitter
                wallSlideSparkEmitter = new Emitter(b, //bounding box of the emitter
                    //new Vector2((float)(facingLeft ? Math.Tan(Math.PI / 18) * NinjaWallSlideSpeed : Math.Tan(Math.PI / 18) * -NinjaWallSlideSpeed),
                    new Vector2(wallSlideFacingLeft ? 0.6215f : -0.6215f, (float)-NinjaWallSlideSpeed), //starting velocity vector (roughly 100 or 80 degrees depending which way ninja is facing)
                    Math.PI / 18,           //maximum angle (in radians) a particle's vector may deviate from the specified one
                    0.3,
                    0.01,                   //intensity (particles are generated at a frequency of 30 frames / thisvalue)
                    300,                    //maximum number of particles
                    30,                     //particle lifespan, in frames
                    SparkTextures,          //Linked list of textures this emitter can use when generating particles
                    new Vector2(0, 1.7f),    //A delta vector acting on particles; in this case, it's working as a lighter form of gravity
                    new Vector2(0, 8f),     //a delta vector cutoff; in this case, it's the max velocity
                    0.2);                   //the fraction of particles generated by this emitter that will employ the above delta vectors to modify their velocity

                wallSlideSparkEmitter.particlesFade = true;
                return true;
            }
            return false;
        }
Beispiel #10
0
        /// <summary>
        /// Makes the ninja wall jump.
        /// Returns true if wall jump was successful, false otherwise
        /// </summary>
        /// <param name="fLeft"></param>
        public bool Action_WallJump(Command c)
        {
            int result = c.WJCollidesWithConnectedPlatforms(this);
            if (result == 2)
            {
                velocity.Y = NinjaJumpHeight;
                wallJumping.reset();
                actionState = NinjaActionState.WallJumping;
                Action_Move(true);
                //facingLeft = c.FacesLeft;

                tempDelay = 10;
                return true;
            }
            else if(result == 4)
            {
                velocity.Y = NinjaJumpHeight;
                wallJumping.reset();
                actionState = NinjaActionState.WallJumping;
                Action_Move(false);
                //facingLeft = c.FacesLeft;

                tempDelay = 10;
                return true;
            }
            return false;
        }
Beispiel #11
0
 /// <summary>
 /// Make the ninja throw its held item
 /// Returns true if item throw was successful, false otherwise
 /// </summary>
 public bool Action_ThrowItem(Command c)
 {
     if (HeldItem != null)
     {
         MusicManager.PlaySoundEffect(SoundEffects.throwItem);
         if (actionState != NinjaActionState.WallSliding) actionState = NinjaActionState.ItemThrowing;
         HeldItem.isFired = true;
         Point target = c.GetActionTargetLocation();
         Point direction = new Point(target.X - c.drawRect.Left, target.Y - c.drawRect.Top);
         HeldItem.SetCenter(new Point(c.drawRect.Center.X, c.drawRect.Center.Y));
         HeldItem.SetDirection(direction);
         HeldItem = null;
         return true;
     }
     return false;
 }
Beispiel #12
0
        /// <summary>
        /// Makes the ninja climb a ledge associated with the command passed in.
        /// Returns true if ledge climb was successful, false otherwise
        /// </summary>
        /// <param name="c"></param>
        public bool Action_LedgeClimb(Command c, LinkedList<Platform> listOfWorldPlatforms)
        {
            LinkedList<Platform> commandConnected = c.ConnectedPlatforms;

            Rectangle collisionBound = drawRect;
            collisionBound.Width *= 2;
            //Player ghost = Copy();
            WorldObject ghost = new WorldObject(drawRect);
            Platform willClimb = null;
            int collisionState;

            if (commandConnected == null) return false;

            //For each connected Platform, check to see if the ninja collides with the side, and then check if its ledge is clear to climb
            foreach (Platform p in commandConnected)
            {
                collisionState = Collision.checkCollisions(this,p);
                if ((collisionState == 2 && velocity.X > 0) || (collisionState == 4 && velocity.X < 0))
                {
                    collisionBound.Y = p.drawRect.Top - collisionBound.Height - 1; // move collision bound to sit on top of the platform.
                    ghost.SetDrawFrame(collisionBound);

                    bool canClimb = true;

                    //check to see if the area where the ninja would ledge climb is clear
                    foreach (Platform p2 in listOfWorldPlatforms)
                    {
                        if (Collision.checkCollisions(ghost, p2) != 0)
                        {
                            canClimb = false;
                            break;
                        }
                    }

                    if (canClimb)
                    {
                        willClimb = p;
                        break;
                    }
                }
            }

            ghost = null;

            if (willClimb == null) return false;

            if (drawRect.Top < willClimb.drawRect.Top)
            {
                actionState = NinjaActionState.WallClimbing;
                velocity.Y = (float)NinjaJumpHeight / 1.25f;
                return true;
            }
            return false;
        }