Page 1 of 2

Copy/Paste this code for perfect player jump with mouse acc.

PostPosted: Thu Feb 19, 2015 11:50 pm
by bat78
Since Hblade was bored and he decided to release something..
Then I decided to do the same.. because I am bored too.

Copy/paste this code (in draw actor). It will make the player jump once if you accelerate the mouse upwards.

Code: Select all
static int timer, checksum, yprev;
double xmprevious, ymprevious;

if(++timer == 5)
{
    timer = 0;
    xmprevious = xmouse;
    ymprevious = ymouse;
}

if(ymouse < (ymprevious-20) && !checksum)
{
    if(!checksum) { checksum = 1; yprev = y; }
    yvelocity = -1;
}

if(y < yprev - 100)
{
    yvelocity = 1;
} else if(y >= yprev && yvelocity == 1) { yvelocity = 0; checksum = 0; }


The code assumes that the center of the screen is the platform surface. If the player is placed above 0, it will fall down to 0 as it is powered by gravity.
You can easily condition the code to be parsed only if the player is on your specific y.. so you are free of possible failures.
For the ease of such use, you can functionize this whole code and set some arguments as a setting.

Re: Copy/Paste this code for perfect player jump with mouse

PostPosted: Fri Feb 20, 2015 2:02 pm
by digiot
Nice one, thanks !

But what is this construct for :
bat78 wrote:
Code: Select all
if(ymouse < (ymprevious-20) && !checksum)
    {
        if(!checksum) { checksum = 1; yprev = y; }
        yvelocity = -1;
    }

Double helps double ?


Cheers !

Re: Copy/Paste this code for perfect player jump with mouse

PostPosted: Fri Feb 20, 2015 8:02 pm
by bat78
This is the gravity powerback. Activates when player do y-20

Re: Copy/Paste this code for perfect player jump with mouse

PostPosted: Fri Feb 20, 2015 8:30 pm
by digiot
bat78 wrote:This is the gravity powerback. Activates when player do y-20

Yes, but I mean the double query for not-checksum.

Re: Copy/Paste this code for perfect player jump with mouse

PostPosted: Fri Feb 20, 2015 9:28 pm
by bat78
digiot wrote:
bat78 wrote:This is the gravity powerback. Activates when player do y-20

Yes, but I mean the double query for not-checksum.

It will be much easier if you just remove it and see what happens than me explaining it.

Re: Copy/Paste this code for perfect player jump with mouse

PostPosted: Fri Feb 20, 2015 9:58 pm
by skydereign
bat78 wrote:
digiot wrote:
bat78 wrote:This is the gravity powerback. Activates when player do y-20

Yes, but I mean the double query for not-checksum.

It will be much easier if you just remove it and see what happens than me explaining it.

digiot you are right in that it a redundant check that doesn't do anything.

Re: Copy/Paste this code for perfect player jump with mouse

PostPosted: Fri Feb 20, 2015 10:13 pm
by bat78
skydereign wrote:
bat78 wrote:
digiot wrote:
bat78 wrote:This is the gravity powerback. Activates when player do y-20

Yes, but I mean the double query for not-checksum.

It will be much easier if you just remove it and see what happens than me explaining it.

digiot you are right in that it a redundant check that doesn't do anything.


Ha, no. He didn't say it is redundant. He asked why it exists. And then..
Then surprisingly you get it wrong. Without that condition, you will be able to jump during the fall.
Next time before you state about me mistaking, please, at least make sure you have tested your insight.

Re: Copy/Paste this code for perfect player jump with mouse

PostPosted: Fri Feb 20, 2015 10:20 pm
by skydereign
bat78 wrote:Ha, no. He didn't say it is redundant. He asked why it exists. And then..
Then surprisingly you get it wrong. Without that condition, you will be able to jump during the fall.
Next time before you state about me mistaking, at least make sure you have tested your insight.

He was curious on the why there were two !checksum checks. The nested one is redundant, and when you remove it it still works properly. It's simple logic.

Code: Select all
if(ymouse < (ymprevious-20) && !checksum)
    {
        // this code only triggers when !checksum is true
        // so there is no need to check again for this next line
        if(!checksum) { checksum = 1; yprev = y; }
        yvelocity = -1;
    }

Re: Copy/Paste this code for perfect player jump with mouse

PostPosted: Fri Feb 20, 2015 10:23 pm
by bat78
skydereign wrote:
bat78 wrote:Ha, no. He didn't say it is redundant. He asked why it exists. And then..
Then surprisingly you get it wrong. Without that condition, you will be able to jump during the fall.
Next time before you state about me mistaking, at least make sure you have tested your insight.

He was curious on the why there were two !checksum checks. The nested one is redundant, and when you remove it it still works properly.


The nested one isn't redundant. Especially in gE.. it could happen that the outer condition parses !checksum as true, but since it is draw actor, since old positions are saved any 5 frames, it could happen to fail.
It was something to do with the way gE handles draw actor right. You told me of that once.

If he meant that, then I can say that this is the insecuring.. though.. nothing other then that. You can remove it.
This is not serious code, it got tested only several times. I just wrote it out of the boredom. Look at my project bitfox for something relevant.

Re: Copy/Paste this code for perfect player jump with mouse

PostPosted: Fri Feb 20, 2015 11:08 pm
by digiot
Ha, ha, ha, yes, it LOOKS like a redundancy, but I wouldn't believe that !
But a short test hasn't shown that jumping during fall on my system.
My guess also was, that it might be an timing issue between the inner and outer
condition.
But what might cause that, idk.
bat78 wrote:This is not serious code, it got tested only several times. I just wrote
it out of the boredom. Look at my project bitfox for something relevant.
This here meets exactly my level of GEing, sorry !


Cheers !

Re: Copy/Paste this code for perfect player jump with mouse

PostPosted: Fri Feb 20, 2015 11:15 pm
by bat78
Could you clarify what is on your level of "gEing".
This time I need to make sure I understand you correctly. :)

Re: Copy/Paste this code for perfect player jump with mouse

PostPosted: Fri Feb 20, 2015 11:46 pm
by digiot
bat78 wrote:Could you clarify what is on your level of "gEing".

Oh, just something, I can follow at least. Your monster-project is definetly not
my league...

Look, with what an idea I'm coming up :
What about, making the checksum variable a global one, instead of a static local one ?

Re: Copy/Paste this code for perfect player jump with mouse

PostPosted: Sat Feb 21, 2015 12:13 am
by bat78
Why? I wanted to make it portable.

Re: Copy/Paste this code for perfect player jump with mouse

PostPosted: Sat Feb 21, 2015 7:59 am
by skydereign
bat78 wrote:Why? I wanted to make it portable.

People generally avoid static because either they don't have much experience using static variables, or that it acts a little weirdly in gE events and a lot of the times actor variables are a better fit. In this case static does make it portable across actors but not clones, since clones share the same static variables (also any actor that inherits the event will share the static value).

Re: Copy/Paste this code for perfect player jump with mouse

PostPosted: Sat Feb 21, 2015 6:07 pm
by digiot
Declaring variables as static is a very essential function feature.
To be honest, I wasn't sure, if you can use statics in the local actor code at all !

But what means "portable" in this context ?

@ bat78 :
The reason I would try global here is, to avoid the timing problems in the
draw actor event, though I haven't seen any on my system.
How did you code that part, have you first taken the normal solution, and
then the problem occurs, and you've tried to fix it with the second not-checksum
query ? Or was you aware of that GE behaviour, and have done it preventive ?

I see, you are very proud of your new bitfox project, and I believe, you are right !
But let me tell you, this little script is much more relevant at least for me,
'coz it brought up a subject, which teaches me something useful in the course
of this thread, thanks !


Cheers !