Moving images as part of screen

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
Zeekee
Regular
Posts: 67
Joined: Wed Jul 23, 2014 10:17 pm
Projects: No One But You, The Anomaly
Organization: Annexe Interactive
Skype: ytmnd111
Soundcloud: zomgaarh
Location: USAF Academy, CO
Contact:

Moving images as part of screen

#1 Post by Zeekee »

I've created a screen for a minigame I've implemented and everything works fine except one thing. The game is simple--the player must traverse a nxn maze to reach the exit. Although everything works fine, I tried implementing a shadow overlay so that the player's field of view is limited, making the maze more challenging, but the way I have it implemented, the FOV only follows the player along the x-axis and not the y-axis (and I have ZERO clue as to why). I figured I'd share what I have here to see if there's anything I'm doing wrong. I have a long programming background, but a lot of the things native to the RenPy engine don't make much sense to me. Here's my screen:

Code: Select all

# Maze screen
screen game_field(board, next_label):

    # Keyboard input
    if board.playerx != board.xfinish or board.playery != board.yfinish:
        key "focus_left" action If( board.board[y][max(x-1, 0)] != 0, [SetVariable("x", max(x-2, 0)), board.set_player(x,y)], NullAction() )
        key "focus_right" action If( board.board[y][min(x+1, board.depth * 2 - 2)] != 0, [SetVariable("x", min(x+2, board.depth * 2 - 2)), board.set_player(x,y)], NullAction() )
        key "focus_up" action If( board.board[max(y-1, 0)][x] != 0, [SetVariable("y", max(y-2, 0)), board.set_player(x,y)], NullAction() )
        key "focus_down" action If( board.board[min(y+1, board.depth * 2 - 2)][x] != 0, [SetVariable("y", min(y+2, board.depth * 2 - 2)), board.set_player(x,y)], NullAction() )
        key "dismiss" action NullAction()
    
    # Generate maze via grid
    vbox spacing 0:
        align align_maze
        #at maze_pos
        
        for row in range(len(board.board)):
            hbox spacing 0:
                for col in range(len(board.board)):
                    if row % 2 == 0 and col % 2 == 0:
                        if row == y and col == x:
                            add "player"
                        elif row == board.yfinish and col == board.xfinish:
                            add "finish"
                        else:
                            add "path"
                    elif row % 2 == 1 and col % 2 == 0:
                        if board.board[row][col] == 1:
                            add "long_path"
                        else:
                            add "long_wall"
                    elif row % 2 == 0 and col % 2 == 1:
                        if board.board[row][col] == 1:
                            add "tall_path"
                        else:
                            add "tall_wall"
                    elif row % 2 == 1 and col % 2 == 1:
                        if board.board[row][col] == 1:
                            add "edge_path"
                        else:
                            add "edge_wall"
                    else:
                        null

    add "fov":
        at maze_pos(board)
        xalign 0.5
        yalign 0.5
        ypos (board.yoffs + 25 + ((board.playery+1)//2) * 50 + (board.playery//2) * 10)
        xpos (board.xoffs + 25 + ((board.playerx+1)//2) * 50 + (board.playerx//2) * 10)

    # If player is at the maze finish coordinates, then jump out of the game to the next label in the script
    if board.playerx == board.xfinish and board.playery == board.yfinish:
        timer 0.01 action Jump(next_label) repeat False
If you'd like to see any other parts of my code, please let me know. It seems that the "xpos (board.xoffs + 25 + ((board.playerx+1)//2) * 50 + (board.playerx//2) * 10)" line works, but the value for ypos never changes.
"When people sometimes misquote me, I don't know if they understand what I'm saying."
-Tommy Wiseau

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2407
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Moving images as part of screen

#2 Post by Ocelot »

A minimal reproducible example as separate project avaliable for download would be nice.
Right now a few guessses.
Are you sure that playery is updated properly? Nothing else in the screen really uses it in a visible manner, so the problem might lie here.
What is in maze_pos transform?
xpos/xalign, ypos/yalign: setting same property multiple times with different values is not something I would expect to work normally.
< < insert Rick Cook quote here > >

User avatar
Zeekee
Regular
Posts: 67
Joined: Wed Jul 23, 2014 10:17 pm
Projects: No One But You, The Anomaly
Organization: Annexe Interactive
Skype: ytmnd111
Soundcloud: zomgaarh
Location: USAF Academy, CO
Contact:

Re: Moving images as part of screen

#3 Post by Zeekee »

Yeah, of course! Here's a zipped file. Super minimal. The maze.rpy file contains the above code along with the python code for the maze. The script file (obviously) shows how each maze is called.

https://drive.google.com/file/d/1rfioSL ... sp=sharing

Also, I'm absolutely sure that the playery and playerx values are both set properly. I'm super confused as to why only one would be updating. Oh, and maze_pos is just a zoom factor that I used for adjusting how large the players FOV is. I thought that I might make it variable later on (like as an argument passed to the screen), but I'm not so sure now.
"When people sometimes misquote me, I don't know if they understand what I'm saying."
-Tommy Wiseau

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2407
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Moving images as part of screen

#4 Post by Ocelot »

As I suspected, setting ypos twice in the same displayable definition messes things up.
aling properties work by setting anchor and pos to the same value, so you are setting xpos and ypos twice.

Replace them with x/yanchor and everything should be working fine:
Image
< < insert Rick Cook quote here > >

User avatar
Zeekee
Regular
Posts: 67
Joined: Wed Jul 23, 2014 10:17 pm
Projects: No One But You, The Anomaly
Organization: Annexe Interactive
Skype: ytmnd111
Soundcloud: zomgaarh
Location: USAF Academy, CO
Contact:

Re: Moving images as part of screen

#5 Post by Zeekee »

Something so simple :(((((

Thank you so much for the insight!
"When people sometimes misquote me, I don't know if they understand what I'm saying."
-Tommy Wiseau

Post Reply

Who is online

Users browsing this forum: Google [Bot]