Author Topic: Beginning Flying Example  (Read 3045 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Beginning Flying Example
« on: January 20, 2020, 04:40:30 pm »
This is just a straight-forward slow down and speed up flying example. You can't turn with this but feel free to add or change anything on it. It's just something I was playing around with the other day and decided to put it on here. The 2D objects on the ground are randomly generated as you fly over them. It shows the speed indicator in the top left corner. I thought of this when I checked out a Starfield I made many months ago with the help of you guys. I changed some things around and cut it in half and made each object move the same speed. I just like how the view of the objects go past you. This could be the start of any type of flying game or simulator or even the start of driving or walking on the ground.

Code: QB64: [Select]
  1. _TITLE "Flying - Use Up and Down Arrow Key for speed."
  2. DIM x(800), y(800), dx(800), dy(800), sz(800), c(800), shape(800), xx(800), ssz(800)
  3.  
  4. SCREEN _NEWIMAGE(800, 800, 32)
  5. LINE (0, 0)-(800, 360), _RGB32(127, 194, 255), BF
  6. LINE (0, 360)-(800, 800), _RGB32(67, 200, 150), BF
  7. 'Set the default speed, amount of objects, and then make the first objects.
  8. speed = .0005
  9. amount = 100
  10.  
  11. FOR objects = 1 TO amount
  12.     GOSUB make:
  13. NEXT objects
  14.  
  15.     _LIMIT 1000
  16.     FOR objects = 1 TO amount
  17.         a$ = INKEY$
  18.         IF a$ = CHR$(27) THEN END
  19.  
  20.         'Detect the arrow keys to make it go faster or slower.
  21.         IF a$ = CHR$(0) + CHR$(72) THEN speed = speed + .0005: warp = warp + 1
  22.         IF a$ = CHR$(0) + CHR$(80) THEN speed = speed - .0005: warp = warp - 1
  23.         IF warp < .002 THEN warp = 0
  24.         IF warp > 10 THEN warp = 10
  25.         IF warp > 0 THEN LOCATE 1, 1: PRINT "Speed: "; warp * 50
  26.         IF speed < .0005 THEN speed = .0005
  27.         IF speed > .02 THEN speed = .02
  28.  
  29.         'Move the objects.
  30.         x(objects) = x(objects) + dx(objects) * speed
  31.         y(objects) = y(objects) + dy(objects) * speed
  32.  
  33.         IF x(objects) < -800 THEN x(objects) = -800
  34.         IF x(objects) > 800 THEN x(objects) = 0
  35.  
  36.         'Get a new object if one goes off the screen.
  37.         IF x(objects) < -6400 OR x(objects) > 6400 OR y(objects) < -400 OR y(objects) > 400 THEN GOSUB make:
  38.  
  39.         'Draw the objects, c(objects) is the choice of colors
  40.         IF c(objects) < 34 THEN
  41.             FOR sz = .25 TO ssz(objects) STEP .25
  42.                 CIRCLE ((x(objects) + _WIDTH / 2) + xx(objects), y(objects) + _HEIGHT / 2), sz, _RGB32(255, 255, 255), , , shape(objects)
  43.             NEXT sz
  44.         END IF
  45.         IF c(objects) >= 34 AND c(objects) < 66 THEN
  46.             FOR sz = .25 TO ssz(objects) STEP .25
  47.                 CIRCLE ((x(objects) + _WIDTH / 2) + xx(objects), y(objects) + _HEIGHT / 2), sz, _RGB32(100, 10, 10), , , shape(objects)
  48.             NEXT sz
  49.         END IF
  50.         IF c(objects) >= 66 THEN
  51.             FOR sz = .25 TO ssz(objects) STEP .25
  52.                 CIRCLE ((x(objects) + _WIDTH / 2) + xx(objects), y(objects) + _HEIGHT / 2), sz, _RGB32(10, 10, 200), , , shape(objects)
  53.             NEXT sz
  54.         END IF
  55.         dy(objects) = y(objects) + 10
  56.         dx(objects) = x(objects) + xx(objects)
  57.     NEXT objects
  58.  
  59.     _DISPLAY
  60.  
  61.     LINE (0, 360)-(800, 800), _RGB32(67, 200, 150), BF
  62.  
  63. make:
  64.  
  65. 'Get a random X number using 2 decimal points - RND and .5 and times it by the width of the screen.
  66.  
  67. x(objects) = (RND - .5) * _WIDTH
  68.  
  69. 'Get a random Y number using 2 decimal points - RND and .5 and times it by the height of the screen.
  70.  
  71. y(objects) = INT(RND * 300) + 1
  72.  
  73. shape(objects) = RND * .5
  74.  
  75. c(objects) = INT(RND * 100) + 1
  76.  
  77. ssz(objects) = INT(RND * 8) + 3
  78.  
  79.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Beginning Flying Example
« Reply #1 on: January 20, 2020, 05:42:19 pm »
Hi Ken,

You might try to make the object get bigger as it approaches the bottom of the screen.