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.
|
|
|
|
|
|
|
2018-11-08 21:39:26 +08:00
|
|
|
|
#pragma once
|
2018-11-16 15:53:39 +08:00
|
|
|
|
#include "base.hpp"
|
2018-11-08 21:39:26 +08:00
|
|
|
|
#include "window.h"
|
2018-11-14 16:39:24 +08:00
|
|
|
|
#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)
|
|
|
|
|
|
{}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-08 21:39:26 +08:00
|
|
|
|
class Game
|
2018-11-17 23:24:16 +08:00
|
|
|
|
: protected Noncopyable
|
2018-11-08 00:21:59 +08:00
|
|
|
|
{
|
2018-11-08 21:39:26 +08:00
|
|
|
|
public:
|
|
|
|
|
|
Game();
|
|
|
|
|
|
|
2018-11-14 01:34:41 +08:00
|
|
|
|
Game(
|
|
|
|
|
|
Options const& options
|
|
|
|
|
|
);
|
2018-11-08 21:39:26 +08:00
|
|
|
|
|
2018-11-14 01:34:41 +08:00
|
|
|
|
virtual ~Game();
|
2018-11-08 21:39:26 +08:00
|
|
|
|
|
|
|
|
|
|
// <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>
|
2018-11-14 01:34:41 +08:00
|
|
|
|
void Init(
|
|
|
|
|
|
Options const& options
|
2018-11-08 00:21:59 +08:00
|
|
|
|
);
|
2018-09-02 14:30:48 +08:00
|
|
|
|
|
2018-11-08 21:39:26 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
void Run();
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
void Quit();
|
|
|
|
|
|
|
|
|
|
|
|
// <20>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
|
2018-11-14 16:39:24 +08:00
|
|
|
|
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
|
|
|
|
|
2018-11-08 21:39:26 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
2018-11-14 01:34:41 +08:00
|
|
|
|
spScene const& GetCurrentScene();
|
2018-10-15 20:16:08 +08:00
|
|
|
|
|
2018-11-19 17:56:17 +08:00
|
|
|
|
private:
|
|
|
|
|
|
void Render();
|
2018-09-04 22:42:34 +08:00
|
|
|
|
|
2018-11-19 17:56:17 +08:00
|
|
|
|
void Update();
|
2018-11-14 16:39:24 +08:00
|
|
|
|
|
|
|
|
|
|
void Dispatch(
|
|
|
|
|
|
MouseEvent const& e
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
void Dispatch(
|
|
|
|
|
|
KeyEvent const& e
|
2018-11-08 21:39:26 +08:00
|
|
|
|
);
|
2018-10-03 18:04:04 +08:00
|
|
|
|
|
2018-11-19 17:56:17 +08:00
|
|
|
|
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
|
|
|
|
|
|
2018-11-08 21:39:26 +08:00
|
|
|
|
private:
|
2018-11-14 01:34:41 +08:00
|
|
|
|
bool initialized_;
|
|
|
|
|
|
bool debug_enabled_;
|
|
|
|
|
|
bool quit_;
|
2018-11-19 17:56:17 +08:00
|
|
|
|
bool window_inactived_;
|
|
|
|
|
|
HWND hwnd_;
|
2018-11-14 01:34:41 +08:00
|
|
|
|
spScene curr_scene_;
|
|
|
|
|
|
spScene next_scene_;
|
|
|
|
|
|
spTransition transition_;
|
2018-11-08 21:39:26 +08:00
|
|
|
|
};
|
|
|
|
|
|
}
|