Magic_Game/core/base/Game.h

116 lines
2.4 KiB
C
Raw Normal View History

2018-10-03 22:02:46 +08:00
// Copyright (c) 2016-2018 Easy2D - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
2018-11-16 15:53:39 +08:00
#include "base.hpp"
#include "window.h"
#include "time.h"
#include "KeyEvent.h"
#include "MouseEvent.h"
2018-09-02 14:30:48 +08:00
2018-11-08 00:21:59 +08:00
namespace easy2d
2018-09-02 14:30:48 +08:00
{
2018-11-12 20:46:54 +08:00
struct Options
{
String title; /* <20><><EFBFBD><EFBFBD> */
int width; /* <20><><EFBFBD><EFBFBD> */
int height; /* <20>߶<EFBFBD> */
LPCWSTR icon; /* ͼ<><CDBC> */
bool debug; /* <20><><EFBFBD><EFBFBD>ģʽ */
Options()
: title(L"Easy2D Game")
, width(640)
, height(480)
, icon(nullptr)
, debug(false)
{}
};
class Game
2018-11-08 00:21:59 +08:00
{
2018-11-12 20:46:54 +08:00
E2D_DISABLE_COPY(Game);
public:
Game();
Game(
Options const& options
);
virtual ~Game();
// <20>˳<EFBFBD>ʱ
virtual void OnExit() {}
// <20><><EFBFBD>ڹر<DAB9>ʱ
// <20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <20><><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD>ڹر<DAB9>
virtual bool OnClose() { return true; }
// <20><>ʼ<EFBFBD><CABC>
void Init(
Options const& options
2018-11-08 00:21:59 +08:00
);
2018-09-02 14:30:48 +08:00
// <20><><EFBFBD><EFBFBD>
void Run();
// <20><><EFBFBD><EFBFBD>
void Quit();
// <20>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
bool EnterScene(
spScene const& scene /* <20><><EFBFBD><EFBFBD> */
);
// <20>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
bool EnterScene(
spScene const& scene, /* <20><><EFBFBD><EFBFBD> */
spTransition const& transition /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
2018-11-08 00:21:59 +08:00
);
2018-09-02 14:30:48 +08:00
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
spScene const& GetCurrentScene();
void DrawScene();
2018-09-04 22:42:34 +08:00
void UpdateScene(
Duration const& dt
);
void Dispatch(
MouseEvent const& e
);
void Dispatch(
KeyEvent const& e
);
2018-10-03 18:04:04 +08:00
private:
bool initialized_;
bool debug_enabled_;
bool quit_;
spScene curr_scene_;
spScene next_scene_;
spTransition transition_;
};
}