Moving problem

Non-platform specific questions.

Postby Novice » Wed Mar 15, 2006 4:02 pm

No prob. 8)
I think a shorter way of doing this would be to asign varables to keys so instead of
Code: Select all
char *key=GetKeyState();


if (key[KEY_DOWN]==0&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "run_up", FORWARD);
else if (key[KEY_DOWN]==1&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "stop_down", FORWARD);
else if (key[KEY_DOWN]==0&&key[KEY_LEFT]==1&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "stop_left", FORWARD);
else if (key[KEY_DOWN]==0&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==1)
ChangeAnimation("Event Actor", "stop_right", FORWARD);

you would use

Code: Select all
if (DOWN==0&&LEFT==0&&RIGHT==0)
ChangeAnimation("Event Actor", "run_up", FORWARD);
else if (DOWN==1&&LEFT==0&&RIGHT==0)
ChangeAnimation("Event Actor", "stop_down", FORWARD);
else if (DOWN==0&&LEFT==1&&RIGHT==0)
ChangeAnimation("Event Actor", "stop_left", FORWARD);
else if (DOWN==0&&LEFT==0&&RIGHT==1)
ChangeAnimation("Event Actor", "stop_right", FORWARD);

It dosent shorten the script much but i think it should work faster baceuse the key states are called only from one place instead of each button.
Im sure ,if everyone gives it a little tought, that togheter we can find a better way to do this.
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby AleX_XelA » Wed Mar 15, 2006 6:29 pm

Actually, there is a problem! I can't go in a diagonal way! Also, I think it would be better to rewrite the code, for the simple fact that keeping as most as we can in the Draw Actor event is the best thing to do. Otherwise, how could I go diagonal with your code? I've tried various things but never got a descent result.
AleX_XelA
 
Posts: 28
Joined: Mon Mar 06, 2006 9:04 pm
Score: 0 Give a positive score

Postby Novice » Wed Mar 15, 2006 10:46 pm

Do you have diagnoal animations or do you want to use some of these you alredy have? I'l try to figure it out in the morning i'm to sleepy now to think.
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby AleX_XelA » Thu Mar 16, 2006 5:20 pm

Well, I'd like it to work like this :

If Actor is going left and I press down
Actor goes down left
Animation stays "run_left"

And it should work like this for any other alternative. I've tried tweaking your code but it doesn't work... Thanks for your help!
AleX_XelA
 
Posts: 28
Joined: Mon Mar 06, 2006 9:04 pm
Score: 0 Give a positive score

Postby Novice » Thu Mar 16, 2006 6:01 pm

Ok i managed to make it work, just one question, do you want the animation to stay run_left no mater wich key was pressed first, down or left or you want to change it to run down if down was pressed first. Do you undestand what i'm trying to say? In my opinion the second option looks better.
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby AleX_XelA » Thu Mar 16, 2006 6:29 pm

The second option of course! I've heard the name somewhere, I think it's called Prioritized Movement... How did you do it?!?! I'll be more than happy to understand how you managed it!
AleX_XelA
 
Posts: 28
Joined: Mon Mar 06, 2006 9:04 pm
Score: 0 Give a positive score

Postby Novice » Thu Mar 16, 2006 8:22 pm

Ok just change the draw code to this, so it will allow all movement
Code: Select all
char *key=GetKeyState();

if (key[KEY_UP]==1) y-=2;
if (key[KEY_DOWN]==1) y+=2;
if (key[KEY_LEFT]==1) x-=2;
if (key[KEY_RIGHT]==1) x+=2;


Now change the animations in the key down events, so if you had this on key down down.
Code: Select all
char *key=GetKeyState();


if (key[KEY_UP]==0&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "run_down", FORWARD);
else if (key[KEY_UP]==1&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "stop_up", FORWARD);
else if (key[KEY_UP]==0&&key[KEY_LEFT]==1&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "stop_left", FORWARD);//CHANGE THIS!!!
else if (key[KEY_UP]==0&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==1)
ChangeAnimation("Event Actor", "stop_right", FORWARD);//AND THIS!!!


change it to
Code: Select all
char *key=GetKeyState();


if (key[KEY_UP]==0&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "run_down", FORWARD);
else if (key[KEY_UP]==1&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "stop_up", FORWARD);
else if (key[KEY_UP]==0&&key[KEY_LEFT]==1&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "run_left", FORWARD);//TO THIS!!!
else if (key[KEY_UP]==0&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==1)
ChangeAnimation("Event Actor", "run_right", FORWARD);//TO THIS!!!


This checks if any other keys except UP are pressed and makes the player run instead of stop. This should be done in all key down events. Let me know if it works correctly because i haven't had the chance to test it out completly.
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby AleX_XelA » Thu Mar 16, 2006 8:34 pm

It works incredibly good! ONE LAST THING though! Can't you do something so that only 2 keys can be pressed for the walking? Because if I start pressing Left, Then Right, And Down, the animations change to something completely different and the Actor goes into a complete different way. That's the last thing and then this walking demo will be 100% glitch free!
AleX_XelA
 
Posts: 28
Joined: Mon Mar 06, 2006 9:04 pm
Score: 0 Give a positive score

Postby Novice » Fri Mar 17, 2006 10:29 am

