Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
need helping with jumping
#1
Hey guys. i'm working on a game with a circle running back and forth over a bridge. eventually, it will be a scrolling game, but for now, you just run back and forth.

i started with a circle going back and forth over a bridge, gaining points each time they got to the other side. now, i'm trying to make it so that my circle jumps when you press "8" on the keyboard, but it's not working.

can someone help me out? i know my code is probably horrible, especially the jumping code. thanks.

i don't know if it's obvious from the jump sub, but i'm trying to have it so once they jump, they go up for a bit and then down.
Code:
'sub declarations

DECLARE SUB intro ()
DECLARE SUB startgame ()
DECLARE SUB drawcirc ()
DECLARE SUB erasecirc ()
DECLARE SUB score ()
DECLARE SUB jump ()

'so all of the subs can access them
COMMON SHARED xpos
COMMON SHARED ypos
COMMON SHARED pts
COMMON SHARED real
COMMON SHARED jumper
COMMON SHARED jcount


SCREEN 13
CLS

CALL intro 'calls the intro SUB, which displays the title screen

CALL startgame ' starts the game



END

SUB drawcirc

CIRCLE (xpos, ypos), 7, 2
CIRCLE (xpos, ypos), 6, 5
CIRCLE (xpos, ypos), 5, 2
CIRCLE (xpos, ypos), 4, 5
CIRCLE (xpos, ypos), 3, 4
CIRCLE (xpos, ypos), 2, 7
CIRCLE (xpos, ypos), 1, 3




END SUB

SUB erasecirc

LINE (0, 20)-(320, 150), 0, BF

END SUB

SUB intro
COLOR 7
PRINT "Bridge Walker!"
PRINT "--------------"
PRINT
PRINT "AKA the best game ever. is there a game better? NO!"
PRINT
PRINT
PRINT "Controls:"
PRINT
PRINT "Move Left   '4'"
PRINT "Move Right- '6'"
PRINT "Jump- '8'"
PRINT "Quit-       Q"
PRINT
PRINT
PRINT "Press any key to continue"
WHILE INKEY$ = ""
WEND
CLS

END SUB

SUB jump

SELECT CASE jcount
CASE 1 TO 4
  ypos = ypos - 4
CASE 5 TO 8
  ypos = ypos + 4
CASE 9
  jumper = 0
  jcount = -1
END SELECT

jcount = jcount + 1



END SUB

SUB save

LOCATE 5, 1
INPUT "Pick a slot:", snum

OPEN "s1.txt" FOR INPUT AS #1
OPEN "s2.txt" FOR INPUT AS #2
OPEN "s3.txt" FOR INPUT AS #3




PRINT "Slot 1:"


PRINT "Slot 2"


PRINT "Slot 3"







END SUB

SUB score

                              
SELECT CASE real

'gives you points if you cross the bridge
CASE 0
GOTO done
CASE 1
IF xpos > 250 THEN pts = pts + 1
CASE 2
IF xpos < 51 THEN pts = pts + 1

END SELECT
done:


'switches real if you reach a side of the bridge
IF xpos < 51 THEN real = 1
IF xpos > 250 THEN real = 2



LOCATE 1, 1
PRINT "Score:"; pts

END SUB

SUB startgame

'Draw the bridge and such
LINE (0, 150)-(50, 200), 6, BF
LINE (51, 150)-(250, 170), 8, BF
LINE (251, 150)-(500, 500), 6, BF

'starting position for the bridgecrosser
xpos = 10
ypos = 142

'starting points
pts = 0
real = 0
jumper = 0
jcount = 0

DO

drawcirc 'draws the circle

DO
ink$ = INKEY$
INKY$ = LCASE$(ink$)
LOOP UNTIL INKY$ = "4" OR INKY$ = "q" OR INKY$ = "6" OR INKY$ = "8"

IF INKY$ = "8" THEN
IF jumper = 0 THEN jumper = 1 AND jcount = 1
IF jumper = 1 THEN CALL jump
END IF


IF INKY$ = "4" THEN xpos = xpos - 4
IF INKY$ = "6" THEN xpos = xpos + 4

CALL erasecirc
CALL score

LOOP UNTIL INKY$ = "q"

END SUB
Reply
#2
It seems you need to read up on what the AND keyword does Wink It's a logical operator, not a statement separator.

Your code:

Code:
IF INKY$ = "8" THEN
IF jumper = 0 THEN jumper = 1 AND jcount = 1
IF jumper = 1 THEN CALL jump
END IF

What is happening there when '8' is pressed is the following (in pseudo code):

Code:
tmp1 = (jcount = 1) <- This will return either -1 or 0 depending on if jcount = 1 or not.
tmp2 = (1 AND tmp1) <- AND compares bits and returns on the matching ones.  Thus, you get a return value of 1 or 0 if tmp1 is -1 or 1.
jumper = tmp2 <- Set the return value

So, what happens ultimately is that jumper is being set to 0 (since jcount is 0) and jcount is never set.

How do you fix this? Replace then AND with a colon (Smile. A colon (Smile is used to separate statements on the same line in BASIC. ie:

Code:
IF INKY$ = "8" THEN
IF jumper = 0 THEN jumper = 1 : jcount = 1
IF jumper = 1 THEN CALL jump
END IF

Further, you may want to move the line 'IF jumper = 1 THEN CALL jump' outside the main IF...THEN statement so that the ball will continue it's jump without having to press '8' constantly Wink

Code:
IF INKY$ = "8" THEN
IF jumper = 0 THEN jumper = 1 : jcount = 1
END IF
IF jumper = 1 THEN CALL jump

If I may be so bold Wink I could suggest a couple other things too.

First, you don't need to get the results of the INKEY$ function then make it lower case, you can do it at once:

Code:
INKY$ = LCASE$(INKEY$)

Second, you can allow the game loop to run even without player input by just making a check to see if INKY$ is null:

Code:
IF INKY$ > "" THEN
   ' Do input processing here
END IF

The problem with this is, the game runs too fast and flickery. Which is why you can third, add a vsync wait using the age-old trick of:

Code:
WAIT &H3DA, 8, 8
WAIT &H3DA, 8

When I modifed your main game loop to do this, the ball bounced nicely with a single key-stroke and I was able to play on!

Resultant game loop:

Code:
DO

   drawcirc 'draws the circle

   INKY$ = LCASE$(INKEY$)

   IF INKY$ > "" THEN
      IF INKY$ = "8" THEN
         IF jumper = 0 THEN jumper = 1: jcount = 1
      END IF

      IF INKY$ = "4" THEN xpos = xpos - 4
      IF INKY$ = "6" THEN xpos = xpos + 4
   END IF

   IF jumper = 1 THEN CALL jump

   WAIT &H3DA, 8, 8
   WAIT &H3DA, 8

   CALL erasecirc
   CALL score

LOOP UNTIL INKY$ = "q"
Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
Reply
#3
That's awesome! Thanks 1000101! you even answered my second question before i was going to ask it! I fixed my first jumping problem, and i was just about to come on and ask about the screen flicker. thanks a lot.

i changed the code around a bit in the jump sub, so you can move in midair, and so the jump isn't as fast. i'm going to add "bad guys" now, so there will be some challenge to the game.
Reply
#4
now i have another problem. i was trying to make a small orb that appeared on the bridge. it doesn't work though. i'm trying to make an orb that will move across the screen for my circle to jump over.
Reply
#5
i fixed that. here's what i have so far, it's still a bit buggy

Code:
DECLARE SUB checkdeath ()
'sub declarations



DECLARE SUB jump ()
DECLARE SUB intro ()
DECLARE SUB startgame ()
DECLARE SUB drawcirc ()
DECLARE SUB erasecirc ()
DECLARE SUB score ()
DECLARE SUB badguys ()
DECLARE SUB orb ()
DECLARE SUB dragon ()
DECLARE SUB checkdead ()
DECLARE SUB DEAD ()


'so all of the subs can access them
COMMON SHARED xpos, ypos
COMMON SHARED pts
COMMON SHARED real, oreal, dreal
COMMON SHARED jumper, jcount
COMMON SHARED oxpos, oypos, orbst
COMMON SHARED inky$
COMMON SHARED drst, dxpos, dypos
COMMON SHARED bmax, badguynum



beg:
SCREEN 13
CLS

intro 'calls the intro SUB, which displays the title screen

startgame ' starts the game

GOTO beg

END

SUB badguys

IF pts = 1 THEN bmax = 1
IF pts = 6 THEN bmax = 2
IF pts = 11 THEN bmax = 3



bchance = INT(RND * 400) + 1

SELECT CASE bchance
CASE 1 TO 2
IF bmax >= badguynum THEN
  IF orbst = 0 THEN orbst = 1
  badguynum = badguynum + 1
END IF
CASE 399 TO 400
IF bmax >= badguynum THEN
  IF drst = 0 THEN drst = 1
  badguynum = badguynum + 1
END IF
END SELECT


IF orbst = 1 OR orbst = 2 THEN CALL orb
IF drst = 1 OR drst = 2 THEN CALL dragon



END SUB

SUB checkdeath

IF orbst = 2 THEN
FOR i = (xpos - 8) TO (xpos + 8)
  FOR j = (oxpos - 5) TO (oxpos + 5)
   IF i = j THEN
    IF oypos = ypos THEN CALL DEAD
   END IF
  NEXT j
NEXT i
END IF





END SUB

SUB DEAD
CLS
PRINT "You died! Your score was "; pts; "."
PRINT "Press the spacebar to continue!"
orbst = 0
drst = 0
DO
fish$ = INKEY$
LOOP UNTIL fish$ = " "

inky$ = "q"


END SUB

SUB dragon

IF drst = 1 THEN
dreal = real
IF dreal = 1 THEN dxpos = 300
IF dreal = 2 THEN dxpos = 20
dypos = 143
drst = 2
END IF



IF dreal = 1 THEN
dxpos = dxpos - 1
END IF

IF dreal = 2 THEN
dxpos = dxpos + 1
END IF


IF dxpos < -10 OR oxpos > 330 THEN drst = 0: badguynum = badguynum - 1

LINE (dxpos - 6, dypos - 10)-(dxpos + 6, dypos + 7), 2, BF



END SUB

SUB drawcirc

CIRCLE (xpos, ypos), 8, 3
CIRCLE (xpos, ypos), 7, 2
CIRCLE (xpos, ypos), 6, 5
CIRCLE (xpos, ypos), 5, 2
CIRCLE (xpos, ypos), 4, 5
CIRCLE (xpos, ypos), 3, 4
CIRCLE (xpos, ypos), 2, 7
CIRCLE (xpos, ypos), 1, 3




END SUB

SUB erasecirc

LINE (0, 20)-(320, 150), 0, BF

END SUB

SUB intro
COLOR 7
PRINT "Bridge Walker!"
PRINT "--------------"
PRINT
PRINT "AKA the best game ever. is there a game better? NO!"
PRINT
PRINT "|---------------|"
PRINT "|Controls:      |"
PRINT "|               |"
PRINT "|Move Left-  '4'|"
PRINT "|Move Right- '6'|"
PRINT "|Jump-       '8'|"
PRINT "|Quit-       'Q'|"
PRINT "|---------------|"

PRINT
PRINT "Press 1 to Start the Game, or 2 to quit:"
DO
choice = VAL(INKEY$)
LOOP UNTIL choice = 1 OR choice = 2

IF choice = 2 THEN END
IF choice = 1 THEN GOTO k

k:



CLS

END SUB

SUB jump

SELECT CASE jcount
CASE 1 TO 50
  ypos = ypos - 1
CASE 51 TO 100
  ypos = ypos + 1
CASE 101
  jumper = 0
  jcount = -1
END SELECT

jcount = jcount + 1



END SUB

SUB orb

IF orbst = 1 THEN
oreal = real
IF oreal = 1 THEN oxpos = 300
IF oreal = 2 THEN oxpos = 20
oypos = 143
orbst = 2
END IF



IF oreal = 1 THEN
oxpos = oxpos - 1
END IF

IF oreal = 2 THEN
oxpos = oxpos + 1
END IF


IF oxpos < -10 OR oxpos > 330 THEN orbst = 0: badguynum = badguynum - 1

pk = INT(RND * 10) + 1


CIRCLE (oxpos, oypos), 5, 4
CIRCLE (oxpos, oypos), 3, 1
CIRCLE (oxpos, oypos), 1, pk


END SUB

SUB save

LOCATE 5, 1
INPUT "Pick a slot:", snum

OPEN "s1.txt" FOR INPUT AS #1
OPEN "s2.txt" FOR INPUT AS #2
OPEN "s3.txt" FOR INPUT AS #3




PRINT "Slot 1:"


PRINT "Slot 2"


PRINT "Slot 3"







END SUB

SUB score

                              
SELECT CASE real

'gives you points if you cross the bridge
CASE 0
GOTO done
CASE 1
IF xpos > 250 THEN pts = pts + 1
CASE 2
IF xpos < 51 THEN pts = pts + 1

END SELECT

done:


'switches real if you reach a side of the bridge
IF xpos < 51 THEN real = 1
IF xpos > 250 THEN real = 2

LOCATE 1, 1
PRINT "Score:"; pts





END SUB

SUB startgame

'Draw the bridge and such
LINE (0, 150)-(50, 200), 6, BF
LINE (51, 150)-(250, 170), 8, BF
LINE (251, 150)-(500, 500), 6, BF

'starting position for the bridgecrosser
xpos = 10
ypos = 143

'starting points
pts = 0
real = 0
jumper = 0
jcount = 0
badguynum = 0

DO

   drawcirc 'draws the circle

   inky$ = LCASE$(INKEY$)

   IF inky$ > "" THEN
      IF inky$ = "8" THEN
         IF jumper = 0 THEN jumper = 1: jcount = 1
      END IF

    
      IF inky$ = "4" THEN xpos = xpos - 2
      IF inky$ = "6" THEN xpos = xpos + 2
   END IF

IF jumper = 1 THEN CALL jump
  
   WAIT &H3DA, 8, 8
  
   WAIT &H3DA, 8

  
   CALL erasecirc
   CALL score
   CALL badguys
   CALL checkdeath



LOOP UNTIL inky$ = "q"

CALL DEAD

END SUB
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)