QB64.org Forum

Active Forums => Programs => Topic started by: SierraKen on July 14, 2019, 10:57:44 pm

Title: Race Car Game
Post by: SierraKen on July 14, 2019, 10:57:44 pm
Hi all,

Today I made a game I've wanted to make since I was a kid when my toy hand-held race car game broke one day.
You start with 5 cars and you move the arrow keys. You can go backwards but it doesn't do anything besides make the lines in the
road move back. I'll put this on my website http://KensProgras.com soon. I know things can be added like oil slick or shooting or whatever
but I think I accomplished a good game in 1 afternoon. :) Tell me what you think. Oh, and I tried to add engine sound but it messed up the sounds
when you hit another car or the side of the road.

(NOTE: This is Version 1, Version 2, which includes many things, is posted on the next page of this forum topic.)

Code: QB64: [Select]
  1. 'I've wanted to make this game since I was a kid when I owned a little hand-held race car game where you steered the little wheel"
  2. 'to avoid the other cars. That toy broke when I was a kid so I've wanted a similar one on the computer. :)
  3. 'Enjoy!
  4. '
  5. 'Made on July 14, 2019 by Ken G.
  6. 'Freeware only.
  7.  
  8. _TITLE "RACE CAR"
  9. SCREEN _NEWIMAGE(640, 480, 32)
  10. begin:
  11. PRINT "                             R  A  C  E    C  A  R"
  12. PRINT "                                  By Ken G."
  13. PRINT "                    Use your arrow keys to steer your car"
  14. PRINT "                    around the other cars as far as you can"
  15. PRINT "                    without hitting them."
  16. PRINT "                    You get 5 cars."
  17. PRINT "                    Every time you hit a street edge, you"
  18. PRINT "                    lose 200 points."
  19. INPUT "                    Press Enter to play!", a$
  20.  
  21.  
  22. LINE (0, 240)-(640, 240), _RGB32(127, 255, 127)
  23. rc = 5
  24. x = 320
  25. y = 250: yy = 450
  26. cx = 350: cy = 420
  27. u = 1
  28. sc = 0
  29. collision = 0
  30. go:
  31. _LIMIT 100
  32. a$ = INKEY$
  33. IF a$ = CHR$(27) THEN END
  34. IF a$ = CHR$(0) + CHR$(72) THEN u = 1: d = 0: r = 0: L = 0
  35. IF a$ = CHR$(0) + CHR$(80) THEN u = 0: d = 1: r = 0: L = 0
  36. IF a$ = CHR$(0) + CHR$(77) THEN r = 1: L = 0
  37. IF a$ = CHR$(0) + CHR$(75) THEN L = 1: r = 0
  38. IF u = 1 THEN
  39.     oy = y
  40.     y = y + 5
  41.     IF y > 640 THEN y = 250
  42.     LINE (x, oy)-(x, oy + 10), _RGB32(0, 0, 0)
  43.     LINE (x, y)-(x, y + 10), _RGB32(127, 255, 127)
  44.     oyy = yy
  45.     yy = yy + 5
  46.     IF yy > 640 THEN yy = 250
  47.     IF yy < 240 THEN yy = 640
  48.     LINE (x, oyy)-(x, oyy + 10), _RGB32(0, 0, 0)
  49.     LINE (x, yy)-(x, yy + 10), _RGB32(127, 255, 127)
  50.  
  51. IF d = 1 THEN
  52.     oy = y
  53.     y = y - 5
  54.     IF y < 240 THEN y = 640
  55.     LINE (x, oy)-(x, oy + 10), _RGB32(0, 0, 0)
  56.     LINE (x, y)-(x, y + 10), _RGB32(127, 255, 127)
  57.     oyy = yy
  58.     yy = yy - 5
  59.     IF yy < 240 THEN yy = 640
  60.     IF yy > 640 THEN yy = 250
  61.     LINE (x, oyy)-(x, oyy + 10), _RGB32(0, 0, 0)
  62.     LINE (x, yy)-(x, yy + 10), _RGB32(127, 255, 127)
  63.  
  64. IF r = 1 THEN
  65.     ocx = cx: ocy = cy
  66.     GOSUB erasecar:
  67.     cx = cx + 2
  68.     'Check street edge.
  69.     IF cx > 570 THEN
  70.         cx = 550
  71.         SOUND 800, .25
  72.         sc = sc - 200
  73.     END IF
  74.     GOSUB drawcar:
  75.  
  76.  
  77. IF L = 1 THEN
  78.     ocx = cx: ocy = cy
  79.     GOSUB erasecar:
  80.     cx = cx - 2
  81.     'Check street edge.
  82.     IF cx < 40 THEN
  83.         cx = 60
  84.         SOUND 800, .25
  85.         sc = sc - 200
  86.     END IF
  87.     GOSUB drawcar:
  88. 'Street Sides
  89. LINE (320, 240)-(0, 480), _RGB32(127, 255, 127)
  90. LINE (320, 240)-(640, 480), _RGB32(127, 255, 127)
  91. GOSUB drawcar:
  92.  
  93. 'Other Car
  94. oc = INT(RND * 1000) + 1
  95. IF oc > 980 AND occ = 0 THEN
  96.     occ = 1
  97.     oxx2 = (RND * 12) - 6
  98.     oyyy = 250
  99.     oxxx = 305
  100. IF occ = 1 THEN
  101.     oldoyyy = oyyy
  102.     oldoxxx = oxxx
  103.     oyyy = oyyy + 5
  104.     oxxx = oxxx + oxx2
  105.     LINE (oldoxxx, oldoyyy)-(oldoxxx + 30, oldoyyy + 30), _RGB32(0, 0, 0), BF
  106.     CIRCLE (oldoxxx, oldoyyy + 5), 5, _RGB32(0, 0, 0)
  107.     CIRCLE (oldoxxx + 30, oldoyyy + 5), 5, _RGB32(0, 0, 0)
  108.     CIRCLE (oldoxxx + 30, oldoyyy + 25), 5, _RGB32(0, 0, 0)
  109.     CIRCLE (oldoxxx, oldoyyy + 25), 5, _RGB32(0, 0, 0)
  110.  
  111.     LINE (oxxx, oyyy)-(oxxx + 30, oyyy + 30), _RGB32(127, 249, 127), BF
  112.     CIRCLE (oxxx, oyyy + 5), 5, _RGB32(127, 227, 127)
  113.     CIRCLE (oxxx + 30, oyyy + 5), 5, _RGB32(127, 227, 127)
  114.     CIRCLE (oxxx + 30, oyyy + 25), 5, _RGB32(127, 227, 127)
  115.     CIRCLE (oxxx, oyyy + 25), 5, _RGB32(127, 227, 127)
  116.  
  117.     IF oyyy > 640 THEN
  118.         occ = 0
  119.         LINE (oxxx, oyyy)-(oxxx + 20, oyyy + 20), _RGB32(0, 0, 0), BF
  120.         CIRCLE (oldoxxx, oldoyyy + 5), 5, _RGB32(0, 0, 0)
  121.         CIRCLE (oldoxxx + 30, oldoyyy + 5), 5, _RGB32(0, 0, 0)
  122.         CIRCLE (oldoxxx + 30, oldoyyy + 25), 5, _RGB32(0, 0, 0)
  123.         CIRCLE (oldoxxx, oldoyyy + 25), 5, _RGB32(0, 0, 0)
  124.  
  125.         oyyy = 250
  126.         oxxx = 320
  127.         collision = 0
  128.         GOTO nex:
  129.     END IF
  130. nex:
  131.  
  132. 'Detect Collision
  133. IF cx > oxxx - 5 AND cx < oxxx + 35 AND cy > oyyy - 5 AND cy < oyyy + 35 THEN
  134.     SOUND 800, .25
  135.     IF collision = 0 THEN rc = rc - 1
  136.     IF rc = 0 THEN GOTO done:
  137.     collision = 1
  138.  
  139.  
  140. LOCATE 1, 1: PRINT "Score: "; sc
  141. sc = sc + 1
  142.  
  143. LOCATE 1, 70: PRINT "Cars:"; rc
  144.  
  145. GOTO go:
  146.  
  147. drawcar:
  148. 'Car
  149. LINE (cx, cy)-(cx + 30, cy + 30), _RGB32(127, 227, 127), BF
  150. LINE (cx + 5, cy - 5)-(cx + 25, cy), _RGB32(127, 227, 127), BF
  151. CIRCLE (cx, cy + 5), 5, _RGB32(127, 227, 127)
  152. CIRCLE (cx + 30, cy + 5), 5, _RGB32(127, 227, 127)
  153. CIRCLE (cx + 30, cy + 25), 5, _RGB32(127, 227, 127)
  154. CIRCLE (cx, cy + 25), 5, _RGB32(127, 227, 127)
  155.  
  156. erasecar:
  157. LINE (ocx, ocy)-(ocx + 30, ocy + 30), _RGB32(0, 0, 0), BF
  158. LINE (ocx + 5, ocy - 5)-(ocx + 25, ocy), _RGB32(0, 0, 0), BF
  159. CIRCLE (ocx, ocy + 5), 5, _RGB32(0, 0, 0)
  160. CIRCLE (ocx + 30, ocy + 5), 5, _RGB32(0, 0, 0)
  161. CIRCLE (ocx + 30, ocy + 25), 5, _RGB32(0, 0, 0)
  162. CIRCLE (ocx, ocy + 25), 5, _RGB32(0, 0, 0)
  163.  
  164. done:
  165. LOCATE 10, 30: PRINT "G A M E    O V E R"
  166. LOCATE 14, 30: PRINT "Score: "; sc
  167. LOCATE 1, 70: PRINT "Cars:"; rc
  168. again:
  169. LOCATE 17, 30
  170. INPUT "Would you like to play again? (Yes/No)", ag$
  171. IF ag$ = "y" OR ag$ = "Y" OR ag$ = "YES" OR ag$ = "yes" OR ag$ = "Yes" OR ag$ = "yES" OR ag$ = "yeS" THEN GOTO begin:
  172.  
  173.  
  174.  
Title: Re: Race Car Game
Post by: Pete on July 14, 2019, 11:04:12 pm
Was that an early arcade game? It seems very familiar.

Pete
Title: Re: Race Car Game
Post by: SierraKen on July 14, 2019, 11:32:57 pm
Here is the original. I got it around 1982 or so. It used paper to scroll inside the track with the cars going by. lol When you hit a car it flashed a light at you and made a sound. :) My game looks a bit more like the arcade game Pole Position, but with no turns, just a straight track, like my old toy was.  lol
Title: Re: Race Car Game
Post by: Petr on July 15, 2019, 02:30:57 am
Hi SierraKen, i like it!

I'm not at home now, but I'm going to look at it more deeply at home. Acceleration and braking fluency can be resolved with the TIMER function, that is, when you add throttle, record time and add a higher speed after some time limit, the same for braking. Definitely a very interesting program. The sounds .... well, I would change the frequency of the sound by the Y-axis distance in the loop.

Something as this:

Code: QB64: [Select]
  1.  
  2. SCREEN _NEWIMAGE(1024, 768, 256)
  3. CarWidth = 70
  4. CarHeight = 115
  5.  
  6.  
  7.     CLS
  8.  
  9.     LINE (512 - CarWidth, 384 - CarHeight)-(512 + CarWidth, 384 + CarHeight), 14, B 'static car
  10.  
  11.     LINE (_MOUSEX - CarWidth, _MOUSEY - CarHeight)-(_MOUSEX + CarWidth, _MOUSEY + CarHeight), 15, B 'car used with mouse
  12.     distance = ABS(_MOUSEY - 384) / 30 'return always positive value
  13.     LOCATE 1
  14.     PRINT distance
  15.  
  16.     FOR S = 150 - distance TO 170 - distance STEP 10
  17.         lenght = S / 900
  18.         SOUND S, lenght
  19.     NEXT S
  20.     _DISPLAY
  21.     _LIMIT 40
  22.  
  23. there muss be _LIMIT used for applying sound difference in time. Or is harder way with SNDLOOP used with SNDSETPOS.
  24.  
Title: Re: Race Car Game
Post by: OldMoses on July 15, 2019, 09:11:11 am
4498, much better than I would expect with my reflexes. Very cool old school rendering. Takes me back...
Title: Re: Race Car Game
Post by: bplus on July 15, 2019, 09:14:48 am
Hi Ken,

