QB64.org Forum

Active Forums => Programs => Topic started by: mynameispaul on November 12, 2020, 04:04:01 pm

Title: Lander (my version)
Post by: mynameispaul on November 12, 2020, 04:04:01 pm
decided to try my attempt at a Lander game.
i'm sure its not as pretty (or just simply as good) as others, but this is my attemp/version
the main menu allows you to make lots of modifications to the game play
the config file includes text to hopefully explain what the settings affect
Title: Re: Lander (my version)
Post by: SierraKen on November 12, 2020, 05:39:26 pm
That's really fun! If you want, you could add exhaust shooting out the bottom when you press the arrow keys. Really good game-play, makes me want to make one. :)
Title: Re: Lander (my version)
Post by: johnno56 on November 12, 2020, 06:29:14 pm
Gotta love the landers!
Title: Re: Lander (my version)
Post by: Richard Frost on November 13, 2020, 01:07:18 am
Can you land it?    I tried a couple times and hit a rock.  Why are there rocks orbiting
at low altitude? Where's the McDonalds?   Why doesn't it smell like cheese?
Title: Re: Lander (my version)
Post by: bplus on November 13, 2020, 11:17:45 am
Quote
Where's the McDonalds?

Oh, that's what my Lander is missing! LOL
Title: Re: Lander (my version)
Post by: bplus on November 13, 2020, 06:59:54 pm
Piece of cake to land:
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 640, 32) ' Lander 30 LOC  2020-11-13
  2. g& = _NEWIMAGE(800, 640, 32)
  3. REDIM g(100)
  4.     CLS: _KEYCLEAR
  5.     h = 30: dx = 1: x = 3: y = 2
  6.     FOR i = 0 TO 99
  7.         IF RND < .5 THEN h = h + INT(RND * 3) - 1 ELSE h = h
  8.         IF h > 39 THEN h = 39
  9.         IF h < 25 THEN h = 25
  10.         LINE (i * 8, h * 16)-(i * 8 + 8, _HEIGHT), _RGB32(128), BF
  11.         g(i) = h
  12.         _PUTIMAGE , 0, g&
  13.     NEXT
  14.     WHILE 1
  15.         _PUTIMAGE , g&, 0
  16.         CIRCLE (x * 8 + 4, y * 16 + 8), 4, &HFF00FFFF
  17.         CIRCLE (x * 8, y * 16 + 16), 4, &HFFFFFF00, 0, _PI
  18.         CIRCLE (x * 8 + 8, y * 16 + 16), 4, &HFFFFFF00, 0, _PI
  19.         IF y >= g(x - 1) OR y >= g(x + 1) OR y >= g(x) OR y >= 40 THEN _PRINTSTRING (46 * 8, 2 * 16), "Crash": EXIT WHILE
  20.         IF y = g(x - 1) - 1 AND y = g(x + 1) - 1 THEN _PRINTSTRING (46 * 8, 2 * 16), "Landed": EXIT WHILE
  21.         kh& = _KEYHIT
  22.         IF kh& = 19200 THEN dx = dx - 1
  23.         IF kh& = 19712 THEN dx = dx + 1
  24.         IF kh& = 18432 THEN y = y - 5
  25.         x = x + dx: y = y + 1
  26.         _LIMIT 2
  27.     WEND
  28.     _DELAY 2
  29.  
  30.  
Title: Re: Lander (my version)
Post by: Aurel on November 15, 2020, 03:58:40 am
Yo Mark

you have in LINE 20 -> Subscript out of range !
by the way simple and nice progi...

but i am too stupid to figure which keys i must use
i figure that kh is a keyhit and looks like
move left  ?
move right ?
up ?

i see just a numbers ??
Title: Re: Lander (my version)
Post by: johnno56 on November 15, 2020, 05:33:07 am
Nope. Not stupid.

Einstein said that he didn't have to remember anything that he could look up.

 I too had difficulty with the key numbers. Check out "_KEYHIT" in the help files.. All shall be revealed...

