Created
July 11, 2015 10:22
-
-
Save old-horizon/101cfc586f718c996c25 to your computer and use it in GitHub Desktop.
シューティング基本(DXライブラリサンプルプログラム) by PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# シューティング基本 | |
# (http://homepage2.nifty.com/natupaji/DxLib/dxprogram.html#N5) | |
# スクリプトと同一ディレクトリ内のDXライブラリを読み込む | |
$root = [System.IO.Path]::GetDirectoryName($MyInvocation.InvocationName) | |
Add-Type -Path $([System.IO.Path]::Combine($root, "DxLibDotNet.dll")) | |
# 名前空間を省略 | |
$DX = "DxLibDLL.DX" -as [type] | |
# ショットの最大数 | |
Set-Variable MAX_SHOT 4 -Option Constant | |
$PlayerX, $PlayerY # プレイヤーの位置 | |
$ShotValid = New-Object int[] $MAX_SHOT # ショットが存在するか、フラグ | |
$ShotX = New-Object int[] $MAX_SHOT; $ShotY = New-Object int[] $MAX_SHOT # ショットの位置 | |
function Main | |
{ | |
$Key | |
$OldKey # 前のキー入力状態 | |
$DX::ChangeWindowMode($DX::TRUE) | |
if ($DX::DXLib_Init() -eq -1) # DXライブラリ初期化処理 | |
{ | |
exit # エラーが起きたら直ちに終了 | |
} | |
# 描画先画面を裏画面にセット | |
$DX::SetDrawScreen($DX::DX_SCREEN_BACK) | |
# プレイヤーの初期位置をセット | |
$PlayerX = 320 | |
$PlayerY = 400 | |
# ショットの存在を初期化する | |
for ($i = 0; $i -lt $MAX_SHOT; $i++) | |
{ | |
$ShotValid[$i] = 0 | |
} | |
# ループ | |
while ($DX::ProcessMessage() -eq 0 -and $DX::CheckHitKey($DX::KEY_INPUT_ESCAPE) -eq 0) | |
{ | |
# キー入力取得 | |
$OldKey = $Key | |
$Key = $DX::GetJoyPadInputState($DX::DX_INPUT_KEY_PAD1) | |
if ($Key -band $DX::PAD_INPUT_RIGHT) { $PlayerX += 3 } # 右を押していたら右に進む | |
if ($Key -band $DX::PAD_INPUT_LEFT) { $PlayerX -= 3 } # 左を押していたら左に進む | |
# ショットの移動処理 | |
for ($j = 0; $j -lt $MAX_SHOT; $j++) | |
{ | |
# ショットデータが無効だったらスキップ | |
if ($ShotValid[$j] -eq 0) { continue } | |
# 位置を上にずらす | |
$ShotY[$j] -= 8 | |
# 画面外に出ていたらショットデータを無効化 | |
if ($ShotY[$j] -lt -32) { $ShotValid[$j] = 0 } | |
} | |
# ショットボタンを押していたらショットを出す | |
# 一つ前のループでショットボタンを押していたらショットは出さない | |
if (($Key -band (-bnot $OldKey)) -band $DX::PAD_INPUT_A) | |
{ | |
# 使われていないショットデータを探す | |
for($j = 0; $j -lt $MAX_SHOT; $j++) | |
{ | |
if ($ShotValid[$j] -eq 0 ) { break } | |
} | |
# もし使われていないショットデータがあったらショットを出す | |
if ($j -ne $MAX_SHOT) | |
{ | |
# ショットの位置を設定 | |
$ShotX[$j] = $PlayerX + 16 | |
$ShotY[$j] = $PlayerY | |
# ショットデータを使用中にセット | |
$ShotValid[$j] = 1 | |
} | |
} | |
# 画面を初期化する | |
$DX::ClearDrawScreen() | |
# プレイヤーを描画する | |
$DX::DrawBox($PlayerX, $PlayerY, $PlayerX + 48, $PlayerY + 48, $DX::GetColor(255, 0, 0), $DX::TRUE) | |
# ショットを描画する | |
for ($j = 0; $j -lt $MAX_SHOT; $j++) | |
{ | |
# ショットデータが有効な時のみ描画 | |
if ($ShotValid[$j] -eq 1) | |
{ | |
$DX::DrawBox($ShotX[$j], $ShotY[$j], $ShotX[$j] + 16, $ShotY[$j] + 16, | |
$DX::GetColor(255, 255, 255), $DX::TRUE) | |
} | |
} | |
# 裏画面の内容を表画面に反映させる | |
$DX::ScreenFlip() | |
} | |
$DX::DxLib_End() # DXライブラリ使用の終了処理 | |
} | |
Main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment