Discuz! Board

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 11236|回复: 2
打印 上一主题 下一主题

语法高亮renpy测试

[复制链接]

6

主题

15

帖子

163

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
163
跳转到指定楼层
楼主
发表于 2017-12-4 13:53:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
[RenPy] 纯文本查看 复制代码
# This file demonstrates how Character objects can be used to customize the
# display of text.

init:
    # With a nestled click-to-continue indicator.
    $ ectc = Character(_('Eileen'),
                       color="#c8ffc8",
                       ctc=anim.Blink("arrow.png"))


    # With a fixed-position ctc indicator.
    $ ectcf = Character(_('Eileen'),
                        color="#c8ffc8",
                        ctc=anim.Filmstrip("sakura.png", (20, 20), (2, 1), .30, xpos=760, ypos=560, xanchor=0, yanchor=0),
                        ctc_position="fixed")

    # With quotes around text.
    $ equote = Character(_('Eileen'),
                         color="#c8ffc8",
                         who_suffix = ':',
                         what_prefix='"',
                         what_suffix='"')

    # Weird-looking.
    $ eweird = Character(_('Eileen'),
                         color="#c8ffc8",
                         what_underline=True,
                         window_left_margin=200,
                         window_yminimum=300)

    # Two-window mode.
    $ etwo = Character(_('Eileen'),
                       color="#c8ffc8",
                       show_two_window=True)

    # Image on the side.
    $ eside = Character(_('Eileen'),
                        color="#c8ffc8",
                        window_left_padding=160,
                        show_side_image=Image("eileen_side.png", xalign=0.0, yalign=1.0))

label demo_character:


    e "The Character object is used to declare characters, and it can also be used to customize the way in which a character speaks."

    e "By supplying it with the appropriate arguments, we can really change around the feel of the game."

    e "In this section, we'll demonstrate some of what can be accomplished by customizing character objects."

    equote "By supplying what_prefix and what_suffix arguments to a Character object, we can automatically add things before each line of text."

    equote "This is a lot easier than having to put those quotes in by hand."

    equote "We can also use who_prefix and who_suffix to add text to the name of the speaker."

    e "We can also supply arguments to the Character object that customize the look of the character name, the text that is being said, and the window itself."

    eweird "These can really change the look of the game."

    eside "A more practical use of that is in conjunction with show_side_image, which lets us position an image next to the text."

    etwo "There's also show_two_window, which puts the character's name in its own window."

    ectc "Finally, we demonstrate a click to continue indicator. In this example, it's nestled in with the text."

    ectcf "A click to continue image can also be placed at a fixed location on the screen."

    e "There's a lot more you can do with Character, as it lets you set style properties on all of the displayed text."

    e "Finally, let me point out a couple of special characters we pre-define."

    show black
    with dissolve

    centered "The \"centered\" character shows text at the center of the screen, without a window."

    centered "It's just a highly customized normal character, that's useful for dates and titles."

    hide black
    with dissolve

    e "The \"extend\" character is very special."

    e "It lets you"

    show eileen vhappy

    extend " extend the previous dialogue"

    show eileen happy

    extend " with additional text."

    e "That lets you have things happen in the middle of text. If you didn't notice, I was changing my expression."

    e "Hopefully, these characters, along with the ones you define, will lead to a very expressive game."

    return
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

6

主题

15

帖子

163

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
163
沙发
 楼主| 发表于 2017-12-4 14:12:08 | 只看该作者
