Listen to QB64 Report!Our podcast on all things QB64 is out now. Listen athttp://podcast.qb64.org
0 Members and 1 Guest are viewing this topic.
Here is a code:Code: QB64: [Select]_TITLE "A Promising Game!"SCREEN _NEWIMAGE(800, 600, 32)COLOR , _RGB32(211, 211, 211)CLSDIM SHARED x AS INTEGERDIM SHARED y AS INTEGERDIM SHARED gravity AS SINGLEDIM SHARED y_change AS SINGLErestart:x = 200y = 200gravity = 9.8CLSDO CLS makechar k$ = UCASE$(INKEY$) IF _KEYDOWN(18432) AND NOT y_change > 50 THEN y = y - 25 y_change = y_change + 1 y = y + gravity ELSEIF _KEYDOWN(20480) AND NOT y_change > 50 THEN y = y + 25 y_change = y_change + 1 y = y + gravity ELSEIF _KEYDOWN(19200) THEN x = x - 10 ELSEIF _KEYDOWN(19712) THEN x = x + 10 END IF y = y + gravity 'Blocks 'LINE (100, 400)-STEP(200, 50), _RGB32(255, 83, 33), BF 'IF collision%(x, y, 20, 20, 100, 400, 200, 50) THEN ' y = oldy ' y_change = 0 ' gravity = 0 'ELSE ' gravity = 9.8 ' oldy = y 'END IF makeobs 100, 400 LINE (500, 400)-STEP(200, 50), _RGB32(127, 255, 127), BF IF collision%(x, y, 20, 20, 500, 400, 200, 50) THEN CLS _PRINTSTRING (300, 300), "LEVEL 1 COMPLETE!" END END IF IF y > 700 THEN GOTO restart _DISPLAY _LIMIT 60LOOP SUB makechar CIRCLE (x, y), 20, _RGB32(100, 150, 255) PAINT (x, y), _RGB32(100, 150, 255), _RGB32(100, 150, 255)END SUB FUNCTION collision% (b1x, b1y, b1w, b1h, b2x, b2y, b2w, b2h) IF (b1y + b1h < b2y) OR (b1y > b2y + b2h) OR (b1x > b2x + b2w) OR (b1x + b1w < b2x) THEN collision% = 0 ELSE collision% = 1 END IFEND FUNCTION SUB makeobs (bx, by) LINE (bx, by)-STEP(200, 50), _RGB32(255, 150, 100), BF IF collision%(x, y, 20, 20, bx, by, 200, 50) THEN y = oldy gravity = 0 y_change = 0 ELSE oldy = y gravity = 9.8 END IFEND SUB What is the bug that brings the player to it's initial position?
Alright, another question!When I press the upper arrow key and the left arrow key at the same time, only the upper arrow key works but not the left arrow key. What is causing it and How do I solve it? HELP!-Prithak
It’s because the _KEYDOWN check is in an ELSEIF statement. Make all those become independent IF checks instead.
It’s because the _KEYDOWN check gimp freejobalert notepad++ is in an ELSEIF statement. Make all those become independent IF checks instead.