Author Topic: Double Jump  (Read 4366 times)

hebedaymun

  • Guest
Double Jump
« on: 2006-03-30, 02:07:43 PM »
Hey, I need a script for a new game I'm working on.  I need it so that when you jump once, you can jump again in mid-air.  You know, a double jump.  Kinda subtle like Castlevania.  Could someone make this for me, please?  Maybe my man, Durnurd?  I don't know...

[by the way, i tried to change the topic title from just 'HELP!!!11', but I don't know if it worked or not.]

Bulbaboy

  • Regular
  • **
  • Posts: 36
    • View Profile
Re: Double Jump
« Reply #1 on: 2006-03-30, 03:32:57 PM »
Try this:

Code: [Select]
Dim nJumpTimes

Sub Player_OnControllerMove(OldActions, NewActions)
   With ProjectObj.GamePlayer.PlayerSprite
      If (Not OldActions) And NewActions And ACTION_BUTTON1 Then
         If (.rDef.SolidTest(.X, .Y + .Height) Or .rDef.SolidTest(.X + .Width - 1, .Y + .Height)) Or (Not .pRideOnRef Is Nothing) Then
            .DY = - .rDef.Template.JumpHeight
            nJumpTimes = 1
         ElseIf nJumpTimes = 1 Then
            .DY = - .rDef.Template.JumpHeight
            nJumpTimes = 2
         End If
      End If
   End With
End Sub

It should work.  It also seems like a gravity of 10 down sucks for games involving jumping and such, but I still managed to get the thing to double-jump.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Double Jump
« Reply #2 on: 2006-03-30, 03:48:13 PM »
The above script works nicely.  A few things are that you can't have Up defined as jump as well.  Or rather, if you do, and the player uses that, they can't double jump with it.  They have to use Button 1 and be on the ground to be able to make a first jump, which makes sense.  Also, some games don't allow you to double-jump after you've begun to fall or if you hit something.  This script is very basic, but is well done for the basic double-jump.  If you want any of the other abilities, it wouldn't require much of an addition.
Edward Dassmesser

Bulbaboy

  • Regular
  • **
  • Posts: 36
    • View Profile
Re: Double Jump
« Reply #3 on: 2006-03-30, 04:35:21 PM »
Yeah, and it also occured to me that falling off a cliff will work a little weird (you can jump if the last jump wasn't a double jump, but not otherwise - probably not what anyone wants).  So, here's what should work even better:

Code: [Select]
Dim nJumpTimes

Sub Player_OnControllerMove(OldActions, NewActions)
   With ProjectObj.GamePlayer.PlayerSprite
      If (.rDef.SolidTest(.X, .Y + .Height) Or .rDef.SolidTest(.X + .Width - 1, .Y + .Height)) Or (Not .pRideOnRef Is Nothing) Then

         nJumpTimes = 1    '#this is the number of times you can jump after falling off a cliff

         If (Not OldActions) And NewActions And ACTION_BUTTON1 Then
            .DY = - .rDef.Template.JumpHeight

            nJumpTimes = 1    '#this is the number of times you can jump after jumping off the ground

         End If
      ElseIf nJumpTimes > 0 Then
         If (Not OldActions) And NewActions And ACTION_BUTTON1 Then
            .DY = - .rDef.Template.JumpHeight
            nJumpTimes = nJumpTimes - 1
         End If
      End If
   End With
End Sub

Now, there are at least three obvious modifications you can make: you can change the number of times you can jump if you fall off a cliff; you can change the number of times you can jump after a normal, grounded jump; and you can change which button you use to jump (note that you have to change BOTH the "ACTION_BUTTON1"s).  If you want the up arrow to be jump, change it to "ACTION_UP".  If you want two buttons, say button 1 and up, do "(ACTION_BUTTON1 Or ACTION_UP)" - the parentheses, of course, are crucial.

The number of jumps, on the other hand, should be self-explanatory - I've even added an unusual character to the beginning of the comment (#) and added whitespace around them so hopefully anyone can see where they are.

And that should take care of one of durnurd's complaints/suggestions, and an obvious flaw that I should've seen before.

hebedaymun

  • Guest
Re: Double Jump
« Reply #4 on: 2006-03-30, 04:55:29 PM »
Sweet, thanks, Bulbaboy!  You're the man!  Sheesh, sorry about bashing on you sometime in the past, I really need to learn how to NOT be an a******.  Oh, yeah, I was wondering, I'm not sure if you mentioned this (and if you did please don't yell!), but would it be possible to modify it to where you need a specific item to activate it?  Instead of having the ability to double jump straight off the bat?  that would make it perfect!  And thanks a bunch again, man.

EDIT: Oh, crap, hold up.  When I put the script with my game it wont even start up...am I doing something wrong here?
« Last Edit: 2006-03-30, 05:08:08 PM by hebedaymun »

Bulbaboy

  • Regular
  • **
  • Posts: 36
    • View Profile
Re: Double Jump
« Reply #5 on: 2006-03-30, 06:09:08 PM »
My guess is you forgot this code, just like I did at first:

Code: [Select]
HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16

Add that to the very end of the script file.  At least, I'm guessing that's the problem.

As for making it so you can't double jump from the start, try this: add "Dim bJumpItem" (or a similar variable name) to the beginning of the file, add this somewhere in the file:

Code: [Select]
Sub Player_OnSpecialFunction(Func)
   If Func.Name = "DoubleJumpUnlock" Then
      bJumpItem = 1
   End If
End Sub

And change the line "ElseIf nJumpTimes > 0 Then" to "ElseIf nJumpTimes > 0 And bJumpItem Then".  Then, just add a special function called "DoubleJumpUnlock" that raises an event and is triggered when you unlock the double jump power.  I think that should work.

hebedaymun

  • Guest
Re: Double Jump
« Reply #6 on: 2006-03-30, 08:13:47 PM »
Thanks, man, I'll check it out.

Bulbaboy

  • Regular
  • **
  • Posts: 36
    • View Profile
Re: Double Jump
« Reply #7 on: 2006-03-30, 10:05:01 PM »
Yeah, no problem.  It IS nice to have something simple enough to make progress on, after all - and someone's gonna have to write a double jump script eventually.

Just... do me/us a favor and don't spam like that again, alright ^_^;?