Author Topic: Race Car Game  (Read 13451 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Race Car Game
« Reply #15 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.  
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Race Car Game
« Reply #16 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!
« Last Edit: July 16, 2019, 12:15:10 am by bplus »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Race Car Game
« Reply #17 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Race Car Game
« Reply #18 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.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Race Car Game
« Reply #19 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Race Car Game
« Reply #20 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.
« Last Edit: July 16, 2019, 01:27:36 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Race Car Game
« Reply #21 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.
« Last Edit: July 16, 2019, 12:09:57 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Race Car Game
« Reply #22 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.  
* toptenracers.txt (Filesize: 0.21 KB, Downloads: 171)
« Last Edit: July 16, 2019, 06:45:28 pm by SierraKen »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Race Car Game
« Reply #23 on: July 16, 2019, 02:20:29 pm »
Nice upgrade, SierraKen.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Race Car Game
« Reply #24 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   
« Last Edit: July 16, 2019, 04:21:57 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Race Car Game
« Reply #25 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.
« Last Edit: July 16, 2019, 03:31:39 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Race Car Game
« Reply #26 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.
« Last Edit: July 16, 2019, 03:59:40 pm by SierraKen »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Race Car Game
« Reply #27 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
« Last Edit: July 16, 2019, 05:00:15 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Race Car Game
« Reply #28 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.
« Last Edit: July 16, 2019, 05:20:56 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Race Car Game
« Reply #29 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.  
« Last Edit: July 16, 2019, 10:23:58 pm by SierraKen »