Your best game yet!
Title: Re: Race Car Game
Post by: SierraKen on July 15, 2019, 12:59:12 pm
Wow thanks guys! Petr, yeah I used _DELAY for a long time with it, I'll try it again. I would rather use that than a TIMER loop if I can. I'll also try to figure out a way to add engine sounds but most likely I won't be able to because 2 SOUND commands at the same time don't work well together on my computer for some reason. I wonder if a mp3 sound would work in the background? I'll look into it. I decided that I'm also going to try and add oil slicks and possibly other details. :) So version 2 will be coming soon, I'll post it here when I'm ready.
Title: Re: Race Car Game
Post by: Pete on July 15, 2019, 01:39:38 pm
This is another one of those cases where I wish there was a way to get programs like this on phone and PDA devices. Windows Phone crapped out, so that pretty much blew out the possibility of a QB64 C/C++ translator at least working on a Windows phone. Android is more JAVA based, but there is an OpenGL for Android. I recall Rob had a JAVA written version of QB64 as something on his wish list, if he ever redid QB64.

This one is remarkably under 200 lines, so I don't know, maybe it could be ported to SmallBasic for Android. It's been a couple of years since I've programmed in that language, so, I really just guessing.

I'm looking forward to the new additions to this race car app. I'm trying to recall if Pole Position had acceleration and deceleration capabilities. I know, I know, if it gets over-complicated, it loses its appeal. Anyway, I do recall a spinning car if it hit an oil slick. I think that would be a great addition.

Pete

Title: Re: Race Car Game
Post by: SierraKen on July 15, 2019, 01:49:10 pm
Awesome Pete! Yeah this would be perfect for cell phones, if it was possible. If you ever do use SmallBasic again, feel free to try and import it. So far I just added acceleration and deceleration using the _delay command, it was easier than I thought. lol Since the street is black I will try to add something like "OIL" in green or something. lol I'm also going to add up the amount of cars you pass so at the end it times the score with the amount of cars because someone can drive at like 5 mph all day and never get hit. LOL I might also add an accelerometer to tell people the speed. I'm having a blast with this! I just have to make time for my daily chores. lol
Title: Re: Race Car Game
Post by: johnno56 on July 15, 2019, 04:35:29 pm
THIS is a cool game. Very simple layout. Continuous movement of the player makes for a challenging game. Unfortunately, my reflexes are not what they used to be and was "killed off" quite quickly, but still a fun game. Nicely done! (not getting killed off.... I meant the making of the game... lol)
Title: Re: Race Car Game
Post by: SierraKen on July 15, 2019, 06:49:58 pm
Thanks Johno! Version 2 should be out soon. I've added oil slicks and acceleration. :) Might add some more things.
Title: Re: Race Car Game
Post by: johnno56 on July 15, 2019, 07:37:28 pm
Looking forward to it...
Title: Re: Race Car Game
Post by: SierraKen on July 15, 2019, 09:27:58 pm
OK it is JUST about done! I got the acceleration/deceleration and speed indicator (You can't go backwards anymore, just slow down to 40 mph). I got 2 buildings at once on the sides of the road, can be 2 on each side or 1 on each side. And I got the oil slick that randomly slides you a direction. Now the last thing I want to add (you can laugh if you want), a Top Ten score list that makes a text file on your computer of the top ten scores so far. Has any of you made one of those yet with QB64? I know how to make a text file and read one, I just have to play with it some to detect the numbers and write the new ones. What I haven't done with QB64 yet is use the APPEND command for the text file and it's been decades since I attempted it, but I will give it a shot. Hold your horses for a little longer folks, I think you all will be surprised on how much the game has changed, I sure am. Oh, in case you are wondering, it's still all green lines, but I like it that way, it sorta gives a green screen 1980's flashback or like TRON or something. :) Just wanted to update ya, will be coming real soon.
Title: Re: Race Car Game
Post by: Pete on July 15, 2019, 10:30:29 pm
Do me a favor. When you go to post it, post it by editing the original post, but don't overwrite the original code. Name this new one something like version 2, and post it in another code box, below the first version. Just include some comments above the new version code box, which explains the additions to your newer version. Sound good?

Pete
Title: Re: Race Car Game
Post by: SierraKen on July 15, 2019, 11:06:15 pm
That's fine Pete, I'll leave the first one but will add to the post to scroll down to version 2. :)
Title: Re: Race Car Game
Post by: Pete on July 15, 2019, 11:36:41 pm
You could, but what I meant was edit the original, and add a second code box for the newer version, as exampled below. It's just easier for people visiting to find everything about the code in the first place they look. Often, threads extend multiple pages. People seldom search all pages to find code, especially when they see the first post contains code. Just a thought. I won't thing any less of you if you don't do it my way. Wow, is that a backhanded non-compliment or what??? :D Anyway, seriously, that car game rocks!

 - Pete

============================

Description of original version stays here.

Code: QB64: [Select]
  1.  
  2. ' Original version code remains here.
  3.  
  4.  

Description of version 2 gets edited in here.

Code: QB64: [Select]
  1.  
  2. ' Version 2 code goes here.
  3.  
  4.  
Title: Re: Race Car Game
Post by: bplus on July 16, 2019, 12:12:56 am
Do me a favor. When you go to post it, post it by editing the original post, but don't overwrite the original code. Name this new one something like version 2, and post it in another code box, below the first version. Just include some comments above the new version code box, which explains the additions to your newer version. Sound good?

Pete

I like to see how game evolves, so posting over original or even under it sucks if you are following the code and it's modifications along the way.

I really hate it when the original code disappears. It makes the rest of the thread disjointed and in congruent, specially for someone new to the thread!

So do me a favor and don't post new mods over the original.

This code is too short to worry about taking up a bunch of room.

If you had a bunch of attached files that goes with the code, that's a different story but then you post the attached in a .zip probably at the start of the thread.

This forum has a method of highlighting your best post that is above the first post and points directly to it for all those who wish to cut to the chase!
Title: Re: Race Car Game
Post by: Pete on July 16, 2019, 12:17:21 am
Don't listen to BPlus. "He's" still transitioning. Why just last year, "his" avatar was wearing a skirt!!!

Pete
Title: Re: Race Car Game
Post by: bplus on July 16, 2019, 12:20:20 am
Don't listen to BPlus. "He's" still transitioning. Why just last year, "his" avatar was wearing a skirt!!!

Pete

Hey Pete,

If you can't make a reasonable argument just smear the person you are disagreeing with.
Title: Re: Race Car Game
Post by: Pete on July 16, 2019, 01:17:24 am
Well, if the shoe fits... especially if it matches the skirt!

Kidding aside, my main concern was not to lose the original post. I often just update my original code. I do that because I don't consider it to be a new version, just a work in progress; but Ken's situation got me thinking about organizing multiple versions. So now, if I had a finished work, I would preserve it, and post the newer version in a new code box, inside the original post. That's because I favor keeping the code first, and discussion about the code in the subsequent posts. I also don't believe too many people searching for code want to read complete threads. If I did believe that, I would post the new version in the next available reply space, but I don't, so I won't. Anyway, it's really not a big deal one way or the other. Just a matter of personal preference.

Pete
Title: Re: Race Car Game
Post by: SMcNeill on July 16, 2019, 01:23:30 am
Quote
.... Kidding aside, my main concern was not to lose the original post.

You can’t.

If you click “view edits of post”, you can see where things have changed...  Even compare changes.

My suggestion:  Just post new versions as you go, and mark the latest with the “Best Answer” option so folks can be certain to be as up to date as possible.
Title: Re: Race Car Game
Post by: SierraKen on July 16, 2019, 12:08:17 pm
LOL guys. Well, like I said earlier, I will just leave the first one since you all seem to want that. And edit the first post saying to scroll down to the better one, because people wanting to learn the code should actually, at least, skim through all the posts to pickup tidbits here and there. If you just have code right in front of you, it only helps for people that know what the commands actually mean.
Last night I actually stayed up until midnight programming trying to make the Top Ten list for my game. I am ALMOST there, I just have to fix one annoying problem, so HOPEFULLY sometime today I will post version 2. Oh and I was wrong earlier, I don't use APPEND, I just read the old one and use that info to make a new one.
Title: Re: Race Car Game
Post by: SierraKen on July 16, 2019, 01:54:11 pm
Here it is!!! Added features on Version 2 are: oil slicks (which if you aren't turning, they randomly slide the car toward the edge of the street), acceleration and deceleration, speed indicator, passed up cars indicator, score change that times it by passed up cars at the end, outside buildings, Top Ten Racers score sheet, and other minor adjustments.
That score sheet was a tricky bug lol. You can see how I did it at the end of the program code. Feel free to use any of this code in your own programs as always. Some of the last minute changes I made was also making the score not less than 1, so when it times it by the cars you pass at the end, it actually helps and not gets worse LOL. I also made the other car able to drive to the edge of the road in case you just decided to sit there all day at the edge not getting points except racking up the amount of cars you passed. So you can't do that anymore. Tell me what you think of the game, and also the Top Ten score sheet. I tried to be fair on the scores it comes with on it although we may never pass up #1 Electro Joe, but we might! None of you might see #10 Jalopy Jay because he will be pushed off the board pretty fast. You can always look at the text file in Notepad before you start playing if you wish to see the score sheet. It will be attached to this post. Well, enough talk, here it is, one of my favorite games I've made! :) Have fun!

(Note: This is Version 2, Version 3 is below on this same forum topic and page with some enhancements.)

Code: QB64: [Select]
  1. 'I've wanted to make this game since I was a kid when I owned a little hand-held race car game where you steered the little wheel"
  2. 'to avoid the other cars. That toy broke when I was a kid so I've wanted a similar one on the computer. :)
  3. 'Enjoy!
  4. '
  5. 'Version 2 was made on July 16, 2019 by Ken G.
  6. 'Freeware only.
  7. '
  8. 'Added features on Version 2 are: oil slicks, acceleration and deceleration, speed indicator, passed up cars indicator,
  9. 'score change that times it by passed up cars at the end, outside buildings, Top Ten Racers score sheet, and other minor adjustments.
  10.  
  11. _TITLE "RACE CAR"
  12. SCREEN _NEWIMAGE(640, 480, 32)
  13. begin:
  14. PRINT "                             R  A  C  E    C  A  R"
  15. PRINT "                                       V. 2"
  16. PRINT "                                    By Ken  G."
  17. PRINT "                    Use your arrow keys to steer your car"
  18. PRINT "                    around the other cars and go as far as you"
  19. PRINT "                    can without hitting them, as well as the round"
  20. PRINT "                    oil slicks."
  21. PRINT "                    Press the up and down arrow keys to move"
  22. PRINT "                    faster or slower and also to stop turning."
  23. PRINT "                    You get 5 cars."
  24. PRINT "                    Every time you hit a street edge, you"
  25. PRINT "                    lose 200 points."
  26. PRINT "                    Every time you hit an oil slick your car"
  27. PRINT "                    moves a random direction."
  28. PRINT "                    Every time you hit another car you lose a car."
  29. INPUT "                    Press Enter to play!", a$
  30.  
  31. DIM name$(50), score(50), nm$(50), scc(50)
  32. LINE (0, 240)-(640, 240), _RGB32(127, 255, 127)
  33. tim = .02
  34. rc = 5
  35. x = 320
  36. y = 250: yy = 450
  37. cx = 350: cy = 420
  38. u = 1
  39. sc = 0
  40. one = 0
  41. collision = 0
  42. collision2 = 0
  43. o = 0
  44. other = 0
  45. sct = 0
  46. go:
  47. _DELAY tim
  48. _LIMIT 200
  49. a$ = INKEY$
  50. IF a$ = CHR$(27) THEN END
  51. IF a$ = CHR$(0) + CHR$(72) THEN
  52.     u = 1
  53.     d = 0
  54.     r = 0
  55.     L = 0
  56.     tim = tim - .004
  57.     IF tim < .008 THEN tim = .008
  58. IF a$ = CHR$(0) + CHR$(80) THEN
  59.     u = 0
  60.     d = 1
  61.     r = 0
  62.     L = 0
  63.     tim = tim + .004
  64.     IF tim > .02 THEN tim = .02
  65.  
  66. IF a$ = CHR$(0) + CHR$(77) THEN r = 1: L = 0
  67. IF a$ = CHR$(0) + CHR$(75) THEN L = 1: r = 0
  68.  
  69. IF u = 1 THEN
  70.     GOSUB linesmoving:
  71.  
  72. IF d = 1 THEN
  73.     GOSUB linesmoving:
  74.  
  75. IF r = 1 THEN
  76.     ocx = cx: ocy = cy
  77.     GOSUB erasecar:
  78.     cx = cx + 2
  79.     'Check street edge.
  80.     IF cx > 570 THEN
  81.         cx = 550
  82.         SOUND 800, .25
  83.         sc = sc - 200
  84.     END IF
  85.     GOSUB drawcar:
  86.  
  87.  
  88. IF L = 1 THEN
  89.     ocx = cx: ocy = cy
  90.     GOSUB erasecar:
  91.     cx = cx - 2
  92.     'Check street edge.
  93.     IF cx < 40 THEN
  94.         cx = 60
  95.         SOUND 800, .25
  96.         sc = sc - 200
  97.     END IF
  98.     GOSUB drawcar:
  99. 'Street Sides
  100. LINE (320, 240)-(0, 480), _RGB32(127, 255, 127)
  101. LINE (320, 240)-(640, 480), _RGB32(127, 255, 127)
  102. GOSUB drawcar:
  103.  
  104. 'Other Car
  105. oc = INT(RND * 1000) + 1
  106. IF oc > 980 AND occ = 0 THEN
  107.     occ = 1
  108.     oxx2 = (RND * 16) - 8
  109.     oyyy = 250
  110.     oxxx = 305
  111. IF occ = 1 THEN
  112.     oldoyyy = oyyy
  113.     oldoxxx = oxxx
  114.     oyyy = oyyy + 5
  115.     oxxx = oxxx + oxx2
  116.     LINE (oldoxxx, oldoyyy)-(oldoxxx + 30, oldoyyy + 30), _RGB32(0, 0, 0), BF
  117.     CIRCLE (oldoxxx, oldoyyy + 5), 5, _RGB32(0, 0, 0)
  118.     CIRCLE (oldoxxx + 30, oldoyyy + 5), 5, _RGB32(0, 0, 0)
  119.     CIRCLE (oldoxxx + 30, oldoyyy + 25), 5, _RGB32(0, 0, 0)
  120.     CIRCLE (oldoxxx, oldoyyy + 25), 5, _RGB32(0, 0, 0)
  121.  
  122.     LINE (oxxx, oyyy)-(oxxx + 30, oyyy + 30), _RGB32(127, 249, 127), BF
  123.     CIRCLE (oxxx, oyyy + 5), 5, _RGB32(127, 227, 127)
  124.     CIRCLE (oxxx + 30, oyyy + 5), 5, _RGB32(127, 227, 127)
  125.     CIRCLE (oxxx + 30, oyyy + 25), 5, _RGB32(127, 227, 127)
  126.     CIRCLE (oxxx, oyyy + 25), 5, _RGB32(127, 227, 127)
  127.  
  128.     IF oyyy > 640 THEN
  129.         occ = 0
  130.         LINE (oxxx, oyyy)-(oxxx + 20, oyyy + 20), _RGB32(0, 0, 0), BF
  131.         CIRCLE (oldoxxx, oldoyyy + 5), 5, _RGB32(0, 0, 0)
  132.         CIRCLE (oldoxxx + 30, oldoyyy + 5), 5, _RGB32(0, 0, 0)
  133.         CIRCLE (oldoxxx + 30, oldoyyy + 25), 5, _RGB32(0, 0, 0)
  134.         CIRCLE (oldoxxx, oldoyyy + 25), 5, _RGB32(0, 0, 0)
  135.         IF collision = 0 THEN
  136.             other = other + 1
  137.             LOCATE 1, 20: PRINT "Passed Up Cars:"; other
  138.         END IF
  139.         oyyy = 250
  140.         oxxx = 320
  141.         collision = 0
  142.         GOTO nex:
  143.     END IF
  144. nex:
  145.  
  146. 'Detect Collision
  147. IF cx > oxxx - 10 AND cx < oxxx + 40 AND cy > oyyy - 5 AND cy < oyyy + 35 THEN
  148.     SOUND 800, .25
  149.     IF collision = 0 THEN rc = rc - 1
  150.     IF rc = 0 THEN GOTO done:
  151.     collision = 1
  152.  
  153.  
  154. 'Oil Slick
  155. oil = INT(RND * 100) + 1
  156. IF oil > 90 AND oil2 = 0 THEN
  157.     oil2 = 1
  158.     oilx2 = (RND * 12) - 6
  159.     oilyyy = 250
  160.     oilxxx = 305
  161. IF oil2 = 1 THEN
  162.     oldoilyyy = oilyyy
  163.     oldoilxxx = oilxxx
  164.     oilyyy = oilyyy + 5
  165.     oilxxx = oilxxx + oilx2
  166.     o = o + 1
  167.     IF o = 1 THEN GOTO oil:
  168.     CIRCLE (oldoilxxx, oldoilyyy + 25), 20, _RGB32(0, 0, 0)
  169.     oil:
  170.     CIRCLE (oilxxx, oilyyy + 25), 20, _RGB32(127, 227, 127)
  171.     IF oilyyy > 640 THEN
  172.         CIRCLE (oldoilxxx, oldoilyyy + 25), 20, _RGB32(0, 0, 0)
  173.         oilyyy = 250
  174.         oilxxx = 330
  175.         collision2 = 0
  176.         o = 0
  177.         oil2 = 0
  178.         GOTO nex2:
  179.     END IF
  180.  
  181. nex2:
  182.  
  183. 'Detect Collision With Oil Slick
  184. IF cx > oilxxx - 5 AND cx < oilxxx + 35 AND cy > oilyyy - 5 AND cy < oilyyy + 35 THEN
  185.     SOUND 800, .25
  186.     IF collision2 = 0 THEN
  187.         RANDOMIZE TIMER
  188.         skid = INT(RND * 100) + 1
  189.         IF skid > 50 THEN r = 1: L = 0
  190.         IF skid <= 50 THEN L = 1: r = 0
  191.         SOUND 900, .25
  192.     END IF
  193.     collision2 = 1
  194.  
  195. 'Buildings
  196. b = INT(RND * 100) + 1
  197. IF b > 80 AND b2 = 0 THEN
  198.     b2 = 1
  199.     bx2 = (RND * 4) - 2
  200.     IF bx2 > 0 THEN
  201.         RANDOMIZE TIMER
  202.         bxxx = INT(RND * 200) + 370
  203.         bx3 = 10
  204.     END IF
  205.     IF bx2 <= 0 THEN
  206.         RANDOMIZE TIMER
  207.         bxxx = INT(RND * 150) + 10
  208.         bx3 = -10
  209.     END IF
  210.     bsz = INT(RND * 30) + 10
  211.     bsz2 = INT(RND * 30) + 10
  212.     byyy = 255
  213. IF b2 = 1 THEN
  214.     oldbyyy = byyy
  215.     oldbxxx = bxxx
  216.     byyy = byyy + 5
  217.     bxxx = bxxx + bx3
  218.     ob = ob + 1
  219.     IF ob = 1 THEN GOTO building:
  220.     'old erase
  221.     LINE (oldbxxx, oldbyyy)-(oldbxxx + bsz, oldbyyy + bsz2), _RGB32(0, 0, 0), B
  222.     building:
  223.     'new
  224.     LINE (bxxx, byyy)-(bxxx + bsz, byyy + bsz2), _RGB32(127, 227, 127), B
  225.     IF byyy > 640 THEN
  226.         'old erase again
  227.         LINE (oldbxxx, oldbyyy)-(oldbxxx + bsz, oldbyyy + bsz2), _RGB32(0, 0, 0), B
  228.         byyy = 250
  229.         'bxxx = 330
  230.         ob = 0
  231.         b2 = 0
  232.         GOTO nex3:
  233.     END IF
  234.  
  235. nex3:
  236.  
  237. bb = INT(RND * 100) + 1
  238. IF bb > 80 AND bb2 = 0 THEN
  239.     bb2 = 1
  240.     bbx2 = (RND * 4) - 2
  241.     IF bbx2 > 0 THEN
  242.         RANDOMIZE TIMER
  243.         bbxxx = INT(RND * 200) + 350
  244.         bbx3 = 10
  245.     END IF
  246.     IF bbx2 <= 0 THEN
  247.         RANDOMIZE TIMER
  248.         bbxxx = INT(RND * 150) + 10
  249.         bbx3 = -10
  250.     END IF
  251.     bbsz = INT(RND * 30) + 10
  252.     bbsz2 = INT(RND * 30) + 10
  253.     bbyyy = 255
  254. IF bb2 = 1 THEN
  255.     oldbbyyy = bbyyy
  256.     oldbbxxx = bbxxx
  257.     bbyyy = bbyyy + 5
  258.     bbxxx = bbxxx + bbx3
  259.     obb = obb + 1
  260.     IF obb = 1 THEN GOTO building:
  261.     'old erase
  262.     LINE (oldbbxxx, oldbbyyy)-(oldbbxxx + bbsz, oldbbyyy + bbsz2), _RGB32(0, 0, 0), B
  263.     building2:
  264.     'new
  265.     LINE (bbxxx, bbyyy)-(bbxxx + bbsz, bbyyy + bbsz2), _RGB32(127, 227, 127), B
  266.     IF bbyyy > 640 THEN
  267.         'old erase again
  268.         LINE (oldbbxxx, oldbbyyy)-(oldbbxxx + bbsz, oldbbyyy + bbsz2), _RGB32(0, 0, 0), B
  269.         bbyyy = 250
  270.         'bbxxx = 330
  271.         obb = 0
  272.         bb2 = 0
  273.         GOTO nex4:
  274.     END IF
  275. nex4:
  276.  
  277. LOCATE 3, 1: PRINT "Speed: "; INT(2 / tim)
  278. LOCATE 3, 13: PRINT "mph"
  279. IF sc < 1 THEN sc = 1
  280. LOCATE 1, 1: PRINT "Score: "; sc
  281. sc = sc + 1
  282.  
  283. LOCATE 1, 73: PRINT "Cars:"; rc
  284.  
  285.  
  286. GOTO go:
  287.  
  288. linesmoving:
  289. oy = y
  290. y = y + 5
  291. IF y > 640 THEN y = 250
  292. IF y < 240 THEN y = 640
  293. LINE (x, oy)-(x, oy + 10), _RGB32(0, 0, 0)
  294. LINE (x, y)-(x, y + 10), _RGB32(127, 255, 127)
  295. oyy = yy
  296. yy = yy + 5
  297. IF yy > 640 THEN yy = 250
  298. IF yy < 240 THEN yy = 640
  299. LINE (x, oyy)-(x, oyy + 10), _RGB32(0, 0, 0)
  300. LINE (x, yy)-(x, yy + 10), _RGB32(127, 255, 127)
  301.  
  302.  
  303. drawcar:
  304. 'Car
  305. LINE (cx, cy)-(cx + 30, cy + 30), _RGB32(127, 227, 127), BF
  306. LINE (cx + 5, cy - 5)-(cx + 25, cy), _RGB32(127, 227, 127), BF
  307. CIRCLE (cx, cy + 5), 5, _RGB32(127, 227, 127)
  308. CIRCLE (cx + 30, cy + 5), 5, _RGB32(127, 227, 127)
  309. CIRCLE (cx + 30, cy + 25), 5, _RGB32(127, 227, 127)
  310. CIRCLE (cx, cy + 25), 5, _RGB32(127, 227, 127)
  311.  
  312. erasecar:
  313. LINE (ocx, ocy)-(ocx + 30, ocy + 30), _RGB32(0, 0, 0), BF
  314. LINE (ocx + 5, ocy - 5)-(ocx + 25, ocy), _RGB32(0, 0, 0), BF
  315. CIRCLE (ocx, ocy + 5), 5, _RGB32(0, 0, 0)
  316. CIRCLE (ocx + 30, ocy + 5), 5, _RGB32(0, 0, 0)
  317. CIRCLE (ocx + 30, ocy + 25), 5, _RGB32(0, 0, 0)
  318. CIRCLE (ocx, ocy + 25), 5, _RGB32(0, 0, 0)
  319.  
  320. done:
  321. LOCATE 10, 30: PRINT "G A M E    O V E R"
  322. LOCATE 1, 1: PRINT "Score: "; sc
  323. scc = sc * other
  324. LOCATE 14, 1: PRINT sc; " x "; other; " Passed Up Cars = Total Score: "; scc
  325. LOCATE 1, 73: PRINT "Cars:"; rc
  326. LOCATE 20, 1: INPUT "Press Enter to see Top Ten list.", topten$
  327.  
  328. 'Top Ten Racers
  329. OPEN "toptenracers.txt" FOR INPUT AS #1
  330. FOR n = 1 TO 10
  331.     IF EOF(1) THEN GOTO nex5:
  332.     INPUT #1, name$(n)
  333.     INPUT #1, score(n)
  334.     IF scc > score(n) AND sct = 0 THEN
  335.         nn = n
  336.         PRINT "You have made the Top Ten!"
  337.         typename:
  338.         INPUT "Type your name here (25 letters and spaces maximum.):", nm$(nn)
  339.         IF LEN(nm$(nn)) > 25 THEN
  340.             PRINT "Name too long, try again."
  341.             GOTO typename:
  342.         END IF
  343.         sccc(nn) = scc
  344.         sct = 1
  345.     END IF
  346.     IF n = 10 AND sct = 0 THEN CLOSE #1: GOTO nex7:
  347. nex5:
  348. OPEN "toptenracers.txt" FOR OUTPUT AS #1
  349. FOR n = 1 TO nn
  350.     IF n <> nn THEN PRINT #1, name$(n): PRINT #1, score(n)
  351.     IF n = nn THEN
  352.         PRINT #1, nm$(n)
  353.         PRINT #1, sccc(n)
  354.     END IF
  355. nex6:
  356. FOR n = nn TO 10
  357.     PRINT #1, name$(n): PRINT #1, score(n)
  358.  
  359. nex7:
  360. PRINT "                            T O P    T E N     R A C E R S"
  361. OPEN "toptenracers.txt" FOR INPUT AS #1
  362. FOR n = 1 TO 10
  363.     IF EOF(1) THEN GOTO nex8:
  364.     INPUT #1, name$(n)
  365.     INPUT #1, score(n)
  366.     PRINT "             "; n; ". "; name$(n); score(n)
  367. nex8:
  368. FOR n = 1 TO 10
  369.     nm$(n) = ""
  370.     score(n) = 0
  371.     name$(n) = ""
  372.     sccc(n) = 0
  373.  
  374. LOCATE 23, 1
  375. INPUT "Would you like to play again? (Yes/No)", ag$
  376. IF ag$ = "y" OR ag$ = "Y" OR ag$ = "YES" OR ag$ = "yes" OR ag$ = "Yes" OR ag$ = "yES" OR ag$ = "yeS" THEN GOTO begin:
  377.  
  378.  
Title: Re: Race Car Game
Post by: Petr on July 16, 2019, 02:20:29 pm
Nice upgrade, SierraKen.
Title: Re: Race Car Game
Post by: Pete on July 16, 2019, 02:30:40 pm
EDIT: Part of post removed due to me not seeing the attached top ten file, which needed to be downloaded.

I find the center divider to be more of a distraction in this version. The oil slicks seldom do anything, especially at high speeds, where they should be near deadly. Take a look at the ellipse drawing routines on the forum. It would help the 3-D effect of the oil slicks.

Pete   
Title: Re: Race Car Game
Post by: SierraKen on July 16, 2019, 03:21:13 pm
Pete, the Top Ten file was created, it was attached to my post with the code. But thank you anyways.  Yeah, I might update the oil slicks, but they do take effect at any speed if you aren't going left or right, besides changing a direction if the randomness tells it to.  As for the middle lines, I'm keeping them there to show the speed of the car better.  I think I need a little break before I tackle it again though, I can't do more coding today from programming so much last night and this morning.

Thanks Petr, I tried my best. Of course it could be better like Pete says. So there might be a Version 3 sometime in the future. I'll post it here if I decide to do it.
Title: Re: Race Car Game
Post by: SierraKen on July 16, 2019, 03:43:08 pm
I'm also playing around with the idea of having the other car slow down the faster you go and actually "move". Because technically they don't even move at all, it's only you that moves so far.  But I did it that way because that's exactly how the handheld toy I had in the 80's was, the other cars went the same speed as the track did when you moved.

Actually I just tried it, it's more complicating than I thought.
Title: Re: Race Car Game
Post by: Pete on July 16, 2019, 04:19:17 pm
Ah, my apologies. I downloaded the text, tried it again, and it works as advertised. I tested 4 spots in the top 10, and all new entries printed to the correct positions. Great job!

If by any chance you wanted to hard code that initial top 10 list into the app, you could do something like this. Now, people like me won't miss the download file...

After CLS, add this, and place the DATA anywhere.

Code: QB64: [Select]
  1. IF _FILEEXISTS("toptenracers.txt") THEN
  2.     OPEN "toptenracers.txt" FOR OUTPUT AS #1
  3.     RESTORE toptendata
  4.     DO
  5.         READ toptenname$, toptenscore!
  6.         IF toptenname$ = "EOF" THEN EXIT DO
  7.         PRINT #1, toptenname$
  8.         PRINT #1, toptenscore!
  9.     LOOP
  10.     CLOSE #1
  11.  
  12. toptendata:
  13. DATA Electro Joe,500000
  14. DATA Flying Felice,450000
  15. DATA Speedy Spencer,400000
  16. DATA Super Sam,350000
  17. DATA Ralph Runner,300000
  18. DATA Suzy Swift,275000
  19. DATA Quick Ken,250000
  20. DATA Tiger Tessa,225000
  21. DATA Brisk Bob,200000
  22. DATA Jalopy Jay,175000
  23.  

Anyway, I'll edit my previous post, as it is not relevant...

BTW - I recall Pole Position, or some such game, slowed the car down if it hit an oil slick, besides spinning it. That decreased the potential score. Oh, and if you insist of keeping the top speed of 249 mph, you might want to think about adding a parachute.

Pete
Title: Re: Race Car Game
Post by: SierraKen on July 16, 2019, 05:18:55 pm
Wow thanks Pete! I just added it to the code for Version 3. Earlier I also made the oil slick look much better using a few other circles inside of it. Right now I'm figuring out a way to make the oil slick do more to the car, as you said earlier. :)  LOL parachute. Yeah I might change the speed some too, starting off at 100 mph and going to 249 seems a bit intense. That's cool about the oil slick, I didn't think about slowing it down, I just might try that.
Title: Re: Race Car Game
Post by: SierraKen on July 16, 2019, 06:44:34 pm
For Version 3 I slowed it down to 75 mph to 187 mph and added how the oil slick slows the car down. The speed of the game is still the same, just the speed numbers are different. I also added Pete's code to automatically generate a Top Ten list when one is missing, or when someone wants to reset it by deleting the toptenracers.txt file. Plus I added how you get an extra car every 3,000 points to make the game last a bit longer. Oh, and I adjusted the timing of the oil slicks coming out, it's a tiny bit less but almost the same as before. Plus I made the oil slick look better. Here is Version 3:

(Note: Updated version is on next page.)

Code: QB64: [Select]
  1. 'I've wanted to make this game since I was a kid when I owned a little hand-held race car game where you steered the little wheel"
  2. 'to avoid the other cars. That toy broke when I was a kid so I've wanted a similar one on the computer. :)
  3. 'Enjoy!
  4. '
  5. 'Version 3 was made on July 16, 2019 by Ken G.
  6. 'Freeware only.
  7. '
  8. 'Thanks to the QB64.org forum guys for the help!
  9. _TITLE "RACE CAR"
  10. SCREEN _NEWIMAGE(640, 480, 32)
  11. begin:
  12. PRINT "                              R  A  C  E    C  A  R"
  13. PRINT "                                       V. 3"
  14. PRINT "                                    By Ken  G."
  15. PRINT "                    Use your arrow keys to steer your car"
  16. PRINT "                    around the other cars and go as far as you"
  17. PRINT "                    can without hitting them, as well as the round"
  18. PRINT "                    oil slicks. You get an extra car every 3000 points."
  19. PRINT "                    Press the up and down arrow keys to move"
  20. PRINT "                    faster or slower and also to stop turning."
  21. PRINT "                    You get 5 cars."
  22. PRINT "                    Every time you hit a street edge, you"
  23. PRINT "                    lose 200 points."
  24. PRINT "                    Every time you hit an oil slick your car"
  25. PRINT "                    moves a random direction."
  26. PRINT "                    Every time you hit another car you lose a car."
  27. PRINT "                    To reset the Top Ten score sheet, delete the file"
  28. PRINT "                    named toptenracers.txt and play a full game."
  29. INPUT "                    Press Enter to play!", a$
  30.  
  31. DIM name$(50), score(50), nm$(50), scc(50)
  32. LINE (0, 240)-(640, 240), _RGB32(127, 255, 127)
  33. tim = .02
  34. t2 = 0
  35. rc = 5
  36. x = 320
  37. y = 250: yy = 450
  38. cx = 350: cy = 420
  39. u = 1
  40. sc = 0
  41. one = 0
  42. collision = 0
  43. collision2 = 0
  44. o = 0
  45. other = 0
  46. sct = 0
  47. go:
  48. _DELAY tim
  49. _LIMIT 200
  50. a$ = INKEY$
  51. IF a$ = CHR$(27) THEN END
  52. IF a$ = CHR$(0) + CHR$(72) THEN
  53.     u = 1
  54.     d = 0
  55.     r = 0
  56.     L = 0
  57.     tim = tim - .002
  58.     IF tim < .008 THEN tim = .008
  59. IF a$ = CHR$(0) + CHR$(80) THEN
  60.     u = 0
  61.     d = 1
  62.     r = 0
  63.     L = 0
  64.     tim = tim + .002
  65.     IF tim > .02 THEN tim = .02
  66.  
  67. IF a$ = CHR$(0) + CHR$(77) THEN r = 1: L = 0
  68. IF a$ = CHR$(0) + CHR$(75) THEN L = 1: r = 0
  69.  
  70. IF u = 1 THEN
  71.     GOSUB linesmoving:
  72.  
  73. IF d = 1 THEN
  74.     GOSUB linesmoving:
  75.  
  76. IF r = 1 THEN
  77.     ocx = cx: ocy = cy
  78.     GOSUB erasecar:
  79.     cx = cx + 2
  80.     'Check street edge.
  81.     IF cx > 570 THEN
  82.         cx = 550
  83.         SOUND 800, .25
  84.         sc = sc - 200
  85.     END IF
  86.     GOSUB drawcar:
  87.  
  88.  
  89. IF L = 1 THEN
  90.     ocx = cx: ocy = cy
  91.     GOSUB erasecar:
  92.     cx = cx - 2
  93.     'Check street edge.
  94.     IF cx < 40 THEN
  95.         cx = 60
  96.         SOUND 800, .25
  97.         sc = sc - 200
  98.     END IF
  99.     GOSUB drawcar:
  100. 'Street Sides
  101. LINE (320, 240)-(0, 480), _RGB32(127, 255, 127)
  102. LINE (320, 240)-(640, 480), _RGB32(127, 255, 127)
  103. GOSUB drawcar:
  104.  
  105. 'Other Car
  106. oc = INT(RND * 1000) + 1
  107. IF oc > 980 AND occ = 0 THEN
  108.     occ = 1
  109.     oxx2 = (RND * 16) - 8
  110.     oyyy = 250
  111.     oxxx = 305
  112. IF occ = 1 THEN
  113.     oldoyyy = oyyy
  114.     oldoxxx = oxxx
  115.     oyyy = oyyy + 5
  116.     oxxx = oxxx + oxx2
  117.     LINE (oldoxxx, oldoyyy)-(oldoxxx + 30, oldoyyy + 30), _RGB32(0, 0, 0), BF
  118.     CIRCLE (oldoxxx, oldoyyy + 5), 5, _RGB32(0, 0, 0)
  119.     CIRCLE (oldoxxx + 30, oldoyyy + 5), 5, _RGB32(0, 0, 0)
  120.     CIRCLE (oldoxxx + 30, oldoyyy + 25), 5, _RGB32(0, 0, 0)
  121.     CIRCLE (oldoxxx, oldoyyy + 25), 5, _RGB32(0, 0, 0)
  122.  
  123.     LINE (oxxx, oyyy)-(oxxx + 30, oyyy + 30), _RGB32(127, 249, 127), BF
  124.     CIRCLE (oxxx, oyyy + 5), 5, _RGB32(127, 227, 127)
  125.     CIRCLE (oxxx + 30, oyyy + 5), 5, _RGB32(127, 227, 127)
  126.     CIRCLE (oxxx + 30, oyyy + 25), 5, _RGB32(127, 227, 127)
  127.     CIRCLE (oxxx, oyyy + 25), 5, _RGB32(127, 227, 127)
  128.  
  129.     IF oyyy > 640 THEN
  130.         occ = 0
  131.         LINE (oxxx, oyyy)-(oxxx + 20, oyyy + 20), _RGB32(0, 0, 0), BF
  132.         CIRCLE (oldoxxx, oldoyyy + 5), 5, _RGB32(0, 0, 0)
  133.         CIRCLE (oldoxxx + 30, oldoyyy + 5), 5, _RGB32(0, 0, 0)
  134.         CIRCLE (oldoxxx + 30, oldoyyy + 25), 5, _RGB32(0, 0, 0)
  135.         CIRCLE (oldoxxx, oldoyyy + 25), 5, _RGB32(0, 0, 0)
  136.         IF collision = 0 THEN
  137.             other = other + 1
  138.             LOCATE 1, 20: PRINT "Passed Up Cars:"; other
  139.         END IF
  140.         oyyy = 250
  141.         oxxx = 320
  142.         collision = 0
  143.         GOTO nex:
  144.     END IF
  145. nex:
  146.  
  147. 'Detect Collision
  148. IF cx > oxxx - 10 AND cx < oxxx + 40 AND cy > oyyy - 5 AND cy < oyyy + 35 THEN
  149.     SOUND 800, .25
  150.     IF collision = 0 THEN rc = rc - 1
  151.     IF rc = 0 THEN GOTO done:
  152.     collision = 1
  153.  
  154.  
  155. 'Oil Slick
  156. oil = INT(RND * 100) + 1
  157. IF oil > 98 AND oil2 = 0 THEN
  158.     oil2 = 1
  159.     oilx2 = (RND * 12) - 6
  160.     oilyyy = 250
  161.     oilxxx = 305
  162. IF oil2 = 1 THEN
  163.     oldoilyyy = oilyyy
  164.     oldoilxxx = oilxxx
  165.     oilyyy = oilyyy + 5
  166.     oilxxx = oilxxx + oilx2
  167.     o = o + 1
  168.     IF o = 1 THEN GOTO oil:
  169.     FOR ooo = 1 TO 25 STEP 5
  170.         CIRCLE (oldoilxxx, oldoilyyy + 25), ooo, _RGB32(0, 0, 0)
  171.     NEXT ooo
  172.     oil:
  173.     FOR ooo = 1 TO 25 STEP 5
  174.         CIRCLE (oilxxx, oilyyy + 25), ooo, _RGB32(127, 227, 127)
  175.     NEXT ooo
  176.     IF oilyyy > 640 THEN
  177.         FOR ooo = 1 TO 25 STEP 5
  178.             CIRCLE (oldoilxxx, oldoilyyy + 25), ooo, _RGB32(0, 0, 0)
  179.         NEXT ooo
  180.         oilyyy = 250
  181.         oilxxx = 330
  182.         collision2 = 0
  183.         o = 0
  184.         oil2 = 0
  185.         GOTO nex2:
  186.     END IF
  187.  
  188. nex2:
  189.  
  190. 'Detect Collision With Oil Slick
  191. IF cx > oilxxx - 5 AND cx < oilxxx + 35 AND cy > oilyyy - 5 AND cy < oilyyy + 35 THEN
  192.     SOUND 800, .25
  193.     IF collision2 = 0 THEN
  194.         RANDOMIZE TIMER
  195.         skid = INT(RND * 100) + 1
  196.         IF skid > 50 THEN r = 1: L = 0
  197.         IF skid <= 50 THEN L = 1: r = 0
  198.         tim = .02
  199.         SOUND 900, .25
  200.     END IF
  201.     collision2 = 1
  202.  
  203. 'Buildings
  204. b = INT(RND * 100) + 1
  205. IF b > 80 AND b2 = 0 THEN
  206.     b2 = 1
  207.     bx2 = (RND * 4) - 2
  208.     IF bx2 > 0 THEN
  209.         RANDOMIZE TIMER
  210.         bxxx = INT(RND * 200) + 370
  211.         bx3 = 10
  212.     END IF
  213.     IF bx2 <= 0 THEN
  214.         RANDOMIZE TIMER
  215.         bxxx = INT(RND * 150) + 10
  216.         bx3 = -10
  217.     END IF
  218.     bsz = INT(RND * 30) + 10
  219.     bsz2 = INT(RND * 30) + 10
  220.     byyy = 255
  221. IF b2 = 1 THEN
  222.     oldbyyy = byyy
  223.     oldbxxx = bxxx
  224.     byyy = byyy + 5
  225.     bxxx = bxxx + bx3
  226.     ob = ob + 1
  227.     IF ob = 1 THEN GOTO building:
  228.     'old erase
  229.     LINE (oldbxxx, oldbyyy)-(oldbxxx + bsz, oldbyyy + bsz2), _RGB32(0, 0, 0), B
  230.     building:
  231.     'new
  232.     LINE (bxxx, byyy)-(bxxx + bsz, byyy + bsz2), _RGB32(127, 227, 127), B
  233.     IF byyy > 640 THEN
  234.         'old erase again
  235.         LINE (oldbxxx, oldbyyy)-(oldbxxx + bsz, oldbyyy + bsz2), _RGB32(0, 0, 0), B
  236.         byyy = 250
  237.         'bxxx = 330
  238.         ob = 0
  239.         b2 = 0
  240.         GOTO nex3:
  241.     END IF
  242.  
  243. nex3:
  244.  
  245. bb = INT(RND * 100) + 1
  246. IF bb > 80 AND bb2 = 0 THEN
  247.     bb2 = 1
  248.     bbx2 = (RND * 4) - 2
  249.     IF bbx2 > 0 THEN
  250.         RANDOMIZE TIMER
  251.         bbxxx = INT(RND * 200) + 350
  252.         bbx3 = 10
  253.     END IF
  254.     IF bbx2 <= 0 THEN
  255.         RANDOMIZE TIMER
  256.         bbxxx = INT(RND * 150) + 10
  257.         bbx3 = -10
  258.     END IF
  259.     bbsz = INT(RND * 30) + 10
  260.     bbsz2 = INT(RND * 30) + 10
  261.     bbyyy = 255
  262. IF bb2 = 1 THEN
  263.     oldbbyyy = bbyyy
  264.     oldbbxxx = bbxxx
  265.     bbyyy = bbyyy + 5
  266.     bbxxx = bbxxx + bbx3
  267.     obb = obb + 1
  268.     IF obb = 1 THEN GOTO building:
  269.     'old erase
  270.     LINE (oldbbxxx, oldbbyyy)-(oldbbxxx + bbsz, oldbbyyy + bbsz2), _RGB32(0, 0, 0), B
  271.     building2:
  272.     'new
  273.     LINE (bbxxx, bbyyy)-(bbxxx + bbsz, bbyyy + bbsz2), _RGB32(127, 227, 127), B
  274.     IF bbyyy > 640 THEN
  275.         'old erase again
  276.         LINE (oldbbxxx, oldbbyyy)-(oldbbxxx + bbsz, oldbbyyy + bbsz2), _RGB32(0, 0, 0), B
  277.         bbyyy = 250
  278.         'bbxxx = 330
  279.         obb = 0
  280.         bb2 = 0
  281.         GOTO nex4:
  282.     END IF
  283. nex4:
  284.  
  285. 'Extra Car
  286. IF sc / 3000 = INT(sc / 3000) AND sc / 3000 <> 0 THEN
  287.     rc = rc + 1
  288.     LOCATE 15, 35: PRINT "EXTRA CAR!"
  289.     SOUND 400, 2
  290.     SOUND 400, 2
  291.     SOUND 400, 2
  292.     t2 = 1
  293. IF t2 > 500 THEN
  294.     LOCATE 15, 35: PRINT "          "
  295.     t2 = 0
  296. IF t2 > 0 THEN t2 = t2 + 1
  297.  
  298. 'Speed Indicator
  299. LOCATE 3, 1: PRINT "Speed: "; INT(1.5 / tim)
  300. LOCATE 3, 13: PRINT "mph"
  301. 'Score
  302. IF sc < 1 THEN sc = 1
  303. LOCATE 1, 1: PRINT "Score: "; sc
  304. sc = sc + 1
  305. 'Cars You Have Leftover
  306. LOCATE 1, 73: PRINT "Cars:"; rc
  307.  
  308.  
  309. GOTO go:
  310.  
  311. linesmoving:
  312. oy = y
  313. y = y + 5
  314. IF y > 640 THEN y = 250
  315. IF y < 240 THEN y = 640
  316. LINE (x, oy)-(x, oy + 10), _RGB32(0, 0, 0)
  317. LINE (x, y)-(x, y + 10), _RGB32(127, 255, 127)
  318. oyy = yy
  319. yy = yy + 5
  320. IF yy > 640 THEN yy = 250
  321. IF yy < 240 THEN yy = 640
  322. LINE (x, oyy)-(x, oyy + 10), _RGB32(0, 0, 0)
  323. LINE (x, yy)-(x, yy + 10), _RGB32(127, 255, 127)
  324.  
  325.  
  326. drawcar:
  327. 'Car
  328. LINE (cx, cy)-(cx + 30, cy + 30), _RGB32(127, 227, 127), BF
  329. LINE (cx + 5, cy - 5)-(cx + 25, cy), _RGB32(127, 227, 127), BF
  330. CIRCLE (cx, cy + 5), 5, _RGB32(127, 227, 127)
  331. CIRCLE (cx + 30, cy + 5), 5, _RGB32(127, 227, 127)
  332. CIRCLE (cx + 30, cy + 25), 5, _RGB32(127, 227, 127)
  333. CIRCLE (cx, cy + 25), 5, _RGB32(127, 227, 127)
  334.  
  335. erasecar:
  336. LINE (ocx, ocy)-(ocx + 30, ocy + 30), _RGB32(0, 0, 0), BF
  337. LINE (ocx + 5, ocy - 5)-(ocx + 25, ocy), _RGB32(0, 0, 0), BF
  338. CIRCLE (ocx, ocy + 5), 5, _RGB32(0, 0, 0)
  339. CIRCLE (ocx + 30, ocy + 5), 5, _RGB32(0, 0, 0)
  340. CIRCLE (ocx + 30, ocy + 25), 5, _RGB32(0, 0, 0)
  341. CIRCLE (ocx, ocy + 25), 5, _RGB32(0, 0, 0)
  342.  
  343. done:
  344. LOCATE 10, 30: PRINT "G A M E    O V E R"
  345. LOCATE 1, 1: PRINT "Score: "; sc
  346. scc = sc * other
  347. LOCATE 14, 1: PRINT sc; " x "; other; " Passed Up Cars = Total Score: "; scc
  348. LOCATE 1, 73: PRINT "Cars:"; rc
  349. LOCATE 20, 1: INPUT "Press Enter to see Top Ten list.", topten$
  350.  
  351. 'Top Ten Racers
  352. IF _FILEEXISTS("toptenracers.txt") THEN
  353.     OPEN "toptenracers.txt" FOR OUTPUT AS #1
  354.     RESTORE toptendata
  355.     DO
  356.         READ toptenname$, toptenscore!
  357.         IF toptenname$ = "EOF" THEN EXIT DO
  358.         PRINT #1, toptenname$
  359.         PRINT #1, toptenscore!
  360.     LOOP
  361.     CLOSE #1
  362.  
  363. OPEN "toptenracers.txt" FOR INPUT AS #1
  364. FOR n = 1 TO 10
  365.     IF EOF(1) THEN GOTO nex5:
  366.     INPUT #1, name$(n)
  367.     INPUT #1, score(n)
  368.     IF scc > score(n) AND sct = 0 THEN
  369.         nn = n
  370.         PRINT "You have made the Top Ten!"
  371.         typename:
  372.         INPUT "Type your name here (25 letters and spaces maximum.):", nm$(nn)
  373.         IF LEN(nm$(nn)) > 25 THEN
  374.             PRINT "Name too long, try again."
  375.             GOTO typename:
  376.         END IF
  377.         sccc(nn) = scc
  378.         sct = 1
  379.     END IF
  380.     IF n = 10 AND sct = 0 THEN CLOSE #1: GOTO nex7:
  381. nex5:
  382. OPEN "toptenracers.txt" FOR OUTPUT AS #1
  383. FOR n = 1 TO nn
  384.     IF n <> nn THEN PRINT #1, name$(n): PRINT #1, score(n)
  385.     IF n = nn THEN
  386.         PRINT #1, nm$(n)
  387.         PRINT #1, sccc(n)
  388.     END IF
  389. nex6:
  390. FOR n = nn TO 10
  391.     PRINT #1, name$(n): PRINT #1, score(n)
  392.  
  393. nex7:
  394. PRINT "                            T O P    T E N     R A C E R S"
  395. OPEN "toptenracers.txt" FOR INPUT AS #1
  396. FOR n = 1 TO 10
  397.     IF EOF(1) THEN GOTO nex8:
  398.     INPUT #1, name$(n)
  399.     INPUT #1, score(n)
  400.     PRINT "             "; n; ". "; name$(n); score(n)
  401. nex8:
  402. FOR n = 1 TO 10
  403.     nm$(n) = ""
  404.     score(n) = 0
  405.     name$(n) = ""
  406.     sccc(n) = 0
  407.  
  408. LOCATE 23, 1
  409. INPUT "Would you like to play again? (Yes/No)", ag$
  410. IF ag$ = "y" OR ag$ = "Y" OR ag$ = "YES" OR ag$ = "yes" OR ag$ = "Yes" OR ag$ = "yES" OR ag$ = "yeS" THEN GOTO begin:
  411.  
  412. toptendata:
  413. DATA Electro Joe,500000
  414. DATA Flying Felice,450000
  415. DATA Speedy Spencer,400000
  416. DATA Super Sam,350000
  417. DATA Ralph Runner,300000
  418. DATA Suzy Swift,275000
  419. DATA Quick Ken,250000
  420. DATA Tiger Tessa,225000
  421. DATA Brisk Bob,200000
  422. DATA Jalopy Jay,175000
  423.  
  424.  
Title: Re: Race Car Game
Post by: Pete on July 16, 2019, 07:06:51 pm
I played it once. I really like the bonus "extra" car. Oil slicks still don't kick in at higher speeds, but work great at more moderate speeds. I like the ore realistic speeds in version 3.

I noticed Atari Pole position has both the curbs and center divider moving. Activision Enduro has no center divider, only the curbs move. Neither have oil slicks, which makes me think I must have been playing some game at an arcade to have experienced that, oh well...

Here is my maiden voyage score...

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

Pete
Title: Re: Race Car Game
Post by: SierraKen on July 16, 2019, 07:36:03 pm
GREAT JOB! I noticed that the oil slicks do slow it down, but not as much as it would going slower with the car. That's because I use a smaller _DELAY number when the car is going faster. The main loop of the program goes faster when the car goes faster. There's nothing I can really do to help that except make the _DELAY longer and the game slower but I don't want to do that. lol I also tried making the car skid off the road when you hit an oil slick, maybe I should add that back in? It does get annoying though since sometimes I keep hitting the oil slicks. I think I'm just going to leave it as it is regarding the oil slicks.
Title: Re: Race Car Game
Post by: Pete on July 16, 2019, 09:46:53 pm
Ken, about RANDOMIZE TIMER. You only have to use it once in the program. That will save you some steps in future endeavors.

Edit: Removed copy of program with modified code to communicate a modification in oil slick effects.

Pete
Title: Re: Race Car Game
Post by: SierraKen on July 16, 2019, 09:59:52 pm
I just got 761049 by driving slower, beating Electro Joe like you did..... Wow your version does work better! The reason I added collision2 is because I thought it would be too much for the computer, but I guess it doesn't. Is that the only change you did? Removing the 1 IF/THEN line? I like this version better than mine lol. Thank you! This will go on my website soon.
Title: Re: Race Car Game
Post by: SierraKen on July 16, 2019, 10:12:00 pm
I deleted all the lines that had collision2 on it and it seems to run great! Thanks again! Here is the updated version. I don't know all lines you changed, but here is mine:

