Increasing height

Advanced game related topics
Nubcake
Enthusiast
Enthusiast
Posts: 195
Joined: Thu Feb 03, 2011 7:44 pm

Increasing height

Post by Nubcake »

Hi

This isn't an 'advanced game topic' but it is for game programming. I'm testing out this 2D game i'm creating and i've been stuck with this problem for hours now.
My player can jump in the game but every time he does , his y co-ordinate increases by about 10 pixels and i'm sure it's a simple error to you but not to me. Why is this happening?

Code: Select all

  If Player\jumping=1
   Sprite\row=13
   Sprite\frames=3
   Sprite\delayed=8
   Player\y-Player\jumph
   If Player\jumph<=0
     Player\jumph=0
   EndIf
   If Sprite\timer=32
     Sprite\timer=0
     Player\jumping=0  
     Player\jumph=0
     Player\jump=1
   EndIf
   If Player\jumph>=1
     Player\jump=0
   EndIf
   Debug Player\y
   If Player\jumph<=1 And Player\jump=1 
     Player\jumph+0.1
   Else
      Player\jumph-0.1
   EndIf
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Increasing height

Post by netmaestro »

It looks baffed but without the rest of the code it's impossible to say where.
BERESHEIT
Nubcake
Enthusiast
Enthusiast
Posts: 195
Joined: Thu Feb 03, 2011 7:44 pm

Re: Increasing height

Post by Nubcake »

netmaestro wrote:It looks baffed but without the rest of the code it's impossible to say where.
The rest of the code is irrelevant , i know this , the problem lies in the one i submitted.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Increasing height

Post by netmaestro »

Ok. Good luck with it.
BERESHEIT
User avatar
Kiffi
Addict
Addict
Posts: 1510
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Increasing height

Post by Kiffi »

Nubcake wrote:
netmaestro wrote:It looks baffed but without the rest of the code it's impossible to say where.
The rest of the code is irrelevant , i know this , the problem lies in the one i submitted.
:lol:
Hygge
User avatar
bobobo
Enthusiast
Enthusiast
Posts: 206
Joined: Mon Jun 09, 2003 8:30 am

Re: Increasing height

Post by bobobo »

maybe it's easier to increase weight than height :mrgreen:
[sorry for that]
사십 둘 .
Zach
Addict
Addict
Posts: 1678
Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:

Re: Increasing height

Post by Zach »

Are you comparing a float to an integer?

Maybe its causing a confusing rounding error for the CPU?


My guess would be try making the comparative (if its not already a float, do that too) 1.0 instead of just "1"
User avatar
skywalk
Addict
Addict
Posts: 4260
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Increasing height

Post by skywalk »

Just put a loop around your logic section and print a 'Truth Table' based on all possibilities. :idea:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
kenmo
Addict
Addict
Posts: 2068
Joined: Tue Dec 23, 2003 3:54 am

Re: Increasing height

Post by kenmo »

I'm trying to make sense of your code...

. What is Player\jumping vs. Player\jump? They both seem to be integer 0/1 flags?

. Player\y is obvious (a float I hope), and Player\jumph seems to be your changing y-velocity (also a float)?

. \timer seems to stop your jump after exactly 32 frames? (instead of checking for collision with anything?)

. \row, \frames, and \delayed seem irrelevant to the jump physics... right? Are they drawing-related variables?

And what do you mean his y-coordinate increases 10 pixels... is it instantaneous, or does he smoothly jump upward but then stop after 10 pixels? If you could fit this code into a small running example, we could probably fix it in minutes.

(It also seems like you're overcomplicating it... typically my "Player" objects just have a y-coordinate, a y-velocity, and an in-air 0/1 flag. Of course there is also a gravity value, and a jump-button-pressed flag as well.)
Post Reply