Help with a "connect the dots" mini game?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
darxori
Newbie
Posts: 6
Joined: Tue Sep 17, 2019 8:21 pm
Projects: The Ride To Ruin
Deviantart: darxori
Soundcloud: darxori
Contact:

Help with a "connect the dots" mini game?

#1 Post by darxori » Mon Dec 09, 2019 12:00 am

Hey there everyone!

I wanted to try and create some kind of "connect the dots" minigame in my VN but I have no idea what I should be trying to do to make it happen.

The game must be able to register if the user hit all the correct points

Something like if the user can connect point A to point B successfully (with perhaps multiple points in succession) then the user gets the green light etc.

My first idea was to look into some kind of drawing function like in this discussion:
viewtopic.php?t=51370

someone managed to figure out how to create straight lines, but i don't know how i'd be able to validate the points

but perhaps there's a simpler way to have a connect the dots game besides having some kind of drawing function... maybe using buttons or something


Any ideas would be appreciated, thanks!
~Hey, at least I tried.

CURRENT PROJECT:
THE RIDE TO RUIN
more info to come soon
Image

User avatar
Per K Grok
Miko-Class Veteran
Posts: 673
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1
Projects: Defenders of Adacan Part 2
itch: per-k-grok
Location: Sverige
Contact:

Re: Help with a "connect the dots" mini game?

#2 Post by Per K Grok » Mon Dec 09, 2019 2:03 pm

darxori wrote:
Mon Dec 09, 2019 12:00 am
Hey there everyone!

I wanted to try and create some kind of "connect the dots" minigame in my VN but I have no idea what I should be trying to do to make it happen.

The game must be able to register if the user hit all the correct points

Something like if the user can connect point A to point B successfully (with perhaps multiple points in succession) then the user gets the green light etc.

My first idea was to look into some kind of drawing function like in this discussion:
viewtopic.php?t=51370

someone managed to figure out how to create straight lines, but i don't know how i'd be able to validate the points

but perhaps there's a simpler way to have a connect the dots game besides having some kind of drawing function... maybe using buttons or something


Any ideas would be appreciated, thanks!

I did make a minigame like that for my game Defenders of Adacan - part 1 the Ascent. https://per-k-grok.itch.io/defenders-of-adacan

Here is a test of the game built with pygame



later adopted to run in ren'py.

I have a class to draw the lines. I have imported pygame to use pygame.draw.line

Code: Select all

init python:
    class LineDisplay(renpy.Displayable):
        def __init__(self, *args, **kwargs):
            super(LineDisplay, self).__init__(*args, **kwargs)

        def render(self, width, height, st, at):
            screen = renpy.Render(640, 480)
            can=im.load_surface("images/blankcanvas.png")
            
            x= len(list_lines)
            y=0
            while y<x:
                pygame.draw.line(can,(0,0,255),list_lines[y][0], list_lines[y][1], 3)
                y += 1

  
            screen.blit(can,(0,0))
            renpy.redraw(self, 0)
            return screen

I have a list with the points that are clickable.

I have a function to check if a click is sufficiently close to one of the clickable points. Requires import math and disable Side Rollback(if any clicks could be in rollback area.)

Code: Select all

    def inCircle(pointX, pointY,gX,gY,distance):
        xDist = pointX-gX
        xDist=math.fabs(xDist)
        yDist = pointY-gY
        yDist=math.fabs(yDist)
        xyDist = (xDist*xDist)+(yDist*yDist)
        if distance >= math.sqrt(xyDist):
            return True
        else:
            return False
You could use buttons instead (or hotspots).

The first click close enough to a clickable point will store the value of that point in the variable startPoint. i.e startpoint= (210, 120)

The second click will store the value in the variable secondPoint.

startPoint and secondPoint will be stored in the variable twoPoints that is appended to the list, list_lines.

LineDisplay will draw the lines in that list.

When twoPoints are appended to list_lines secondPoint becomes the new startPoint and the next click will give us a new secondPoint.

Post Reply

Who is online

Users browsing this forum: No registered users