Code: QB64: [Select]
  1. 'I've wanted to make this game since I was a kid when I owned a little hand-held race car game where you steered the little wheel"
  2. 'to avoid the other cars. That toy broke when I was a kid so I've wanted a similar one on the computer. :)
  3. 'Enjoy!
  4. '
  5. 'Version 3 was made on July 16, 2019 by Ken G.
  6. 'Freeware only.
  7. '
  8. 'Thanks to the QB64.org forum guys for the help!
  9. _TITLE "RACE CAR"
  10. SCREEN _NEWIMAGE(640, 480, 32)
  11. begin:
  12. PRINT "                              R  A  C  E    C  A  R"
  13. PRINT "                                       V. 3"
  14. PRINT "                                    By Ken  G."
  15. PRINT "                    Use your arrow keys to steer your car"
  16. PRINT "                    around the other cars and go as far as you"
  17. PRINT "                    can without hitting them, as well as the round"
  18. PRINT "                    oil slicks. You get an extra car every 3000 points."
  19. PRINT "                    Press the up and down arrow keys to move"
  20. PRINT "                    faster or slower and also to stop turning."
  21. PRINT "                    You get 5 cars."
  22. PRINT "                    Every time you hit a street edge, you"
  23. PRINT "                    lose 200 points."
  24. PRINT "                    Every time you hit an oil slick your car"
  25. PRINT "                    moves a random direction."
  26. PRINT "                    Every time you hit another car you lose a car."
  27. PRINT "                    To reset the Top Ten score sheet, delete the file"
  28. PRINT "                    named toptenracers.txt and play a full game."
  29. INPUT "                    Press Enter to play!", a$
  30.  
  31. DIM name$(50), score(50), nm$(50), scc(50)
  32. LINE (0, 240)-(640, 240), _RGB32(127, 255, 127)
  33. tim = .02
  34. t2 = 0
  35. rc = 5
  36. x = 320
  37. y = 250: yy = 450
  38. cx = 350: cy = 420
  39. u = 1
  40. sc = 0
  41. one = 0
  42. collision = 0
  43. o = 0
  44. other = 0
  45. sct = 0
  46. go:
  47. _DELAY tim
  48. _LIMIT 200
  49. a$ = INKEY$
  50. IF a$ = CHR$(27) THEN END
  51. IF a$ = CHR$(0) + CHR$(72) THEN
  52.     u = 1
  53.     d = 0
  54.     r = 0
  55.     L = 0
  56.     tim = tim - .002
  57.     IF tim < .008 THEN tim = .008
  58. IF a$ = CHR$(0) + CHR$(80) THEN
  59.     u = 0
  60.     d = 1
  61.     r = 0
  62.     L = 0
  63.     tim = tim + .002
  64.     IF tim > .02 THEN tim = .02
  65.  
  66. IF a$ = CHR$(0) + CHR$(77) THEN r = 1: L = 0
  67. IF a$ = CHR$(0) + CHR$(75) THEN L = 1: r = 0
  68.  
  69. IF u = 1 THEN
  70.     GOSUB linesmoving:
  71.  
  72. IF d = 1 THEN
  73.     GOSUB linesmoving:
  74.  
  75. IF r = 1 THEN
  76.     ocx = cx: ocy = cy
  77.     GOSUB erasecar:
  78.     cx = cx + 2
  79.     'Check street edge.
  80.     IF cx > 570 THEN
  81.         cx = 550
  82.         SOUND 800, .25
  83.         sc = sc - 200
  84.     END IF
  85.     GOSUB drawcar:
  86.  
  87.  
  88. IF L = 1 THEN
  89.     ocx = cx: ocy = cy
  90.     GOSUB erasecar:
  91.     cx = cx - 2
  92.     'Check street edge.
  93.     IF cx < 40 THEN
  94.         cx = 60
  95.         SOUND 800, .25
  96.         sc = sc - 200
  97.     END IF
  98.     GOSUB drawcar:
  99. 'Street Sides
  100. LINE (320, 240)-(0, 480), _RGB32(127, 255, 127)
  101. LINE (320, 240)-(640, 480), _RGB32(127, 255, 127)
  102. GOSUB drawcar:
  103.  
  104. 'Other Car
  105. oc = INT(RND * 1000) + 1
  106. IF oc > 980 AND occ = 0 THEN
  107.     occ = 1
  108.     oxx2 = (RND * 16) - 8
  109.     oyyy = 250
  110.     oxxx = 305
  111. IF occ = 1 THEN
  112.     oldoyyy = oyyy
  113.     oldoxxx = oxxx
  114.     oyyy = oyyy + 5
  115.     oxxx = oxxx + oxx2
  116.     LINE (oldoxxx, oldoyyy)-(oldoxxx + 30, oldoyyy + 30), _RGB32(0, 0, 0), BF
  117.     CIRCLE (oldoxxx, oldoyyy + 5), 5, _RGB32(0, 0, 0)
  118.     CIRCLE (oldoxxx + 30, oldoyyy + 5), 5, _RGB32(0, 0, 0)
  119.     CIRCLE (oldoxxx + 30, oldoyyy + 25), 5, _RGB32(0, 0, 0)
  120.     CIRCLE (oldoxxx, oldoyyy + 25), 5, _RGB32(0, 0, 0)
  121.  
  122.     LINE (oxxx, oyyy)-(oxxx + 30, oyyy + 30), _RGB32(127, 249, 127), BF
  123.     CIRCLE (oxxx, oyyy + 5), 5, _RGB32(127, 227, 127)
  124.     CIRCLE (oxxx + 30, oyyy + 5), 5, _RGB32(127, 227, 127)
  125.     CIRCLE (oxxx + 30, oyyy + 25), 5, _RGB32(127, 227, 127)
  126.     CIRCLE (oxxx, oyyy + 25), 5, _RGB32(127, 227, 127)
  127.  
  128.     IF oyyy > 640 THEN
  129.         occ = 0
  130.         LINE (oxxx, oyyy)-(oxxx + 20, oyyy + 20), _RGB32(0, 0, 0), BF
  131.         CIRCLE (oldoxxx, oldoyyy + 5), 5, _RGB32(0, 0, 0)
  132.         CIRCLE (oldoxxx + 30, oldoyyy + 5), 5, _RGB32(0, 0, 0)
  133.         CIRCLE (oldoxxx + 30, oldoyyy + 25), 5, _RGB32(0, 0, 0)
  134.         CIRCLE (oldoxxx, oldoyyy + 25), 5, _RGB32(0, 0, 0)
  135.         IF collision = 0 THEN
  136.             other = other + 1
  137.             LOCATE 1, 20: PRINT "Passed Up Cars:"; other
  138.         END IF
  139.         oyyy = 250
  140.         oxxx = 320
  141.         collision = 0
  142.         GOTO nex:
  143.     END IF
  144. nex:
  145.  
  146. 'Detect Collision
  147. IF cx > oxxx - 10 AND cx < oxxx + 40 AND cy > oyyy - 5 AND cy < oyyy + 35 THEN
  148.     SOUND 800, .25
  149.     IF collision = 0 THEN rc = rc - 1
  150.     IF rc = 0 THEN GOTO done:
  151.     collision = 1
  152.  
  153.  
  154. 'Oil Slick
  155. oil = INT(RND * 100) + 1
  156. IF oil > 98 AND oil2 = 0 THEN
  157.     oil2 = 1
  158.     oilx2 = (RND * 12) - 6
  159.     oilyyy = 250
  160.     oilxxx = 305
  161. IF oil2 = 1 THEN
  162.     oldoilyyy = oilyyy
  163.     oldoilxxx = oilxxx
  164.     oilyyy = oilyyy + 5
  165.     oilxxx = oilxxx + oilx2
  166.     o = o + 1
  167.     IF o = 1 THEN GOTO oil:
  168.     FOR ooo = 1 TO 25 STEP 5
  169.         CIRCLE (oldoilxxx, oldoilyyy + 25), ooo, _RGB32(0, 0, 0)
  170.     NEXT ooo
  171.     oil:
  172.     FOR ooo = 1 TO 25 STEP 5
  173.         CIRCLE (oilxxx, oilyyy + 25), ooo, _RGB32(127, 227, 127)
  174.     NEXT ooo
  175.     IF oilyyy > 640 THEN
  176.         FOR ooo = 1 TO 25 STEP 5
  177.             CIRCLE (oldoilxxx, oldoilyyy + 25), ooo, _RGB32(0, 0, 0)
  178.         NEXT ooo
  179.         oilyyy = 250
  180.         oilxxx = 330
  181.         o = 0
  182.         oil2 = 0
  183.         GOTO nex2:
  184.     END IF
  185.  
  186. nex2:
  187.  
  188. 'Detect Collision With Oil Slick
  189. IF cx > oilxxx - 5 AND cx < oilxxx + 35 AND cy > oilyyy - 5 AND cy < oilyyy + 35 THEN
  190.     SOUND 800, .25
  191.     skid = INT(RND * 100) + 1
  192.     IF skid > 50 THEN r = 1: L = 0
  193.     IF skid <= 50 THEN L = 1: r = 0
  194.     tim = .02
  195.     SOUND 900, .25
  196.  
  197. 'Buildings
  198. b = INT(RND * 100) + 1
  199. IF b > 80 AND b2 = 0 THEN
  200.     b2 = 1
  201.     bx2 = (RND * 4) - 2
  202.     IF bx2 > 0 THEN
  203.         RANDOMIZE TIMER
  204.         bxxx = INT(RND * 200) + 370
  205.         bx3 = 10
  206.     END IF
  207.     IF bx2 <= 0 THEN
  208.         RANDOMIZE TIMER
  209.         bxxx = INT(RND * 150) + 10
  210.         bx3 = -10
  211.     END IF
  212.     bsz = INT(RND * 30) + 10
  213.     bsz2 = INT(RND * 30) + 10
  214.     byyy = 255
  215. IF b2 = 1 THEN
  216.     oldbyyy = byyy
  217.     oldbxxx = bxxx
  218.     byyy = byyy + 5
  219.     bxxx = bxxx + bx3
  220.     ob = ob + 1
  221.     IF ob = 1 THEN GOTO building:
  222.     'old erase
  223.     LINE (oldbxxx, oldbyyy)-(oldbxxx + bsz, oldbyyy + bsz2), _RGB32(0, 0, 0), B
  224.     building:
  225.     'new
  226.     LINE (bxxx, byyy)-(bxxx + bsz, byyy + bsz2), _RGB32(127, 227, 127), B
  227.     IF byyy > 640 THEN
  228.         'old erase again
  229.         LINE (oldbxxx, oldbyyy)-(oldbxxx + bsz, oldbyyy + bsz2), _RGB32(0, 0, 0), B
  230.         byyy = 250
  231.         ob = 0
  232.         b2 = 0
  233.         GOTO nex3:
  234.     END IF
  235.  
  236. nex3:
  237.  
  238. bb = INT(RND * 100) + 1
  239. IF bb > 80 AND bb2 = 0 THEN
  240.     bb2 = 1
  241.     bbx2 = (RND * 4) - 2
  242.     IF bbx2 > 0 THEN
  243.         RANDOMIZE TIMER
  244.         bbxxx = INT(RND * 200) + 350
  245.         bbx3 = 10
  246.     END IF
  247.     IF bbx2 <= 0 THEN
  248.         RANDOMIZE TIMER
  249.         bbxxx = INT(RND * 150) + 10
  250.         bbx3 = -10
  251.     END IF
  252.     bbsz = INT(RND * 30) + 10
  253.     bbsz2 = INT(RND * 30) + 10
  254.     bbyyy = 255
  255. IF bb2 = 1 THEN
  256.     oldbbyyy = bbyyy
  257.     oldbbxxx = bbxxx
  258.     bbyyy = bbyyy + 5
  259.     bbxxx = bbxxx + bbx3
  260.     obb = obb + 1
  261.     IF obb = 1 THEN GOTO building:
  262.     'old erase
  263.     LINE (oldbbxxx, oldbbyyy)-(oldbbxxx + bbsz, oldbbyyy + bbsz2), _RGB32(0, 0, 0), B
  264.     building2:
  265.     'new
  266.     LINE (bbxxx, bbyyy)-(bbxxx + bbsz, bbyyy + bbsz2), _RGB32(127, 227, 127), B
  267.     IF bbyyy > 640 THEN
  268.         'old erase again
  269.         LINE (oldbbxxx, oldbbyyy)-(oldbbxxx + bbsz, oldbbyyy + bbsz2), _RGB32(0, 0, 0), B
  270.         bbyyy = 250
  271.         obb = 0
  272.         bb2 = 0
  273.         GOTO nex4:
  274.     END IF
  275. nex4:
  276.  
  277. 'Extra Car
  278. IF sc / 3000 = INT(sc / 3000) AND sc / 3000 <> 0 THEN
  279.     rc = rc + 1
  280.     LOCATE 15, 35: PRINT "EXTRA CAR!"
  281.     SOUND 400, 2
  282.     SOUND 400, 2
  283.     SOUND 400, 2
  284.     t2 = 1
  285. IF t2 > 500 THEN
  286.     LOCATE 15, 35: PRINT "          "
  287.     t2 = 0
  288. IF t2 > 0 THEN t2 = t2 + 1
  289.  
  290. 'Speed Indicator
  291. LOCATE 3, 1: PRINT "Speed: "; INT(1.5 / tim)
  292. LOCATE 3, 13: PRINT "mph"
  293. 'Score
  294. IF sc < 1 THEN sc = 1
  295. LOCATE 1, 1: PRINT "Score: "; sc
  296. sc = sc + 1
  297. 'Cars You Have Leftover
  298. LOCATE 1, 73: PRINT "Cars:"; rc
  299.  
  300.  
  301. GOTO go:
  302.  
  303. linesmoving:
  304. oy = y
  305. y = y + 5
  306. IF y > 640 THEN y = 250
  307. IF y < 240 THEN y = 640
  308. LINE (x, oy)-(x, oy + 10), _RGB32(0, 0, 0)
  309. LINE (x, y)-(x, y + 10), _RGB32(127, 255, 127)
  310. oyy = yy
  311. yy = yy + 5
  312. IF yy > 640 THEN yy = 250
  313. IF yy < 240 THEN yy = 640
  314. LINE (x, oyy)-(x, oyy + 10), _RGB32(0, 0, 0)
  315. LINE (x, yy)-(x, yy + 10), _RGB32(127, 255, 127)
  316.  
  317.  
  318. drawcar:
  319. 'Car
  320. LINE (cx, cy)-(cx + 30, cy + 30), _RGB32(127, 227, 127), BF
  321. LINE (cx + 5, cy - 5)-(cx + 25, cy), _RGB32(127, 227, 127), BF
  322. CIRCLE (cx, cy + 5), 5, _RGB32(127, 227, 127)
  323. CIRCLE (cx + 30, cy + 5), 5, _RGB32(127, 227, 127)
  324. CIRCLE (cx + 30, cy + 25), 5, _RGB32(127, 227, 127)
  325. CIRCLE (cx, cy + 25), 5, _RGB32(127, 227, 127)
  326.  
  327. erasecar:
  328. LINE (ocx, ocy)-(ocx + 30, ocy + 30), _RGB32(0, 0, 0), BF
  329. LINE (ocx + 5, ocy - 5)-(ocx + 25, ocy), _RGB32(0, 0, 0), BF
  330. CIRCLE (ocx, ocy + 5), 5, _RGB32(0, 0, 0)
  331. CIRCLE (ocx + 30, ocy + 5), 5, _RGB32(0, 0, 0)
  332. CIRCLE (ocx + 30, ocy + 25), 5, _RGB32(0, 0, 0)
  333. CIRCLE (ocx, ocy + 25), 5, _RGB32(0, 0, 0)
  334.  
  335. done:
  336. LOCATE 10, 30: PRINT "G A M E    O V E R"
  337. LOCATE 1, 1: PRINT "Score: "; sc
  338. scc = sc * other
  339. LOCATE 14, 1: PRINT sc; " x "; other; " Passed Up Cars = Total Score: "; scc
  340. LOCATE 1, 73: PRINT "Cars:"; rc
  341. LOCATE 20, 1: INPUT "Press Enter to see Top Ten list.", topten$
  342.  
  343. 'Top Ten Racers
  344. IF _FILEEXISTS("toptenracers.txt") THEN
  345.     OPEN "toptenracers.txt" FOR OUTPUT AS #1
  346.     RESTORE toptendata
  347.     DO
  348.         READ toptenname$, toptenscore!
  349.         IF toptenname$ = "EOF" THEN EXIT DO
  350.         PRINT #1, toptenname$
  351.         PRINT #1, toptenscore!
  352.     LOOP
  353.     CLOSE #1
  354.  
  355. OPEN "toptenracers.txt" FOR INPUT AS #1
  356. FOR n = 1 TO 10
  357.     IF EOF(1) THEN GOTO nex5:
  358.     INPUT #1, name$(n)
  359.     INPUT #1, score(n)
  360.     IF scc > score(n) AND sct = 0 THEN
  361.         nn = n
  362.         PRINT "You have made the Top Ten!"
  363.         typename:
  364.         INPUT "Type your name here (25 letters and spaces maximum.):", nm$(nn)
  365.         IF LEN(nm$(nn)) > 25 THEN
  366.             PRINT "Name too long, try again."
  367.             GOTO typename:
  368.         END IF
  369.         sccc(nn) = scc
  370.         sct = 1
  371.     END IF
  372.     IF n = 10 AND sct = 0 THEN CLOSE #1: GOTO nex7:
  373. nex5:
  374. OPEN "toptenracers.txt" FOR OUTPUT AS #1
  375. FOR n = 1 TO nn
  376.     IF n <> nn THEN PRINT #1, name$(n): PRINT #1, score(n)
  377.     IF n = nn THEN
  378.         PRINT #1, nm$(n)
  379.         PRINT #1, sccc(n)
  380.     END IF
  381. nex6:
  382. FOR n = nn TO 10
  383.     PRINT #1, name$(n): PRINT #1, score(n)
  384.  
  385. nex7:
  386. PRINT "                            T O P    T E N     R A C E R S"
  387. OPEN "toptenracers.txt" FOR INPUT AS #1
  388. FOR n = 1 TO 10
  389.     IF EOF(1) THEN GOTO nex8:
  390.     INPUT #1, name$(n)
  391.     INPUT #1, score(n)
  392.     PRINT "             "; n; ". "; name$(n); score(n)
  393. nex8:
  394. FOR n = 1 TO 10
  395.     nm$(n) = ""
  396.     score(n) = 0
  397.     name$(n) = ""
  398.     sccc(n) = 0
  399.  
  400. LOCATE 23, 1
  401. INPUT "Would you like to play again? (Yes/No)", ag$
  402. IF ag$ = "y" OR ag$ = "Y" OR ag$ = "YES" OR ag$ = "yes" OR ag$ = "Yes" OR ag$ = "yES" OR ag$ = "yeS" THEN GOTO begin:
  403.  
  404. toptendata:
  405. DATA Electro Joe,500000
  406. DATA Flying Felice,450000
  407. DATA Speedy Spencer,400000
  408. DATA Super Sam,350000
  409. DATA Ralph Runner,300000
  410. DATA Suzy Swift,275000
  411. DATA Quick Ken,250000
  412. DATA Tiger Tessa,225000
  413. DATA Brisk Bob,200000
  414. DATA Jalopy Jay,175000
  415.  
  416.  
Title: Re: Race Car Game
Post by: Pete on July 16, 2019, 10:37:57 pm
I tweaked the delay and added a timer. I also increased the collision parameters for the oil slicks. The effect is to kill the speed by 3x wen you hit an oil slick, but over 3/4 of a second, it progressively adds speed, until it's back to the original speed it was traveling at, before it hit the skids!

Anyway, I'll keep it up for now.

The lines changed are roughly...

IF cx > oilxxx - 25 AND cx < oilxxx + 35 AND cy > oilyyy - 25 AND cy < oilyyy + 35 THEN ' Changed collisions parameters.

I moved...

