非プログラマのRen'Pyノート:screenで作る、カレンダー表示とサンプルスクリプト(実質破綻しているためあまり参考にならないです)
開発中のゲーム「LoveSoTea」では天気によって主人公の体調が左右される(低気圧に弱い)のでお天気表示を実装したい。
少し調べてみると愛用ノベルゲームエンジンRen'Py(以下renpy)ではpythonが使えるので、モジュール? か何か? をインポート? すれば実際の天気を引用できるっぽい? のですが解説を読んでも1ミリも分かりません。
そういう難しいのを無理して使ったところで後で詰みかねないですし、非プログラマの私が自分で管理できる範囲でそれっぽくする過程を、順を追って公開します。
順は追わんでよい、最終結果だけ見たい方は飛ばしてもらっていいんですが、カレンダーの変数の話が入ってくると(ここの解説できる自信全然ないです)renpyなんもわからん人は本当になんもわからんで終わる可能性があり、引用して使われるなら真ん中辺がおすすめです。
文字をスクリーンでいい感じに配置する
screen show_tenki():
add "bg_sky_blue"
#add "mihon"
hbox:
xalign 0.5
yalign 0.1
vbox:
xsize 200 #サイズを固定しないと文字幅でマージンが変わる
text "3/1":
style "tenki_text"
text "金曜日":
style "tenki_youbi_text"
vbox:#ここスマホ入れるので後で幅を広めにする
xsize 200
text "3/2":
style "tenki_text"
text "金曜日":
style "tenki_youbi_text"
vbox:
xsize 200
text "3/3":
style "tenki_text"
text "金曜日":
style "tenki_youbi_text"
vbox:
xsize 200
text "3/4":
style "tenki_text"
text "金曜日":
style "tenki_youbi_text"
vbox:
xsize 200
text "3/5":
style "tenki_text"
text "金曜日":
style "tenki_youbi_text"
vbox:
xsize 200
text "3/6":
style "tenki_text"
text "金曜日":
style "tenki_youbi_text"
vbox:
xsize 200
text "3/7":
style "tenki_text"
text "金曜日":
style "tenki_youbi_text"
style tenki_text:
xalign 0.5
text_align 0.5
size 98
color "#fff"
font "GenJyuuGothicL-Medium.ttf"
style tenki_youbi_text:
xalign 0.5
size 42
text_align 0.5
color "#fff"
font "GenJyuuGothicL-Medium.ttf"
label test:
show screen show_tenki
"表示おわり"
textをimageにしてFixedするのでもできるかも知れませんが、screenではvboxを使って均等に並べるのがお手軽にできるのでscereenでやります。
ベースとなるデザインに寄せ位置合わせ
元々作っていた配置見本をaddで背景に貼って文字位置やサイズなどを正確に合わせます。位置を調整したものとスクリプトサンプルがこちら。
screen show_tenki():
add "bg_sky_blue"
add "mihon"#これを位置合わせ用に貼ってる。
hbox:
xalign 0.5
yalign 0.16
vbox:
xsize 200#サイズを固定しないと文字幅でマージンが変わる
style "tenki_vbox"
xpos 0.32 #これだけチョイよせ
text "28":
style "tenki_text"
text "金曜日":
style "tenki_youbi_text"
add "icon_tenki_hare_l":
at anm_tenki
vbox:#ここスマホ入れるので後で幅を広めにする
xsize 490
style "tenki_vbox"
text "28":
style "tenki_text"
text "金曜日":
style "tenki_youbi_text"
add "icon_tenki_hare_l":
at anm_tenki
vbox:
xsize 210
style "tenki_vbox"
text "28":
style "tenki_text"
text "金曜日":
style "tenki_youbi_text"
add "icon_tenki_hare_l":
at anm_tenki
vbox:
xsize 210
style "tenki_vbox"
text "28":
style "tenki_text"
text "金曜日":
style "tenki_youbi_text"
add "icon_tenki_hare_l":
at anm_tenki
vbox:
xsize 210
style "tenki_vbox"
text "28":
style "tenki_text"
text "金曜日":
style "tenki_youbi_text"
add "icon_tenki_hare_l":
at anm_tenki
vbox:
xsize 210
style "tenki_vbox"
text "28":
style "tenki_text"
text "金曜日":
style "tenki_youbi_text"
add "icon_tenki_hare_l":
at anm_tenki
vbox:
xsize 210
style "tenki_vbox"
text "28":
style "tenki_text"
text "金曜日":
style "tenki_youbi_text"
add "icon_tenki_hare_l":
at anm_tenki
use phone_date(phone_tenki)#テキストの上に被せるのでここに書く
style tenki_vbox:
spacing -25
xalign 0.5
style tenki_text:
xalign 0.5
text_align 0.5
size 120
color "#fff"
font "GenJyuuGothicL-Medium.ttf"
style tenki_youbi_text:
xalign 0.5
size 42
text_align 0.5
color "#fff"
font "GenJyuuGothicL-Medium.ttf"
transform anm_tenki:#晴れマークはクルクルまわる
zoom 0.42
xalign 0.5
rotate 0
linear 10 rotate 360
repeat
transform phone_tenki:#phoneは下からぴょいっと表示される
xalign 0.185
ypos 1.0
pause 0.3
easein 0.5 ypos 0.1
label test:
show screen show_tenki
"表示おわり"
これだと静止画でわかりませんが、太陽はくるくるまわりスマホは下からぴょいっと出てきます。つまりアニメーションが多少入っている。
自分がやった場合大体ここまでで1時間ちょっとくらいです(デザインの時間は含めず)。月表示を忘れてたので後で足します。
現状、7日分の日付が入っておりますが、憧れのP4Gっぽくするには+前後数日分の日付が画面外に必要+左から右へ1日分動くアニメが必要なので、なんとかして入れます。
その前に変数をなんとかする
ただし非プログラマこと私の場合、変数の代入ができると思ってたのに後でやろうとするとこの仕組みでは実はできなかった、みたいなことになりかねませんので、ここでカレンダーの変数を整理し……ようとしたのですが、
自分で書いててなんかバカっぽいなこのスクリプト、っていう直感が働くことがあり、それは大体合っています。このように「今日+前後の日数や曜日の取得」が自力ではとても煩雑になったので、twitterで助けを求めます。
するとrenpy勢より早くpythonなどがわかる凄腕プログラマさんたちが駆けつけてくださり、おかげさまで曜日と月日をまとめることができました。
スッとさせた参考資料貼っておきます。
label test:
#カレンダー参考4(これが一番使いやすそう)
#https://lemmasoft.renai.us/forums/viewtopic.php?p=308964#p308964
$ month_information={1:(1,31),2:(2,28),3:(3,31),4:(4,30),5:(5,31),
6:(6,30),7:(7,31),8:(8,31),9:(9,30),10:(10,31),11:(11,30),12:(12,31)}
$ day = 26 #ゲーム初日
$ month = 4 #ゲーム開始月
$ day_max = 30 #4月なのでとりあえず仮入れ必要
$ num_youbi = 0 #0=月曜
#曜日のリスト
$ youbi_list = ["月","火","水","木","金","土","日"]
label test_day:
if day > day_max:#もし当月のmax日付「以上」の時は
$ day = 1
$ month += 1
$ month_name,day_max = month_information[month] #これなんだろう
if month == 12:#もし当月のmax日付かつ12月=12月31日は
$ month = 1
$ youbi = str(youbi_list[(num_youbi)%7])
"今日は [month]月[day]日[youbi]曜日。\n翌日にするよ"
$ day += 1 #突然10日とか増やすとmax以上になるよ
$ num_youbi += 1
jump test_day #繰り返しテスト
普通の「1日ずつ増えるカレンダー」ならこれで十分かと思います(年対応はしていませんが多少わかる方なら入れられるはず)。
激ムズ! 前後天気の取得(見せしめ)
しかし、自分の場合「今日を基準に±日数と天気を取得したい、しかもそれが毎日変わる」のでここからさらに難しくなります。難しいっていうか「晴れ曇り雨の3種類だとしても日付ごとに取得するのでやたら長くなり管理が難しい」お天気表示。
いわゆるインゲーム? 的には手動で調整したいこともありますのでがんばります。がんばりますが1年分は大変なのと、ちゃんと動くかの確認もしたいので、ゲーム序盤の4月中くらいをなんとかがんばって作ります。
#カレンダーのしくみ部分
label cal_day:
$ modal_true = False
##天気の判定##############################
#4月の天気 https://tenki.jp/past/2021/04/weather/6/29/47759/
#カレンダー参考(これが一番使いやすそう)
#https://lemmasoft.renai.us/forums/viewtopic.php?p=308964#p308964
#以下リンクを参考に「雨の日リスト」「曇りの日リスト」をつくりそれ以外は晴れとする
#https://atmarkit.itmedia.co.jp/ait/articles/2012/18/news022.html
$ today += 1
$ num_youbi += 1
$ day_3 += 1
$ day_2 += 1
$ day_1 += 1
$ day1 += 1
$ day2 += 1
$ day3 += 1
$ day4 += 1
$ day5 += 1
$ day6 += 1
if day6 > day_max:
$ day6 = 1
$ month_name, day_max = month_information[month+1]
elif day6 > 1 and day6 < 7:
$ month_name, day_max = month_information[month+1]
if int(str(month_name) + str(day6).zfill(2)) in list_rainy:
$ tenki6 = "anm_tenki_ame"
elif int(str(month_name) + str(day6).zfill(2)) in list_cloudy:
$ tenki6 = "anm_tenki_kumori"
else:
$ tenki6 ="anm_tenki_hare"
#一回元に戻す? 正気か?
$ month_name, day_max = month_information[month]
if day5 > day_max:
$ day5 = 1
$ month_name, day_max = month_information[month+1]
elif day5 > 1 and day5 < 6:
$ month_name, day_max = month_information[month+1]
if int(str(month_name) + str(day5).zfill(2)) in list_rainy:
$ tenki5 = "anm_tenki_ame"
elif int(str(month_name) + str(day5).zfill(2)) in list_cloudy:
$ tenk5 = "anm_tenki_kumori"
else:
$ tenki5 ="anm_tenki_hare"
#一回元に戻す? 正気か?
$ month_name, day_max = month_information[month]
if day4 > day_max:
$ day4 = 1
$ month_name, day_max = month_information[month+1]
elif day4 > 1 and day4 < 5:
$ month_name, day_max = month_information[month+1]
if int(str(month_name) + str(day4).zfill(2)) in list_rainy:
$ tenki4 = "anm_tenki_ame"
elif int(str(month_name) + str(day4).zfill(2)) in list_cloudy:
$ tenki4 = "anm_tenki_kumori"
else:
$ tenki4 ="anm_tenki_hare"
#一回元に戻す? 正気か?
$ month_name, day_max = month_information[month]
if day3 > day_max:
$ day3 = 1
$ month_name, day_max = month_information[month+1]
elif day3 > 1 and day3 < 4:
$ month_name, day_max = month_information[month+1]
if int(str(month_name) + str(day3).zfill(2)) in list_rainy:
$ tenki3 = "anm_tenki_ame"
elif int(str(month_name) + str(day3).zfill(2)) in list_cloudy:
$ tenki3 = "anm_tenki_kumori"
else:
$ tenki3 ="anm_tenki_hare"
#一回元に戻す? 正気か?
$ month_name, day_max = month_information[month]
if day2 > day_max:
$ day2 = 1
$ month_name, day_max = month_information[month+1]
elif day2 > 1 and day2 < 3:
$ month_name, day_max = month_information[month+1]
if int(str(month_name) + str(day2).zfill(2)) in list_rainy:
$ tenki2 = "anm_tenki_ame"
elif int(str(month_name) + str(day2).zfill(2)) in list_cloudy:
$ tenki2 = "anm_tenki_kumori"
else:
$ tenki2 ="anm_tenki_hare"
#一回元に戻す? 正気か?
$ month_name, day_max = month_information[month]
if day1 > day_max:
$ day1 = 1
$ month_name, day_max = month_information[month+1]
elif day1 > 1 and day1 < 2:
$ month_name, day_max = month_information[month+1]
if int(str(month_name) + str(day1).zfill(2)) in list_rainy:
$ tenki1 = "anm_tenki_ame"
elif int(str(month_name) + str(day1).zfill(2)) in list_cloudy:
$ tenki1 = "anm_tenki_kumori"
else:
$ tenki1 ="anm_tenki_hare"
#一回元に戻す? 正気か?
$ month_name, day_max = month_information[month]
if today > day_max:#もし当月のmax日付「以上」の時は月初にリセット
$ today = 1
$ month += 1
if month == 12:#もし当月のmax日付かつ12月=12月31日は
$ month_now += 1
if int(str(month) + str(today).zfill(2)) in list_rainy:
$ tenki_today = "anm_tenki_ame"
elif int(str(month) + str(today).zfill(2)) in list_cloudy:
$ tenki_today = "anm_tenki_kumori"
else:
$ tenki_today ="anm_tenki_hare"
if today > 1 and today < 4:
$ month_name, day_max = month_information[month-1]
if day_3 > day_max:
$ day_3 = 1
if day_3 >= 1 and day_3 <= 3:
$ month_name, day_max = month_information[month]
if int(str(month_name) + str(day_3).zfill(2)) in list_rainy:
$ tenki_3 = "anm_tenki_ame"
elif int(str(month_name) + str(day_3).zfill(2)) in list_cloudy:
$ tenki_3 = "anm_tenki_kumori"
else:
$ tenki_3 ="anm_tenki_hare"
if today > 1 and today < 4:
$ month_name, day_max = month_information[month-1]
if day_2 > day_max:
$ day_2 = 1
if day_2 >= 1 and day_2 <= 2:
$ month_name, day_max = month_information[month]
if int(str(month_name) + str(day_2).zfill(2)) in list_rainy:
$ tenki_2 = "anm_tenki_ame"
elif int(str(month_name) + str(day_2).zfill(2)) in list_cloudy:
$ tenki_2 = "anm_tenki_kumori"
else:
$ tenki_2 ="anm_tenki_hare"
if today > 1 and today < 4:
$ month_name, day_max = month_information[month-1]
if day_1 > day_max:
$ day_1 = 1
$ month_name, day_max = month_information[month]
if int(str(month_name) + str(day_1).zfill(2)) in list_rainy:
$ tenki_1 = "anm_tenki_ame"
elif int(str(month_name) + str(day_1).zfill(2)) in list_cloudy:
$ tenki_1 = "anm_tenki_kumori"
else:
$ tenki_1 ="anm_tenki_hare"
$ youbi = str(youbi_list[(num_youbi)%7])#曜日を代入
show screen calendar()
with dissolve
#show text "今日は [month]月[today]日[youbi]曜日。\n月末は[day_max]":
# alpha 0.0
#pause
##日付を番号にした後、祝祭日判定をする##############################
$ year = 2021
$ ymd = int(str(year)+str(month).zfill(2)+str(today).zfill(2))
#"今、年月日は[ymd]です"
if youbi == 5 or youbi == 6:
$ oyasumi = True
elif ymd >= 20210321 and ymd <= 20210410:#京都市は21から10日まで冬休み
$ oyasumi = True
elif ymd >= 20210503 and ymd <= 20210505 :#ゴールデンウィーク
$ oyasumi = True #実際には、5/1が土曜で休み
elif ymd == 20210429:#※4/29は模試があるので休みじゃない
$ oyasumi = False
else:
$ oyasumi = False
pause 1.8
##天気により空背景を変える##############################
if tenki_today == "anm_tenki_kumori":
hide eff_rain
hide eff_rain_mae
with dissolve
scene bg_kumori
with dissolve
elif tenki_today == "anm_tenki_ame":
play sound rain_small
scene bg_kumori with dissolve
show eff_rain
show eff_rain_mae
else:
hide eff_rain
hide eff_rain_mae
play sound suzume
scene bg_aozora
with dissolve
$ num_jikantai = 1 #1=朝
hide screen calendar with Dissolve(0.5)
#call change_status
$ modal_true = True
return
これもう、この時点でめちゃくちゃなので何の参考にもならないと思います。なるとしたら以下、screen部分の見た目くらいでしょうか。
スマホを表示するとかえって「今日」がわかりにくくなるかなーと思ったので、スポットライトっぽい表示にしようと、いい感じの画像を追加したり幅など色々調整を加えつつ……。
#カレンダー+天気表示(アプリ用)############################
screen calendar():
modal modal_true
add "bg_sky_blue":
at transform:
alpha 0.0
linear 0.2 alpha 1.0
hbox: #横に均等に一旦並べる
xpos 0
yalign 0.16
if btn_close:
at transform:
on show:
xoffset -240 #前もって移動しておく
alpha 0.0
linear 0.2 alpha 1.0
else:
at transform:
on show:
alpha 0.0
linear 0.2 alpha 1.0
pause 0.5
linear 0.7 xoffset -240 #表示後に左に移動
vbox:#縦に並べる
style "tenki_vbox"
text "[day_3]":
style "tenki_text"
text youbi_list[(num_youbi - 3)%7]:
style "tenki_youbi_text"
add "[tenki_3]"
vbox:#縦に並べる
style "tenki_vbox"
text "[day_2]":
style "tenki_text"
text youbi_list[(num_youbi - 2)%7]:
style "tenki_youbi_text"
add "[tenki_2]"
vbox:
style "tenki_vbox"
text "[day_1]":
style "tenki_text"
text youbi_list[(num_youbi - 1)%7]:
style "tenki_youbi_text"
add "[tenki_1]"
vbox: #ここがtoday
style "tenki_vbox"
text "[today]":
style "tenki_text"
text youbi_list[(num_youbi)%7]:
style "tenki_youbi_text"
add "[tenki_today]"
vbox:
style "tenki_vbox"
text "[day1]":
style "tenki_text"
text youbi_list[(num_youbi + 1)%7]:
style "tenki_youbi_text"
add "[tenki1]"
vbox:
style "tenki_vbox"
text "[day2]":
style "tenki_text"
text youbi_list[(num_youbi + 2)%7]:
style "tenki_youbi_text"
add "[tenki2]"
vbox:
style "tenki_vbox"
text "[day3]":
style "tenki_text"
text youbi_list[(num_youbi + 3)%7]:
style "tenki_youbi_text"
add "[tenki3]"
vbox:
style "tenki_vbox"
text "[day4]":
style "tenki_text"
text youbi_list[(num_youbi + 4)%7]:
style "tenki_youbi_text"
add "[tenki4]"
vbox:
style "tenki_vbox"
text "[day5]":
style "tenki_text"
text youbi_list[(num_youbi + 5)%7]:
style "tenki_youbi_text"
add "[tenki5]"
vbox:
style "tenki_vbox"
text "[day6]":
style "tenki_text"
text youbi_list[(num_youbi + 6)%7]:
style "tenki_youbi_text"
add "[tenki6]"
add "bg_blue.png":
if btn_close:
at transform:
alpha 0.0
xpos 600
linear 0.2 alpha 0.75
else:
at transform:
alpha 0.0
xpos 480
linear 0.7 xoffset 120 alpha 0.75
add "bg_blue.png":
if btn_close:
at transform:
alpha 0.0
xpos -1440
linear 0.2 alpha 0.75
else:
at transform:
alpha 0.0
xpos -1320
linear 0.7 xoffset -120 alpha 0.75
text "[month]{size=128}月{/size}":
xpos 300
yalign 1.2
text_align 0.5
size 248
color "#fff"
font "GenJyuuGothicL-Medium.ttf"
if btn_close:
at transform:
alpha 0.0
yoffset -150
linear 0.2 alpha 1.0
else:
at transform:
alpha 0.0
pause 1.5
linear 0.5 xoffset 20 yoffset -150 alpha 1.0
if btn_close:
frame:#右上の閉じるボタン##############################
background "ribbon"
xalign 0.97
xsize 100
textbutton "×":
text_size 72
hover_sound "audio/pi.mp3"
activate_sound "audio/piyo.mp3"
text_color "#555555"
text_hover_color "#fff"
keysym('K_q')
action [Hide("calendar"), SetVariable("btn_close", False)]
style tenki_vbox:
spacing -25
xalign 0.5
xsize 240
style tenki_text:
xalign 0.5
text_align 0.5
size 120
color "#fff"
font "GenJyuuGothicL-Medium.ttf"
style tenki_youbi_text:
xalign 0.5
size 42
text_align 0.5
color "#fff"
font "GenJyuuGothicL-Medium.ttf"
image anm_tenki_hare:#個別にアニメさせるのでimageに変更
"icon_tenki_hare_l"
zoom 0.5
xalign 0.5
rotate 0
linear 10 rotate 360
repeat
image anm_tenki_kumori:
"icon_tenki_kumori_l"
zoom 0.5
xalign 0.5
yanchor -0.2
linear 1.5 alpha 0.0
linear 1.5 alpha 1.0
repeat
image anm_tenki_ame:
"icon_tenki_ame_l"
zoom 0.5
xalign 0.5
yanchor -0.2
linear 1.5 alpha 0.0
linear 1.5 alpha 1.0
repeat
transform phone_tenki:
xalign 0.185
ypos 1.0
pause 0.3
easein 0.5 ypos 0.1
##パーティクル系ここから##################################
### 雨
image eff_rain = Fixed(
SnowBlossom("eff_rain1.png", count=30, xspeed=(0, 0), yspeed=(1000, 1200), start=5),
SnowBlossom("eff_rain2.png", count=15, xspeed=(0, 0), yspeed=(1200, 1400), start=2)) #数字を増やすと早く落ちるよ
image eff_rain_mae = SnowBlossom("eff_rain3.png", count=2, xspeed=(0, 0), yspeed=(1800, 2000))
以下、呼び出し部分です。
#スクリプトのほう
##スタートここから#####################################################
label start:
$ ymd = 20210405
$ month = 4
$ month_name = 4
$ today = 5
$ youbi = "月曜"
$ num_youbi = 1
$ jikantai = "PM"
$ num_jikantai = 1
$ oyasumi = True #春休みなので大体True
$ tenki_today = "anm_tenki_hare"
$ month_information={1:(1,31),2:(2,28),3:(3,31),4:(4,30),5:(5,31),6:(6,30),7:(7,31),8:(8,31),9:(9,30),10:(10,31),11:(11,30),12:(12,31)}
$ day_max = 30 #4月なのでとりあえず仮入れ必要
$ day_3 = today - 3
$ day_2 = today - 2
$ day_1 = today - 1
$ day1 = today + 1
$ day2 = today + 2
$ day3 = today + 3
$ day4 = today + 4
$ day5 = today + 5
$ day6 = today + 6
$ tenki_3 = "anm_tenki_hare"
$ tenki_2 = "anm_tenki_hare"
$ tenki_1 = "anm_tenki_hare"
$ tenki1 = "anm_tenki_hare"
$ tenki2 = "anm_tenki_hare"
$ tenki3 = "anm_tenki_hare"
$ tenki4 = "anm_tenki_hare"
$ tenki5 = "anm_tenki_hare"
$ tenki6 = "anm_tenki_hare"
$ youbi_list = ["月","火","水","木","金","土","日"]
$ list_rainy = [416, 417, 420, 428, 429, 505] #この日は雨
$ list_cloudy = [404, 406, 410, 413, 423, 424, 426, 501, 503, 507] #この日は曇り
$ btn_close = False
$ modal_true = True
label start_01:###########################
"1日経過"
window hide
call cal_day
jump start_01
とりあえずこんな感じで動くのだけは確認しました。いやまあ動いてるんですけど、正気か? 鋼の錬金術師でいうところの人体錬成失敗したやつくらいではないか?
上記スクリプトを実際に動かしたものがこちら。
……いやペルソナやないか!!!!
今詳しい方にもうちょっと何とかならんか聞いてるところで、改善できればまたこちらに追記します。
この記事が気に入ったらサポートをしてみませんか?