Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Jumping function?

Author
Message
Lavalord7
17
Years of Service
User Offline
Joined: 9th Jan 2007
Location:
Posted: 27th Nov 2008 00:11
I can't figure out how to put jumping into a function... does anyone know how to do this?

zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 27th Nov 2008 00:36 Edited at: 27th Nov 2008 00:36
What type of game? (2d/sidecroller/3d)
And what exactly are you having problems with. (the jump code itself, trajectories, landing platforms)

Rather than using true physics, I usually simulate my jump raising it's height for a period of time and then lowering it. I do the actual jump code in a subroutine rather than a function, becuase the jump takes place over several game loops. So I have to keep track of variables/counters and reset them to inital values after the jump is complete.

In other words, I can't just put my jump code in a for-next loop outside of the main game loop, because if I did I would stall the rest of the game and the game loop doing so.

"When I look at that square... I wish FPSC noobs would stay on their side of the forums and stop polluting these boards." - Benjamin
Lavalord7
17
Years of Service
User Offline
Joined: 9th Jan 2007
Location:
Posted: 27th Nov 2008 01:45 Edited at: 27th Nov 2008 01:49
Ah, a subroutine. That could be done, I didn't even think of that. I'll try that.
EDIT: Nevermind, it does the same thing as the function.

To answer your other questions, it's a fpsish 3d thing, and I'm having problems with writing the code itself.

zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 27th Nov 2008 02:11 Edited at: 27th Nov 2008 02:14
Take a look at this example from forum user Turoid.



This is the best one I found for an FPS. At least I think it works very well, and it is simple to understand.

"When I look at that square... I wish FPSC noobs would stay on their side of the forums and stop polluting these boards." - Benjamin
Lavalord7
17
Years of Service
User Offline
Joined: 9th Jan 2007
Location:
Posted: 27th Nov 2008 02:27 Edited at: 27th Nov 2008 03:07
EDIT2: I got it, thanks!
EDIT3: How do you make functions return values?

zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 27th Nov 2008 04:27 Edited at: 27th Nov 2008 17:35
endfunction [value]

or exitfunction [value] if you need to escape from a function early

note: [value] can be a literal value like 5 or "Hello" or it can be a variable.

===

When calling the function you would setup a proper variable to receive the value or use the return value as a condition. So say a function returns a string.

examples

e.g. storing the return value or using it

mystring$ = callfunction(passinvar,passinvar2)
if callfunction(passinvar,passinvar2) = "Yes"

e.g. returning value via exitfunction & endfunction

function callfunction(var1,var2)
rem function code here
rem if var1 and var2 are the same returnvar$="Yes" else returnvar$="No"
returnvar$=""
if var1 = var2
returnvar$="Yes"
exitfunction returnvar$
endif
returnvar$="No"
endfunction returnvar$

"When I look at that square... I wish FPSC noobs would stay on their side of the forums and stop polluting these boards." - Benjamin
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 27th Nov 2008 07:00 Edited at: 27th Nov 2008 07:01
Just thought i'd post this, may find it interesting or completely usless, but you never know till you try right.

Jumping Box - A box that jumps ever 2 seconds:


A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Lavalord7
17
Years of Service
User Offline
Joined: 9th Jan 2007
Location:
Posted: 28th Nov 2008 23:49 Edited at: 30th Nov 2008 00:38
EDIT: I got it, nevermind.

Login to post a reply

Server time is: 2024-11-24 16:59:53
Your offset time is: 2024-11-24 16:59:53