Sponsors



Go Back   Zune Boards > Zune Discussions > Zune Games > Development Discussions

New Member?



 
Register Zunecentive FAQ Members List Calendar Search Today's Posts Mark Forums Read

Development Discussions All developers who are coding games may stop by here for any help, suggestions, and everything development related.

Reply
 
LinkBack Thread Tools
Old 07-03-2008, 08:53 PM   #1 (permalink)
Experienced Zuner
 
Rockman87's Avatar
 
Join Date: Nov 2007
Location: UT, USA
Posts: 182
Reputation: 23
Send a message via MSN to Rockman87
$zB: 121
Donate
Default [In Progress]Xmonster...need a little help

I am programing a game called Xmonster. Right now I have all the basics programed. Everything is working fine except a few things. It is runable on the zune. But, I ran into a little wall.

I have sprites to imatate walking, however it only displays left and right animation because they are the last of the program...even when you are pressing up and down. If I comment out the left and right animations, the up and down work. Please help me find out how to code it so the character faces the direction he is walking.


Movement Code:
Code:
//Touch Control for the person
            GamePadState gamepadstatus = GamePad.GetState(PlayerIndex.One);
            
            //Vertical Movement
            personPos.Y += (int)((gamepadstatus.ThumbSticks.Left.Y * 5) * -1);
            if ((int)((gamepadstatus.ThumbSticks.Left.Y * 5) * -1) < 0)

                vert = -1;

            else

                vert = 1;
            //Horizontal movement
            personPos.X += (int)((gamepadstatus.ThumbSticks.Left.X * 5) * 1);
            if ((int)((gamepadstatus.ThumbSticks.Left.X * 5) * 1) < 0)

                horiz = -1;

            else

                horiz = 1;

Drawing code:
Code:
if (vert == 1)
            {
                if (pose == 1)
                    spriteBatch.Draw(walkDown1, personPos, Color.White);
                else
                    spriteBatch.Draw(walkDown2, personPos, Color.White);


            }
            else
            {
                if (pose == 1)
                    spriteBatch.Draw(walkUp1, personPos, Color.White);
                else
                    spriteBatch.Draw(walkUp2, personPos, Color.White);

            }

            if (horiz == -1)
            {
                if (pose == 1)
                    spriteBatch.Draw(walkLeft1, personPos, Color.White);
                else
                    spriteBatch.Draw(walkLeft2, personPos, Color.White);

            }
            else
            {
                if (pose == 1)
                    spriteBatch.Draw(walkRight1, personPos, Color.White);
                else
                    spriteBatch.Draw(walkRight2, personPos, Color.White);

            }
            spriteBatch.Draw(monster, monsterPos, Color.White);
            pose = pose * -1;
If you need the full program...please mail me and I'll give you the link.
Thanks

the monster sprite, is a sprite from the zune game caveIn...I needed an extra sprite for the testing of this program...It will so be replaced once the code is correct.
__________________

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
Remove Advertisements Sponsored Links
Advertisement
 
Old 07-03-2008, 09:10 PM   #2 (permalink)
zB Programmer
Experienced Member
 
LedZepp's Avatar
 
Join Date: Mar 2007
Posts: 966
Reputation: 114
$zB: 626
Donate
Default

I dont know if this will work but you can try doing this in your button press code when you press right(or left) set the vertical variable to zero, and when up or down is pressed set the vertical variable to 0

I believe what is happening is that when you press(say right) the horizontal is assigned 1, but if you press up then vert is assigned 1 too, therefore both variables are assigned directions and only the very last if statement(the way you have it) carries out(because first it checks for side directions(and even though it finds the right one, it goes to the next if statement and finds that thats true too so it does that one), then it checks up/down)
__________________

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

Last edited by LedZepp : 07-03-2008 at 09:17 PM.




LedZepp is offline   Reply With Quote
Old 07-04-2008, 08:58 AM   #3 (permalink)
Experienced Zuner
 
Rockman87's Avatar
 
Join Date: Nov 2007
Location: UT, USA
Posts: 182
Reputation: 23
Send a message via MSN to Rockman87
$zB: 121
Donate
Default

Hey thanks... that helped alot. It did not fix the problem... but I had to use what you said along with another addition. I created a lastgamepadstate. Then before it set new values it check to see if the lastgamepadstate == the current gamepadstate. If not then it changed thte value and painted it to the screen. I had to use your recomendation to tell it what to paint...so it wouldn't paint all of them.

Thanks
__________________

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
Old 07-04-2008, 11:10 AM   #4 (permalink)
zB Programmer
Jr. Member
 
DiNoGames's Avatar
 
Join Date: May 2008
Location: Bremen, germany
Posts: 347
Reputation: 101
Send a message via Skype™ to DiNoGames
$zB: 257
Donate
Default

Quote:
Originally Posted by Rockman87 View Post
Code:
if (vert == 1)
            {
                if (pose == 1)
                    spriteBatch.Draw(walkDown1, personPos, Color.White);
                else
                    spriteBatch.Draw(walkDown2, personPos, Color.White);


            }
            else
            {
                if (pose == 1)
                    spriteBatch.Draw(walkUp1, personPos, Color.White);
                else
                    spriteBatch.Draw(walkUp2, personPos, Color.White);

            }

            if (horiz == -1)
            {
                if (pose == 1)
                    spriteBatch.Draw(walkLeft1, personPos, Color.White);
                else
                    spriteBatch.Draw(walkLeft2, personPos, Color.White);

            }
            else
            {
                if (pose == 1)
                    spriteBatch.Draw(walkRight1, personPos, Color.White);
                else
                    spriteBatch.Draw(walkRight2, personPos, Color.White);

            }
            spriteBatch.Draw(monster, monsterPos, Color.White);
            pose = pose * -1;
I bet your code draws the vertical movement. But you do not notice because no matter if you walk vertical, you draw a horizontal sprite over the vertical one, speak you draw the horizontal sprite always.

Why?

Because you check if horiz is -1 and what if it zero (as supposed when you do not walk horizontally)? Well, instead of doing nothing you say: ELSE
So no matter which value is stored in horiz (including 0), when its unequal to -1 it goes through the following code:

Code:
                if (pose == 1)
                    spriteBatch.Draw(walkRight1, personPos, Color.White);
                else
                    spriteBatch.Draw(walkRight2, personPos, Color.White);
Can you see your problem?
__________________

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.






DiNoGames is offline   Reply With Quote
Old 07-04-2008, 02:17 PM   #5 (permalink)
Experienced Zuner
 
Rockman87's Avatar
 
Join Date: Nov 2007
Location: UT, USA
Posts: 182
Reputation: 23
Send a message via MSN to Rockman87
$zB: 121
Donate
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
Old 07-05-2008, 05:13 AM   #6 (permalink)
zB Programmer
Jr. Member
 
DiNoGames's Avatar
 
Join Date: May 2008
Location: Bremen, germany
Posts: 347
Reputation: 101
Send a message via Skype™ to DiNoGames
$zB: 257
Donate
Default