Ok this i solved this problem, now when you press three buttons at once all the possibilities are covered so if you press RIGH,DOWN and then LEFT the player will walk down an so on. I haven't covered the possibility of someone pressing all four buttons but IMO if somebodey does this then they probably shouldn't be allowed to play games and should be shot on sight. Just kidding but i doubt that there will be a need for that. So here is how it goes:

Add this to Key down (DOWN)
Code: Select all
else if (key[KEY_UP]==0&&key[KEY_LEFT]==1&&key[KEY_RIGHT]==1)
ChangeAnimation("Event Actor", "run_down", FORWARD);
else if (key[KEY_UP]==1&&key[KEY_LEFT]==1&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "run_left", FORWARD);
else if (key[KEY_UP]==1&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==1)
ChangeAnimation("Event Actor", "run_right", FORWARD);


Key down (UP)
Code: Select all
else if (key[KEY_DOWN]==0&&key[KEY_LEFT]==1&&key[KEY_RIGHT]==1)
ChangeAnimation("Event Actor", "run_up", FORWARD);
else if (key[KEY_DOWN]==1&&key[KEY_LEFT]==1&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "run_left", FORWARD);
else if (key[KEY_DOWN]==1&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==1)
ChangeAnimation("Event Actor", "run_right", FORWARD);


Key down (LEFT)
Code: Select all
else if (key[KEY_UP]==0&&key[KEY_RIGHT]==1&&key[KEY_DOWN]==1)
ChangeAnimation("Event Actor", "run_down", FORWARD);
else if (key[KEY_UP]==1&&key[KEY_RIGHT]==1&&key[KEY_DOWN]==0)
ChangeAnimation("Event Actor", "run_up", FORWARD);
else if (key[KEY_UP]==1&&key[KEY_RIGHT]==0&&key[KEY_DOWN]==1)
ChangeAnimation("Event Actor", "run_left", FORWARD);


Key down (RIGHT)
Code: Select all
else if (key[KEY_UP]==0&&key[KEY_LEFT]==1&&key[KEY_DOWN]==1)
ChangeAnimation("Event Actor", "run_down", FORWARD);
else if (key[KEY_UP]==1&&key[KEY_LEFT]==0&&key[KEY_DOWN]==1)
ChangeAnimation("Event Actor", "run_right", FORWARD);
else if (key[KEY_UP]==1&&key[KEY_LEFT]==1&&key[KEY_DOWN]==0)
ChangeAnimation("Event Actor", "run_up", FORWARD);


Key up (Down)
Code: Select all
else if (key[KEY_UP]==0&&key[KEY_LEFT]==1&&key[KEY_RIGHT]==1)
ChangeAnimation("Event Actor", "stop_down", FORWARD);


Key up (UP)
Code: Select all
else if (key[KEY_DOWN]==0&&key[KEY_LEFT]==1&&key[KEY_RIGHT]==1)
ChangeAnimation("Event Actor", "stop_up", FORWARD);


Key up (LEFT)
Code: Select all
else if (key[KEY_UP]==1&&key[KEY_DOWN]==1&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "stop_left", FORWARD);


Key up (RIGHT)
Code: Select all
else if (key[KEY_UP]==1&&key[KEY_DOWN]==1&&key[KEY_LEFT]==0)
ChangeAnimation("Event Actor", "stop_right", FORWARD);


And that's it.
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby AleX_XelA » Fri Mar 17, 2006 5:25 pm

Thanks a LOT man, you are a great coder! It's really helpful! Thanks!
AleX_XelA
 
Posts: 28
Joined: Mon Mar 06, 2006 9:04 pm
Score: 0 Give a positive score

Postby richaal » Thu Apr 20, 2006 12:33 pm

Sorry for the post. I will post later with the real solution I found out.


Ok so this is what I have done to make the actor move in the direction the first key is pressed, if u press right it goes right no matter what other key you press. This is the code I'll put it only for left and right but you can apply it to all the directions you want: (Oh i forgot this also moves the actor)
---------------------------------------------------------------
first I created 2 variables: dir and aniselect.
---------------------------------------------------------------
left key pressed code:

if (dir == 0)
dir = 1;

if( dir == 1)
if( x >= -100)
x -= 5;
if( aniselect == 0) {
ChangeAnimation( "player", "run_left", FORWARD);
aniselect = 1;
}
---------------------------------------------------------
left key released code:

if( dir == 1 && aniselect == 1) {
dir = 0;
aniselect = 0;
ChangeAnimation( "player", "paused_left", FORWARD);
}
------------------------------------------------------------
right key pressed code:

if( dir==0)
dir = 2;

if( dir == 2)
if (x <= 100)
x += 5;

if (aniselect == 0) {
ChangeAnimation("player", "run_right", FORWARD);
aniselect = 2; }
-----------------------------------------------------------------
right key released code:

if( dir == 2 && aniselect == 2){
dir=0;
aniselect = 0;
ChangeAnimation( "player", "pause_right", FORWARD);
}
----------------------------------------------------------------

If you have any questions just ask! Hope its usefull
richaal
 
Posts: 2
Joined: Tue Apr 18, 2006 1:19 pm
Score: 0 Give a positive score

Previous

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest