Simple minigames (Screen Language only).

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Message
Author
User avatar
Alex
Eileen-Class Veteran
Posts: 1935
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Simple minigames (Screen Language only).

#1 Post by Alex » Sun Nov 11, 2012 6:50 am

Here they are - some rather simple minigames that were made using only standard SL functionality. No programming skills are required, just your imagination and nice graphics...))

Numbers.
Player must click some buttons in predefined order before time gone.

Memoria.
Player must turn cards to find pairs (or triplets, quadruplets).

Find the differences.
Player must find differences between two similar looking images.

Fifteen game.
Classic fifteen game or kind of puzzle if an image is used (the amount of tiles can be customized).

Simple battle game.
Group battle game.
Two RPG-style battle games that are not so fancy and code-wise, but I hope will help people to understand the basics.

Race game.
Yet another simple game where player ought to press buttons to win.

Tower of Hanoi.
Yet another implementation of classic game (with moves counter and autosolver)
(inspired by - http://lemmasoft.renai.us/forums/viewto ... 53#p399420)

To run these games you need to copy/paste the code (in script.rpy or in separate rpy-file), then you can add a mainmenu button to run it

Code: Select all

textbutton "MiniGame" action Start ("numbers_game") # name of mini-game label
or call the game label to play it midgame

Code: Select all

    menu:
        "Numbers":
            call numbers_game
        "Memoria":
            call memoria_game
        "Find the differences":
            call differences_game
        "Fifteen game":
            call fifteen_game
        "Simple battle game":
            call battle_game_1
        "Group battle game":
            call battle_game_2
        "Race game":
            call race_game
        "Tower of Hanoi":
            hanoi_game(blocks_number=8) # pass the desireble number of blocks
Last edited by Alex on Sat Feb 27, 2016 4:56 pm, edited 6 times in total.

User avatar
Alex
Eileen-Class Veteran
Posts: 1935
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Simple minigames (Screen Language only).

#2 Post by Alex » Sun Nov 11, 2012 6:52 am

Numbers.

Code: Select all

transform roto_transform (roto_var):
    # ATL transform that will rotate our displayables to "roto_var" degrees
    rotate roto_var
    rotate_pad False

##### The game screen
screen numbers_scr:
    
    # It is better to operate this game with mouse only, so just disable cursor and enter keys
    key "K_LEFT" action Hide("nonexistent_screen")
    key "K_RIGHT" action Hide("nonexistent_screen")
    key "K_UP" action Hide("nonexistent_screen")
    key "K_DOWN" action Hide("nonexistent_screen")
    key "K_RETURN" action Hide("nonexistent_screen")
    key "K_KP_ENTER" action Hide("nonexistent_screen")
    
    ##### Timer
    #
    # It returns "smth" every second and "win" (if all buttons were clicked) or "lose" (if time was up)
    timer 1 action [Return("smth"), If( game_timer>1, If( numbers_buttons[-1]["b_to_show"] == False, Return("win"), SetVariable("game_timer", game_timer-1) ), Return("lose") ) ] repeat True
    text "[game_timer]" size 25 xpos 10 ypos 10

    
    for each_b in sorted(numbers_buttons, reverse=True):
        if each_b["b_to_show"]:
            $ text_var = each_b["b_value"]
            $ i = each_b["b_number"] - 1
            button:
                
                # Will show image if "b_value" was set as file name or displayable.
                #background None
                #add each_b["b_value"]
                # Also it is neccessary to comment out the next  4 lines.
                
                #background "image.png"          # Sets button's appearance
                text '[text_var]{size=18}.{/size}' size 30 align (0.5, 0.55) color "#000"
                xminimum 100 xmaximum 100
                yminimum 100 ymaximum 100
                xpos each_b["b_x_pos"]
                ypos each_b["b_y_pos"]
                anchor (0.5, 0.5)
                action If (i == -1, SetDict(numbers_buttons[each_b["b_number"] ], "b_to_show", False),
                    If (numbers_buttons[i]["b_to_show"] == False,
                        SetDict(numbers_buttons[each_b["b_number"] ], "b_to_show", False),
                        SetVariable("game_timer", game_timer-1) )  )          # Wrong click reduces the time left by 1 second
                at roto_transform (renpy.random.randint (0, 10)*36)
                
    
    # It might be usefull to show the order of buttons to click if it's not obvious.
    side "c b":
        area (150, 05, 640, 70)         # The size of hint's area
        
        viewport id "vp":
            draggable True
            
            hbox:
                xalign 1.0
                
                # The same buttons declaration, but they will be scaled down
                for each_b in numbers_buttons:
                    $ text_var = each_b["b_value"]
                    button:
                                        
                        # Will show image if "b_value" was set as file name or displayable.
                        #background None
                        #add each_b["b_value"]
                        # Also it is neccessary to comment out the next  4 lines.
                
                        #background "image.png"          # Sets button's appearance
                        text '[text_var]{size=18}.{/size}' size 30 align (0.5, 0.55) color "#000"
                        xminimum 100 xmaximum 100
                        yminimum 100 ymaximum 100
                        action If (each_b["b_to_show"], Hide("nonexistent_screen"), None)
                        at Transform(zoom=0.5)           # Size
        
        bar value XScrollValue("vp")
        

init:
    ##### Images
    image img1 = "img1.png"
    image img2 = "img2.png"

label numbers_game:
    
    #####
    #
    # At first, let's set the values for buttons
    $ numbers_buttons = []
    $ buttons_values = []
    
    # This might be numbers,
    python:
        for i in range (1, renpy.random.randint (10, 15) ):
            buttons_values.append (str(i) )
    
    # or letters,
    #$ buttons_values = [u"а", u"б", u"в", u"г", u"д", u"е", u"ё", u"ж", u"з", u"и", u"й", u"к", u"л", u"м", u"н", u"о", u"п", u"р", u"с", u"т", u"у", u"ф", u"х", u"ц", u"ч", u"ш", u"щ", u"ъ", u"ы", u"ь", u"э", u"ю", u"я" ]

    # or images,
    #$ buttons_values = ["img1", "img2", "my_img.png"]

    # This will make the description for all buttons (numbers, values and positions)
    python:
        for i in range (0, len(buttons_values) ):
            numbers_buttons.append ( {"b_number":i, "b_value":buttons_values[i], "b_x_pos":(renpy.random.randint (10, 70))*10, "b_y_pos":(renpy.random.randint (15, 50))*10, "b_to_show":True} )
    
    "To win the game - click all the buttons one after another (start from \"1\")."
    
    # Before start the game, let's set the timer
    $ game_timer = 20
    
    # Shows the game screen
    show screen numbers_scr
    
    # The loop will exist untill game screen returns win or lose
    label loop:
        $ result = ui.interact()
        $ game_timer = game_timer
        if result == "smth":
            jump loop

    if result == "lose":
        hide screen numbers_scr
        $ renpy.pause (0.1, hard = True)
        $ renpy.pause (0.1, hard = True)
        $ renpy.pause (0.1, hard = True)
        $ renpy.pause (0.1, hard = True)
        "You lose! Try again."
        jump numbers_game
        
    if result == "win":
        hide screen numbers_scr
        $ renpy.pause (0.1, hard = True)
        $ renpy.pause (0.1, hard = True)
        $ renpy.pause (0.1, hard = True)
        $ renpy.pause (0.1, hard = True)
        "You win!"
        return
Attachments
image.png
image.png (15.36 KiB) Viewed 21418 times
Last edited by Alex on Sat Jan 12, 2013 10:23 am, edited 3 times in total.

User avatar
Alex
Eileen-Class Veteran
Posts: 1935
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Simple minigames (Screen Language only).

#3 Post by Alex » Sun Nov 11, 2012 6:53 am

Memoria.

Code: Select all

##### The game screen
screen memo_scr:    
    
    ##### Timer
    timer 1.0 action If (memo_timer > 1, SetVariable("memo_timer", memo_timer - 1), Jump("memo_game_lose") ) repeat True
    
    text str(memo_timer) xalign 0.5 yalign 0.05
    
    
    ##### Cards
    #
    # To use images, just comment out lines that show text and uncomment lines that show images
    grid 3 4:
        for card in cards_list:
            button:
                background None

                if card["c_chosen"]:        # shows the face of the card
                    text card["c_value"]    # will show text
                    #add card["c_value"]    # will show image

                else:                       # shows the back of the card
                    text "X"                # will show text
                    #add "C"                # will show image

                action If ( (card["c_chosen"] or not can_click), None, [SetDict(cards_list[card["c_number"]], "c_chosen", True), Return(card["c_number"]) ] )
 

    

init:
    python:
        def cards_shuffle(x):
            renpy.random.shuffle(x)
            return x

    ##### Images
    image A = "img_1.png"         # different card images
    image B = "img_2.png"
    image C = "back.png"          # back of the card

    

    
label memoria_game:
    
    #####
    #
    # At first, let's set the cards to play (the amount should match the grid size - in this example 12)
    $ values_list = ["A", "A", "A", "A", "A", "A", "B",  "B", "B", "B", "B", "B"]
    
    # Then - shuffle them
    $ values_list = cards_shuffle(values_list)
    
    # And make the cards_list that describes all the cards
    $ cards_list = []
    python:
        for i in range (0, len(values_list) ):
            cards_list.append ( {"c_number":i, "c_value": values_list[i], "c_chosen":False} )   

    # Before start the game, let's set the timer
    $ memo_timer = 50.0
    
    # Shows the game screen
    show screen memo_scr
    
    # The game loop
    label memo_game_loop:
        $ can_click = True
        $ turned_cards_numbers = []
        $ turned_cards_values = []
        
        # Let's set the amount of cards that should be opened each turn (all of them should match to win)
        $ turns_left = 3
        
        label turns_loop:
            if turns_left > 0:
                $ result = ui.interact()
                $ memo_timer = memo_timer
                $ turned_cards_numbers.append (cards_list[result]["c_number"])
                $ turned_cards_values.append (cards_list[result]["c_value"])
                $ turns_left -= 1
                jump turns_loop
        
        # To prevent further clicking befor chosen cards will be processed
        $ can_click = False
        # If not all the opened cards are matched, will turn them face down after pause
        if turned_cards_values.count(turned_cards_values[0]) != len(turned_cards_values):
            $ renpy.pause (1.0, hard = True)
            python:
                for i in range (0, len(turned_cards_numbers) ):
                    cards_list[turned_cards_numbers[i]]["c_chosen"] = False
        
        # If cards are matched, will check if player has opened all the cards
        else:
            $ renpy.pause (1.0, hard = True)
            python: 
                
                # Let's remove opened cards from game field
                # But if you prefere to let them stay - just comment out next 2 lines
                for i in range (0, len(turned_cards_numbers) ):
                    cards_list[turned_cards_numbers[i]]["c_value"] = Null()
                    
                    
                for j in cards_list:
                    if j["c_chosen"] == False:
                        renpy.jump ("memo_game_loop")
                renpy.jump ("memo_game_win")
                
                

        jump memo_game_loop

label memo_game_lose:
    hide screen memo_scr
    $ renpy.pause (0.1, hard = True)
    $ renpy.pause (0.1, hard = True)
    "You lose! Try again."
    jump memoria_game

label memo_game_win:
    hide screen memo_scr
    $ renpy.pause (0.1, hard = True)
    $ renpy.pause (0.1, hard = True)
    "You win!"
    return

User avatar
Alex
Eileen-Class Veteran
Posts: 1935
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Simple minigames (Screen Language only).

#4 Post by Alex » Sun Nov 11, 2012 6:59 am

Find the differences.

Code: Select all

screen differences_scr:
    
    ##### Timer
    timer 1.0 action [Return("smth_2"), If (diff_timer > 1, SetVariable("diff_timer", diff_timer - 1), Jump("diff_game_lose") ) ] repeat True
    
    text str(diff_timer) xalign 0.5 yalign 0.05
    
    ##### Two screens with practically identical images
    use left_scr(x=pic_name)
    use right_scr(x=pic_name)

    
screen left_scr:
    
    # Screen at left has all differences
    fixed:
        xpos 50 ypos 100
        button:
            background None
            $ base_pic = ("base_image_%s.png" % x)
            add base_pic
            action SetVariable ("diff_timer", diff_timer -1)
            mouse "left"
        
        for spot in differences_list:
            $ pic_1 = ("spot_%d_1_%s.png" % (spot["s_number"], x) )          # changed spot 
            $ pic_2 = ("spot_%d_0_%s.png" % (spot["s_number"], x ))          # normal spot
            $ pic_3 = ("spot_%d_done_%s.png" % (spot["s_number"], x) )       # done mark
            
            if spot["is_difference"]:
                button:
                    background None
                    add pic_1 
                    action [SetDict(differences_list[spot["s_number"]], "is_solved", True), Return("smth") ]
                    focus_mask True
                    mouse "left"
                
            else:
                button:
                    background None
                    add pic_2 
                    action None
                    focus_mask True
                    mouse "left"
                    
            if spot["is_solved"]:
                button:
                    background None
                    add pic_3 
                    action None
                    focus_mask True
                    mouse "left"
            



screen right_scr:
    
    # Screen at right has all the normal spots
    fixed:
        xpos 300 ypos 100
        button:
            background None
            $ base_pic = ("base_image_%s.png" % x)
            add base_pic
            action SetVariable ("diff_timer", diff_timer -1)
            mouse "right"
        
        for spot in differences_list:
            $ pic_1 = ("spot_%d_0_%s.png" % (spot["s_number"], x) )          # normal spot
            $ pic_2 = ("spot_%d_0_%s.png" % (spot["s_number"], x) )          # normal spot
            $ pic_3 = ("spot_%d_done_%s.png" % (spot["s_number"], x) )       # done mark
            
            if spot["is_difference"]:
                button:
                    background None
                    add pic_1 
                    action [SetDict(differences_list[spot["s_number"]], "is_solved", True), Return("smth") ]
                    focus_mask True
                    mouse "right"
                
            else:
                button:
                    background None
                    add pic_2 
                    action None
                    focus_mask True
                    mouse "right"
                    
            if spot["is_solved"]:
                button:
                    background None
                    add pic_3 
                    action None
                    focus_mask True
                    mouse "right"


init:
    
    # Should set the mouse cursor, 'cause we'll need the left and right ones
    # Those cursors have two arrows and the distance between them is (picture width + gap between left and right screen)
    # So in this example the left one has active point at (0, 0) and right - at (250, 0)
    $ config.mouse = {"default": [("cur.png", 0, 0)], "left": [("left_cur.png", 0, 0)], "right": [("right_cur.png", 250, 0)]}

    python:
        def spots_shuffle(x):
            renpy.random.shuffle(x)
            return x

label differences_game:
    
    #####
    #
    # At first, let's set the number of possible differences and how many of them the player should find 
    $ differences_list = [] 
    $ differnces_total_number = 3
    $ differnces_number = 2
    $ values_l = []
    
    # And make the differences_list that describes all the spots
    python:
        for i in range (0, differnces_number):
            values_l.append (True)
        for i in range (0, (differnces_total_number - differnces_number) ):
            values_l.append (False)
        
        values_l = spots_shuffle(values_l)
        
        for i in range (0, differnces_total_number):
            differences_list.append({"s_number":i, "is_difference":values_l[i], "is_solved":False} )
    
            
    
    # Before start the game, let's set the timer
    $ diff_timer = 20
    
    # Shows the game screen with the named image.
    # Images must be named as
    # "base_image_[different names for each image].png" - image itself
    # "spot_0_0_[different names for each image].png" - first spot of an image in normal state _0_0_
    # "spot_2_1_[different names for each image].png" - third spot of an image in different state _2_1_
    # "spot_3_done)_[different names for each image].png" - done mark for fourth spot of an image _3_done_

    # There is only one image in this example, so just put it twice to show how it should work
    $ chosen_pic = renpy.random.choice( ("car", "car") )

    show screen differences_scr(pic_name=chosen_pic)
    

    # The game loop
    label diff_loop:
       $ result = ui.interact()
       $ diff_timer = diff_timer
       python:
           for i in range (0, len(differences_list)-1 ):
               one_of_spots = differences_list[i]
               # Loop will exist till at least one of differences doesn't found
               if one_of_spots["is_difference"] and not one_of_spots["is_solved"]:
                   renpy.jump("diff_loop")
                   
       jump diff_game_win
        
label diff_game_lose:
    hide screen differences_scr
    $ renpy.pause (0.1, hard = True)
    $ renpy.pause (0.1, hard = True)
    "You lose! Try again."
    jump differences_game

label diff_game_win:
    $ renpy.pause (1.0, hard = True)
    hide screen differences_scr
    $ renpy.pause (0.1, hard = True)
    $ renpy.pause (0.1, hard = True)
    "You win!"
    return
base_image_car.png
base_image_car.png (22.8 KiB) Viewed 21426 times
spot_0_0_car.png
spot_0_0_car.png (3.26 KiB) Viewed 21426 times
spot_0_1_car.png
spot_0_1_car.png (558 Bytes) Viewed 21426 times
spot_0_done_car.png
spot_0_done_car.png (2.21 KiB) Viewed 21426 times
spot_1_0_car.png
spot_1_0_car.png (4.71 KiB) Viewed 21426 times
spot_1_1_car.png
spot_1_1_car.png (3.19 KiB) Viewed 21426 times
spot_1_done_car.png
spot_1_done_car.png (2.76 KiB) Viewed 21426 times
spot_2_0_car.png
spot_2_0_car.png (4.74 KiB) Viewed 21426 times
spot_2_1_car.png
spot_2_1_car.png (3.2 KiB) Viewed 21426 times
spot_2_done_car.png
spot_2_done_car.png (2.96 KiB) Viewed 21426 times
cur.png
cur.png (4.57 KiB) Viewed 21426 times
left_cur.png
left_cur.png (6.94 KiB) Viewed 21426 times
right_cur.png
right_cur.png (6.77 KiB) Viewed 21426 times

User avatar
Alex
Eileen-Class Veteran
Posts: 1935
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Simple minigames (Screen Language only).

#5 Post by Alex » Fri Jan 04, 2013 7:20 pm

Fifteen game.

Code: Select all

##### The game screen.
screen fifteen_scr:
    
    ##### Timer.
    if timer_on:
        timer 1.0 action If(fifteen_timer > 0, [SetVariable("fifteen_timer", fifteen_timer-1), Return("smth")], Return("time_is_up") ) repeat True
        text str(fifteen_timer) xalign 0.1 yalign 0.1
    
    ##### Game field.
    frame:
        xalign 0.5 yalign 0.5
        background Solid("#ccc") #Frame("pic_1.png", 5, 5) # The background might be set as a solid color or a frame, that uses predefined displayable or file name, also you can delete this line to have default frame background.
        
        grid grid_width grid_height spacing 0:
            for every_tile in tiles_list:
                if every_tile["tile_value"] == empty_tile_value and not fifteen_is_solved:
                    null

                else:
                    button:
                        #####
                        #
                        # To use just numbers (classic fifteen game) - uncomment next 4 lines and comment out lines that are used to show an image.
                        # It is neccessary to set the size of buttons.
                        # (The background might be set as a solid color or a frame, that uses predefined displayable or file name, also you can delete this line to have default button background.)
                        #xminimum 70 xmaximum 70
                        #yminimum 70 ymaximum 70
                        #background Solid("#c00")
                        #text str(every_tile["tile_value"]) xalign 0.5 yalign 0.5
                        #
                        #####
                        

                        #####
                        #
                        # Next lines are used to show an image.
                        left_padding 0 right_padding 0 top_padding 0 bottom_padding 0
                        left_margin 0 right_margin 0 top_margin 0 bottom_margin 0
                        add LiveCrop( ( (every_tile["tile_value"]-1)%grid_width*tile_width,
                                        (every_tile["tile_value"]-1)//grid_width*tile_height,
                                        tile_width,
                                        tile_height),
                                        chosen_img)
                        #
                        #####
                            
                        
                        action [ If (every_tile["tile_number"] not in top_row,
                                   true = If (tiles_list[every_tile["tile_number"]-grid_width]["tile_value"] == empty_tile_value,
                                     true = [SetDict( tiles_list[every_tile["tile_number"]-grid_width], "tile_value", every_tile["tile_value"] ), SetDict( tiles_list[every_tile["tile_number"]], "tile_value", empty_tile_value ) ],
                                     false = None),
                                   false = None),
                                 If (every_tile["tile_number"] not in bottom_row,
                                   true = If (tiles_list[min(len(tiles_list)-1, every_tile["tile_number"]+grid_width)]["tile_value"] == empty_tile_value,
                                     true = [SetDict( tiles_list[min(len(tiles_list)-1, (every_tile["tile_number"]+grid_width))], "tile_value", every_tile["tile_value"] ), SetDict( tiles_list[every_tile["tile_number"]], "tile_value", empty_tile_value ) ],
                                     false = None),
                                   false = None),
                                 If (every_tile["tile_number"] not in left_column,
                                   true = If (tiles_list[every_tile["tile_number"]-1]["tile_value"] == empty_tile_value,
                                     true = [SetDict( tiles_list[every_tile["tile_number"]-1], "tile_value", every_tile["tile_value"] ), SetDict( tiles_list[every_tile["tile_number"]], "tile_value", empty_tile_value ) ],
                                     false = None),
                                   false = None),
                                 If (every_tile["tile_number"] not in right_column,
                                   true = If (tiles_list[min(len(tiles_list)-1, (every_tile["tile_number"]+1))]["tile_value"] == empty_tile_value,
                                     true = [SetDict( tiles_list[min(len(tiles_list)-1, (every_tile["tile_number"]+1))], "tile_value", every_tile["tile_value"] ), SetDict( tiles_list[every_tile["tile_number"]], "tile_value", empty_tile_value ) ],
                                     false = None),
                                   false = None), Return("smth")
                               ]

    ##### A button that will let player quit the game (especially useful if there will be no timer to finish the game).
    textbutton "Quit" action Jump("quit_fifteen_game") xalign 0.9 yalign 0.1
    
    ##### A button that will show the whole image, should be used only if game uses images (not numbers).
    textbutton "Show/hide image" action If( renpy.get_screen("full_image"), Hide("full_image"), Show("full_image") ) xalign 0.5 yalign 0.1


##### Screen that contains an image to show (not useful in classic fifteen game).
#
screen full_image:
    add chosen_img xalign 0.5 yalign 0.5 at pic_trans


transform pic_trans:
    alpha 0.0 zoom 0.7
    on show:
        parallel:
            linear 1.0 alpha 1.0
        parallel:
            linear 0.6 zoom 1.2
            linear 0.4 zoom 1.0
    on hide:
        linear 0.5 alpha 0.0
#
#####


label fifteen_game:

    ##### Game settings.
    #
    # Let's set the size of game field in tiles, for example 9 tiles (3 x 3).
    $ grid_width = 3
    $ grid_height = 3
    
    # Next 4 lines are used to set an image to solve (could be deleted for clasic fifteen game).
    # It is recommended that all images will be smaller than screen size.
    $ chosen_img = renpy.random.choice ( ("abstract.png", "flower.png") )
    $ chosen_img_width, chosen_img_height = renpy.image_size(chosen_img)
    $ tile_width = chosen_img_width/grid_width
    $ tile_height = chosen_img_height/grid_height
    #

    # Some useful calculations:
    $ top_row = []
    python:
        for i in range(0, grid_width):
            top_row.append (i)
    $ bottom_row = []
    python:
        for i in range(0, grid_width):
            bottom_row.append ( (grid_width*(grid_height-1)+i) )
    $ left_column = []
    python:
        for i in range(0, grid_height):
            left_column.append (grid_width*i)
    $ right_column = []
    python:
        for i in range(0, grid_height):
            right_column.append (grid_width*(i+1)-1)

    
    # Let's set the game field - all the tiles are on their places.
    $ tiles_list = []
    python:
        for i in range (0, grid_height):
            for j in range (0, grid_width):
                tiles_list.append ( {"tile_number":(i*grid_width+j), "tile_value":(i*grid_width+(j+1))} )


    # Let's set a missed tile - it can be a random one or the last one (as in classic fifteen game).
    $ empty_tile_value = renpy.random.randint ( 1, grid_width*grid_height )
    #$ empty_tile_value = grid_width*grid_height
    #
    
    # Some variables:
    # will let us control if the missed tile should be shown
    $ fifteen_is_solved = False
    # sets the timer to make game more difficult
    $ fifteen_timer = 1000
    # will let us control the timer
    $ timer_on = False
    
    # This will show the game screen.
    show screen fifteen_scr
    
    # To be sure that puzzle can be solved, just randomly move some tiles.
    # This process could be shown to player - uncomment the line that sets the pause between moves.
    # The number of moves should be great enought to shuffle tiles good,
    # also it should be odd to avoid situation when random moves will bring all the tiles back on their starting positions.
    $ shuffle_moves = 21
    label tiles_shuffle:
        if shuffle_moves >0:
            python:
                possible_moves_list = []
                for j in tiles_list:
                    if j["tile_value"] == empty_tile_value:
                        if j["tile_number"] not in top_row:
                            possible_moves_list.append ("top")
                        if j["tile_number"] not in bottom_row:
                            possible_moves_list.append ("bottom")
                        if j["tile_number"] not in left_column:
                            possible_moves_list.append ("left")
                        if j["tile_number"] not in right_column:
                            possible_moves_list.append ("right")
                        move_tile = renpy.random.choice (possible_moves_list)
                        if move_tile == "top":
                            tiles_list[j["tile_number"]]["tile_value"] = tiles_list[j["tile_number"]-grid_width]["tile_value"]
                            tiles_list[j["tile_number"]-grid_width]["tile_value"] = empty_tile_value
                        elif move_tile == "bottom":
                            tiles_list[j["tile_number"]]["tile_value"] = tiles_list[j["tile_number"]+grid_width]["tile_value"]
                            tiles_list[j["tile_number"]+grid_width]["tile_value"] = empty_tile_value
                        elif move_tile == "left":
                            tiles_list[j["tile_number"]]["tile_value"] = tiles_list[j["tile_number"]-1]["tile_value"]
                            tiles_list[j["tile_number"]-1]["tile_value"] = empty_tile_value
                        elif move_tile == "right":
                            tiles_list[j["tile_number"]]["tile_value"] = tiles_list[j["tile_number"]+1]["tile_value"]
                            tiles_list[j["tile_number"]+1]["tile_value"] = empty_tile_value
                        shuffle_moves -= 1
                        #renpy.pause(0.1)           # If used pause should be not so long.
                        renpy.jump("tiles_shuffle")
                
    # Now we can start the timer.
    $ timer_on = True
    
    # The game loop.
    label fifteen_game_loop:
        $ result = ui.interact()
        $ fifteen_timer = fifteen_timer
        if result == "time_is_up":
            jump fifteen_lose
        python:
            for j in tiles_list:
                if j["tile_value"]-1 != j["tile_number"]: # will continue the game if at least one tile is not in its place
                    renpy.jump("fifteen_game_loop")
        jump fifteen_win

label fifteen_win:
    # This will turn off the timer.
    $ timer_on = False
    $ renpy.pause(0.1, hard = True)
    $ renpy.pause(0.1, hard = True)
    
    # This will show the missed tile in its place.
    $ fifteen_is_solved = True
    
    "You win!"
    hide screen fifteen_scr
    return

label fifteen_lose:
    $ timer_on = False
    $ renpy.pause(0.1, hard = True)
    $ renpy.pause(0.1, hard = True)
    "To slow... Try again."
    hide screen fifteen_scr
    jump fifteen_game

label quit_fifteen_game:
    hide screen fifteen_scr
    "Enough for now..."
    return
abstract.png
abstract.png (66 KiB) Viewed 20872 times
flower.png
flower.png (61.31 KiB) Viewed 20872 times

marigoldsofthenight
Regular
Posts: 44
Joined: Sat Aug 14, 2010 5:31 pm
Contact:

Re: Simple minigames (Screen Language only).

#6 Post by marigoldsofthenight » Thu Feb 07, 2013 10:19 pm

I have no clue how to go about incorporating these into a novel. Think you could release these as demos?

User avatar
Kitten the Cat
Regular
Posts: 60
Joined: Sun Jul 31, 2011 12:29 pm
Projects: The Onigami House [NaNo12], Beyond the Veil [NaNo14]
Organization: Riceball Games
Location: Sydney, Australia
Contact:

Re: Simple minigames (Screen Language only).

#7 Post by Kitten the Cat » Mon Mar 04, 2013 11:42 pm

Oh wow. Thank you so much for these! I love incorporating minigames in VNs :) Might use some of them in future games.
Currently working on Beyond the Veil, our NaNoRenO '14 entry.
Image

User avatar
AsHLeX
Veteran
Posts: 462
Joined: Wed Dec 25, 2013 1:09 pm
Completed: Starlight Dreamers, Mysterious Melody, Town of Memories, Marked, To Fly, The Change, Him From The Past, A Forgotten Memory
Projects: Cafe Mysteria
Location: Malaysia
Contact:

Re: Simple minigames (Screen Language only).

#8 Post by AsHLeX » Sun Feb 09, 2014 11:31 am

I have a question. For the mini-game "numbers",
When I uncomment the line

Code: Select all

# or images,
    $ buttons_values = ["img1", "img2", "my_img.png"]
and define the images

Code: Select all

image img1 = "img1.png"
image img2 = "img2.png"
all I get is words showing "img1" "img2" and "my_img.png"
Did I do something wrong? Thank you so much for reading this.
Image Image

User avatar
Alex
Eileen-Class Veteran
Posts: 1935
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Simple minigames (Screen Language only).

#9 Post by Alex » Sun Feb 09, 2014 12:30 pm

You also need to make some changes in button's code:

Code: Select all

            button:
                
                # Will show image if "b_value" was set as file name or displayable.
                background None
                add each_b["b_value"]
                # Also it is neccessary to comment out the next  4 lines.
                
                #background "image.png"          # Sets button's appearance
                #text '[text_var]{size=18}.{/size}' size 30 align (0.5, 0.55) color "#000"
                #xminimum 100 xmaximum 100
                #yminimum 100 ymaximum 100

User avatar
AsHLeX
Veteran
Posts: 462
Joined: Wed Dec 25, 2013 1:09 pm
Completed: Starlight Dreamers, Mysterious Melody, Town of Memories, Marked, To Fly, The Change, Him From The Past, A Forgotten Memory
Projects: Cafe Mysteria
Location: Malaysia
Contact:

Re: Simple minigames (Screen Language only).

#10 Post by AsHLeX » Sun Feb 23, 2014 3:35 am

Ahhh...thank. you so much! It works now >w< s orry for the very late reply >o< i was away on hiatus for awhile...
thanks again! I'll be using some of the mini-games in my upcoming game :)
Image Image

User avatar
AsHLeX
Veteran
Posts: 462
Joined: Wed Dec 25, 2013 1:09 pm
Completed: Starlight Dreamers, Mysterious Melody, Town of Memories, Marked, To Fly, The Change, Him From The Past, A Forgotten Memory
Projects: Cafe Mysteria
Location: Malaysia
Contact:

Re: Simple minigames (Screen Language only).

#11 Post by AsHLeX » Sat Mar 01, 2014 4:57 am

Ahh I'm so sorry but I came up with some weird glitch.
When I click on the card (the one marked with a white X), all the cards just disappeared and only one card was showing. I tried it a few times and got similar results with the cards just disappearing off the screen for no reason. I think i might have messed up your code but i'm not too sure where I went wrong because before I copied the game into a new folder it seemed to be working perfectly fine but now if has some weird errors.
Code I used:

Code: Select all

#memoria game help
screen scarlettmemory:
    key "dismiss" action [[]]
    frame:
        xalign 0.5 yalign 0.5
        vbox:
            text "{b}Memory Game" at centre
            text "Match all the cards in the time limit given."
            text "Careful, once you start, there's no going back!"
            textbutton "START" action Hide("scarlettmemory") at centre
            null height 20
            
##### The game screen
screen memo_scr:   
   
    ##### Timer
    timer 1.0 action If (memo_timer > 1, SetVariable("memo_timer", memo_timer - 1), Jump("memo_game_lose") ) repeat True
   
    text str(memo_timer) xalign 0.95 yalign 0.05
   
   
    ##### Cards
    #
    # To use images, just comment out lines that show text and uncomment lines that show images
    grid 8 6:
        for card in cards_list:
            button:
                background None

                if card["c_chosen"]:        # shows the face of the card
                    #text card["c_value"]    # will show text
                    add card["c_value"]    # will show image

                else:                       # shows the back of the card
                    #text "X"                # will show text
                    add "y"                # will show image

                action If ( (card["c_chosen"] or not can_click), None, [SetDict(cards_list[card["c_number"]], "c_chosen", True), Return(card["c_number"]) ] )
 

   

init:
    python:
        def cards_shuffle(x):
            renpy.random.shuffle(x)
            return x

    ##### Images
    image a = "1.png"         # different card images
    image b = "2.png"
    image c = "3.png"          
    image d = "4.png"
    image e = "5.png"
    image f = "6.png"
    image g = "7.png"
    image h = "8.png"
    image i = "9.png"
    image j = "10.png"
    image k = "11.png"
    image l = "12.png"
    image m = "13.png"
    image n ="14.png"
    image o = "15.png"
    image p ="16.png"
    image q = "17.png"
    image r = "18.png"
    image s = "19.png"
    image t = "20.png"
    image u = "21.png"
    image v = "22.png"
    image w = "23.png"
    image x = "24.png"
    image y = "back.png"
    