[RenPy] 纯文本查看 复制代码
init:

    image bg pong field = "pong_field.png"

    python:

        class PongDisplayable(renpy.Displayable):

            def __init__(self):

                renpy.Displayable.__init__(self)

                # Some displayables we use.
                self.paddle = Image("pong.png")
                self.ball = Image("pong_ball.png")
                self.player = Text(_("Player"), size=36)
                self.eileen = Text(_("Eileen"), size=36)
                self.ctb = Text(_("Click to Begin"), size=36)

                # The sizes of some of the images.
                self.PADDLE_WIDTH = 8
                self.PADDLE_HEIGHT = 79
                self.BALL_WIDTH = 15
                self.BALL_HEIGHT = 15
                self.COURT_TOP = 108
                self.COURT_BOTTOM = 543

                # If the ball is stuck to the paddle.
                self.stuck = True

                # The positions of the two paddles.
                self.playery = (self.COURT_BOTTOM - self.COURT_TOP) / 2
                self.computery = self.playery

                # The speed of the computer.
                self.computerspeed = 350.0

                # The position, dental-position, and the speed of the
                # ball.
                self.bx = 88
                self.by = self.playery
                self.bdx = .5
                self.bdy = .5
                self.bspeed = 300.0

                # The time of the past render-frame.
                self.oldst = None

                # The winner.
                self.winner = None

            def visit(self):
                return [ self.paddle, self.ball, self.player, self.eileen, self.ctb ]

            # Recomputes the position of the ball, handles bounces, and
            # draws the screen.
            def render(self, width, height, st, at):

                # The Render object we'll be drawing into.
                r = renpy.Render(width, height)

                # Figure out the time elapsed since the previous frame.
                if self.oldst is None:
                    self.oldst = st

                dtime = st - self.oldst
                self.oldst = st

                # Figure out where we want to move the ball to.
                speed = dtime * self.bspeed
                oldbx = self.bx

                if self.stuck:
                    self.by = self.playery
                else:
                    self.bx += self.bdx * speed
                    self.by += self.bdy * speed

                # Move the computer's paddle. It wants to go to self.by, but
                # may be limited by it's speed limit.
                cspeed = self.computerspeed * dtime
                if abs(self.by - self.computery) <= cspeed:
                    self.computery = self.by
                else:
                    self.computery += cspeed * (self.by - self.computery) / abs(self.by - self.computery)

                # Handle bounces.

                # Bounce off of top.
                ball_top = self.COURT_TOP + self.BALL_HEIGHT / 2
                if self.by < ball_top:
                    self.by = ball_top + (ball_top - self.by)
                    self.bdy = -self.bdy
                    renpy.sound.play("pong_beep.wav", channel=0)

                # Bounce off bottom.
                ball_bot = self.COURT_BOTTOM - self.BALL_HEIGHT / 2
                if self.by > ball_bot:
                    self.by = ball_bot - (self.by - ball_bot)
                    self.bdy = -self.bdy
                    renpy.sound.play("pong_beep.wav", channel=0)

                # This draws a paddle, and checks for bounces.
                def paddle(px, py, hotside):

                    # Render the paddle image. We give it an 800x600 area
                    # to render into, knowing that images will render smaller.
                    # (This isn't the case with all displayables. Solid, Frame,
                    # and Fixed will expand to fill the space allotted.)
                    # We also pass in st and at.
                    pi = renpy.render(self.paddle, 800, 600, st, at)

                    # renpy.render returns a Render object, which we can
                    # blit to the Render we're making.
                    r.blit(pi, (int(px), int(py - self.PADDLE_HEIGHT / 2)))

                    if py - self.PADDLE_HEIGHT / 2 <= self.by <= py + self.PADDLE_HEIGHT / 2:

                        hit = False

                        if oldbx >= hotside >= self.bx:
                            self.bx = hotside + (hotside - self.bx)
                            self.bdx = -self.bdx
                            hit = True

                        elif oldbx <= hotside <= self.bx:
                            self.bx = hotside - (self.bx - hotside)
                            self.bdx = -self.bdx
                            hit = True

                        if hit:
                            renpy.sound.play("pong_boop.wav", channel=1)
                            self.bspeed *= 1.10

                # Draw the two paddles.
                paddle(68, self.playery, 68 + self.PADDLE_WIDTH)
                paddle(724, self.computery, 724)

                # Draw the ball.
                ball = renpy.render(self.ball, 800, 600, st, at)
                r.blit(ball, (int(self.bx - self.BALL_WIDTH / 2),
                              int(self.by - self.BALL_HEIGHT / 2)))

                # Show the player names.
                player = renpy.render(self.player, 800, 600, st, at)
                r.blit(player, (20, 25))

                # Show Eileen's name.
                eileen = renpy.render(self.eileen, 800, 600, st, at)
                ew, eh = eileen.get_size()
                r.blit(eileen, (790 - ew, 25))

                # Show the "Click to Begin" label.
                if self.stuck:
                    ctb = renpy.render(self.ctb, 800, 600, st, at)
                    cw, ch = ctb.get_size()
                    r.blit(ctb, (400 - cw / 2, 30))


                # Check for a winner.
                if self.bx < -200:
                    self.winner = "eileen"

                    # Needed to ensure that event is called, noticing
                    # the winner.
                    renpy.timeout(0)

                elif self.bx > 1000:
                    self.winner = "player"
                    renpy.timeout(0)

                # Ask that we be re-rendered ASAP, so we can show the next
                # frame.
                renpy.redraw(self, 0)

                # Return the Render object.
                return r

            # Handles events.
            def event(self, ev, x, y, st):

                import pygame

                # Mousebutton down == start the game by setting stuck to
                # false.
                if ev.type == pygame.MOUSEBUTTONDOWN and ev.button == 1:
                    self.stuck = False

                # Set the position of the player's paddle.
                y = max(y, self.COURT_TOP)
                y = min(y, self.COURT_BOTTOM)
                self.playery = y

                # If we have a winner, return him or her. Otherwise, ignore
                # the current event.
                if self.winner:
                    return self.winner
                else:
                    raise renpy.IgnoreEvent()


