View Single Post
Old 07-04-2008, 03:17 PM   #5 (permalink)
Rockman87
Experienced Zuner
 
Rockman87's Avatar
 
Join Date: Nov 2007
Location: UT, USA
Posts: 199
Reputation: 25
Send a message via MSN to Rockman87
Default

I rewrote my whole program using a classfile to handle all the movement and positions of the characters. Everything is working right now...thanks for your help. See if this code looks good. This is my first ever C# program.

Movement Calculation:
Code:
//Calculates the next position for the character
        public Vector2 updatePerson()
        {
            //Touch Control for the person
            gamepadStatus = GamePad.GetState(PlayerIndex.One);

            //Vertical Movement
            //Checks to see if last gampad status is the same as current
            if (lastGamepadStatus.ThumbSticks.Left.Y != gamepadStatus.ThumbSticks.Left.Y)
            {
                personPos.Y += (int)((gamepadStatus.ThumbSticks.Left.Y * 5) * -1);
                if ((int)((gamepadStatus.ThumbSticks.Left.Y * 5) * -1) < 0)
                {
                    vert = -1;
                }
                else
                {
                    vert = 1;
                }
                horiz = 0;
            }

            //Horizontal movement
            //Checks to see if last gampad status is the same as current
            if (lastGamepadStatus.ThumbSticks.Left.X != gamepadStatus.ThumbSticks.Left.X)
            {
                personPos.X += (int)((gamepadStatus.ThumbSticks.Left.X * 5) * 1);
                if ((int)((gamepadStatus.ThumbSticks.Left.X * 5) * 1) < 0)
                {
                    horiz = -1;
                }
                else
                {
                    horiz = 1;
                }
                vert = 0;
            }
            //Checks for the Person being off the screen
            if (personPos.Y >= 293)
                personPos.Y = 293;
            if (personPos.Y <= 0)
                personPos.Y = 0;
            if (personPos.X >= 226)
                personPos.X = 226;
            if (personPos.X <= 0)
                personPos.X = 0;
            return personPos;

        }

        public void poseCalculation()
        {
            //Character Animations
            poseCalc++;
            if (poseCalc == 10)
            {
                pose = pose * -1;
                poseCalc = 1;
            }
        }
        //Sends values for Drawing IF statements to correctly draw sprites
        public int[] directionUpdate()
        {
            directionCalc[0] = horiz;
            directionCalc[1] = vert;
            directionCalc[2] = pose;
            return directionCalc;
        }
Paint Sprites:
Code:
spriteBatch.Draw(bg, new Rectangle(0, 0, 240, 320), Color.White);

            if (directionInfo[1] != 0)
            {
                if (directionInfo[1] == 1)
                {
                    if (directionInfo[2] == 1)
                        spriteBatch.Draw(walkDown1, personPos, Color.White);
                    else
                        spriteBatch.Draw(walkDown2, personPos, Color.White);


                }
                else
                {
                    if (directionInfo[2] == 1)
                        spriteBatch.Draw(walkUp1, personPos, Color.White);
                    else
                        spriteBatch.Draw(walkUp2, personPos, Color.White);

                }
            }

            if (directionInfo[0] != 0)
            {
                if (directionInfo[0] == -1)
                {
                    if (directionInfo[2] == 1)
                        spriteBatch.Draw(walkLeft1, personPos, Color.White);
                    else
                        spriteBatch.Draw(walkLeft2, personPos, Color.White);

                }
                else
                {
                    if (directionInfo[2] == 1)
                        spriteBatch.Draw(walkRight1, personPos, Color.White);
                    else
                        spriteBatch.Draw(walkRight2, personPos, Color.White);

                }
            }

            if (directionInfo[2] == 1)
                spriteBatch.Draw(monster, monsterPos, Color.White);
            else
                spriteBatch.Draw(monsterWalk, monsterPos, Color.White);
            if (charsLocation.gameOver())
                spriteBatch.DrawString(Font, "Game Over", gameOver, Color.Red);
            base.Draw(gameTime);
            spriteBatch.End();
If you see a way to improve my coding or make it faster...just let me know. Right now everything works great!
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.



To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.




Rockman87 is offline   Reply With Quote