Magic_Game/Demo/main.cpp

54 lines
890 B
C++
Raw Normal View History

2017-10-13 11:42:36 +08:00
#include "..\Easy2D\easy2d.h"
2017-10-14 01:07:34 +08:00
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
2017-10-13 11:42:36 +08:00
{
EApp app;
2017-10-14 01:07:34 +08:00
if (app.init(L"Easy2D Demo", 640, 480, true))
2017-10-13 11:42:36 +08:00
{
auto scene = new EScene();
auto node = new ENode();
node->setPos(50, 80);
node->setSize(30, 180);
scene->add(node);
2017-10-14 10:02:15 +08:00
auto listener = new EMouseClickListener([=](EPoint) {
if (EMouseMsg::getMsg() == EMouseMsg::MOUSE_MSG::MOVE)
2017-10-13 17:14:00 +08:00
{
2017-10-14 10:02:15 +08:00
node->setPos(EMouseMsg::getPos());
2017-10-13 17:14:00 +08:00
}
2017-10-14 10:02:15 +08:00
});
2017-10-13 20:16:31 +08:00
auto listener = new EKeyPressListener([=] {
if (EKeyMsg::isCapitalLockOn())
{
if (EKeyMsg::getVal() == EKeyMsg::KEY::LEFT)
{
node->move(-3, 0);
}
if (EKeyMsg::getVal() == EKeyMsg::KEY::RIGHT)
{
node->move(3, 0);
}
}
2017-10-13 17:14:00 +08:00
});
2017-10-14 01:07:34 +08:00
listener->bindWithNode(node);
2017-10-14 10:02:15 +08:00
scene->bindListener(listener);
2017-10-13 17:14:00 +08:00
2017-10-13 11:42:36 +08:00
app.enterScene(scene);
app.run();
}
return 0;
}