label demo_minigame:

    e "You may want to mix Ren'Py with other forms of gameplay. There are many ways to do this."

    e "The first is with the UI functions, which can be used to create powerful button and menu based interfaces."

    e "These are often enough for many simulation-style games."

    e "We also have two more ways in which Ren'Py can be extended. Both require experience with Python programming, and so aren't for the faint of heart."

    e "Renpygame is a library that allows pygame games to be run inside Ren'Py."

    e "When using renpygame, Ren'Py steps out of the way and gives you total control over the user's experience."

    e "You can get renpygame from the Frameworks page of the Ren'Py website."

    e "If you want to integrate your code with Ren'Py, you can write a user-defined displayable."

    e "User-defined displayables are somewhat more limited, but integrate better with the rest of Ren'Py."

    e "For example, one could support loading and saving while a user-defined displayable is shown."

    e "Now, why don't we play some pong?"

label demo_minigame_pong:

    window hide None

    # Put up the pong background, in the usual fashion.
    scene bg pong field

    # Run the pong minigame, and determine the winner.
    python:
        ui.add(PongDisplayable())
        winner = ui.interact(suppress_overlay=True, suppress_underlay=True)

    scene bg washington
    show eileen vhappy

    window show None


    if winner == "eileen":

        e "I win!"

    else:

        e "You won! Congratulations."


    show eileen happy

    menu:
        e "Would you like to play again?"

        "Sure.":
            jump demo_minigame_pong
        "No thanks.":
            pass


    e "Remember to be careful about putting minigames in a visual novel, since not every visual novel player wants to be good at arcade games."

    return
回复 支持 反对

使用道具 举报

6

主题

15

帖子

163

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
163
板凳
 楼主| 发表于 2017-12-4 14:38:45 | 只看该作者
[RenPy] 纯文本查看 复制代码
# This file contains a demonstration of the user interaction
# functions.

screen viewport_screen:

    viewport:
        scrollbars "both"
        xmaximum 400
        ymaximum 400

        side_xpos 100
        side_ypos 100
        side_spacing 5

        draggable True
        mousewheel True

        add "concert2.jpg"

    textbutton _("Dismiss"):
        xpos 300
        xanchor 0.5
        ypos 550
        yanchor 0.5

        action Return(True)

