LuaTest - data.h

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

#ifndef         DATA_DEF
#define         DATA_DEF

#include        <DxLib.h>
#include        <string>
#include        <vector>
#include        <map>
#include        "lua\lua.hpp"

#include        "lua.h"
#include        "graph.h"
#include        "mover.h"
#include        "player.h"
#include        "pad.h"

class Data {

private:
        int     nowCount_;
        int     timer_;
        
public:
        Lua     lua;
        
        Data() : nowCount_(0), timer_(0) {}
        virtual ~Data() {}
        MapGraph        mapGraph;
        Player          player;
        Pad             pad;
        
        virtual int     open()
                // オープン
        {
                
                lua.open(this);
                
                SetMainWindowText("LuaTest");
                SetGraphMode(640, 480, 16);
                ChangeWindowMode(TRUE);
                SetOutApplicationLogValidFlag(FALSE);
                
                // DXライブラリ開始
                if (DxLib_Init()) return -1;
                SetDrawScreen(DX_SCREEN_BACK);
                
                // Data内初期化
                nowCount_ = GetNowCount();
                timer_ = 0;
                
                // テスト画像格納フォルダ
                mapGraph.load(".\\image");
                
                // 初期位置指定(Luaから取得)
                player.init(&lua);
                
                pad.setInputPre(GetJoypadInputState(DX_INPUT_KEY_PAD1));
                
                return 0;
        }
        
        virtual void    close()
                // クローズ
        {
                
                DxLib_End();
                lua.close();
        }
        
        
        virtual void    prev()
                // ループ内前処理
        {
                
                pad.setInput(GetJoypadInputState(DX_INPUT_KEY_PAD1));
        }
        
        
        virtual void    post()
                // ループ内後処理
        {
                
                pad.setInputPre(pad.getInput());
                
                // なんちゃってfps60
                while (GetNowCount() - nowCount_ < 17);
                timer_++;
        }
        
        virtual void    draw()
                // 描画
        {
                
                player.draw(&lua);
        }
        
        virtual int     exec()
                // 実行
        {
                
                player.exec(&lua);
                
                return 0;
        }
};

#endif