Author Topic: JackStack - Halloween puzzle game  (Read 10911 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: JackStack - Halloween puzzle game
« Reply #15 on: October 07, 2021, 10:59:21 am »
@Dav I think Christmas comes every year, the task is to keep the presents coming too. :)

If you get the stack to top, don't you deserve to start over and add to your score? It's really gets hard to get a stack to top so it should be rewarded by a game continuance, maybe at a faster pace or smaller boxes, aha! yes that.... just keep game going as reward for stacking all boxes. That alone would make game less "boring"?

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: JackStack - Halloween puzzle game
« Reply #16 on: October 07, 2021, 02:07:05 pm »
@Dav wrote:

Quote
I still run @Petr ‘s Christmas demo now and then - it’s a very enjoyable one.

Thank you, Dav. That really pleased me a lot. Christmas for me is connected with pictures of Josef Lada. They are very distinctive and nice. You can see it here:

https://www.google.com/search?q=josef+lada+v%C3%A1noce+obr%C3%A1zky&tbm=isch&ved=2ahUKEwj3k6yH8LjzAhW-gM4BHfVcAVoQ2-cCegQIABAA&oq=josef+lada+v%C3%A1noce+obr%C3%A1zky&gs_lcp=CgNpbWcQAzoECAAQHlDFeVjciwFg844BaABwAHgAgAFLiAGVBJIBATiYAQCgAQGqAQtnd3Mtd2l6LWltZ8ABAQ&sclient=img&ei=KTVfYbfbCL6Bur4P9bmF0AU&bih=734&biw=1536&rlz=1C1GIGM_enCZ654CZ654#imgrc=mBAbxq3EV2Z4dM

So far, I am not working on any program with this topic, not even on anything on New Year's Eve. So far, I have only written two programs, both large, both unfinished and - both on a completely different topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: JackStack - Halloween puzzle game
« Reply #17 on: October 07, 2021, 02:14:13 pm »
@Dav


I really like your game, especially appreciate the idea and design!


Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: JackStack - Halloween puzzle game
« Reply #19 on: October 07, 2021, 02:30:41 pm »
@bplus

Thanks for the link. Nice :) If we hinting Theme.... maybe. I can't promise it. Given the ideas, I would need to write another program. When I write a program with twenty fingers (the first half with my hands and the second half of the source under the table from the middle to the end with my feet on a laptop) and with that program I then put it together,  will then catch everything :)

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: JackStack - Halloween puzzle game
« Reply #20 on: October 09, 2021, 09:12:12 pm »
Thanks, @Petr.

I decided to turn this into a game called Trick Or Treat, with several stages.  All game play uses just the space bar.  Right now there's the jacks stacker stage that is in the current download, and I've added the "Fly the Witch through the candy field" without getting hit, sort of like flappy bird where the space key raises the witch.  And there's a candy grid stage, where you pick 20 candies without hitting a witch on the grid, and there a spinning wheel where you stop on the jack-o-lantern 5 times with hitting other things (rotation speed increases).  Have a few other to add.  Hopefully will have it done before Halloween.  Trying to come up with a one key puzzle that is kind of fun  Here's a few screenshots...

- Dav

trickortreat1.jpg
 
trickortreat2.jpg
 
trickortreat3.jpg


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: JackStack - Halloween puzzle game
« Reply #21 on: October 10, 2021, 01:23:15 am »
Wow dav!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: JackStack - Halloween puzzle game
« Reply #22 on: October 10, 2021, 04:46:07 am »
It looks really nice, Dav!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: JackStack - Halloween puzzle game
« Reply #23 on: October 12, 2021, 01:07:54 pm »
I'm having a little problem getting the collision detection working well on the flying witch stage.   I'm not very experienced with that area, but I tried to use Terry's collision detection method described in his tutorials.  Needs tweaking, the witch falls out of the sky without hitting a candy.

Here's the flying witch stage (simplified) for download if anyone wants to help out. 

Press the space bar to raise the witch, avoid hitting the candies.

-Dav

   (59k)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: JackStack - Halloween puzzle game
