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

Talk about making games.

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

Postby bat78 » Thu Feb 19, 2015 11:50 pm

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.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

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

Postby digiot » Fri Feb 20, 2015 2:02 pm

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 !
User avatar
digiot
 
Posts: 211
Joined: Sat Mar 17, 2012 2:29 pm
Score: 7 Give a positive score

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

Postby bat78 » Fri Feb 20, 2015 8:02 pm

This is the gravity powerback. Activates when player do y-20
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

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

Postby digiot » Fri Feb 20, 2015 8:30 pm

bat78 wrote:This is the gravity powerback. Activates when player do y-20

Yes, but I mean the double query for not-checksum.
User avatar
digiot
 
Posts: 211
Joined: Sat Mar 17, 2012 2:29 pm
Score: 7 Give a positive score

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

Postby bat78 » Fri Feb 20, 2015 9:28 pm

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.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

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

Postby skydereign » Fri Feb 20, 2015 9:58 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

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

Postby bat78 » Fri Feb 20, 2015 10:13 pm

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.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

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

Postby skydereign » Fri Feb 20, 2015 10:20 pm

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;
    }
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

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

Postby bat78 » Fri Feb 20, 2015 10:23 pm

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.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

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

Postby digiot » Fri Feb 20, 2015 11:08 pm

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 !
User avatar
digiot
 
Posts: 211
Joined: Sat Mar 17, 2012 2:29 pm
Score: 7 Give a positive score

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

Postby bat78 » Fri Feb 20, 2015 11:15 pm

Could you clarify what is on your level of "gEing".
This time I need to make sure I understand you correctly. :)
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

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

Postby digiot » Fri Feb 20, 2015 11:46 pm

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 ?
User avatar
digiot
 
Posts: 211
Joined: Sat Mar 17, 2012 2:29 pm
Score: 7 Give a positive score

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

Postby bat78 » Sat Feb 21, 2015 12:13 am

Why? I wanted to make it portable.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

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

Postby skydereign » Sat Feb 21, 2015 7:59 am

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).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

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

Postby digiot » Sat Feb 21, 2015 6:07 pm

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 !
User avatar
digiot
 
Posts: 211
Joined: Sat Mar 17, 2012 2:29 pm
Score: 7 Give a positive score

Next

Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron