Of platforms, invisible barriers, and Multi-Jumps

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

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.

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.

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.

Try tracking Player\y


Forum Codes you can use either code or codebox

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.

Try moving the line GRAVITY = 0 from the If statement If KeyHit(UPKEY), to the If statement If player\y >= 482.

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?

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.

Graphics 400,300,32,2
frametimer=CreateTimer(60)
Const player$="0"
Const ground$="xxxxxxxxxx"
Const leftarrow$="<=="
Const rightarrow$="==>"
Const gate$="ll"

Global gameover=False
Global time=2000
Global jump=10
Global door=False

Type player 
	Field x,y
End Type

Type arrow
	Field image$
End Type

Global platformer.player=New player
platformer\x=10
platformer\y=270

Global dir.arrow=New arrow
dir\image$=rightarrow$

While gameover=False
	WaitTimer(frametimer)
	UpdatePlatformerBackground()
	UpdatePlatformerPlayer()
	Gravity()
	Flip
	Cls
	Delay 10
Wend

Function UpdatePlatformerBackground()
	;Text StringWidth(ground$)*1,280,ground$   <=== Floor pieces
	;Text StringWidth(ground$)*2,280,ground$
	;Text StringWidth(ground$)*3,280,ground$
	;Text StringWidth(ground$)*4,280,ground$
	If time>0
		Text 0,280,ground$
		Text 100,250,ground$
		Text 200,220,ground$
		Text 100,190,ground$
		Text 0,160,ground$
		Text 0,130,ground$
		Text 0,100,ground$
		Text 0,70,ground$
		Color 128,128,128
		Text 150,100,"Leap of Faith"
		Color 255,255,255
		Text 340,150,ground$
		Text 340,120,ground$
		Text 340,90,ground$
		Text 340,60,ground$
		Text 240,30,ground$
		Text 120,30,ground$ 
	EndIf
	
	Text 370,0,dir\image$	
	Text 370,12,time
	Text 370,24,jump
	time=time-1
	If time<=0
		time=0
	EndIf 
	Text 120,20,gate$
End Function 

Function UpdatePlatformerPlayer()
	Text platformer\x,platformer\y,player$
	If KeyDown(2)
		If dir\image$=leftarrow$
			platformer\x=platformer\x-4
		EndIf
		If dir\image$=rightarrow$
			platformer\x=platformer\x+4
		EndIf 
	EndIf
	If KeyHit(3)
		If dir\image$=leftarrow$
			dir\image$=rightarrow$
		Else
			dir\image=leftarrow$
		EndIf 
	EndIf
	If KeyHit(11)
		platformer\y=platformer\y-jump
		jump=0 
	EndIf 
	
	If platformer\x<=0
		platformer\x=0
	EndIf
	If platformer\x>=395
		platformer\x=395
	EndIf	
	If platformer\y>300
		gameover=True
	EndIf
	jump=jump+1
	If jump>=50
		jump=50
	EndIf 
End Function 


Function Gravity()
	If time>0
	;0,280;0,160;0,130;0,100;0,70;0,10
	If platformer\x>=0 And platformer\x<=0+StringWidth(ground$)
		If platformer\y>=270 And platformer\y<=282
			platformer\y=270
		EndIf
		If platformer\y>=150 And platformer\y<=162
			platformer\y=150
		EndIf
		If platformer\y>=120 And platformer\y<=132
			platformer\y=120
		EndIf 
		If platformer\y>=90 And platformer\y<=102
			platformer\y=90
		EndIf
		If platformer\y>=60 And platformer\y<=72
			platformer\y=60
		EndIf 
	EndIf	
	;100,250 and 100,190
	If platformer\x>=100 And platformer\x<=100+StringWidth(ground$)
		If platformer\y>=240 And platformer\y<=252
			platformer\y=240
		EndIf
		If platformer\y>=180 And platformer\y<=192
			platformer\y=180
		EndIf
	EndIf
	;200,220
	If platformer\x>=200 And platformer\x<=200+StringWidth(ground$)
		If platformer\y>=210 And platformer\y<=222
			platformer\y=210
		EndIf
	EndIf
	;150,100
	If platformer\x>=150 And platformer\x<=150+StringWidth(ground$)
		If platformer\y>=90 And platformer\y<=102
			platformer\y=90
		EndIf
	EndIf
	;340,150;340,120;340,90;340,60
	If platformer\x>=340 And platformer\x<=340+StringWidth(ground$)
		If platformer\y>=140 And platformer\y<=152
			platformer\y=140
		EndIf
		If platformer\y>=110 And platformer\y<=122
			platformer\y=110
		EndIf 
		If platformer\y>=80 And platformer\y<=92
			platformer\y=80
		EndIf
		If platformer\y>=50 And platformer\y<=62
			platformer\y=50
		EndIf  
	EndIf
	;240,30
	If platformer\x>=240 And platformer\x<=240+StringWidth(ground$)
		If platformer\y>=20 And platformer\y<=32
			platformer\y=20
		EndIf
	EndIf
	;120,30
	If platformer\x>=120 And platformer\x<=120+StringWidth(ground$)
		If platformer\y>=20 And platformer\y<=32
			platformer\y=20
		EndIf
	EndIf
	;gate
	If platformer\x>=120 And platformer\x<=120+StringWidth(gate$)
		If platformer\y>=20 And platformer\y<=32
			platformer\y=20
			Text 0,0,"You win!!"
			door=True
			gameover=True 
		EndIf
	EndIf
	
	EndIf 
	platformer\y=platformer\y+4
End Function


Hope it helps in some way.

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.

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!

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.

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.

Try changing
If KeyHit(UPKEY)
to
If KeyHit(UPKEY) and gravity = 0


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!