今回はWindows専用ではありますが、DxLibを使った簡易デスクトップキャラクターアプリを載せました。また、環境はWindows10、Atom、MSYS2(MinGW64)、g++(7.3.0)、Gnu Make(4.2.1)ってかんじです。
下の画像にある通り、PlantUMLを使った簡単なクラス図?も作ってみました。(楽しい!)
Character.h
#ifndef INCLUDE_CHARACTER_H
#define INCLUDE_CHARACTER_H
enum Actions {
None,
Blink,
Surprised,
Callout,
};
class Character {
private:
int graphHandle[12], callout;
int Counter;
int sdNum;
int AnimeLoop;
bool isCallout;
Actions ActType;
void GetAction();
public:
Character();
~Character();
void Update();
void Draw();
};
#endif /* end of include guard: INCLUDE_CHARACTER_H */
Screen.h
#include <windows.h>
#ifndef INCLUDE_SCREEN_H
#define INCLUDE_SCREEN_H
class Screen {
private:
bool StartFlag_L;
POINT StartCursorPos, NowCursorPos, StartWindowPos;
void MoveWindow();
void ContextMenu();
public:
Screen();
void Update();
};
#endif /* end of include guard: INCLUDE_SCREEN_H */
Input.h
#ifndef INCLUDE_INPUT_H
#define INCLUDE_INPUT_H
extern int Key[256];
enum MouseCondition {
Click_L,
Click_R,
NoClick,
};
int UpdateKey();
int mouseClick();
#endif /* end of include guard: INCLUDE_INPUT_H */
Config.h
#ifndef INCLUDE_CONFIG_H #define INCLUDE_CONFIG_H int setup(); #endif /* end of include guard: INCLUDE_CONFIG_H */
DesktopChara.cpp
#include "Character.h"
#include "Screen.h"
#include "Config.h"
#include "Input.h"
#include <windows.h>
#include "DxLib.h"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
if (setup() != 0) return -1;
Character chara;
Screen sc;
while (DxLib::ScreenFlip() == 0 && DxLib::ProcessMessage() == 0 &&
DxLib::ClearDrawScreen() == 0 && UpdateKey() == 0 && Key[KEY_INPUT_ESCAPE] == 0) {
chara.Update();
chara.Draw();
sc.Update();
}
DxLib::DxLib_End();
return 0;
}
PlantUML

適当です。
WinMain関数のないC++ファイルはここでは省略します。気になったら、こちらからクローンしてみてください。
投稿者:88IO

コメント