« Reply #24 on: October 12, 2021, 01:15:29 pm »
I haven't seen your code Dav but is it just 2 image boxes to check for collision or are you trying by pixels or polygons?

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: JackStack - Halloween puzzle game
« Reply #25 on: October 12, 2021, 01:17:54 pm »
I'm using two block images, both 75x75 pixels.  Here's the collision code (should have posted it...)

- Dav

Code: QB64: [Select]
  1.  
  2.         wx1 = witchflyx: wy1 = witchflyy  'witch x/y's
  3.         wx2 = wx1 + 75: wy2 = wy1 + 75
  4.  
  5.         jx1 = jackysx(j): jy1 = jackysy(j)  'candies x/y
  6.         jx2 = jx1 + 75: jy2 = jy1 + 75
  7.  
  8.         hit = 0
  9.         IF wx2 >= jx1 THEN
  10.             IF wx1 <= jx2 THEN
  11.                 IF wy2 >= jy1 THEN
  12.                     IF wy1 <= jy2 THEN hit = 1
  13.                 END IF
  14.             END IF
  15.         END IF
  16.  
  17.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: JackStack - Halloween puzzle game
« Reply #26 on: October 12, 2021, 01:37:37 pm »
OK try this, your corn might need to be centered x-75/2, y-75/2 and a smaller more forgiving width=radius for spinning plus a little less corn please! ;-))
Code: QB64: [Select]
  1.  
  2.  
  3. Screen _NewImage(640, 640, 32)
  4.  
  5. board& = _LoadImage("background.png", 32)
  6. jack& = _LoadImage("pumpkin.png")
  7. witch& = _LoadImage("witch.png"): witchx = -300: witchy = 100 + (Rnd * 300)
  8. grass& = _LoadImage("grass.png")
  9. candy& = _LoadImage("candy.png")
  10.  
  11. jackys = 7 ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 11 * 75 is about the whole height
  12. Dim Shared jackysx(jackys), jackysy(jackys), jackysr(jackys)
  13.  
  14. raise& = _SndOpen("sfx_roll.ogg")
  15.  
  16. '======
  17. restart:
  18. '======
  19.  
  20. witchflyx = 20
  21. witchflyy = 300
  22. grassx = 0
  23.  
  24. candycount = 0
  25.  
  26. For j = 1 To jackys
  27.     jackysx(j) = _Width + (Rnd * _Width) * 2
  28.     jackysy(j) = 40 + (Rnd * (_Height - 100))
  29.     jackysr(j) = Rnd * 360
  30.  
  31.  
  32.  
  33.     Cls , _RGB(99, 49, 0)
  34.  
  35.     PPRINT 300, 10, 16, _RGB(255, 255, 255), 255, Str$(candycount)
  36.  
  37.     _PutImage (grassx, 0), grass&
  38.     _PutImage (grassx + 640, 0), grass&
  39.  
  40.     'draw candies
  41.     For j = 1 To jackys
  42.         '_PUTIMAGE (jackysx(j), jackysy(j)), candy&
  43.         RotoZoom3 jackysx(j), jackysy(j), candy&, 1, 1, _D2R(jackysr(j))
  44.         jackysr(j) = jackysr(j) + 3
  45.         If jackysr(j) > 360 Then jackysr(j) = 1
  46.     Next
  47.  
  48.     'if pressed space
  49.     If Inp(&H60) = 57 Then
  50.  
  51.         If Not _SndPlaying(raise&) Then _SndPlay raise&
  52.  
  53.         witchflyy = witchflyy - 2
  54.         witchflyx = witchflyx + 1
  55.     Else
  56.         _SndStop raise&
  57.         witchflyy = witchflyy + 1
  58.         witchflyx = witchflyx - .5
  59.     End If
  60.  
  61.     'keep witch in bounds
  62.     If witchflyx < 5 Then witchflyx = 5
  63.     If witchflyx > _Width - 75 Then witchflyx = _Width - 75
  64.     If witchflyy < 40 Then witchflyy = 40
  65.     If witchflyy > 500 Then witchflyy = 500
  66.  
  67.     _Limit 150
  68.  
  69.     _PutImage (witchflyx, witchflyy), witch&
  70.     _Display
  71.  
  72.     grassx = grassx - 1
  73.     If grassx <= -640 Then grassx = 0
  74.  
  75.  
  76.     '========================= collision dectection here ===========
  77.  
  78.     'see if witch hit a candy
  79.     For j = 1 To jackys
  80.  
  81.         wx1 = witchflyx: wy1 = witchflyy
  82.         wx2 = wx1 + 75: wy2 = wy1 + 75
  83.         jx1 = jackysx(j): jy1 = jackysy(j)
  84.         jx2 = jx1 + 75: jy2 = jy1 + 75
  85.  
  86.  
  87.         'hit = 0
  88.         'If wx2 >= jx1 Then
  89.         '    If wx1 <= jx2 Then
  90.         '        If wy2 >= jy1 Then
  91.         '            If wy1 <= jy2 Then hit = 1
  92.         '        End If
  93.         '    End If
  94.         'End If
  95.         hit = collision%(wx1, wy1, 50, 50, jackysx(j) - 37, jackysy(j) - 37, 60, 60)
  96.  
  97.         If hit Then
  98.  
  99.             _SndPlayFile "sfx_dropdown.mp3"
  100.  
  101.             Cls , _RGB(99, 49, 0)
  102.             PPRINT 300, 10, 16, _RGB(255, 255, 255), 255, Str$(candycount)
  103.             _PutImage (grassx, 0), grass&
  104.             _PutImage (grassx + 640, 0), grass&
  105.  
  106.             'draw jacks
  107.             For j2 = 1 To jackys
  108.                 ' _PUTIMAGE (jackysx(j), jackysy(j)), candy&
  109.                 RotoZoom3 jackysx(j2), jackysy(j2), candy&, 1, 1, _D2R(jackysr(j2))
  110.             Next
  111.  
  112.             tmp& = _CopyImage(_Display)
  113.             'spin witch out here
  114.             r = 1
  115.             For dy = witchflyy + 35 To _Height Step 3
  116.                 _PutImage (0, 0), tmp&
  117.                 RotoZoom3 witchflyx + 75, dy, witch&, 1, 1, _D2R(r)
  118.                 r = r + 5: If r > 360 Then r = 1
  119.                 _Limit 150
  120.                 _Display
  121.             Next
  122.             _FreeImage tmp&
  123.  
  124.             Exit Do
  125.  
  126.         End If
  127.  
  128.     Next
  129.  
  130.  
  131.     'move candies, compute
  132.     For j = 1 To jackys
  133.  
  134.         jackysx(j) = jackysx(j) - 2
  135.         If jackysx(j) < -75 Then
  136.  
  137.             candycount = candycount + 1
  138.  
  139.             'If won...
  140.             If candycount > 75 Then
  141.                 _SndPlayFile "sfx_clap.ogg"
  142.                 _Delay 3
  143.                 End
  144.             End If
  145.  
  146.             jackysx(j) = _Width + (Rnd * _Width) * 2
  147.             jackysy(j) = 40 + (Rnd * (_Height - 100))
  148.         End If
  149.     Next
  150.  
  151.  
  152. GoTo restart
  153.  
  154.  
  155.  
  156. Sub PPRINT (x, y, size, clr&, trans&, text$)
  157.     'This sub outputs to the current _DEST set
  158.     'It makes trans& the transparent color
  159.  
  160.     'x/y is where to print text
  161.     'size is the font size to use
  162.     'clr& is the color of your text
  163.     'trans& is the background transparent color
  164.     'text$ is the string to print
  165.  
  166.     '=== get users current write screen
  167.     orig& = _Dest
  168.  
  169.     '=== if you are using an 8 or 32 bit screen
  170.     bit = 32: If _PixelSize(0) = 1 Then bit = 256
  171.  
  172.     '=== step through your text
  173.     For t = 0 To Len(text$) - 1
  174.         '=== make a temp screen to use
  175.         pprintimg& = _NewImage(16, 16, bit)
  176.         _Dest pprintimg&
  177.         '=== set colors and print text
  178.         Cls , trans&: Color clr&
  179.         Print Mid$(text$, t + 1, 1);
  180.         '== make background color the transprent one
  181.         _ClearColor _RGB(0, 0, 0), pprintimg&
  182.         '=== go back to original screen  to output
  183.         _Dest orig&
  184.         '=== set it and forget it
  185.         x1 = x + (t * size): x2 = x1 + size
  186.         y1 = y: y2 = y + size
  187.         _PutImage (x1 - (size / 2), y1)-(x2, y2 + (size / 3)), pprintimg&
  188.         _FreeImage pprintimg&
  189.     Next
  190.  
  191. ' Description:
  192. ' Started from a mod of Galleon's in Wiki that both scales and rotates an image.
  193. ' This version scales the x-axis and y-axis independently allowing rotations of image just by changing X or Y Scales
  194. ' making this tightly coded routine a very powerful and versatile image tool.
  195.  
  196.  
  197. Sub RotoZoom3 (X As Long, Y As Long, Image As Long, xScale As Single, yScale As Single, radianRotation As Single)
  198.     ' This assumes you have set your drawing location with _DEST or default to screen.
  199.     ' X, Y - is where you want to put the middle of the image
  200.     ' Image - is the handle assigned with _LOADIMAGE
  201.     ' xScale, yScale - are shrinkage < 1 or magnification > 1 on the given axis, 1 just uses image size.
  202.     ' These are multipliers so .5 will create image .5 size on given axis and 2 for twice image size.
  203.     ' radianRotation is the Angle in Radian units to rotate the image
  204.     ' note: Radian units for rotation because it matches angle units of other Basic Trig functions
  205.     '       and saves a little time converting from degree.
  206.     '       Use the _D2R() function if you prefer to work in degree units for angles.
  207.  
  208.     Dim px(3) As Single: Dim py(3) As Single ' simple arrays for x, y to hold the 4 corners of image
  209.     Dim W&, H&, sinr!, cosr!, i&, x2&, y2& '   variables for image manipulation
  210.     W& = _Width(Image&): H& = _Height(Image&)
  211.     px(0) = -W& / 2: py(0) = -H& / 2 'left top corner
  212.     px(1) = -W& / 2: py(1) = H& / 2 ' left bottom corner
  213.     px(2) = W& / 2: py(2) = H& / 2 '  right bottom
  214.     px(3) = W& / 2: py(3) = -H& / 2 ' right top
  215.     sinr! = Sin(-radianRotation): cosr! = Cos(-radianRotation) ' rotation helpers
  216.     For i& = 0 To 3 ' calc new point locations with rotation and zoom
  217.         x2& = xScale * (px(i&) * cosr! + sinr! * py(i&)) + X: y2& = yScale * (py(i&) * cosr! - px(i&) * sinr!) + Y
  218.         px(i&) = x2&: py(i&) = y2&
  219.     Next
  220.     _MapTriangle _Seamless(0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image To(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  221.     _MapTriangle _Seamless(0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image To(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  222.  
  223.  
  224. Function collision% (b1x, b1y, b1w, b1h, b2x, b2y, b2w, b2h)
  225.     ' x, y represent the box left most x and top most y
  226.     ' w, h represent the box width and height which is the usual way sprites / tiles / images are described
  227.     ' such that boxbottom = by + bh
  228.     '        and boxright = bx + bw
  229.     'so the specific gosub above is generalized to a function procedure here!
  230.     If (b1y + b1h < b2y) Or (b1y > b2y + b2h) Or (b1x > b2x + b2w) Or (b1x + b1w < b2x) Then
  231.         collision% = 0
  232.     Else
  233.         collision% = -1 ' Collsion is true
  234.     End If
  235.  
  236.  
  237.  
  238.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: JackStack - Halloween puzzle game
« Reply #27 on: October 12, 2021, 01:43:34 pm »
PS the witch almost has a chance now! but might need to control new corn so that there is actually some open space to fly to and through.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: JackStack - Halloween puzzle game
« Reply #28 on: October 12, 2021, 01:44:25 pm »
PPS Nice adaption from flappy!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: JackStack - Halloween puzzle game
« Reply #29 on: October 12, 2021, 01:52:24 pm »
That's great, @bplus!   Nice collision function.  I've seen that before posted somewhere here, had forgotten about it.   Cool.  Thanks for the help!

- Dav