[quote=Rockman87;257171]
Code:
                personPos.Y += (int)((gamepadStatus.ThumbSticks.Left.Y * 5) * -1);
                if ((int)((gamepadStatus.ThumbSticks.Left.Y * 5) * -1) < 0)
                {
.
.
.
I think in your code its not very important, but never do the same calculations more than once if not needed.
Store the value instead.
In addition, why do you add a value to personPos.Y and negate it by multiplying with -1? You could better subtract it from the beginning. It would be the same...

Applying these things, the code should rather look like:

Code:
    int TmpValue =  (int)(gamepadStatus.ThumbSticks.Left.Y * 5);           
    personPos.Y -= TmpValue;
    if (TmpValue < 0)
    {
.
.
.
__________________

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.






DiNoGames is offline   Reply With Quote
Old 07-05-2008, 07:42 AM   #7 (permalink)
Experienced Zuner
 
Rockman87's Avatar
 
Join Date: Nov 2007
Location: UT, USA
Posts: 182
Reputation: 23
Send a message via MSN to Rockman87
$zB: 121
Donate
Default

Ya, your correct... that does make more sense. That will keep the game running faster.

You probably noticed that the previous methods above are methods I call from a class file into my main program. Is this more efficient than just having all the code in your main program. Is this faster?
__________________

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
Old 07-05-2008, 09:31 AM   #8 (permalink)
zB Programmer
Jr. Member
 
DiNoGames's Avatar
 
Join Date: May 2008
Location: Bremen, germany
Posts: 347
Reputation: 101
Send a message via Skype™ to DiNoGames
$zB: 257
Donate
Default

Classes are the way to go... I don't think that its a good idea to put everything in the main program. Make use of OOP as much as you can.
__________________

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.






DiNoGames is offline   Reply With Quote
Old 07-05-2008, 12:20 PM   #9 (permalink)
Experienced Zuner
 
Rockman87's Avatar
 
Join Date: Nov 2007
Location: UT, USA
Posts: 182
Reputation: 23
Send a message via MSN to Rockman87
$zB: 121
Donate
Default

Why wont this code work.... It deploys error free but does not update the speed of the monster.


Main game code: This piece of code scores and then sends the score to the Level Control class( if multiple of 10) to see if person reached the next level
Code:
//Check to see if scores
            if (anyCollisions[0] == true)
            {
                score++;
                scoreStr = score.ToString();
                personPos2 = charsLocation.updatePerson2();
                if (score % 10 == 0)
                    level.advanceLevel(score);
                charsLocation.collisionReset();
            }
Level Control class: This method in the Level control class updates the level and sends the new speed of the monster to the class file that controls all the movement and positions of characters
Code:
public  void advanceLevel(int score)
        {
            //Level 2
            if (score == 10)
            {
                monsterControl.changeMonSpeed(2.0f);
                
            }
Movement class: This piece of code recieves the value that Level class sent and saves it as the speed of the monster...(then when the game updates again...it should be going at the new speed.
Code:
public void changeMonSpeed(float chngSpeed)
        {
            monsterSpeed = 2f;
        }
To my knowledge this should change monsterSpeed in the movement class and everything should work great...but it doesn't. The monster goes the same speed even when your score is 10 or greater.

this is how the monster moves in the movement class:
Code:
public Vector2 updateMonster()
        {
            //Position for the Monster
            if (monsterPos.Y < personPos.Y)
                monsterPos.Y += monsterSpeed;
            else
                monsterPos.Y -= monsterSpeed;
            if (monsterPos.X < personPos.X)
                monsterPos.X += monsterSpeed;
            else
                monsterPos.X -= monsterSpeed;
            return monsterPos;
        }
__________________

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
Old 07-05-2008, 12:28 PM   #10 (permalink)
zB Programmer
Experienced Member
 
LedZepp's Avatar
 
Join Date: Mar 2007
Posts: 966
Reputation: 114
$zB: 626
Donate
Default

Upload your whole movement class to PasteBin, it will help us help you
__________________

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




LedZepp is offline   Reply With Quote
Old 07-05-2008, 12:38 PM   #11 (permalink)
Experienced Zuner
 
Rockman87's Avatar
 
Join Date: Nov 2007
Location: UT, USA
Posts: 182
Reputation: 23
Send a message via MSN to Rockman87
$zB: 121
Donate
Default

ok... my movement class(Locations) is on paste bin

[edit]If you checked paste bin before you see this message check again... l didn't change something in my code. Because it wasn't working used a solid value instead of a var for debugging purposes... now it is back a variable

http://pastebin.com/m66dd0130
__________________

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.

Last edited by Rockman87 : 07-05-2008 at 12:50 PM.




Rockman87 is offline   Reply With Quote
Old 07-05-2008, 12:48 PM   #12 (permalink)
zB Programmer
Experienced Member
 
LedZepp's Avatar
 
Join Date: Mar 2007
Posts: 966
Reputation: 114
$zB: 626
Donate
Default

Well I cant see anything wrong, The only thing that could be happening is that this line:
Code:
level.advanceLevel(score);
Might not be executing, put a breakpoint on it and see if it ever gets hit, if not then thats your problem.
__________________

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




LedZepp is offline   Reply With Quote
Old 07-05-2008, 12:59 PM   #13 (permalink)
Experienced Zuner
 
Rockman87's Avatar
 
Join Date: Nov 2007
Location: UT, USA
Posts: 182
Reputation: 23
Send a message via MSN to Rockman87
$zB: 121
Donate
Default

I put the break point where you said... it reaches the break point... so then I added breakpoints to all the other places, even the one that changes monster speed. It reaches them all.

If it hits the line that changes the speed...why doesn't the speed change?
__________________

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
Old 07-05-2008, 12:59 PM   #14 (permalink)
Experienced Zuner
 
soccermansince1993's Avatar
 
Join Date: May 2008
Posts: 220
Reputation: 7
$zB: 345
Donate
Default

You could ask other game creators if you could borrow parts of their codes!
Just a thought!



soccermansince1993 is offline   Reply With Quote
Old 07-05-2008, 01:01 PM   #15 (permalink)
zB Programmer
Experienced Member
 
LedZepp's Avatar
 
Join Date: Mar 2007
Posts: 966
Reputation: 114
$zB: 626
Donate
Default

Could it be that the score is increasing too fast, and before you know it the moster is moving at 2f instead of .25f? try increasing the 2f to like 20f and see if you see a difference

Quote:
You could ask other game creators if you could borrow parts of their codes!
Just a thought!
And what good would that do, then he(or she) wouldnt learn by themselves and just use something another person has created.
__________________

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

Last edited by LedZepp : 07-05-2008 at 01:04 PM.




LedZepp is offline   Reply With Quote
Old 07-05-2008, 01:02 PM   #16 (permalink)
zB Programmer
Jr. Member
 
DiNoGames's Avatar
 
Join Date: May 2008
Location: Bremen, germany
Posts: 347
Reputation: 101
Send a message via Skype™ to DiNoGames
$zB: 257
Donate
Default

public void changeMonSpeed(float chngSpeed)
{
monsterSpeed = 2f;
}


You send the new speed to the function but you do not set it... you always set it to 2f.

monsterSpeed += chngSpeed;

would be the way to go.....
__________________

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.






DiNoGames is offline   Reply With Quote
Old 07-05-2008, 01:09 PM   #17 (permalink)
Experienced Zuner
 
Rockman87's Avatar
 
Join Date: Nov 2007
Location: UT, USA
Posts: 182
Reputation: 23
Send a message via MSN to Rockman87
$zB: 121
Donate