LuaTest - Lua側のソース

-- Project      LuaTest
-- Source       pad.lua
-- Date         08/03/17
-- Author       yamahara
-- Environment  Bcc++ & DXライブラリ & Lua
-- Etc          Copyright(C) 2008 sansuido. All rights reserved.

function pressA() return cppPadIsPressA(DID) end
function pushA() return cppPadIsPushA(DID) end
function pressB() return cppPadIsPressB(DID) end
function pushB() return cppPadIsPushB(DID) end
function pressUP() return cppPadIsPressUP(DID) end
function pushUP() return cppPadIsPushUP(DID) end
function pressDOWN() return cppPadIsPressDOWN(DID) end
function pushDOWN() return cppPadIsPushDOWN(DID) end
function pressLEFT() return cppPadIsPressLEFT(DID) end
function pushLEFT() return cppPadIsPushLEFT(DID) end
function pressRIGHT() return cppPadIsPressRIGHT(DID) end
function pushRIGHT() return cppPadIsPushRIGHT(DID) end
-- Project      LuaTest
-- Source       player.lua
-- Date         08/03/17
-- Author       yamahara
-- Environment  Bcc++ & DXライブラリ & Lua
-- Etc          Copyright(C) 2008 sansuido. All rights reserved.

function player_init(
        MID
        )
        
        cppMoverSet(MID, 100, 100, 1, 0)
        
        return
end

function player_draw(
        MID
        )
        
        -- 本来、angleは画像の向きに使うが、
        -- ここでは、枚数指定として使用
        local   x, y, exp, angle = cppMoverGet(MID)
        cppDrawGraph(DID, x, y, exp, 0,
                "test", angle)
        
        return
end

function player_exec(
        MID
        )
        
        local   xcalc, ycalc
        local   angle = cppMoverGetAngle(MID)
        local   speed = 5
        
        xcalc = 0
        ycalc = 0
        -- cppPadPressUPでも良いが、
        -- pad.luaで簡易な関数を作っておいたのでそちらを利用
        if pressUP() then
                ycalc = speed * -1
                angle = 0
        end
        
        if pressDOWN() then
                ycalc = speed * 1
                angle = 2
        end
        
        if pressLEFT() then
                xcalc = speed * -1
                angle = 1
        end
        
        if pressRIGHT() then
                xcalc = speed * 1
                angle = 3
        end
        
        cppMoverCalc(MID, xcalc, ycalc)
        cppMoverSetAngle(MID, angle)
        
        return
end
-- Project      LuaTest
-- Source       luatest.lua
-- Date         08/03/17
-- Author       yamahara
-- Environment  Bcc++ & DXライブラリ & Lua
-- Etc          Copyright(C) 2008 sansuido. All rights reserved.

require "pad"
require "player"

--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-
-- 変数の説明
--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-

-- [DID]
-- データIDです
-- 毎回渡すのも面倒なので「大域変数」になってます
-- というか、ぶっちゃけ、cpp側のデータポインタです
-- グラフィックの処理時等に要求されます

--------------------------------
-- [MID]
--------------------------------
-- 移動用IDです
-- 引数で渡ってきます
-- moverの処理時に要求されます

--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-
-- 定義関数
--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-

--------------------------------
-- cppMoverGet(MID)

-- return x, y, exp, angle
--------------------------------

-- moverの明細をゲットします

--------------------------------
-- cppMoverSet(MID, x, y, exp, angle)

-- return
--------------------------------

-- moverの情報をセットします

--------------------------------
-- cppMoverCalc(MID, xcalc, ycalc)

-- return x, y
--------------------------------

-- moverの位置を移動させます
-- 戻り値で、計算結果を取得できます

--------------------------------
-- cppMoverGetTimer(MID)

-- return timer
--------------------------------

-- moverのタイマーをゲットします

--------------------------------
-- cppDrawGraph(DID, x, y, exp, angle, key, no)

-- return stat
--------------------------------

-- 画像を画面に描画します
-- expは拡大率(1.0で1倍)
-- angleは向きです
-- key はimageフォルダ内のファイル名を指定します
-- noは分割位置です

-- 例えば、(x=128,y=64)の画像を(x=32,y=32)にて分割した場合

-- [_][_][_][_]
-- [_][_][_][_]

-- という、8つのセルになります

-- [0][1][2][3]
-- [4][5][6][7]

-- というナンバーの振り方になります
-- 上の場合、noの有効指定範囲は(0〜7)となります

-- 戻り値の結果が-1の場合、描画に失敗しています

--------------------------------
-- cppPadIsPressA(DID)
-- cppPadIsPushA(DID)
-- cppPadIsPressB(DID)
-- cppPadIsPushB(DID)
-- cppPadIsPressUP(DID)
-- cppPadIsPushUP(DID)
-- cppPadIsPressDOWN(DID)
-- cppPadIsPushDOWN(DID)
-- cppPadIsPressLEFT(DID)
-- cppPadIsPushLEFT(DID)
-- cppPadIsPressRIGHT(DID)
-- cppPadIsPushRIGHT(DID)

-- return bool (true or false)
--------------------------------

-- 各種ボタン押しを取得します
-- [Press]は、押しっぱなし
-- [Push]は、一回目に押されたボタンだけを取得します
-- [A]は、Aボタン キーボードではZです
-- [B]は、Bボタン キーボードではXです
-- [UP][DOWN][LEFT][RIGHT]は、
-- パッドかキーボードの↑↓←→です

-- 戻り値は、boolを取得します

-- pad.luaには、サンプルとして、padの簡易関数を書いておきました