Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - AmandaC

Pages: [1]
1
QB64 Discussion / Re: Why is this happening?
« on: May 06, 2019, 12:37:13 pm »
Here is a code:
Code: QB64: [Select]
  1. _TITLE "A Promising Game!"
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3. COLOR , _RGB32(211, 211, 211)
  4. DIM SHARED y_change AS SINGLE
  5. restart:
  6. x = 200
  7. y = 200
  8. gravity = 9.8
  9.     CLS
  10.     makechar
  11.     k$ = UCASE$(INKEY$)
  12.     IF _KEYDOWN(18432) AND NOT y_change > 50 THEN
  13.         y = y - 25
  14.         y_change = y_change + 1
  15.         y = y + gravity
  16.     ELSEIF _KEYDOWN(20480) AND NOT y_change > 50 THEN
  17.         y = y + 25
  18.         y_change = y_change + 1
  19.         y = y + gravity
  20.     ELSEIF _KEYDOWN(19200) THEN
  21.         x = x - 10
  22.     ELSEIF _KEYDOWN(19712) THEN
  23.         x = x + 10
  24.     END IF
  25.     y = y + gravity
  26.     'Blocks
  27.     'LINE (100, 400)-STEP(200, 50), _RGB32(255, 83, 33), BF
  28.     'IF collision%(x, y, 20, 20, 100, 400, 200, 50) THEN
  29.     '    y = oldy
  30.     '    y_change = 0
  31.     '    gravity = 0
  32.     'ELSE
  33.     '    gravity = 9.8
  34.     '    oldy = y
  35.     'END IF
  36.     makeobs 100, 400
  37.     LINE (500, 400)-STEP(200, 50), _RGB32(127, 255, 127), BF
  38.     IF collision%(x, y, 20, 20, 500, 400, 200, 50) THEN
  39.         CLS
  40.         _PRINTSTRING (300, 300), "LEVEL 1 COMPLETE!"
  41.         END
  42.     END IF
  43.     IF y > 700 THEN GOTO restart
  44.  
  45.     _DISPLAY
  46.     _LIMIT 60
  47.  
  48. SUB makechar
  49.     CIRCLE (x, y), 20, _RGB32(100, 150, 255)
  50.     PAINT (x, y), _RGB32(100, 150, 255), _RGB32(100, 150, 255)
  51.  
  52. FUNCTION collision% (b1x, b1y, b1w, b1h, b2x, b2y, b2w, b2h)
  53.     IF (b1y + b1h < b2y) OR (b1y > b2y + b2h) OR (b1x > b2x + b2w) OR (b1x + b1w < b2x) THEN
  54.         collision% = 0
  55.     ELSE
  56.         collision% = 1
  57.     END IF
  58.  
  59. SUB makeobs (bx, by)
  60.     LINE (bx, by)-STEP(200, 50), _RGB32(255, 150, 100), BF
  61.     IF collision%(x, y, 20, 20, bx, by, 200, 50) THEN
  62.         y = oldy
  63.         gravity = 0
  64.         y_change = 0
  65.     ELSE
  66.         oldy = y
  67.         gravity = 9.8
  68.     END IF
  69.  

What is the bug that brings the player to it's initial position?
It’s because the _KEYDOWN check gimp freejobalert notepad++  is in an ELSEIF statement.  Make all those become independent IF checks instead.
Thanks Both of you for this. I was also facing the same and happened to find this has already been answered.

Regards,
Amanda

Pages: [1]