8.27.2011

Python: assign list to all zero

我學python 一陣子了,但一直不知道如何一次assign給list同一個值,
之前都是用range()來assign給list的,查了一下google,但似乎沒相關的說明,
原來我要問的問題太基本了,後來終於發現,原來很簡單,
如果要assign給list a,10000個0,那就:

a = [0] * 10000

同理,如果要assign給list a,9999個1,那就:

a = [1] * 9999

7.12.2011

Renpy 與 python

renpy可以用'$'或'python:'來插入python的程式碼,
不過注意,不要用來'import' pyhon的library,
否則很容易造成 遊戲存檔失效,
如果要'import'一些額外的library,
請在'init python:'中加入即可。

7.09.2011

Renpy 6.12.1: How do I show a variable in the text?

要怎麼在對話的text中秀出變數,Renpy 官網提供以下三種方法:
$ food = "apple sauce"

"I would like to try some %(food)s, please."
"I would like to try some %s, please." % food
"I would like to try some " + food + ", please."
 不過,我在Renpy 6.12.1試的結果,目前只支援第一種:
"I would like to try some %(food)s, please."

其它兩種,不確定以前有沒有支援,目前看來是不行用的。

7.02.2011

Renpy 6.12.1: Drag and Drop

Renpy 6.12.1支援滑鼠托拉(Drag and Drop)的功能,
官網有範例,不過若直接複製貼上範例code,
會發現有些小錯誤:
1. 請將drag_group改成draggroup
2. 去下載圖片,裡面的圖記得改成自己圖片的名稱

修改後範例如下:

init python:

    def detective_dragged(drags, drop):

        if not drop:
            return

        store.detective = drags[0].drag_name
        store.city = drop.drag_name

        return True

screen send_detective_screen:

    # A map as background.
    add "europe.jpg"

    # A drag group ensures that the detectives and the cities.
    draggroup:

        # Our detectives.
        drag:
            drag_name "Ivy"
            child "ivy.png"
            droppable False
            dragged detective_dragged
            xpos 100 ypos 100
        drag:
            drag_name "Zack"
            child "zack.png"
            droppable False
            dragged detective_dragged
            xpos 150 ypos 100

        # The cities they can go to.
        drag:
            drag_name "London"
            child "london.png"
            draggable False
            xpos 450 ypos 140
        drag:
            drag_name "Paris"
            draggable False
            child "paris.png"
            xpos 500 ypos 280

label send_detective:
    "We need to investigate! Who should we send, and where should they go?"

    call screen send_detective_screen

    "Okay, we'll send %(detective)s to %(city)s."

9.08.2010

十月長工

安徽省 民歌

十月長工

正月好唱正月終,
家裏無米斗量空,
借人一担還兩担,
今年只好打長工。

二月好唱二月終,
二月初一我上工,
我子哭來妻子叫,
眼淚流了幾茶盅。

三月好唱三月終,
身背犁灣下南沖,
南頭犁到北頭轉,
一把汗珠一棵種。

四月好唱四月終,
老板的麥子黃橙橙,
從早割麥割到晚,
老板還說我不中。

五月好唱五月終,
車水拔草忙得凶,
白天做活不得閑,
夜晚抽烟不放工。

六月好唱六月終,
六月日頭熱火龍,
老板出去洋傘打,
熱火曬死我長工。

七月好唱七月終,
割罷稻子又下種,
又催收來又催種,
老板就是活閻羅。

八月好唱八月終
老板的稻場趕得凶,
稻子打了幾千石,
長工還是兩手空。

九月好唱九月終,
桂花做酒香噴噴,
老板一天三遍酒,
沒把半盅我長工。

十月好唱十月終,
十月三十我下工,
老板鷄子殺一只,
鷄頭鷄脚我長工。

老板說:
「盡你吃來盡你咽,
明年幫工我家來。」
長工說:
「你吃青草放驢屁,
明年來你家做女婿。」

其它安徽民歌:
十月唱空

8.06.2010

Ren'Py 6.11.0 超新手的圖形化時鐘範例(in windows)

Ren'Py可以加入圖形化時鐘,
可參考:Adding a simple and somewhat functioning Analog Clock(英文)
不過不小修改這個範例 ,直接用這個code在Ren'Py 6.11.0卻不能執行。
所以我把修改後,可以在Ren'Py 6.11.0下執行的code公開,
主要是renpy.image(name,image)需要兩個參數,
其它只是一些小修改。


#script.rpy code 
init python: 
    clock = False
    minutes = 540
    renpy.image("clock","Clock.png") # Short Clockhand
    renpy.image("clock_1","Clock_1.png") # Long Clockhand
    renpy.image("clock_2","Clock_2.png") # Clockface
  
    def Clock():
        if clock: # if False - clock is hide
            ui.at(Position(xpos=150, ypos=140, xanchor="center", yanchor="center"))
            ui.add("clock_2")
            # xalign and yalign can be replaced by xpos and ypos - position where the center of the clock should be
            # this segment is the one responsible for the clockface

            ui.at(Position(xpos=150, ypos=140, xanchor="center", yanchor="center"))
            ui.at(RotoZoom((minutes*6), (minutes*6), 5.0, 1, 1, 1, rot_bounce= False, rot_anim_timebase=False, opaque=False), )
            ui.add("clock")
            # this segment is the one responsible for the short clock hand.

            ui.at(Position(xpos=150, ypos=140, xanchor="center", yanchor="center"))
            ui.at(RotoZoom ((minutes*0.5), (minutes*0.5), 5.0, 1, 1, 1, rot_bounce= False, rot_anim_timebase=False, opaque=False))
            ui.add("clock_1")
            # this segment is the one responsible for the long clock hand.

    config.overlay_functions.append(Clock)



init:
label start:

    $ clock = True
    with dissolve


#End of script.rpy 

另外就是Clock.png, Clock_1.png及Clock_2.png請放在
../renpy-6.11.0/common/
注意圖形檔案及檔名不要錯了哦。

8.01.2010

Ren'Py 6.11.0 超新手中文顯示簡介 (in windows)

Ren'Py是一個免費跨平台的AVG(視覺小說)製作軟体,
介面沒有商業軟体的戀愛遊戲製作大師二,來得人性化,
不過戀二已經是很久以前的軟体了,而且是商業軟体,
所以除了人性化外,很多方面不如Ren'Py,
而Ren'Py最大的特點是以英文為主,
所以如何中文顯示,就成為新手面臨的一大課題,
網路上有許多中文顯示的文件,
不過大多數都已經過舊,
新版的Ren'Py顯示中文,其實很簡單:
1. (Optional)首先下載開源的中文字型(如文泉驛中文字体)
2. 將字型放到程式下的common目錄下。
3. 建一project,去修改 遊戲所在資料夾中,option.rpy

style.default.font = "fontname.ttf"


這邊fontname.ttf即是中文字型檔檔名
(參:http://www.renpy.org/wiki/renpy/doc/FAQ#How_do_I_change_the_default_font.3F)

此時,你Select Project且Launch之後,成功的話,
就可以看到中文了。
額外的中文修改(可能有其用途,不清楚)
參考:http://www.renpy.org/wiki/renpy/doc/cookbook/Chinese_and_Japanese

Good Luck!