IF tim < .008 THEN tim = .008 ' Moved to under Go: It needed to be encountered sooner to offset faster speeds oil slicks reducing the delay below zero. I know, I estimated pretty good, but I didn't want to spend the extra time for exact math.

I removed this block if statement:  IF collision2 = 0 THEN ... END IF

I added: IF z1 = 0 THEN oldtim = tim: tim = tim * 3: z1 = TIMER  ' This line saves the old delay, starts a timer, and decreases speed by 3x.

Finally, I added this before the GOTO Go line...

IF z1 THEN
    IF ABS(z1 - TIMER) >= .75 THEN ' This event is triggered after .75 seconds after an oil slick collision.
        tim = oldtim
        z1 = 0
    ELSE
        tim = tim - .0005 ' This progressively lets the car speed back up, simulating the skid effect.
    END IF
END IF

Anyway, I hope that helps. Sorry for the initial lack of explanation. I love to code, but I never used to comment my own code, either.

Pete




Title: Re: Race Car Game
Post by: SierraKen on July 16, 2019, 10:59:43 pm
Well I'm glad that works better for you. I think every computer is slightly different on things and I like the way my code is right now, so I'm not going to go dig into this deeper. But I appreciate you trying to help. Your IF/THEN collision2 stuff really makes the game sound better. To me, programming is like an art form and the more of other people's stuff I add to it, the less I feel it's mine. Except of course for 1 or 2 lines which I can understand how to do. But adding other stuff that I haven't really done before I really can't do it. This is like my little creation. lol Of course comments and suggestions are always welcome. :)
Title: Re: Race Car Game
Post by: SierraKen on July 17, 2019, 12:11:32 am
I got the game on my website now. I thanked "the guys at the QB64.org forum" again on the page for helping me with this. You can see all my programs and games here:
http://www.kensprograms.com/

The Race Car game is at the bottom.
Title: Re: Race Car Game
Post by: Pete on July 17, 2019, 01:19:02 am
I do miss the joystick and paddle controllers. I made a mouse version with mouse wheel accelerator. It's not as good as a joystick, but I'm just not a fan of the keyboard for games. I got used to the center divider. Without the curbs moving, like in Activision Enduro, yes, you need that for the speed effect. It just took me awhile to get the missiles from Space Invaders out of my head. Go figure.

Great Game!

Pete
Title: Re: Race Car Game
Post by: Petr on July 17, 2019, 02:06:18 am
Hi. The joystick is supported in QB64 (I never tried it because I don't have one), it should be STRIG statement for  activating read joystick envents  and STRIG function to handle the joystick buttons.
Title: Re: Race Car Game
Post by: johnno56 on July 17, 2019, 12:26:40 pm
Cool game. Much better than the original version. Nicely done!

Unfortunately, my poor driving skills, prevented me from getting onto the high score table... lol
Title: Re: Race Car Game
Post by: SierraKen on July 17, 2019, 12:36:49 pm
Thanks Johno :).

That's awesome about the joystick control, I might still have one somewhere to use. Are they USB ones or the old Com Port?
Title: Re: Race Car Game
Post by: Pete on July 17, 2019, 01:44:32 pm
Hi Petr,

Yes, I'm aware of those QB64 statements, but like you, I'm stickless, or maybe it's joyless. Wait, either way, that didn't come out right.

To all,

Kidding aside, I'm have so much fun with this. I made some modifications, which include using the right and left mouse buttons to accelerate and brake. That works better than the mouse wheel, as it has more of a pedal feel. Moving the mouse right to left steers the car. Steering and acceleration / deceleration can be done at the same time.

As most of you know, I don't do graphics, but I was one of the four people in on that tool box project for ellipse fill. I decided to study the code, and found it wasn't difficult at all to substitute solid filled dark grey ellipses for the oil slick circles. I also tweaked some delays to smooth out the modifications, and I think the end product came out pretty well.

I'd love to post the project as modified, but maybe if I can get Ken's permission, I'd post it on the QBasic Forum. That would prevent  muddying up Ken's project here. I also removed the code I posted yesterday, for the same reason. I just wanted to communicate what I was doing, and not hijack the project. It's a lot easier to show it than say it, that's for sure. Anyway, this is one of the few graphics projects that sparked my interest.

Pete
Title: Re: Race Car Game
Post by: Petr on July 17, 2019, 02:01:16 pm
Hi Pete. I hope SierraKen gives you permission, I'd like to try it :-D
Title: Re: Race Car Game
Post by: SierraKen on July 17, 2019, 02:07:42 pm
Pete, you didn't have to delete your stuff. But sure, go ahead and post it anywhere you wish, but please keep my name somewhere on it as well, like on the top of the code you can put this:
'Original game design by Ken G., modified with permission by Pete.
Or something like that. You really don't even need the "with permission" part. And I apologize if I came across too stern with yesterday's post, I just wanted to say something about it. But, just like the reason why I put the codes on my website, is to teach people and let them go at it. :) But see, I just wanted the ORIGINAL one mostly by me anyway. :) After that, they are all out there in the wild. LOL I probably should say that in my Terms of Use page on my website, it says that if people ever want to sell my code for themselves, please don't use more than half of the code. But that is only for selling of course. To see my Terms of Use page, go to the very bottom of my website to the link, or go directly to it here: http://www.kensprograms.com/terms.html
Title: Re: Race Car Game
Post by: Pete on July 17, 2019, 03:48:16 pm
It's great we are on the same page about this. Also, no worries on the whole "stern" thing. I took that as you have a clear understanding of how you want your project to be, and that's admirable. It would be easier to communicate intent better in person than over a forum, but until they come up with teleporters, we're stuck with this method.

Anyway, I posted the version I modified here: https://www.tapatalk.com/groups/qbasic/viewtopic.php?f=754391&t=39525

Please have a look, and if there is anything you would like changed, let me know; I'd be happy to do so.

Pete

Title: Re: Race Car Game
Post by: SierraKen on July 17, 2019, 04:10:59 pm
The oil slick looks great! I'll keep mine though just for the retro early-80's feel hehe. I just tried your version and it runs great! Well except for 1 thing which you may try to change. That's the fact that the mouse doesn't work when the pointer is off of the window. The only fix to that that I know of is to change the game to _FULLSCREEN and the game would be the entire screen. That way you also wouldn't have to worry about changing coordinate variables because it just makes the coordinates larger. If you do this, make sure and add something like "Esc to quit anytime." at the front welcome page and somewhere on top of the game display window, if there's room to fit it, or maybe on line 2 or 3 or something so people can stop the game since there will be no X to close the program at _FULLSCREEN. And while you are there at the front welcome page, feel free to add "Modifications by Pete" somewhere under my Ken G. name. But other than that, I like the feel to the game, it runs really well. 
Title: Re: Race Car Game
Post by: Pete on July 17, 2019, 04:36:18 pm
Yes, about the mouse. I know and you can't even keep that under control with _MOUSEMOVE when it reaches the edges. I wish that could be corrected in QB64, or we had a way to keep the mouse in the program window only. The only other way I know of is to hide the mouse pointer completely, not just like I hid it in the program window, but hide it also on the desktop, using a Windows API call. Unfortunately, that would make it a Windows only app. No Mac or Linux usr could try it. :(.

In regards to the name modification, you mean something like this?

Code: QB64: [Select]
  1. DEFINT A-R
  2. 'I've wanted to make this game since I was a kid when I owned a little hand-held race car game where you steered the little wheel"
  3. 'to avoid the other cars. That toy broke when I was a kid so I've wanted a similar one on the computer. :)
  4. 'Enjoy!
  5. '
  6. 'Version 3 was made on July 16, 2019 by Ken G.
  7. 'Modifications made by Pete on July 17, 2019.
  8. 'Freeware only.
  9. '
  10. 'Thanks to the QB64.org forum guys for the help!
  11. _TITLE "RACE CAR"
  12. SCREEN _NEWIMAGE(640, 480, 32)
  13.  
  14. begin:
  15. PRINT "                               R  A  C  E    C  A  R"
  16. PRINT "                                       V. 3"
  17. PRINT "                     By Ken  G. with Modifications by Pete"
  18. PRINT "                 Use the mouse moving it l/r to steer your car"
  19. PRINT "                 around the other cars and go as far as you"
  20. PRINT "                 can without hitting them, as well as the round"
  21. PRINT "                 oil slicks. You get an extra car every 3000 points."
  22. PRINT "                 Click the left or right mouse buttons to move"
  23. PRINT "                 your race car faster or slower."
  24. PRINT "                 You get 5 cars."
  25. PRINT "                 Every time you hit a street edge, you"
  26. PRINT "                 lose 200 points."
  27. PRINT "                 Every time you hit an oil slick your car"
  28. PRINT "                 moves a random direction."
  29. PRINT "                 Every time you hit another car you lose a car."
  30. PRINT "                 To reset the Top Ten score sheet, delete the file"
  31. PRINT "                 named toptenracers.txt and play a full game."
  32. INPUT "                 Press Enter to play! ", a$

Let me know if you had something else in mind. Like I said, until we make teleporters...

Hey, if you ever make a YouTube video, let me know, I'll embed the video, too.

Oh, I almost forgot, I changed the instructions in my modified version to indicate it uses the mouse.

Pete
Title: Re: Race Car Game
Post by: SierraKen on July 17, 2019, 04:40:33 pm
Name looks perfect. Not sure about doing a YouTube video yet. I bookmarked that forum, will take a look at it more sometime.
Title: Re: Race Car Game
Post by: Pete on July 17, 2019, 05:12:59 pm
Great! Also, you are welcome to join the QB Forum, if you like. I only give new members posting rights to the community forum, but I'd make an exception in your case, and provide you with full posting / editing abilities. The reason for the limitations, it's an old forum, which I took control of a little over 10 years ago, when QB was abandoned and our previous forum owner passed. By archiving most of it, I can better preserve it and not have spammers to deal with. Rob (Galleon) actually started his QB64 project and posted updates in a special sub-forum, which I asked the previous forum owner to add. The Big Programs Forum and the Programs I am Proud forum would be places I recommend you have a look at. Also, check out TheBOB's sub-forum, he is a professional graphics artist. He also has his own samples folder in the QB64 download zip file. No worries either if you don't want to join. It's not like I'm giving away free decoder rings with every membership!

Pete
Title: Re: Race Car Game
Post by: Petr on July 17, 2019, 05:15:14 pm
Nice modification, Pete!
Title: Re: Race Car Game
Post by: SierraKen on July 17, 2019, 05:30:12 pm
Thanks Pete, I'll think about it. I put a lot of time in this forum right now and I don't know if I want to give time for other forums. But I am curious, is this also your forum?

http://www.petesqbsite.com/phpBB3/index.php?sid=94dd1676bc2f20d929ef10cf97860345
Title: Re: Race Car Game
Post by: Pete on July 17, 2019, 05:58:53 pm
That's the "other" Pete. Actually, Pete Berg's been at it, at least forum-wise, more years than me! The QB64 folder also contains samples from his site. Clippy, who contributed most of the QB64 wiki entries now moderates that site, but surprise, Pete Berg returned a few months back, joined The QBasic Forum at Tapatalk, but so far, has not been too active in the community.

There are times I wished I'd encouraged people at Rob's (Galleon's) [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there] forum to post their projects in the QBasic / QB64 sub-forum. That's the one I said Mac, our former forum owner, and I opened for Rob. Rob opened his own [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there] forum when our N54 QBasic forum got hacked. Fortunately, the people at Network54 were able to restore the forum in a couple of weeks time. I always thought, at some point, Rob should and would have his own forum. I don't think either of us anticipated it would happen the way it did, and now, ironically enough, Rob closed down his forum a short time ago, and while the QBasic Forum posts still remain online, nearly everything that was posted to [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there] is now gone. Anyway, just some QB history.

Pete
Title: Re: Race Car Game
Post by: SierraKen on July 17, 2019, 09:23:22 pm
That's interesting Pete, thanks!
Title: Re: Race Car Game
Post by: Ashish on July 19, 2019, 09:18:20 am
Good Job!
Title: Re: Race Car Game
Post by: SierraKen on July 19, 2019, 01:34:33 pm
Thanks Ashish!

I been trying to think of something else to make, but nothing so far, unless I want to finish that Tunnels game I started, although I don't know how good I can make that one.