メモメモ ...〆(・_・)
投稿者:
きゅうり
投稿日:2012/12/30 21:38
基本的にゲームを作り始める時に書くスクリプトをメモ。
くっつけてみた。
FPS管理のスクリプトをWikiからお借りしたver.
Q.なんでtrueじゃなくて1なんですか?
A.入力を簡潔にする為。ほぼどっちでも同じですが。
UやD、L、Rとかも同じです。
ちなみにこれをコピペしただけでは何も動作しません。
ツイート
startInput()
minloop = 1
while minloop == 1
while hasInput()
takeInput()
if
end
end
waitTime(30)
end
endInput()
goEnding()
#-----関数設定----- def gHyoji(g_id,m_x,m_y,m_w,m_h,s_x,s_y,s_w,s_h,g_x,g_y,g_kai,g_z) s_id = createSprite(g_id) setSpriteRect(s_id, m_x, m_y, m_w, m_h, s_x, s_y, s_w, s_h) setSpritePosition(s_id, g_x, g_y) setSpriteRotation(s_id, g_kai) setSpriteZOrder(s_id, g_z) return s_id end def txtHyoji(x,y,w,h,txt) txt_id = createText(x, y, w, h) setText(txt_id, txt) return txt_id end
くっつけてみた。
#-----初期設定-----
#メニュー類
setMenuItemVisible(getMenuBackLog(), false)
setMenuItemVisible(getMenuHideWindow(), false)
setMenuItemVisible(getMenuSave(), false)
setMenuItemVisible(getMenuLoad(), false)
setMenuOpenKeyEnable(false)
#変数類
co = 1#画像更新時に1にする 更新の「こ」(co)
L = 0#左キーが押されてる間は1
R = 0#右(ry
U = 0#上(ry
D = 0#下(ry
#-----関数設定-----
def gHyoji(g_id,m_x,m_y,m_w,m_h,s_x,s_y,s_w,s_h,g_x,g_y,g_kai,g_z)
s_id = createSprite(g_id)
setSpriteRect(s_id, m_x, m_y, m_w, m_h, s_x, s_y, s_w, s_h)
setSpritePosition(s_id, g_x, g_y)
setSpriteRotation(s_id, g_kai)
setSpriteZOrder(s_id, g_z)
return s_id
end
def txtHyoji(x,y,w,h,txt)
txt_id = createText(x, y, w, h)
setText(txt_id, txt)
return txt_id
end
#画像類
setCanvasVisible(true)
#----メインループ----
startInput()
minloop = 1
while minloop == 1
while hasInput()
takeInput()
if isKeyDown("LEFT")
L = 1
elsif isKeyUp("LEFT")
L = 0
elsif isKeyDown("RIGHT")
R = 1
elsif isKeyUp("RIGHT")
R = 0
elsif isKeyDown("UP")
U = 1
elsif isKeyUp("UP")
U = 0
elsif isKeyDown("DOWN")
D = 1
elsif isKeyUp("DOWN")
D = 0
end
#-----いろいろ実行-----
#--------------------
if co == 1
drawCanvas()
co = 0
end
end
waitTime(30)
end
FPS管理のスクリプトをWikiからお借りしたver.
# ----- 初期設定 -----
# - メニュー類
setMenuItemVisible(getMenuBackLog(), false)
setMenuItemVisible(getMenuHideWindow(), false)
setMenuItemVisible(getMenuSave(), false)
setMenuItemVisible(getMenuLoad(), false)
setMenuOpenKeyEnable(false)
# ----- 変数の設定 -----
# - FPS関係
fps = 0
fpscount = 0
oldfpstime = 0
draw_setting = 50 #ゲームのメイン処理実行タイミングを設定(ミリ秒)
draw_count = 0
olddrawtime = 0
draw_flg = false
# - キー関係
L = 0#左キーが押されてる間は1
R = 0#右(ry
U = 0#上(ry
D = 0#下(ry
# ----- 関数設定 -----
def gHyoji(g_id,m_x,m_y,m_w,m_h,s_x,s_y,s_w,s_h,g_x,g_y,g_kai,g_z)
s_id = createSprite(g_id)
setSpriteRect(s_id, m_x, m_y, m_w, m_h, s_x, s_y, s_w, s_h)
setSpritePosition(s_id, g_x, g_y)
setSpriteRotation(s_id, g_kai)
setSpriteZOrder(s_id, g_z)
return s_id
end
def txtHyoji(x,y,w,h,txt)
txt_id = createText(x, y, w, h)
setText(txt_id, txt)
return txt_id
end
# - 画像類
setCanvasVisible(true)
# ----- メインループ -----
setBaseTime() #時間計測の開始
startInput() #入力受付の開始
minloop = 1
while minloop == 1
#----- FPSの計測と判定 -----
timer = getTime() #差分の時間を取得
fps = fps + 1 #FPSのカウント
fpscount = timer - oldfpstime
if fpscount < (draw_setting * fps)
draw_flg = true #最低限のFPSを満たしている場合描画OK
else
#最低限のFPSを満たしていない場合、前回描画したかどうか
if draw_flg
draw_flg = false
else
draw_flg = true
end
end
if fpscount > 999
#1秒を超えたらFPSのカウントをリセットする
fps = 0
oldfpstime = timer
fpscount = fpscount % 1000
end
#----- ゲームのメイン処理実行判定 -----
draw_count = timer - olddrawtime #メイン処理実行タイミングのカウント
if draw_setting < draw_count
#ゲームのメイン処理実行タイミングになっていたら、カウントをリセットする
olddrawtime = timer
draw_count = draw_count % draw_setting
while hasInput()
takeInput()
if isKeyDown("LEFT")
L = 1
elsif isKeyUp("LEFT")
L = 0
elsif isKeyDown("RIGHT")
R = 1
elsif isKeyUp("RIGHT")
R = 0
elsif isKeyDown("UP")
U = 1
elsif isKeyUp("UP")
U = 0
elsif isKeyDown("DOWN")
D = 1
elsif isKeyUp("DOWN")
D = 0
end
end
#----- ゲームのメイン処理を入れる場所 -----
#(ゲームの終了時はmainloopをfalseに)
if draw_flg
drawCanvas() #描画OKならキャンバスを更新
end
else
waitTime(1) #ゲームのメイン処理実行タイミングになるまで保留
end
end
endInput() #入力受付の終了
Q.なんでtrueじゃなくて1なんですか?
A.入力を簡潔にする為。ほぼどっちでも同じですが。
UやD、L、Rとかも同じです。
ちなみにこれをコピペしただけでは何も動作しません。
コメントする
コメントするには、ログインする必要があります。
気になるとか。
すいません、入れました。