Author Topic: Cats and Mouse Game  (Read 3347 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Cats and Mouse Game
« on: December 09, 2019, 05:01:44 pm »
Using the code from my other thread called Mouse Trail, I was able to make this game within a few hours today. Half-way through it I remembered that B+ made a very similar game just like this months ago so I decided to just make my own version. I'll post a picture of the game below too. You control the mouse with your mouse away from the 2 big cats to try to eat the cheese. The speed of the cats increases at a gradual rate as the game goes on. I use an equation to make the speed also go higher if your mouse dies so it won't start over from the slowest speed again. Instead it uses the score you had for the speed for the next mouse. When you start out, the cats are off the screen so it takes a few seconds to see you and chase you.  All of the text is in the title bar. When all your players are used up, press Enter to start again, which it says in the title bar. Unless you are super good, the game only lasts a couple minutes or so, feel free to change anything in the code to suite your needs. I tried my hardest to make the mouse and cats look good. :)
There is no extra file, just the code below, and the picture I'm about to post here. Have fun and tell me what you think of it, thanks. Also, thank you to b+ and SMcNeill for some help.

Code: QB64: [Select]
  1. 'Cats and Mouse Game by Ken G.
  2. 'Written on Dec. 9, 2019.
  3. 'Thank you to b+ and SMcNeill from the QB64.org forum for some help!
  4.  
  5. _TITLE "Cats and Mouse Game - by Ken G. - Use mouse to get to the cheese before a cat gets you."
  6. DisplayScreen = _NEWIMAGE(800, 600, 32)
  7. WorkScreen = _NEWIMAGE(800, 600, 32)
  8. MouseScreen = _NEWIMAGE(800, 600, 32)
  9. begin:
  10. score = 0
  11. speed = 1
  12. SCREEN DisplayScreen
  13. player = 20
  14. start:
  15. IF score > 0 THEN speed = INT(score / 1000)
  16. xx = 400: yy = 1000
  17. xx2 = 0: yy2 = 1000
  18.     _LIMIT 100
  19.         mouseX = _MOUSEX
  20.         mouseY = _MOUSEY
  21.         mouseLeftButton = _MOUSEBUTTON(1)
  22.         mouseRightButton = _MOUSEBUTTON(2)
  23.         mouseMiddleButton = _MOUSEBUTTON(3)
  24.     LOOP
  25.     _SOURCE WorkScreen: _DEST WorkScreen
  26.     'Draw on your work screen.
  27.     IF mouseX > xx THEN xx = xx + speed
  28.     IF mouseY > yy THEN yy = yy + speed
  29.     IF mouseX > xx2 THEN xx2 = xx2 + speed
  30.     IF mouseX > yy2 THEN yy2 = yy2 + speed
  31.     IF mouseX < xx THEN xx = xx - speed
  32.     IF mouseY < yy THEN yy = yy - speed
  33.     IF mouseX < xx2 THEN xx2 = xx2 - speed
  34.     IF mouseX < yy2 THEN yy2 = yy2 - speed
  35.     speed = speed + .001
  36.     IF speed > 10000 THEN speed = 10000
  37.     'Check to see if a cat got to your mouse.
  38.     FOR tt = -50 TO 50
  39.         IF mouseX + tt > xx - 1 AND mouseX + tt < xx + 101 AND mouseY + tt > yy - 1 AND mouseY + tt < yy + 101 THEN player = player - 1: LINE (xx, yy)-(xx + 100, yy + 100), _RGB32(255, 0, 0), BF: SOUND 200, .2: GOTO start:
  40.         IF mouseX + tt > xx2 - 1 AND mouseX + tt < xx2 + 101 AND mouseY + tt > yy2 - 1 AND mouseY + tt < yy2 + 101 THEN player = player - 1: LINE (xx2, yy2)-(xx2 + 100, yy2 + 100), _RGB32(255, 0, 0), BF: SOUND 200, .2: GOTO start:
  41.     NEXT tt
  42.     b = b + 1
  43.     IF b / 1000 = INT(b / 1000) THEN
  44.         again2:
  45.         RANDOMIZE TIMER
  46.         bx = RND * 780
  47.         by = RND * 580
  48.         b = 0
  49.     END IF
  50.     'Draw cheese.
  51.     LINE (bx, by)-(bx + 50, by + 50), _RGB32(255, 255, 127), BF
  52.     CIRCLE (bx + 15, by + 15), 10, _RGB32(222, 188, 127)
  53.     PAINT (bx + 15, by + 15), _RGB32(222, 188, 127)
  54.     CIRCLE (bx + 30, by + 30), 7, _RGB32(222, 188, 127)
  55.     PAINT (bx + 30, by + 30), _RGB32(222, 188, 127)
  56.  
  57.     'Check to see if you got the cheese.
  58.     FOR tt = -50 TO 50
  59.         IF mouseX + tt > bx - 1 AND mouseX + tt < bx + 51 AND mouseY + tt > by - 1 AND mouseY + tt < by + 51 THEN
  60.             score = score + 100
  61.             LINE (bx, by)-(bx + 50, by + 50), _RGB32(0, 0, 0), BF
  62.             FOR snd = 500 TO 850 STEP 50
  63.                 SOUND snd, .2
  64.             NEXT snd
  65.             GOTO again2:
  66.         END IF
  67.     NEXT tt
  68.     IF player < 1 THEN player = 0
  69.     score$ = STR$(score)
  70.     player$ = STR$(player)
  71.     ti$ = "Cats and Mouse Game - by Ken G. - - Score: " + score$ + "            Players: " + player$
  72.     _TITLE ti$
  73.     IF player < 1 THEN
  74.         _TITLE ti$ + "   Game Over - Press Enter To Play Again"
  75.         INPUT ag$
  76.         GOTO begin:
  77.     END IF
  78.     'First Cat
  79.     'head
  80.     LINE (xx, yy)-(xx + 100, yy + 100), _RGB32(255, 188, 127), BF
  81.     'ears
  82.     LINE (xx, yy)-(xx + 20, yy - 20), _RGB32(255, 188, 127)
  83.     LINE (xx + 20, yy - 20)-(xx + 40, yy), _RGB32(255, 188, 127)
  84.     PAINT (xx + 20, yy - 5), _RGB32(255, 188, 127)
  85.     LINE (xx + 60, yy)-(xx + 80, yy - 20), _RGB32(255, 188, 127)
  86.     LINE (xx + 80, yy - 20)-(xx + 100, yy), _RGB32(255, 188, 127)
  87.     PAINT (xx + 80, yy - 5), _RGB32(255, 188, 127)
  88.     'eyes
  89.     CIRCLE (xx + 30, yy + 20), 15, _RGB32(255, 255, 255), , , .5
  90.     PAINT (xx + 30, yy + 20), _RGB32(255, 255, 255)
  91.     CIRCLE (xx + 30, yy + 20), 5, _RGB32(255, 0, 0)
  92.     PAINT (xx + 30, yy + 20), _RGB32(255, 0, 0)
  93.     CIRCLE (xx + 70, yy + 20), 15, _RGB32(255, 255, 255), , , .5
  94.     PAINT (xx + 70, yy + 20), _RGB32(255, 255, 255)
  95.     CIRCLE (xx + 70, yy + 20), 5, _RGB32(255, 0, 0)
  96.     PAINT (xx + 70, yy + 20), _RGB32(255, 0, 0)
  97.  
  98.     'mouth
  99.     CIRCLE (xx + 50, yy + 70), 20, _RGB32(255, 0, 0), , , .5
  100.     PAINT (xx + 50, yy + 70), _RGB32(255, 0, 0)
  101.     'nose
  102.     CIRCLE (xx + 45, yy + 50), 4, _RGB32(0, 0, 0)
  103.     PAINT (xx + 45, yy + 50), _RGB32(0, 0, 0)
  104.     CIRCLE (xx + 55, yy + 50), 4, _RGB32(0, 0, 0)
  105.     PAINT (xx + 55, yy + 50), _RGB32(0, 0, 0)
  106.     'whiskers
  107.     LINE (xx + 20, yy + 50)-(xx - 20, yy + 30), _RGB32(255, 255, 255)
  108.     LINE (xx + 20, yy + 50)-(xx - 20, yy + 50), _RGB32(255, 255, 255)
  109.     LINE (xx + 20, yy + 50)-(xx - 20, yy + 70), _RGB32(255, 255, 255)
  110.     LINE (xx + 80, yy + 50)-(xx + 120, yy + 30), _RGB32(255, 255, 255)
  111.     LINE (xx + 80, yy + 50)-(xx + 120, yy + 50), _RGB32(255, 255, 255)
  112.     LINE (xx + 80, yy + 50)-(xx + 120, yy + 70), _RGB32(255, 255, 255)
  113.  
  114.     'Second Cat
  115.     'head
  116.     LINE (xx2, yy2)-(xx2 + 100, yy2 + 100), _RGB32(255, 188, 127), BF
  117.     'ears
  118.     LINE (xx2, yy2)-(xx2 + 20, yy2 - 20), _RGB32(255, 188, 127)
  119.     LINE (xx2 + 20, yy2 - 20)-(xx2 + 40, yy2), _RGB32(255, 188, 127)
  120.     PAINT (xx2 + 20, yy2 - 5), _RGB32(255, 188, 127)
  121.     LINE (xx2 + 60, yy2)-(xx2 + 80, yy2 - 20), _RGB32(255, 188, 127)
  122.     LINE (xx2 + 80, yy2 - 20)-(xx2 + 100, yy2), _RGB32(255, 188, 127)
  123.     PAINT (xx2 + 80, yy2 - 5), _RGB32(255, 188, 127)
  124.     'eyes
  125.     CIRCLE (xx2 + 30, yy2 + 20), 15, _RGB32(255, 255, 255), , , .5
  126.     PAINT (xx2 + 30, yy2 + 20), _RGB32(255, 255, 255)
  127.     CIRCLE (xx2 + 30, yy2 + 20), 5, _RGB32(255, 0, 0)
  128.     PAINT (xx2 + 30, yy2 + 20), _RGB32(255, 0, 0)
  129.     CIRCLE (xx2 + 70, yy2 + 20), 15, _RGB32(255, 255, 255), , , .5
  130.     PAINT (xx2 + 70, yy2 + 20), _RGB32(255, 255, 255)
  131.     CIRCLE (xx2 + 70, yy2 + 20), 5, _RGB32(255, 0, 0)
  132.     PAINT (xx2 + 70, yy2 + 20), _RGB32(255, 0, 0)
  133.  
  134.     'mouth
  135.     CIRCLE (xx2 + 50, yy2 + 70), 20, _RGB32(255, 0, 0), , , .5
  136.     PAINT (xx2 + 50, yy2 + 70), _RGB32(255, 0, 0)
  137.     'nose
  138.     CIRCLE (xx2 + 45, yy2 + 50), 4, _RGB32(0, 0, 0)
  139.     PAINT (xx2 + 45, yy2 + 50), _RGB32(0, 0, 0)
  140.     CIRCLE (xx2 + 55, yy2 + 50), 4, _RGB32(0, 0, 0)
  141.     PAINT (xx2 + 55, yy2 + 50), _RGB32(0, 0, 0)
  142.     'whiskers
  143.     LINE (xx2 + 20, yy2 + 50)-(xx2 - 20, yy2 + 30), _RGB32(255, 255, 255)
  144.     LINE (xx2 + 20, yy2 + 50)-(xx2 - 20, yy2 + 50), _RGB32(255, 255, 255)
  145.     LINE (xx2 + 20, yy2 + 50)-(xx2 - 20, yy2 + 70), _RGB32(255, 255, 255)
  146.     LINE (xx2 + 80, yy2 + 50)-(xx2 + 120, yy2 + 30), _RGB32(255, 255, 255)
  147.     LINE (xx2 + 80, yy2 + 50)-(xx2 + 120, yy2 + 50), _RGB32(255, 255, 255)
  148.     LINE (xx2 + 80, yy2 + 50)-(xx2 + 120, yy2 + 70), _RGB32(255, 255, 255)
  149.  
  150.  
  151.     _SOURCE MouseScreen
  152.     'Draw your mouse.
  153.     'body
  154.     CIRCLE (mouseX, mouseY), 50, _RGB32(172, 61, 0), , , .5
  155.     PAINT (mouseX, mouseY), _RGB32(172, 61, 0)
  156.     'eye
  157.     CIRCLE (mouseX - 25, mouseY - 20), 5, _RGB32(255, 255, 255), , , .5
  158.     PAINT (mouseX - 25, mouseY - 20), _RGB32(255, 255, 255)
  159.     CIRCLE (mouseX - 27, mouseY - 20), 2, _RGB32(0, 0, 0)
  160.     PAINT (mouseX - 27, mouseY - 20), _RGB32(0, 0, 0)
  161.     'nose
  162.     CIRCLE (mouseX - 50, mouseY), 5, _RGB32(105, 6, 0)
  163.     PAINT (mouseX - 50, mouseY), _RGB32(105, 6, 0)
  164.     'mouth
  165.     CIRCLE (mouseX - 30, mouseY + 15), 10, _RGB32(255, 0, 0), , , .35
  166.     PAINT (mouseX - 30, mouseY + 15), _RGB32(255, 0, 0)
  167.     'tail
  168.     LINE (mouseX + 49, mouseY)-(mouseX + 85, mouseY), _RGB32(172, 61, 0)
  169.     'ear
  170.     CIRCLE (mouseX - 20, mouseY - 31), 7, _RGB32(172, 61, 0), , , 1.75
  171.     PAINT (mouseX - 20, mouseY - 31), _RGB32(172, 61, 0)
  172.  
  173.     LINE (0, 0)-(_WIDTH, _HEIGHT), _RGBA(0, 0, 0, 30), BF
  174.     _PUTIMAGE , WorkScreen, DisplayScreen
  175.     _PUTIMAGE , MouseScreen, DisplayScreen
  176.     _DISPLAY
  177.  

 
