Imitation Baldur's Gate dice animation effect

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.
Post Reply
Message
Author
User avatar
Andredron
Miko-Class Veteran
Posts: 719
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Imitation Baldur's Gate dice animation effect

#1 Post by Andredron »

Post - https://www.renpy.cn/thread-1508-1-1.html

Image
A while ago, I imitated Baldur's Gate in the group to implement a random dice rolling effect on a whim.

The code was poorly written. Finally, with the help of ZYKsslm boss, I finally made the code run normally without too many bugs
(actually it still does). There is a bug, that is, the result frame will appear earlier than the animation frame for a moment, so we can only find a way to delay the display of the result frame.

Let’s briefly talk about the idea. The logic of this dice is to play a dice animation after clicking on the dice, and finally display the final points of the dice.
If you watch it frame by frame, you will find that the dice rotate at high speed and produce dynamic blur. It is almost impossible to see the points of the dice, only the points of the dice are reached. When the result is given, the precise number is displayed abruptly
, so the animation can be split into two ends, one is the high-speed moving dice, and the other is the display
of the result. If it is turned into code, the logic of this section is:
click to roll the dice → random Get the dice points → Play the dice animation → Play the result animation Implementation link You can create this dice animation in various ways, it can be hand-drawn or 3D. I simply used blender to create a six-sided dice animation.

This is just a simple dice effect. It mainly introduces to you the idea of ​​analyzing and realizing an effect. The
same idea can be used to do many other things. If you want to submit homework, you are welcome to submit it under this post
(by the way, this dice rolling cost me a lot of money). It took two hours to implement, and I finished the animation in half an hour, and the remaining one and a half hours were spent writing bugs. In the end, the boss of ZYKsslm took over ten minutes to solve the battle. Maybe I am really not suitable for writing code )

Code: Select all


image d0 = Solid("#00000000")
image d1 = Movie(play="images/1.webm", loop=False)
image d2 = Movie(play="images/2.webm", loop=False)
image d3 = Movie(play="images/3.webm", loop=False)
image d4 = Movie(play="images/4.webm", loop=False)
image d5 = Movie(play="images/5.webm", loop=False)
image d6 = Movie(play="images/6.webm", loop=False)

image d0p = "1.png"
image d1p = "1.png"
image d2p = "2.png"
image d3p = "3.png"
image d4p = "4.png"
image d5p = "5.png"
image d6p = "6.png"
 
default index = 1
default c = 0
 
label start:
    call screen roll
    return
 
screen roll():
    $ mv = f"d{index}"
    $ img = f"d{index}p"
    showif c:
        add img zoom 0.5 align (0.5, 0.5) 
        add mv zoom 0.5 align (0.5, 0.5)
 
    textbutton "roll!":
        align (0.5, 0.85)
        action [SetScreenVariable("c", c+1), SetScreenVariable("index", renpy.random.randint(1, 6))]


Post Reply

Who is online

Users browsing this forum: No registered users