{"id":197278,"date":"2013-10-13T15:58:12","date_gmt":"2013-10-13T11:58:12","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=197278"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=197278","title":{"rendered":"<span class=\"post_title\">\u041f\u0438\u0448\u0435\u043c \u0438\u0433\u0440\u044b \u043d\u0430 C++, \u0427\u0430\u0441\u0442\u044c 1\/3 \u2014 \u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u0438\u043d\u0438-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<a href=\"http:\/\/habrahabr.ru\/post\/197280\/\">\u041f\u0438\u0448\u0435\u043c \u0438\u0433\u0440\u044b \u043d\u0430 C++, \u0427\u0430\u0441\u0442\u044c 2\/3 \u2014 State-based \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/a><br \/>  <a href=\"http:\/\/habrahabr.ru\/post\/197288\/\">\u041f\u0438\u0448\u0435\u043c \u0438\u0433\u0440\u044b \u043d\u0430 C++, \u0427\u0430\u0441\u0442\u044c 3\/3 \u2014 \u041a\u043b\u0430\u0441\u0441\u0438\u043a\u0430 \u0436\u0430\u043d\u0440\u0430<\/a><\/p>\n<p>  \u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439, \u0425\u0430\u0431\u0440\u0430\u0445\u0430\u0431\u0440!<\/p>\n<p>  \u041d\u0430 \u0445\u0430\u0431\u0440\u0435 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u043a\u043e\u0432 \u043f\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0438\u0433\u0440, \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043e\u0442\u0435\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0434\u0435\u0432\u0435\u043b\u043e\u043f\u0435\u0440\u043e\u0432?<br \/>  \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u0430\u043c \u0441\u0432\u043e\u0438 \u0443\u0440\u043e\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0447\u0430\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438\u0433\u0440\u044b \u043d\u0430 C++ \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c SDL!<\/p>\n<h4>\u0427\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c<\/h4>\n<p>  <\/p>\n<ul>\n<li>\u0425\u043e\u0442\u044f \u0431\u044b \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u043d\u0438\u044f C++ (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c Visual Studio)<\/li>\n<li>\u0422\u0435\u0440\u043f\u0435\u043d\u0438\u0435<\/li>\n<\/ul>\n<h4>\u041e \u0447\u0435\u043c \u044d\u0442\u0430 \u0447\u0430\u0441\u0442\u044c?<\/h4>\n<p>  <\/p>\n<ul>\n<li>\u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u0430\u0440\u043a\u0430\u0441 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0438\u0433\u0440, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0449\u0438\u043a\u0430 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c SDL. \u042d\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0433\u0440\u0430\u0444\u0438\u043a\u0438.<\/li>\n<\/ul>\n<p>  \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u043e\u0441\u0442\u0430\u0445 \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u044d\u043a\u0448\u0435\u043d\u0430, \u044d\u0442\u043e \u043b\u0438\u0448\u044c \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \ud83d\ude42<\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<h4>\u041f\u043e\u0447\u0435\u043c\u0443 SDL?<\/h4>\n<p>  \u042f \u0432\u044b\u0431\u0440\u0430\u043b \u044d\u0442\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043a\u0430\u043a \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043b\u0435\u0433\u043a\u0443\u044e \u0438 \u0431\u044b\u0441\u0442\u0440\u0443\u044e \u0432 \u043e\u0441\u0432\u043e\u0435\u043d\u0438\u0438. \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e OpenGL \u0438\u043b\u0438 DirectX \u0434\u043e \u0441\u0442\u043e\u0442\u044b\u0441\u044f\u0447\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0438\u0437\u0434\u0430\u043d\u0438\u044f \u0437\u043c\u0435\u0439\u043a\u0438 \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u043d\u0435\u043c\u0430\u043b\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u0430\u0442\u044c.<\/p>\n<h4>1.1. \u041d\u0430\u0447\u0430\u043b\u043e \u043d\u0430\u0447\u0430\u043b<\/h4>\n<p>  \u0421\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c SDL \u0441 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0430\u0439\u0442\u0430.<br \/>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 Win32 \u0432 Visual Studio, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c lib&#8217;\u044b \u0438 includ&#8217;\u044b SDL (\u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0443\u043c\u0435\u0435\u0442\u0435 \u044d\u0442\u043e\u0433\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0442\u043e \u0433\u0443\u0433\u043b \u0432\u0430\u043c \u0432 \u043f\u043e\u043c\u043e\u0449\u044c!)<\/p>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e\u0431\u0430\u0439\u0442\u043d\u0443\u044e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0443 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0434\u0435\u043c \u0432 \u041f\u0440\u043e\u0435\u043a\u0442-&gt;\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430-&gt;\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438-&gt;\u041d\u0430\u0431\u043e\u0440 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432-&gt;\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e\u0431\u0430\u0439\u0442\u043d\u0443\u044e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0443.<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b main.cpp  <\/p>\n<pre><code class=\"cpp\">#include &lt;Windows.h&gt;  int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int) { \treturn 0; } <\/code><\/pre>\n<p>  \u041f\u043e\u043a\u0430 \u0447\u0442\u043e \u043e\u043d \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442.<\/p>\n<p>  \u0426\u0430\u0440\u044c \u0438 \u0431\u043e\u0433 \u043a\u0430\u0440\u043a\u0430\u0441\u0430 \u2014 \u043a\u043b\u0430\u0441\u0441 Game<br \/>  Game.h  <\/p>\n<pre><code class=\"cpp\">#ifndef _GAME_H_ #define _GAME_H_  class Game { private: \tbool run;  public: \tGame(); \tint Execute();  \tvoid Exit(); };  #endif <\/code><\/pre>\n<p>  Game.cpp  <\/p>\n<pre><code class=\"cpp\">#include &quot;Game.h&quot;  Game::Game() { \trun = true; }  int Game::Execute() { \twhile(run); \treturn 0; }  void Game::Exit() { \trun = false; } <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b Project.h, \u043e\u043d \u043d\u0430\u043c \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c  <\/p>\n<pre><code class=\"cpp\">#ifndef _PROJECT_H_ #define _PROJECT_H_  #include &lt;Windows.h&gt;  #include &quot;Game.h&quot;  #endif <\/code><\/pre>\n<p>  \u0418\u0437\u043c\u0435\u043d\u044f\u0435\u043c main.cpp  <\/p>\n<pre><code class=\"cpp\">#include &quot;Project.h&quot;  int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int) { \tGame game; \treturn game.Execute(); } <\/code><\/pre>\n<p>  \u0423\u0436\u0435 \u0447\u0443\u0442\u043e\u0447\u043a\u0443 \u043f\u043e\u043b\u0443\u0447\u0448\u0435, \u043d\u043e \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u043d\u0435 \u0433\u0443\u0441\u0442\u043e.<\/p>\n<h4>1.2. \u0413\u0440\u0430\u0444\u0438\u043a\u0430<\/h4>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0430\u0436 2 \u043a\u043b\u0430\u0441\u0441\u0430 \u2014 Graphics \u0434\u043b\u044f \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u0433\u0440\u0430\u0444\u0438\u043a\u0438 \u0438 Image \u0434\u043b\u044f \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a<\/p>\n<p>  Graphics.h  <\/p>\n<pre><code class=\"cpp\">#ifndef _GRAPHICS_H_ #define _GRAPHICS_H_  #include &quot;Project.h&quot;  #include &quot;Image.h&quot; class Image;  class Graphics { private: \tSDL_Surface* Screen;  public: \tGraphics(int width, int height);  \tImage* NewImage(char* file); \tImage* NewImage(char* file, int r, int g, int b); \tbool DrawImage(Image* img, int x, int y); \tbool DrawImage(Image* img, int x, int y, int startX, int startY, int endX, int endY);  \tvoid Flip(); };  #endif <\/code><\/pre>\n<p>  Image.h  <\/p>\n<pre><code class=\"cpp\">#ifndef _IMAGE_H #define _IMAGE_H  #include &quot;Project.h&quot;  class Image { private: \tSDL_Surface* surf; public: \tfriend class Graphics;  \tint GetWidth(); \tint GetHeight(); };  #endif <\/code><\/pre>\n<p>  \u0418\u0437\u043c\u0435\u043d\u044f\u0435\u043c Project.h  <\/p>\n<pre><code class=\"cpp\">#ifndef _PROJECT_H_ #define _PROJECT_H_  #pragma comment(lib,&quot;SDL.lib&quot;)  #include &lt;Windows.h&gt; #include &lt;SDL.h&gt;  #include &quot;Game.h&quot; #include &quot;Graphics.h&quot; #include &quot;Image.h&quot;  #endif <\/code><\/pre>\n<p>  SDL_Surface \u2014 \u043a\u043b\u0430\u0441\u0441 \u0438\u0437 SDL \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<br \/>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c Graphics<br \/>  NewImage \u2014 \u0435\u0441\u0442\u044c 2 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438. \u041f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0433\u0440\u0443\u0437\u0438\u0442 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443, \u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0435\u0449\u0435 \u0438 \u0434\u0430\u0435\u0442 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435. \u0415\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u043a\u0440\u0430\u0441\u043d\u044b\u0439 \u0444\u043e\u043d \u0432 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435, \u0442\u043e \u0432\u0432\u043e\u0434\u0438\u043c r=255,g=0,b=0<br \/>  DrawImage \u2014 \u0442\u043e\u0436\u0435 2 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438. \u041f\u0435\u0440\u0432\u044b\u0439 \u0440\u0438\u0441\u0443\u0435\u0442 \u0432\u0441\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0446\u0435\u043b\u0438\u043a\u043e\u043c, \u0432\u0442\u043e\u0440\u043e\u0439 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0430\u0441\u0442\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438. startX, startY \u2014 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043d\u0430\u0447\u0430\u043b\u0430 \u0447\u0430\u0441\u0442\u0438 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438. endX, endY \u2014 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0447\u0430\u0441\u0442\u0438 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438. \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0440\u0438\u0441\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0430\u0442\u043b\u0430\u0441\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a. \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0430\u0442\u043b\u0430\u0441\u0430:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/e79\/99b\/f1d\/e7999bf1dc77f727fd70e3e45b75cca1.gif\" alt=\"image\"\/><br \/>  <i>(\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432\u0437\u044f\u0442\u043e \u0438\u0437 \u0432\u0435\u0431-\u0440\u0435\u0441\u0443\u0440\u0441\u0430 interesnoe.info)<\/i><\/p>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c Image<br \/>  \u041e\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0432\u043e\u0439 \u0441\u0443\u0440\u0444\u0435\u0439\u0441 \u0438 \u0434\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0441\u0432\u043e\u0438\u043c \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u043c \u0447\u043b\u0435\u043d\u0430\u043c \u043a\u043b\u0430\u0441\u0441\u0443 Graphics, \u0430 \u043e\u043d \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0443\u0440\u0444\u0435\u0439\u0441.<br \/>  \u041f\u043e \u0441\u0443\u0442\u0438, \u044d\u0442\u043e \u043e\u0431\u0435\u0440\u0442\u043a\u0430 \u043d\u0430\u0434 SDL_Surface. \u0422\u0430\u043a\u0436\u0435 \u043e\u043d \u0434\u0430\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438<\/p>\n<p>  Graphics.cpp  <\/p>\n<pre><code class=\"cpp\">#include &quot;Graphics.h&quot;  Graphics::Graphics(int width, int height) { \tSDL_Init(SDL_INIT_EVERYTHING); \tScreen = SDL_SetVideoMode(width,height,32,SDL_HWSURFACE|SDL_DOUBLEBUF); }  Image* Graphics::NewImage(char* file) { \tImage* image = new Image(); \timage-&gt;surf = SDL_DisplayFormat(SDL_LoadBMP(file));  \treturn image; }  Image* Graphics::NewImage(char* file, int r, int g, int b) { \tImage* image = new Image(); \timage-&gt;surf = SDL_DisplayFormat(SDL_LoadBMP(file));  \tSDL_SetColorKey(image-&gt;surf, SDL_SRCCOLORKEY | SDL_RLEACCEL, \t\tSDL_MapRGB(image-&gt;surf-&gt;format, r, g, b));  \treturn image; }  bool Graphics::DrawImage(Image* img, int x, int y) { \tif(Screen == NULL || img-&gt;surf == NULL)         return false;       SDL_Rect Area;     Area.x = x;     Area.y = y;       SDL_BlitSurface(img-&gt;surf, NULL, Screen, &Area);   \treturn true; }  bool Graphics::DrawImage(Image* img, int x, int y, int startX, int startY, int endX, int endY) { \tif(Screen == NULL || img-&gt;surf == NULL)         return false;       SDL_Rect Area;     Area.x = x;     Area.y = y;      SDL_Rect SrcArea; \tSrcArea.x = startX; \tSrcArea.y = startY; \tSrcArea.w = endX; \tSrcArea.h = endY;  \tSDL_BlitSurface(img-&gt;surf, &SrcArea, Screen, &Area);  \treturn true; }  void Graphics::Flip() { \tSDL_Flip(Screen); \tSDL_FillRect(Screen,NULL, 0x000000); } <\/code><\/pre>\n<p>  \u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f SDL \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u044d\u043a\u0440\u0430\u043d.<br \/>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f Flip \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u043e\u0441\u043b\u0435 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a, \u043e\u043d\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0435\u0435\u0441\u044f \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0438 \u0447\u0438\u0441\u0442\u0438\u0442 \u044d\u043a\u0440\u0430\u043d \u0432 \u0447\u0435\u0440\u043d\u044b\u0439 \u0446\u0432\u0435\u0442 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0448\u043d\u0435\u0439 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438.<br \/>  \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u0430\u043b\u043e\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b, \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0438\u0445 \u0441\u0430\u043c\u043e\u043c\u0443<\/p>\n<p>  Image.cpp  <\/p>\n<pre><code class=\"cpp\">#include &quot;Image.h&quot;  int Image::GetWidth() { \treturn surf-&gt;w; }  int Image::GetHeight() { \treturn surf-&gt;h; } <\/code><\/pre>\n<p>  \u041d\u0435\u0442, \u0432\u044b \u0432\u0441\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0435, \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u0438\u043c \ud83d\ude42<\/p>\n<p>  \u041d\u0430\u0434\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c Game.h, Game.cpp \u0438 main.cpp<br \/>  Game.h  <\/p>\n<pre><code class=\"cpp\">#ifndef _GAME_H_ #define _GAME_H_  #include &quot;Project.h&quot; class Graphics;  class Game { private: \tbool run;  \tGraphics* graphics;  public: \tGame(); \tint Execute(int width, int height);  \tvoid Exit(); };  #endif <\/code><\/pre>\n<p>  \u0422\u0443\u0442 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 Graphics \u0438 \u0432 Execute \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u044d\u043a\u0440\u0430\u043d\u0430<\/p>\n<p>  Game.cpp  <\/p>\n<pre><code class=\"cpp\">#include &quot;Game.h&quot;  Game::Game() { \trun = true; }  int Game::Execute(int width, int height) { \tgraphics = new Graphics(width,height);  \twhile(run); \t \tSDL_Quit(); \treturn 0; }  void Game::Exit() { \trun = false; } <\/code><\/pre>\n<p>  \u041d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e, \u0440\u0430\u0437\u0432\u0435 \u0447\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e SDL_Quit \u0434\u043b\u044f \u043e\u0447\u0438\u0441\u0442\u043a\u0438 SDL<\/p>\n<p>  main.cpp  <\/p>\n<pre><code class=\"cpp\">#include &quot;Project.h&quot;  int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int) { \tGame game; \treturn game.Execute(500,350); } <\/code><\/pre>\n<p>  \u0422\u0443\u0442 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u044d\u043a\u0440\u0430\u043d \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c 500 \u043d\u0430 350.<\/p>\n<h4>1.3. \u0412\u0432\u043e\u0434<\/h4>\n<p>  \u041d\u0430\u0434\u043e \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e \u0432\u0432\u043e\u0434\u043e\u043c \u0441 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c Input.h  <\/p>\n<pre><code class=\"cpp\">#ifndef _INPUT_H_ #define _INPUT_H_  #include &quot;Project.h&quot;  class Input { private: \tSDL_Event evt;  public:     void Update();  \tbool IsMouseButtonDown(byte key); \tbool IsMouseButtonUp(byte key); \tPOINT GetButtonDownCoords();  \tbool IsKeyDown(byte key); \tbool IsKeyUp(byte key); \tbyte GetPressedKey();  \tbool IsExit(); };  #endif <\/code><\/pre>\n<p>  SDL_Event \u2014 \u043a\u043b\u0430\u0441\u0441 \u043a\u0430\u043a\u043e\u0433\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0435\u0433\u043e \u043c\u044b \u0434\u0435\u0440\u0436\u0438\u043c \u0432 Input&#8217;\u0435 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0446\u0438\u043a\u043b<br \/>  \u041d\u0438\u0436\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u043c\u0435\u0442\u043e\u0434\u044b, \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u043e\u0441\u043e\u0431\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0430. \u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u043c\u0435\u0442\u043e\u0434\u044b \u0441 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435\u043c Down \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043a\u043b\u0430\u0432\u0438\u0448\u0430 \u0431\u044b\u043b\u0430 \u043d\u0430\u0436\u0430\u0442\u0430, \u0430 \u0441 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435\u043c Up \u2014 \u043a\u043e\u0433\u0434\u0430 \u043e\u043f\u0443\u0449\u0435\u043d\u0430.<\/p>\n<p>  Input.cpp  <\/p>\n<pre><code class=\"cpp\">#include &quot;Input.h&quot;  void Input::Update() { \twhile(SDL_PollEvent(&evt)); }  bool Input::IsMouseButtonDown(byte key) { \tif(evt.type == SDL_MOUSEBUTTONDOWN) \t\tif(evt.button.button == key) \t\t\treturn true; \treturn false; }  bool Input::IsMouseButtonUp(byte key) { \tif(evt.type == SDL_MOUSEBUTTONUP) \t\tif(evt.button.button == key) \t\t\treturn true; \treturn false; }  POINT Input::GetButtonDownCoords() { \tPOINT point; \tpoint.x = evt.button.x; \tpoint.y = evt.button.y;  \treturn point; }  bool Input::IsKeyDown(byte key) { \treturn (evt.type == SDL_KEYDOWN && evt.key.keysym.sym == key); }  bool Input::IsKeyUp(byte key) { \treturn (evt.type == SDL_KEYUP && evt.key.keysym.sym == key); }  byte Input::GetPressedKey() { \treturn evt.key.keysym.sym; }  bool Input::IsExit() { \treturn (evt.type == SDL_QUIT); } <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0448 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Update, \u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442 \u0442\u0438\u043f \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438 \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u0418\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u0442\u0435\u043f\u0435\u0440\u044c Game.h \u0438 Game.cpp  <\/p>\n<pre><code class=\"cpp\">#ifndef _GAME_H_ #define _GAME_H_  #include &quot;Project.h&quot;  #include &quot;Graphics.h&quot; class Graphics; #include &quot;Input.h&quot; class Input;  class Game { private: \tbool run;  \tGraphics* graphics; \tInput* input;  public: \tGame(); \tint Execute(int width, int height);  \tGraphics* GetGraphics(); \tInput* GetInput();  \tvoid Exit(); };  #endif <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 Input \u0438 \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043c\u0435\u0442\u043e\u0434\u044b-\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u0435\u043b\u0438 Graphics \u0438 Input<\/p>\n<p>  Game.cpp  <\/p>\n<pre><code class=\"cpp\">#include &quot;Game.h&quot;  Game::Game() { \trun = true; }  int Game::Execute(int width, int height) { \tgraphics = new Graphics(width,height); \tinput = new Input();  \twhile(run) \t{ \t\tinput-&gt;Update(); \t} \t \tdelete graphics; \tdelete input;  \tSDL_Quit(); \treturn 0; }  Graphics* Game::GetGraphics() { \treturn graphics; }  Input* Game::GetInput() { \treturn input; }  void Game::Exit() { \trun = false; } <\/code><\/pre>\n<h4>1.4. \u0418\u0442\u043e\u0433\u0438<\/h4>\n<p>  \u042d\u0442\u043e \u0431\u044b\u043b \u043f\u0435\u0440\u0432\u044b\u0439 \u0443\u0440\u043e\u043a. \u0415\u0441\u043b\u0438 \u0432\u044b \u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430, \u044f \u0432\u0430\u0441 \u043f\u043e\u0437\u0434\u0440\u0430\u0432\u043b\u044f\u044e! \u0423 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u043e\u043b\u044f, \u043f\u0440\u0438\u0441\u0443\u0449\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0443 \ud83d\ude42 \u0421\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0443\u0440\u043e\u043a\u0438 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u0435\u0449\u0435 \u043c\u043d\u043e\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e!<\/p>\n<p>  \u041f\u043e \u0432\u0441\u0435\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u0430\u043c \u043e\u0431\u0440\u0430\u0449\u0430\u0439\u0442\u0435\u0441\u044c \u0432 \u041b\u0421, \u0430 \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0435 \u043f\u043e\u0432\u0435\u0437\u043b\u043e \u0431\u044b\u0442\u044c \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043d\u0430 \u0445\u0430\u0431\u0440\u0435, \u043f\u0438\u0448\u0438\u0442\u0435 \u043d\u0430 \u043c\u0435\u0439\u043b izarizar@mail.ru<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/197278\/\"> http:\/\/habrahabr.ru\/post\/197278\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<a href=\"http:\/\/habrahabr.ru\/post\/197280\/\">\u041f\u0438\u0448\u0435\u043c \u0438\u0433\u0440\u044b \u043d\u0430 C++, \u0427\u0430\u0441\u0442\u044c 2\/3 \u2014 State-based \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/a><br \/>  <a href=\"http:\/\/habrahabr.ru\/post\/197288\/\">\u041f\u0438\u0448\u0435\u043c \u0438\u0433\u0440\u044b \u043d\u0430 C++, \u0427\u0430\u0441\u0442\u044c 3\/3 \u2014 \u041a\u043b\u0430\u0441\u0441\u0438\u043a\u0430 \u0436\u0430\u043d\u0440\u0430<\/a><\/p>\n<p>  \u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439, \u0425\u0430\u0431\u0440\u0430\u0445\u0430\u0431\u0440!<\/p>\n<p>  \u041d\u0430 \u0445\u0430\u0431\u0440\u0435 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u043a\u043e\u0432 \u043f\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0438\u0433\u0440, \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043e\u0442\u0435\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0434\u0435\u0432\u0435\u043b\u043e\u043f\u0435\u0440\u043e\u0432?<br \/>  \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u0430\u043c \u0441\u0432\u043e\u0438 \u0443\u0440\u043e\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0447\u0430\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438\u0433\u0440\u044b \u043d\u0430 C++ \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c SDL!<\/p>\n<h4>\u0427\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c<\/h4>\n<p>  <\/p>\n<ul>\n<li>\u0425\u043e\u0442\u044f \u0431\u044b \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u043d\u0438\u044f C++ (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c Visual Studio)<\/li>\n<li>\u0422\u0435\u0440\u043f\u0435\u043d\u0438\u0435<\/li>\n<\/ul>\n<h4>\u041e \u0447\u0435\u043c \u044d\u0442\u0430 \u0447\u0430\u0441\u0442\u044c?<\/h4>\n<p>  <\/p>\n<ul>\n<li>\u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u0430\u0440\u043a\u0430\u0441 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0438\u0433\u0440, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0449\u0438\u043a\u0430 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c SDL. \u042d\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0433\u0440\u0430\u0444\u0438\u043a\u0438.<\/li>\n<\/ul>\n<p>  \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u043e\u0441\u0442\u0430\u0445 \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u044d\u043a\u0448\u0435\u043d\u0430, \u044d\u0442\u043e \u043b\u0438\u0448\u044c \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \ud83d\ude42<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-197278","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/197278","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=197278"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/197278\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=197278"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=197278"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=197278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}