Cats and Mouse Game by Ken G.jpg
* Cats and Mouse Game by Ken G.jpg (Filesize: 62.17 KB, Dimensions: 801x625, Views: 196)
« Last Edit: December 09, 2019, 05:04:05 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Cats and Mouse Game
« Reply #1 on: December 09, 2019, 05:22:20 pm »
Ha, cute!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Cats and Mouse Game
« Reply #2 on: December 09, 2019, 05:33:23 pm »
LOL Thanks :). These kinds of games and programs keep my mind going. :) And in this one I learned that to start the enemies from off the screen, which you guys have told me before. That way they won't be right on you as it starts.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Cats and Mouse Game
« Reply #3 on: December 09, 2019, 06:00:14 pm »
11,700 first try. Is that a lot??? Towards the end, it gets almost as hard as getting cheese on a coupon sale at Trader Joe's. Yeah, just try dodging those catty women, hungry for Gouda.

Nice effects. I liked it. I might even go as far to say... Gouda job! (My fellow Italian friend, Tempo, might not see that one as a pun.  Oh well.

Pete
 
« Last Edit: December 09, 2019, 06:03:08 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: Cats and Mouse Game
« Reply #4 on: December 09, 2019, 06:08:55 pm »
ROFL Thanks Pete! Dang, 11,700! You are way better than I am. lol