ConsoleGameEngine

Форк
0
80 строк · 1.3 Кб
1
#define CGE_IMPL
2
#include "ConsoleGameEngine.hpp"
3

4
#include "escapi.h"
5

6
constexpr int nVariates = 16;
7

8
class Example : public ConsoleGameEngine
9
{
10
public:
11
	Example()
12
	{
13
		sAppName = L"Example";
14
		sFont = L"Times New Roman";
15
	}
16

17
	SimpleCapParams capture;
18
	int nCameras;
19

20
private:
21
	union Color
22
	{
23
		int rgb;
24
		uint8_t c[4];
25
	};
26

27
protected:
28
	bool OnUserCreate() override
29
	{
30
		nCameras = setupESCAPI();
31

32
		if (nCameras == 0)
33
			return false;
34

35
		capture.mWidth = ScreenWidth();
36
		capture.mHeight = ScreenHeight();
37
		capture.mTargetBuf = new int[capture.mWidth * capture.mHeight];
38

39
		if (initCapture(0, &capture) == 0)
40
			return false;
41

42
		return true;
43
	}
44

45
	bool OnUserUpdate(float fDeltaTime) override
46
	{
47
		doCapture(0);
48
		while (isCaptureDone(0) == 0) {}
49

50
		for (int x = 0; x < ScreenWidth(); x++)
51
			for (int y = 0; y < ScreenHeight(); y++)
52
			{
53
				// Get a pixel
54

55
				Color pixel;
56
				pixel.rgb = capture.mTargetBuf[y * ScreenWidth() + x];
57

58
				// Convert to the Command Prompt pixel analogue
59

60
				float fLuminance = (0.2987 * pixel.c[2] + 0.587 * pixel.c[1] + 0.114 * pixel.c[0]) / 255.0 * nVariates;
61

62
				wchar_t c = (int)fLuminance + 'A';
63

64
				// Display the pixel
65
				Draw(x, y, c, FG_WHITE);
66
			}
67

68
		return true;
69
	}
70
};
71

72
int main()
73
{
74
	Example demo;
75

76
	if (demo.ConstructConsole(256, 240, 4, 4) == rcode::OK)
77
		demo.Run();
78

79
	return 0;
80
}
81

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.