J
Title: Re: Lander (my version)
Post by: bplus on November 15, 2020, 11:23:21 am
Use arrow keys left, right and up, now wad keys added. Off-sides x problem now = Crash!
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 640, 32) ' b+ Lander 30 LOC (double parking cheat) 2020-11-13
  2. g& = _NEWIMAGE(800, 640, 32)
  3. REDIM g(-100 TO 200)
  4.     CLS: _KEYCLEAR
  5.     h = 30: dx = 1: x = 3: y = 2
  6.     FOR i = -10 TO 110
  7.         IF RND < .5 THEN h = h + INT(RND * 3) - 1 ELSE h = h
  8.         IF h > 39 THEN h = 39
  9.         IF h < 25 THEN h = 25
  10.         LINE (i * 8, h * 16)-(i * 8 + 8, _HEIGHT), _RGB32(128), BF
  11.         g(i) = h
  12.         _PUTIMAGE , 0, g&
  13.     NEXT
  14.     WHILE 1
  15.         _PUTIMAGE , g&, 0
  16.         CIRCLE (x * 8 + 4, y * 16 + 8), 4, &HFF00FFFF
  17.         CIRCLE (x * 8, y * 16 + 16), 4, &HFFFFFF00, 0, _PI
  18.         CIRCLE (x * 8 + 8, y * 16 + 16), 4, &HFFFFFF00, 0, _PI
  19.         IF y >= g(x - 1) OR y >= g(x + 1) OR y >= g(x) OR y >= 40 OR x < -5 OR x > 105 THEN _PRINTSTRING (46 * 8, 2 * 16), "Crash": EXIT WHILE
  20.         IF y = g(x - 1) - 1 AND y = g(x + 1) - 1 THEN _PRINTSTRING (46 * 8, 2 * 16), "Landed": EXIT WHILE
  21.         kh& = _KEYHIT
  22.         IF kh& = 19200 OR kh& = 97 THEN dx = dx - 1
  23.         IF kh& = 19712 OR kh& = 100 THEN dx = dx + 1
  24.         IF kh& = 18432 OR kh& = 119 THEN y = y - 5
  25.         x = x + dx: y = y + 1
  26.         _LIMIT 2
  27.     WEND
  28.     _DELAY 2
  29. ' 2020-11-15 fix off-sides x, add alternate keys: a=left d=right w=up  so now arrow keys or WAD system works
  30.  

BTW this was originally ASCII with LOCATE: PRINT but cant draw or print off screen so if thrust Lander over top edge of screen it also use to error out with LOCATE. Now you can wait for it to drift back in screen, cool! (If you dont drift too far off sides also.) This is why _PRINTSTRING is superior to LOCATE and PRINT.

Really should be able to set down Lander anywhere you desire except McD's.

Title: Re: Lander (my version)
Post by: Aurel on November 15, 2020, 03:44:05 pm
Mark
I want to say that i cannot control lander
when i press
LEFT arrow key ....leander not respond
same for others arrow keys
with
wasd only W respond and lander little bit jump
my question is can i use virtual key codes like i use in
o2 compiler with

% vk_LEFT     = &H25
% vk_UP       = &H26
% vk_RIGHT    = &H27
% vk_DOWN     = &H28

Title: Re: Lander (my version)
Post by: Aurel on November 15, 2020, 03:48:42 pm
well i tried and not work i dont know why

 IF kh& = &H25  THEN dx = dx - 1   'it should be left arrow key
 IF kh& = &H27  THEN dx = dx + 1  'it should be right arrow key
Title: Re: Lander (my version)
Post by: bplus on November 15, 2020, 03:51:18 pm
@Aurel check your keys with this:
Code: QB64: [Select]
  1. WHILE 1 'find code for keypress
  2.     k$ = INKEY$
  3.     hk& = _KEYHIT
  4.     IF LEN(k$) THEN
  5.         SELECT CASE LEN(k$)
  6.             CASE 1: PRINT "1 char keypress = "; ASC(k$); "  keyhit = "; hk&
  7.             CASE 2: PRINT "2 char keypress = "; ASC(RIGHT$(k$, 1)); "  keyhit = "; hk&
  8.         END SELECT
  9.     END IF
  10.     _DISPLAY
  11.     _LIMIT 60
  12. PRINT "Goodbye."
  13.  
  14. 'findings
  15. '<esc> pressed twice exits this screen! number printed after 2nd press of any
  16.  
  17. 'Alt + letter  -> 2 char keypress numbers seem to jump all around they are QWERTY order?
  18.  
  19. 'Ctrl + letter -> 1 char A = 1, B = 2...
  20. 'Ctrl + m is same as <enter>
  21.  
  22. 'arrows
  23. 'up 72, dowm 80, left 75, right 77
  24.  