screen edgescroll_screen:

    viewport:
        edgescroll (150, 500)
        add "concert2.jpg"

screen demo_imagemap:
    imagemap:
        auto "imagemap_%s.jpg"

        hotspot (8, 200, 78, 78) action Return("swimming")
        hotspot (204, 50, 78, 78) action Return("science")
        hotspot (452, 79, 78, 78) action Return("art")
        hotspot (602, 316, 78, 78) action Return("go home")

init:

    # The variable we store the entered name of the character in.
    $ povname = ""

    # And this is a DynamicCharacter that has the same stored in
    # povname.
    $ pov = DynamicCharacter("povname", color=(192, 64, 64, 255))


    # This is code for a day planner, or at least sort of. To be
    # honest, the code in the dse game is a bit better. Take this
    # as more of an example of what Ren'Py can do.
    python:
        def day_planner():

            periods = [ _('Morning'), _('Afternoon'), _('Evening') ]
            periods_small = {'Morning': _('morning'), 'Afternoon': _('afternoon'), 'Evening': _('evening') }
            choices = [ _('Study'), _('Exercise'),
                        _('Eat'), _('Drink'), _('Be Merry') ]

            plan = { _('Morning') : _('Eat'),
                     _('Afternoon') : _('Drink'),
                     _('Evening') : _('Be Merry') }

            day = _('March 25th')

            stats = [
                (_('Strength'), 100, 10),
                (_('Intelligence'), 100, 25),
                (_('Moxie'), 100, 100),
                (_('Chutzpah'), 100, 75),
                ]

            editing = None

            def button(text, selected, returns, **properties):

                if selected:
                    role='selected_'
                else:
                    role=''

                ui.button(clicked=ui.returns(returns),
                          style='button', role=role, **properties)
                ui.text(text, style='button_text')


            while True:

                # Stats Window
                ui.frame(xpos=0,
                         ypos=0,
                         xanchor='left',
                         yanchor='top',
                         xfill=True,
                         )

                ui.vbox()

                ui.text(_('Statistics'))
                ui.null(height=20)

                for name, range, value in stats:

                    ui.hbox()
                    ui.text(name, minwidth=150)
                    ui.bar(range, value, ypos=0.5, yanchor='center')
                    ui.close()

                ui.close()

                # Period Selection Window.
                ui.frame(xpos=0,
                         ypos=200,
                         xanchor='left',
                         yanchor='top',
                         xfill=False,
                         xminimum=300
                         )

                ui.vbox(xpos=0.5, xanchor='center')
                ui.text(day, xpos=0.5, xanchor='center', textalign=0.5)
                ui.null(height=20)

                for i in periods:
                    renpy.store.period_tmp = i
                    renpy.store.plan_tmp = plan[i]
                    button("[period_tmp!t]: [plan_tmp!t]", editing == i, ("edit", i), xminimum=250)

                ui.null(height=20)
                ui.textbutton(_("Continue"),
                              clicked=ui.returns(("done", True)),
                              xminimum=250)
                ui.null(height=20)
                ui.close()


                # Choice window.
                if editing:
                    ui.frame(xpos=300,
                             ypos=200,
                             xanchor='left',
                             yanchor='top',
                             xfill=False,
                             xminimum=500,
                             xmargin = 10
                             )

                    ui.vbox()
                    renpy.store.periods_small_selected = periods_small[editing]
                    ui.text(_("What will you do in the [periods_small_selected!t]?"))
                    ui.null(height=20)

                    for i in choices:
                        button(i,
                               plan[editing] == i,
                               ("set", i),
                               xpos=0,
                               xanchor='left',
                               xminimum=250)

                    ui.close()

                # Window at the bottom.
                e(_("To get to the next screen, click the 'Continue' button."), interact=False)

                type, value = ui.interact()

                if type == "done":
                    break

                if type == "edit":
                    editing = value

                if type == "set":
                    plan[editing] = value
                    editing = None

            return plan