label scarlettdelay:
   
    #####
    #
    # At first, let's set the cards to play (the amount should match the grid size - in this example 12)
    $ values_list = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x"]
   
    # Then - shuffle them
    $ values_list = cards_shuffle(values_list)
   
    # And make the cards_list that describes all the cards
    $ cards_list = []
    python:
        for i in range (0, len(values_list) ):
            cards_list.append ( {"c_number":i, "c_value": values_list[i], "c_chosen":False} )   

    # Before start the game, let's set the timer
    $ memo_timer = 370.0
   
    # Shows the game screen
    show screen memo_scr
   
    # The game loop
    label memo_game_loop:
        $ can_click = True
        $ turned_cards_numbers = []
        $ turned_cards_values = []
       
        # Let's set the amount of cards that should be opened each turn (all of them should match to win)
        $ turns_left = 2
       
        label turns_loop:
            if turns_left > 0:
                $ result = ui.interact()
                $ memo_timer = memo_timer
                $ turned_cards_numbers.append (cards_list[result]["c_number"])
                $ turned_cards_values.append (cards_list[result]["c_value"])
                $ turns_left -= 1
                jump turns_loop
       
        # To prevent further clicking befor chosen cards will be processed
        $ can_click = False
        # If not all the opened cards are matched, will turn them face down after pause
        if turned_cards_values.count(turned_cards_values[0]) != len(turned_cards_values):
            $ renpy.pause (1.0, hard = True)
            python:
                for i in range (0, len(turned_cards_numbers) ):
                    cards_list[turned_cards_numbers[i]]["c_chosen"] = False
       
        # If cards are matched, will check if player has opened all the cards
        else:
            $ renpy.pause (1.0, hard = True)
            python:
               
                # Let's remove opened cards from game field
                # But if you prefere to let them stay - just comment out next 2 lines
                for i in range (0, len(turned_cards_numbers) ):
                    cards_list[turned_cards_numbers[i]]["c_value"] = Null()
                   
                   
                for j in cards_list:
                    if j["c_chosen"] == False:
                        renpy.jump ("memo_game_loop")
                renpy.jump ("memo_game_win")
               
               

        jump memo_game_loop

label memo_game_lose:
    hide screen memo_scr
    $ renpy.pause (0.1, hard = True)
    $ renpy.pause (0.1, hard = True)
    return

label memo_game_win:
    hide screen memo_scr
    $ renpy.pause (0.1, hard = True)
    $ renpy.pause (0.1, hard = True)
    $ memoriagame = True
    return
I have a feeling I went wrong somewhere...but i'm not sure where. @@
Attachments
glitch2.jpg
glitch1.jpg
Image Image

User avatar
Alex
Eileen-Class Veteran
Posts: 1935
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Simple minigames (Screen Language only).

#12 Post by Alex » Sat Mar 01, 2014 8:35 am

Hmm... just a thought - check the size of all images (any chance one of them is too big, so when it's shown, every cell in grid became bigger too).

User avatar
AsHLeX
Veteran
Posts: 462
Joined: Wed Dec 25, 2013 1:09 pm
Completed: Starlight Dreamers, Mysterious Melody, Town of Memories, Marked, To Fly, The Change, Him From The Past, A Forgotten Memory
Projects: Cafe Mysteria
Location: Malaysia
Contact:

Re: Simple minigames (Screen Language only).

#13 Post by AsHLeX » Sat Mar 01, 2014 8:59 am

I checked the sizes but its the same D:
The old game file which I put it in works perfectly fine but for some reason the moment I copied it into the new file it didn't work anymore :( I recopied everything again just now but still same problem... Could it have something to do with the screens or something? (Sorry, I don't know much) D:
Edit: I copied the exact same code into a new folder and tried again and it works.
Still not sure what's the problem because I don't see any difference between the three folders :(
Could some other part of the script be affecting it?
Re-edit: So I was testing the game again and the cards just disappeared right off the screen (nothing I did could make it come back)
Image Image

User avatar
Alex
Eileen-Class Veteran
Posts: 1935
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Simple minigames (Screen Language only).

#14 Post by Alex » Sat Mar 01, 2014 12:40 pm

Hm, could you send me your project to test?

User avatar
AsHLeX
Veteran
Posts: 462
Joined: Wed Dec 25, 2013 1:09 pm
Completed: Starlight Dreamers, Mysterious Melody, Town of Memories, Marked, To Fly, The Change, Him From The Past, A Forgotten Memory
Projects: Cafe Mysteria
Location: Malaysia
Contact:

Re: Simple minigames (Screen Language only).

#15 Post by AsHLeX » Sun Mar 02, 2014 2:42 am

https://db.tt/w8IS3Ms8
Just extract it and open ren'py...It should work I think.
But the ren'py that i'm using is the old version so i'm not sure if it's compatible.
The code is @ memoria.rpy and line 2965 of script.rpy
Thank you so much :D
P.S: I wasn't sure if I should post the link here of pm it to you so I decided to post it here. (Sorry if I shouldn't have done that.)
Image Image

Post Reply

Who is online

Users browsing this forum: No registered users