Of platforms, invisible barriers, and Multi-Jumps

BlitzPlus Forums/BlitzPlus Programming/Of platforms, invisible barriers, and Multi-Jumps

Tomas Khan(Posted 2008) [#1]
I have been working on a simple single-screen "fight the enemies" game recently, and previously it's worked fairly well. However, I have now encountered some problems.

The conditions: Everything is slippery, including three operational platforms. This should not change.

The problems: The player simply refuses to move left, and either he can't jump at all (which makes platforms irrelevant) or else can jump in mid-air (which reminds me of a code for Super Mario Bros. 3 called Multi-Jumps)... as many times as he wants.

The relevant code:
Left and right (on slippery surfaces):

If KeyDown(RIGHTKEY)
	player\xv = player\xv + 1
	player\direction = DIRECTIONRIGHT
	player\frame = (player\frame + 1)Mod (8) + (8 * player\direction - 8)
ElseIf KeyDown(LEFTKEY)
	player\xv = player\xv - 1
	player\direction = DIRECTIONLEFT
	player\frame = (player\frame + 1)Mod (8) + (8 * player\direction - 8)
Else
	If player\xv > 0
		player\xv = player\xv - 1
	ElseIf player\xv < 0
		player\xv = player\xv + 1
	EndIf
EndIf

If player\xv > player\maxxv ;This is positive
	player\xv = player\maxxv
ElseIf player\xv < player\minxv ;... and this negative
	player\xv = player\minxv
EndIf

player\x = player\x + player\xv ;This to actually move him

If player\x < 20
	player\x = 20
ElseIf player\x > 780
	player\x = 780
EndIf 



The jump code:

If KeyHit(UPKEY)
	player\dnru = 1
	JUMP = 4
	GRAVITY = 0
EndIf

If JUMP = 4
	JUMP = 4
	
	If player\xv = 0
		player\xv = 1
	EndIf
	
	player\y = player\y - MOVEY + GRAVITY
	
	GRAVITY = GRAVITY + 1
EndIf

If player\y > 482
	player\y = 482
EndIf

If player\y >= 482
	player\dnru = 0
	JUMP = 0
	GRAVITY = MOVEY
EndIf



Explanation: JUMP seems stuck at 4, player\dnru at 1; thus, were I to put in code to ignore Up he wouldn't jump at all. Also, he turns left but doesn't move left, almost as if it were keeping player\xv at 0. He has moved left and right before; he just doesn't now.

The basic question: Why aren't JUMP and player\dnru changing?

Thanks in advance to everyone with answers or ideas.


KillerX(Posted 2008) [#2]
Whenever you change the the values, print them so that you can see which ones aren't changing, and which If statements aren't executing.

Also, put you code inside of code tags when you post it.


Tomas Khan(Posted 2008) [#3]
I'm already tracking JUMP and player\dnru, as well as player\direction (even though I knew what his direction was, I wanted to be sure it wasn't a directional problem). So I know which ones aren't changing; I just don't know why.

And when you say "code tags," do you mean the tag called "code" or the tag called "codebox"? I suppose it depends on the situation, though.


KillerX(Posted 2008) [#4]
Try tracking Player\y


Forum Codes you can use either code or codebox


Tomas Khan(Posted 2008) [#5]
You mean as in to see whether he's actually on the ground or not? Hmm. Maybe that will help.

... Well, he's right where he should be, as my code states. I'm also tracking player\xv now to see what it's doing.

... Found the problem with the not-move-left thing, that "If JUMP = 4 and player\xv = 0, player\xv = 1." Well, that's good, at least. Now the only thing we'll have to deal with is the Multi-Jumps.


KillerX(Posted 2008) [#6]
Try moving the line GRAVITY = 0 from the If statement If KeyHit(UPKEY), to the If statement If player\y >= 482.


Tomas Khan(Posted 2008) [#7]
That gives us a 'pogo' effect. Because JUMP isn't changing, it tells him to jump again when he lands. It does stop the Multi-Jumps, though, and he doesn't pogo on the platforms (but he can't jump on the platforms right now, and I think if I put in a gravity-resetting line in the platform code he'd pogo on them too).

If we could just figure out why JUMP and player\dnru aren't changing... They should be changing, shouldn't they?

EDIT: Okay, that's odd. For some reason player\dnru was sticking because of the "fall from platform" code I had, which set player\dnru to 1. I can now get it to change to 0 by landing, and with an extra "And player\dnru = 0" on the jump conditional I've made a mostly successful jumping system...

But what about JUMP? And how could I keep the player from having a (single) mid-air jump allowed after falling from a platform?


Sauer(Posted 2008) [#8]
This may help, it was from a mini game embedded in Dungeons of Fear. It may be of use; I solved the double jump problem by not eliminating the double jump, but by making it so weak its useless. As for the single jump when falling, just set the jump "power" to 0 when a fall is detected... this could be done by a simple variable If-Then statement in my code, but I didn't add it.



Hope it helps in some way.


Tomas Khan(Posted 2008) [#9]
Hmm... I guess I'm not sure that I can fix the "platform jump," since it was a line in that conditional that kept the player from jumping normally in the first place. Maybe I'll just leave the "platform jump" in -- a little developer secret, say.

If you have any ideas on how to completely fix it without messing up the other jumps, of course, it would be nice to hear about it. Otherwise, I suppose this is just how it's going to be. Thank you both for your help.

Oh, but Sauer, I'm afraid I didn't exactly understand just how you fixed your double-jumps. Could you edit in some extra comments, perhaps, to explain a little more about the way you prevent extra jumping? That might be helpful -- and it could be helpful enough to merit more tinkering with the jump code.


Sauer(Posted 2008) [#10]
Well, here's a brief explanation.

Basically, when the player jumps, it subtracts a certain number from player y (JUMP). What I did, is that every time a player jumps, JUMP is set to zero. Throughout the program, JUMP is increased until it reaches 50.

It may help to think of JUMP as your "jumping power." When you jump, it depletes your jumping power, and you have to wait for it to count up again. This prevents the player from jumping repeatedly in mid-air, because every time they hit jump, their power is drained to 0.

If this doesn't make sense, try running the code I posted. (1) moves, (2) changes direction of movement, as signified by the arrow in the top right, and (0) jumps. The third number from the top right is your JUMP power. Try it out, that may be the easiest way to understand how it works.

If you still don't understand, I'll take it back and comment it up. Right now I just don't have the time.

Good luck!


Tomas Khan(Posted 2008) [#11]
Well, I use a MOVEY-GRAVITY system, as you can see above. I don't exactly understand how your system works, but when I tried putting a jump-inhibiting line into this

[pseudocode]

If Not ImagesOverlap ;(player and platform) And JUMP <> 1
	JUMP = 4
EndIf

[/pseudocode]


he wouldn't jump at all. So I'm confused.


Sauer(Posted 2008) [#12]
To be honest, I don't really get your code either, so I guess we're in the same spot ;)

I can't help you any further though... but I know someone here can. I wish you the best of luck, sorry my code wasn't of help.


KillerX(Posted 2008) [#13]
Try changing
If KeyHit(UPKEY)
to
If KeyHit(UPKEY) and gravity = 0



Tomas Khan(Posted 2008) [#14]
It's fixed! I put in an extra "[If] GRAVITY <= MOVEY" on the jump conditional, and now he can't jump if he's falling! I'll test it out about a million times now to make sure it's completely operational, but it appears that the problem is solved. Thank you both very, very much!