Title: Re: Lander (my version)
Post by: Aurel on November 15, 2020, 04:10:23 pm
ok!
Title: Re: Lander (my version)
Post by: Aurel on November 15, 2020, 04:19:56 pm
well ok
now respond ...let say somehow but moving ship is too hard to control
i put key parts on the start of while loop
like this :
Code: QB64: [Select]
  1.    
  2.    
  3.      SCREEN _NEWIMAGE(800, 640, 32) ' b+ Lander 30 LOC (double parking cheat) 2020-11-13
  4.     g& = _NEWIMAGE(800, 640, 32)
  5.     REDIM g(-100 TO 200)
  6.     DO
  7.         CLS: _KEYCLEAR
  8.         h = 30: dx = 1: x = 3: y = 2
  9.         FOR i = -10 TO 110
  10.             IF RND < .5 THEN h = h + INT(RND * 3) - 1 ELSE h = h
  11.             IF h > 39 THEN h = 39
  12.             IF h < 25 THEN h = 25
  13.             LINE (i * 8, h * 16)-(i * 8 + 8, _HEIGHT), _RGB32(128), BF
  14.             g(i) = h
  15.             _PUTIMAGE , 0, g&
  16.         NEXT
  17.         WHILE 1
  18.             kh& = _KEYHIT
  19.             IF kh& = 19200 THEN dx = dx - 2
  20.             IF kh& = 19712 THEN dx = dx + 2
  21.             IF kh& = 18432 THEN y = y - 5
  22.            
  23.             _PUTIMAGE , g&, 0
  24.             CIRCLE (x * 8 + 4, y * 16 + 8), 4, &HFF00FFFF
  25.             CIRCLE (x * 8, y * 16 + 16), 4, &HFFFFFF00, 0, _PI
  26.             CIRCLE (x * 8 + 8, y * 16 + 16), 4, &HFFFFFF00, 0, _PI
  27.             IF y >= g(x - 1) OR y >= g(x + 1) OR y >= g(x) OR y >= 40 OR x < -5 OR x > 105 THEN _PRINTSTRING (46 * 8, 2 * 16), "Crash": EXIT WHILE
  28.             IF y = g(x - 1) - 1 AND y = g(x + 1) - 1 THEN _PRINTSTRING (46 * 8, 2 * 16), "Landed": EXIT WHILE
  29.             x = x + dx: y = y + 1
  30.             _LIMIT 2
  31.         WEND
  32.         _DELAY 2
  33.     LOOP
  34.     ' 2020-11-15 fix off-sides x, add alternate keys: a=left d=right w=up  so now arrow keys or WAD system works
  35.          
Title: Re: Lander (my version)
Post by: SMcNeill on November 15, 2020, 04:24:35 pm
Try a higher limit.  You’re only running at 2 FPS.
Title: Re: Lander (my version)
Post by: bplus on November 15, 2020, 06:20:50 pm
Try a higher limit.  You’re only running at 2 FPS.

Yeah, well be careful with that, you are falling one character height per frame and dx should be just +1 or -1 = one character width per frame. So in 20 frames or so you will be landed.

Really I debated whether to make left arrow dx = -1 and right arrow dx = 1 but then I would need a key to make dx = 0.

This is a complete toy Lander don't over think this. Just wait until Lander is over spot you want to land and press the left arrow to stop progress to the right and just keep the Lander Up with up arrow until you cut the right progress and let it drop straight down to ground, piece of cake!

Aurel this is two much:
Code: QB64: [Select]
  1.             kh& = _KEYHIT
  2.             IF kh& = 19200 THEN dx = dx - 2
  3.             IF kh& = 19712 THEN dx = dx + 2
  4.             IF kh& = 18432 THEN y = y - 5
  5.