question about jumping ???

Game Editor comments and discussion.

question about jumping ???

Postby tinkergnomie » Sun Nov 24, 2013 3:36 pm

hello everyone ..... hows it going ?

i was wondering about how could you script a draw actor event that's triggered by
perhaps a button state change or something of that nature ?? i tried do work it a
few different ways ... but none of those ways worked... so ugh i'm stumped!!!
could there possibly be anyone to assist me with this ?
tinkergnomie
 
Posts: 6
Joined: Thu Oct 31, 2013 10:08 am
Score: 0 Give a positive score

Re: question about jumping ???

Postby DarkParadox » Sun Nov 24, 2013 4:48 pm

There's some functions in GE just for getting key states in scripts. The one you'll most likely need is called GetKeyState()
For jumping, though, it'll repeat every frame, so in this example, make a variable using Game-Editor's GUI that's called jumping and is set to an actor variable, then place code like this in your actor's draw actor event:
Code: Select all
// This sets our variable, we use this to check
// which keys are active.
char* key = GetKeyState();

// And now we start checking our variable.
// the "&& jumping" makes sure this only happens
// if keydown for SPACE is YES and jumping is NO
// so it doesn't keep repeating.
if(key[KEY_SPACE] == 1 && jumping == 0) {
    yvelocity = -8;
    jumping = 1;
}

In this case, you'll also want to make another event on this actor, where collision with the top of the ground sets jumping to 0, so you can jump again.

You can make as many IF statements as you want, of course, using most of the keys on the keyboard. This here is the list of all the keys that you can use like in the above example:
Code: Select all
KEY_BACKSPACE
KEY_TAB
KEY_CLEAR
KEY_RETURN
KEY_PAUSE
KEY_ESCAPE
KEY_SPACE
KEY_EXCLAIM
KEY_QUOTEDBL
KEY_HASH
KEY_DOLLAR
KEY_AMPERSAND
KEY_QUOTE
KEY_LEFTPAREN
KEY_RIGHTPAREN
KEY_ASTERISK
KEY_PLUS
KEY_COMMA
KEY_MINUS
KEY_PERIOD
KEY_SLASH
KEY_0
KEY_1
KEY_2
KEY_3
KEY_4
KEY_5
KEY_6
KEY_7
KEY_8
KEY_9
KEY_COLON
KEY_SEMICOLON
KEY_LESS
KEY_EQUALS
KEY_GREATER
KEY_QUESTION
KEY_AT
KEY_LEFTBRACKET
KEY_BACKSLASH
KEY_RIGHTBRACKET
KEY_CARET
KEY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WN
KEY_GP2X_BUTTON_LEFT
KEY_GP2X_BUTTON_RIGHT
KEY_GP2X_BUTTON_UPLEFT
KEY_GP2X_BUTTON_UPRIGHT
KEY_GP2X_BUTTON_DOWNLEFT
KEY_GP2X_BUTTON_DOWNRIGHT
KEY_GP2X_BUTTON_CLICK
KEY_GP2X_BUTTON_A
KEY_GP2X_BUTTON_B
KEY_GP2X_BUTTON_X
KEY_GP2X_BUTTON_Y
KEY_GP2X_BUTTON_L
KEY_GP2X_BUTTON_R
KEY_GP2X_BUTTON_START
KEY_GP2X_BUTTON_SELECT
KEY_GP2X_BUTTON_VOLUP
KEY_GP2X_BUTTON_VOLDOWN
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: question about jumping ???

Postby tinkergnomie » Mon Nov 25, 2013 12:44 pm

hello dark paradox.....


i tried doing what you explained as best as i could understand it and still it doesn't seem to work.
all it seems to do is when i press the key is the actor flies upward ( yvelocity=-8) .....???
perhaps there's something missing from your instructions ???? i tried putting the first set of code into the
actors "draw actor" event just as you instructed,.... then i went into the variables section and declared
"jumping" as an "actor variable". i'm not sure what else i should have done in light of seeing your code ....
is there some other variable(s) i might need to establish for this to happen???
tinkergnomie
 
Posts: 6
Joined: Thu Oct 31, 2013 10:08 am
Score: 0 Give a positive score

Re: question about jumping ???

Postby tinkergnomie » Mon Nov 25, 2013 4:13 pm

i just tried to do the following code below......
it works as a jump ... but as long as the key is pressed the actor
will continue to rise up in the air and thats not exactly what i was hoping
for to happen.


// This sets our variable, we use this to check
// which keys are active.
char* key = GetKeyState();
// And now we start checking our variable.
// the "&& jumping" makes sure this only happens
// if keydown for SPACE is YES and jumping is NO
// so it doesn't keep repeating.
if(key[KEY_SPACE] == 1 && jumping == 0)
{
yvelocity = -8;
jumping = 1;
}

if(key[KEY_SPACE] == 0 && jumping == 1)
{
yvelocity = +8;
jumping = 0;
}
******************************************************************

however .... as long as i have the key constantly pressed the actor keeps flying upwards and i was hoping to fix that where when i press the key the jump lasts for maybe 2 seconds or less then the actor i would like to have plummet to the ground.
tinkergnomie
 
Posts: 6
Joined: Thu Oct 31, 2013 10:08 am
Score: 0 Give a positive score

Re: question about jumping ???

Postby DarkParadox » Mon Nov 25, 2013 4:42 pm

No, no no...
In a new event, Collision with TOP of whatever actor is your GROUND, put this code:
Code: Select all
jumping = 0;


And in your draw-actor event:
Code: Select all
char* key = GetKeyState();
if(key[KEY_SPACE] == 1 && jumping == 0)
{
yvelocity = -8;
jumping = 1;
}

// This is for gravity.
yvelocity = yvelocity + 0.8;


The variable "jumping" keeps track of if our actor is in the air or not (1 or 0). If our actor is not currently jumping (jumping==0), and space is pressed (key[KEY_SPACE]==1), it should trigger it's movement upward (yvelocity = -8), and set jumping to say we've already pressed the jump key (jumping=1). Then, when we collide with the top of the ground, we set jumping to 0 again, to say that we've finished jumping and can jump again.
(yvelocity = yvelocity + 0.8 ) is for gravity. It's constantly adding a little downward momentum to our actor to offset jumps or whatever.
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: question about jumping ???

Postby tinkergnomie » Mon Nov 25, 2013 5:26 pm

hello dark paradox. .. thank you for the new code info, it worked excellently.
thanks a million,.... i really appreciate you helping me understand this.
tinkergnomie
 
Posts: 6
Joined: Thu Oct 31, 2013 10:08 am
Score: 0 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest