Moving Code Problem

Talk about making games.

Moving Code Problem

Postby PWNED » Wed Sep 15, 2010 1:27 am

Hey Everyone!

I have another problem with code and I need some help

I want to make my character to move in only one direction at a time aka. press down then up and your character only moves down and is only facing down until I let go of the down key

How do I write this???? plz help
PWNED
 
Posts: 16
Joined: Wed Jul 21, 2010 10:17 pm
Score: 0 Give a positive score

Re: Moving Code Problem

Postby Waluigiftw » Sun Oct 31, 2010 2:38 am

Not sure what you mean exactly? Please elaborate, but if you mean limiting a players movements while one key is being pressed you could always use variables and if staetements, but if you mean the animation then you could also use variables
User avatar
Waluigiftw
 
Posts: 61
Joined: Mon Sep 06, 2010 2:49 pm
Location: Fox lake
Score: 3 Give a positive score

Re: Moving Code Problem

Postby Camper1995 » Sun Oct 31, 2010 8:47 am

Well, this is a bit advanced coding, but nothing impossible.
You know, if I will write the to you here, it will be very long.

So, you have to find some RPG movement demo.

I tihnk that mrJolteon or Hbalde made some. Its in game development section.
Say hello to my little friend.
User avatar
Camper1995
 
Posts: 707
Joined: Tue Dec 30, 2008 7:20 pm
Location: Lost in the past.
Score: 44 Give a positive score

Re: Moving Code Problem

Postby skydereign » Sun Oct 31, 2010 8:59 am

It wouldn't be very hard, just create a variable just say move, and have this in the keydown events for the directions you want.
Code: Select all
if(move==0)
{
    xvelocity=2;
    // set x and y velocity according to the movement
    move=DIR;
}


And on keyup, this.
Code: Select all
if(move==DIR)
{
    move=0;
    xvelocity=0;
    yvelocity=0;
}


Of course you would either need to set the DIR manually, or use #define to set the values. Each direction gets its own DIR value, (1=right, 2=up, 3=left, 4=down).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest