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-14 16:39:24 +08:00
|
|
|
|
#include "time.h"
|
2018-11-21 19:24:18 +08:00
|
|
|
|
#include "window.h"
|
2018-11-21 16:26:52 +08:00
|
|
|
|
#include "render.h"
|
2018-11-21 19:24:18 +08:00
|
|
|
|
#include "input.h"
|
|
|
|
|
|
#include "audio.h"
|
2018-11-22 19:31:44 +08:00
|
|
|
|
#include "Event.hpp"
|
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
|
|
|
|
|
|
{
|
2018-11-21 16:26:52 +08:00
|
|
|
|
String title; // <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
int width; // <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
int height; // <20>߶<EFBFBD>
|
|
|
|
|
|
LPCWSTR icon; // ͼ<><CDBC>
|
2018-11-21 19:24:18 +08:00
|
|
|
|
bool vsync; // <20><>ֱͬ<D6B1><CDAC>
|
2018-11-21 16:26:52 +08:00
|
|
|
|
bool debug; // <20><><EFBFBD><EFBFBD>ģʽ
|
|
|
|
|
|
|
2018-11-12 20:46:54 +08:00
|
|
|
|
Options()
|
|
|
|
|
|
: title(L"Easy2D Game")
|
|
|
|
|
|
, width(640)
|
|
|
|
|
|
, height(480)
|
|
|
|
|
|
, icon(nullptr)
|
2018-11-21 19:24:18 +08:00
|
|
|
|
, vsync(true)
|
2018-11-12 20:46:54 +08:00
|
|
|
|
, 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
|
|
|
|
|
2018-11-22 19:31:44 +08:00
|
|
|
|
// <20>˳<EFBFBD><CBB3><EFBFBD>Ϸ
|
2018-11-08 21:39:26 +08:00
|
|
|
|
virtual void OnExit() {}
|
|
|
|
|
|
|
2018-11-22 19:31:44 +08:00
|
|
|
|
// <20><><EFBFBD>ڹر<DAB9>
|
2018-11-08 21:39:26 +08:00
|
|
|
|
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-22 19:31:44 +08:00
|
|
|
|
void EnterScene(
|
2018-11-14 16:39:24 +08:00
|
|
|
|
spScene const& scene /* <20><><EFBFBD><EFBFBD> */
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
|
2018-11-22 19:31:44 +08:00
|
|
|
|
void EnterScene(
|
2018-11-14 16:39:24 +08:00
|
|
|
|
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-21 19:24:18 +08:00
|
|
|
|
// <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>
|
|
|
|
|
|
void SetTimeScale(float scale);
|
|
|
|
|
|
|
2018-11-19 17:56:17 +08:00
|
|
|
|
private:
|
2018-11-22 19:31:44 +08:00
|
|
|
|
void Render(HWND);
|
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
|
|
|
|
|
2018-11-22 19:31:44 +08:00
|
|
|
|
bool HandleMessage(
|
|
|
|
|
|
HWND hwnd,
|
|
|
|
|
|
UINT msg,
|
|
|
|
|
|
WPARAM wparam,
|
|
|
|
|
|
LPARAM lparam
|
2018-11-14 16:39:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
void Dispatch(
|
2018-11-22 19:31:44 +08:00
|
|
|
|
Event* event
|
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-22 19:31:44 +08:00
|
|
|
|
bool debug_;
|
|
|
|
|
|
bool active_;
|
2018-11-21 19:24:18 +08:00
|
|
|
|
float time_scale_;
|
2018-11-14 01:34:41 +08:00
|
|
|
|
spScene curr_scene_;
|
|
|
|
|
|
spScene next_scene_;
|
|
|
|
|
|
spTransition transition_;
|
2018-11-08 21:39:26 +08:00
|
|
|
|
};
|
|
|
|
|
|
}
|