init python:

    def stats_frame(name, level, hp, maxhp, **properties):

        ui.frame(xfill=False, yminimum=None, **properties)

        ui.hbox() # (name, "HP", bar) from (level, hp, maxhp)
        ui.vbox() # name from ("HP", bar)

        ui.text(name, size=20)

        ui.hbox() # "HP" from bar
        ui.text("HP", size=20)
        ui.bar(maxhp, hp,
               xmaximum=150)

        ui.close()
        ui.close()

        ui.vbox() # Level from (hp/maxhp)

        ui.text("Lv. %d" % level, xalign=0.5, size=20)
        ui.text("%d/%d" % (hp, maxhp), xalign=0.5, size=20)

        ui.close()
        ui.close()

label fight(ename, elevel, ehp, pname="Zanthier", plevel=4, php=40):
    $ stats_frame(pname, plevel, int(php * .73), php, xalign=.02, yalign=.05)
    $ stats_frame(ename, elevel, ehp, ehp, xalign=.98, yalign=.05)

    return

label demo_ui:

    e "Ren'Py gives a number of ways of interacting with the user."

    e "You've already seen say statements and menus."

    menu:

        e "But were you aware that you can have dialogue and menus onscreen at the same time?"

        "Yes.":

            show eileen vhappy

            e "Good!"

            show eileen happy

        "No.":

            e "Well, now you know."

    if not renpy.variant('touch'):

        e "We can also prompt the user to enter some text."

        $ povname = renpy.input(_("What is your name?")) or _("Guy Shy")

        pov "My name is [povname!t]."


    e "Imagemaps let the user click on an image to make a choice. For example, the following screen lets you pick what to do after school:"

    # Show an imagemap.
    window hide None
    call screen demo_imagemap
    window show None

    # Call screen assignes the chosen result from the imagemap to the
    # _return variable. We can use an if statement to vary what
    # happens based on the user's choice.

    if _return == "swimming":

        e "You chose swimming."

        e "Swimming seems like a lot of fun, but I didn't bring my bathing suit with me."

    elif _return == "science":

        e "You chose science."

        e "I've heard that some schools have a competitive science team, but to me research is something that can't be rushed."

    elif _return == "art":

        e "You chose art."

        e "Really good background art is hard to make, which is why so many games use filtered photographs. Maybe you can change that."

    elif _return == "go home":

        e "You chose to go home."

    e "Anyway..."

    e "We also support viewports, that allow us to display things that are bigger then the screen."

    e "This viewport can be adjusted by dragging, by the mouse wheel, and by the scrollbars."

    window hide

    show eileen happy at right
    with move

    call screen viewport_screen

    show screen edgescroll_screen
    with dissolve


    e "Viewports also support edge scrolling, which is automatic scrolling when the mouse reaches their edge."

    hide screen edgescroll_screen
    show eileen happy at center
    with dissolve

    window show

    e "While these constructs are probably enough for most visual novels, dating simulations may be more complicated."

    e "The ui functions allow you to create quite complicated interfaces."

    e "For example, try the following scheduling and stats screen, which could be used by a stat-based dating simulation."

    hide eileen
    with dissolve

    $ day_planner()

    show eileen happy
    with dissolve

    e "For a better implementation of this, take a look at the dating sim engine (DSE) that ships with Ren'Py."

    call fight("Eileen", 10, 99, pname=povname) from _call_fight_1

    e "The ui functions can be also be used to show the sorts of stats you'd need if your game involves combat."

    call fight("Eileen", 10, 99, pname=povname) from _call_fight_2

    e "Hopefully, the ui functions will let you write whatever visual novel or dating sim you want."

    return
回复 支持 反对

使用道具 举报

小黑屋|手机版|Archiver|Comsenz Inc.  

GMT+8, 2024-11-23 15:28 , Processed in 0.054035 second(s), 26 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表