添加资源文件,添加项目文件,初次编译通过

This commit is contained in:
Kirigaya Kazuto 2017-05-18 13:07:33 +08:00
parent 6e60fbfd6b
commit 6ded19818a
47 changed files with 627 additions and 8 deletions

2
.gitignore vendored
View File

@ -246,3 +246,5 @@ ModelManifest.xml
# FAKE - F# Make
.fake/
*.ttf
*.txt

View File

@ -1,11 +1,22 @@
// BattleGame.cpp : 定义控制台应用程序的入口点。
//
#include "MiniEngine/MiniEngine.h"
using namespace MiniEngine;
#include "stdafx.h"
#include "global.h"
#include "Game.h"
char timebuff[128];
int main()
int AppMain()
{
return 0;
sprintf(timebuff, "BattleGame BuildTime(%s %s)", __DATE__, __TIME__);
Window wnd(timebuff, 1024, 768);
Renderer rnd = wnd.getRenderer();
Font font("msyh.ttf", 18);
global.wnd = &wnd;
global.rnd = &rnd;
global.font = &font;
global.frame = new Frame;
GameMain();
return 0;
}

View File

@ -83,15 +83,18 @@
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>D:\VisualStudio2015\BattleGame\BattleGame;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>SDL2.lib;SDL2main.lib;SDL2test.lib;SDL2_ttf.lib;SDL2_image.lib;SDL2_mixer.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>D:\VisualStudio2015\BattleGame\BattleGame\SDL2lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -145,22 +148,35 @@
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Button.h" />
<ClInclude Include="Env.h" />
<ClInclude Include="Game.h" />
<ClInclude Include="global.h" />
<ClInclude Include="MapEditor.h" />
<ClInclude Include="MiniEngine\MiniEngine.h" />
<ClInclude Include="MiniEngine\MiniEngine_Event.h" />
<ClInclude Include="Scene.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="UnitInit.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="BattleGame.cpp" />
<ClCompile Include="Button.cpp" />
<ClCompile Include="Game.cpp" />
<ClCompile Include="global.cpp" />
<ClCompile Include="MapEditor.cpp" />
<ClCompile Include="MiniEngine\MiniEngine.cpp" />
<ClCompile Include="MiniEngine\MiniEngine_Event.cpp" />
<ClCompile Include="MiniEngine\MiniEngine_Windows.cpp" />
<ClCompile Include="Scene.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="UnitInit.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -30,6 +30,27 @@
<ClInclude Include="MiniEngine\MiniEngine_Event.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="Button.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="Env.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="Game.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="global.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="MapEditor.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="Scene.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="UnitInit.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
@ -47,5 +68,23 @@
<ClCompile Include="MiniEngine\MiniEngine_Windows.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="Button.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="Game.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="global.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="MapEditor.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="Scene.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="UnitInit.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>

133
BattleGame/Button.cpp Normal file
View File

@ -0,0 +1,133 @@
#include "Button.h"
using namespace MiniEngine;
#include <algorithm>
using namespace std;
ButtonBase::ButtonBase()
{
_status=0;
}
void ButtonBase::onMouseOver(Looper&, Event&)
{
}
void ButtonBase::onMouseDown(Looper&, Event&)
{
}
void ButtonBase::onMouseUp(Looper&, Event&)
{
}
void ButtonBase::onMouseOut(Looper&, Event&)
{
}
//virtual
void ButtonBase::draw()
{
}
//virtual override
void StaticButtonBase::draw()
{
global.rnd->copyTo(text,pos);
}
LooperAdapter::LooperAdapter(Looper& lp)
{
lp.updater=[&]()
{
global.rnd->clear();
for_each(_update_vec.begin(),_update_vec.end(),[](const function<void()>& func)
{
func();
});
global.rnd->update();
};
_plooper=&lp;
}
void LooperAdapter::addUpdater(const std::function<void()>& updateFunc)
{
_update_vec.push_back(updateFunc);
}
Looper * LooperAdapter::getLooperPtr() const
{
return _plooper;
}
ButtonAdapter::ButtonAdapter(LooperAdapter & looperAdapter)
{
_plpa = &looperAdapter;
}
void ButtonAdapter::addButton(ButtonBase* pButton)
{
Looper* pLooper=_plpa->getLooperPtr();
pLooper->add(SDL_MOUSEMOTION,function<int(Looper&,Event&)>([=](Looper& lp,Event& ev)->int
{
if(pButton->_status==1) /// mouseOver -> ...
{
if(!Point(ev.motion.x,ev.motion.y).inRect(pButton->pos)) /// mouseOver -> mouseOut
{
pButton->onMouseOut(lp,ev);
pButton->_status =0;
return 1;
}
}
else if(pButton->_status ==0) /// Normal -> ...
{
if(Point(ev.motion.x,ev.motion.y).inRect(pButton->pos)) /// Normal -> mouseOver
{
pButton->onMouseOver(lp,ev);
pButton->_status =1;
return 1;
}
}
return 0;
}));
pLooper->add(SDL_MOUSEBUTTONDOWN, function<int(Looper&, Event&)>([=](Looper& lp,Event& ev)->int
{
if(pButton->_status ==1) /// mouseOver
{
if(Point(ev.button.x,ev.button.y).inRect(pButton->pos)) /// mouseOver -> mouseDown
{
pButton->onMouseDown(lp,ev);
pButton->_status =2;
return 1;
}
}
return 0;
}));
pLooper->add(SDL_MOUSEBUTTONUP,function<int(Looper&,Event&)>([=](Looper& lp,Event& ev)->int
{
if(pButton->_status ==2) /// mouseDown
{
if(Point(ev.button.x,ev.button.y).inRect(pButton->pos)) /// mouseDown -> mouseOver
{
pButton->onMouseUp(lp,ev);
pButton->_status =1;
return 1;
}
}
return 0;
}));
_plpa->addUpdater([=](){pButton->draw();});
}

42
BattleGame/Button.h Normal file
View File

@ -0,0 +1,42 @@
#include "global.h"
#include "MiniEngine/MiniEngine_Event.h"
class ButtonBase
{
public:
ButtonBase();
virtual void onMouseOver(Looper&,Event&);
virtual void onMouseDown(Looper&,Event&);
virtual void onMouseUp(Looper&,Event&);
virtual void onMouseOut(Looper&,Event&);
virtual void draw();
MiniEngine::Rect pos;
int _status;/// 0 Normal 1 MouseOver 2 MouseDown
};
class StaticButtonBase : public ButtonBase
{
public:
MiniEngine::Texture text;
virtual void draw() override;
};
class LooperAdapter
{
public:
LooperAdapter(Looper& lp);
void addUpdater(const std::function<void()>& updateFunc);
Looper* getLooperPtr() const;
private:
std::vector<std::function<void()>> _update_vec;
Looper* _plooper;
};
class ButtonAdapter
{
public:
ButtonAdapter(LooperAdapter&);
void addButton(ButtonBase* pButton);
private:
LooperAdapter* _plpa;
};

13
BattleGame/Env.h Normal file
View File

@ -0,0 +1,13 @@
#pragma once
#include "MiniEngine/MiniEngine.h"
#include "Scene.h"
struct Env
{
MiniEngine::Window* wnd;
MiniEngine::Renderer* rnd;
MiniEngine::Font* font;
Frame* frame;
MiniEngine::StringEngine* strEngine;
};

41
BattleGame/Game.cpp Normal file
View File

@ -0,0 +1,41 @@
#include "Game.h"
using namespace MiniEngine;
#include "MapEditor.h"
#include "UnitInit.h"
#include "global.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
void InitStringEngine()
{
StringEngine* _str_engine=new StringEngine("Strings.xml","zh_CN");
if(_str_engine==nullptr||(!_str_engine->ready()))
{
printf("[Error] String Engine is not ready. \n");
abort();
}
global.strEngine = _str_engine;
}
void QuitStringEngine()
{
delete global.strEngine;
global.strEngine = nullptr;
}
void GameMain()
{
/// Reset random number generator
srand(time(NULL));
InitStringEngine();
InitUnitData();
global.frame->run(new MapEditorScene);
}

3
BattleGame/Game.h Normal file
View File

@ -0,0 +1,3 @@
#pragma once
#include "MiniEngine/MiniEngine.h"
void GameMain();

39
BattleGame/MapEditor.cpp Normal file
View File

@ -0,0 +1,39 @@
#include "MapEditor.h"
#include "Button.h"
using namespace MiniEngine;
using namespace std;
struct SizePack
{
int line,col;
};
//virtual
void MapEditorScene::start(void* ptr)
{
SizePack* ppack=(SizePack*)global.frame->run(new MapEditorMapSizeConfigureScene,new SizePack);
}
class MapEditorMapSizeConfigureSceneReturnButton : public StaticButtonBase
{
public:
};
//virtual
void MapEditorMapSizeConfigureScene::start(void* ptr)
{
Rect winSize=global.wnd->getSize();
Texture text_a1 = global.font->renderUTF8(*(global.rnd),global.strEngine->getString("INPUT_SIZE"), RGBA(255, 255, 255, 255));
Texture text_a2 = global.font->renderUTF8(*(global.rnd),global.strEngine->getString("BACK"), RGBA(255, 255, 255, 255));
Texture text_a3 = global.font->renderUTF8(*(global.rnd),global.strEngine->getString("CREATE_MAP"), RGBA(255, 255, 255, 255));
Texture text_b1 = global.font->renderUTF8(*(global.rnd),global.strEngine->getString("W:"), RGBA(255, 255, 255, 255));
Texture text_b2 = global.font->renderUTF8(*(global.rnd),global.strEngine->getString("H:"), RGBA(255, 255, 255, 255));
Texture text_c1 = global.font->renderUTF8(*(global.rnd),global.strEngine->getString("999"), RGBA(255, 255, 255, 255));
Looper lp;
LooperAdapter lpa(lp);
ButtonAdapter btna(lpa);
}

14
BattleGame/MapEditor.h Normal file
View File

@ -0,0 +1,14 @@
#pragma once
#include "Scene.h"
class MapEditorScene : public Scene
{
public:
virtual void start(void* ptr) override;
};
class MapEditorMapSizeConfigureScene : public Scene
{
public:
virtual void start(void* ptr) override;
};

@ -1 +1 @@
Subproject commit 7c22fb544d626811866293346c9d48ca132583e6
Subproject commit 26beb30f77323299abd126faf1ca32127c1d0254

49
BattleGame/Scene.cpp Normal file
View File

@ -0,0 +1,49 @@
#include "Scene.h"
using namespace std;
/// Default Implement
//virtual
void Scene::start(void*)
{
printf("[Warning] Empty Scene %p\n",this);
}
void Frame::push(Scene* pScene,void* ptr)
{
_stk.push(make_pair(pScene,ptr));
}
void Frame::show()
{
if(!_stk.empty())
{
std::pair<Scene*,void*> pr=_stk.top();
pr.first->start(pr.second);
}
}
void* Frame::pop()
{
if(!_stk.empty())
{
std::pair<Scene*,void*> pr=_stk.top();
_stk.pop();
return pr.second;
}
else
{
return nullptr;
}
}
bool Frame::empty()
{
return _stk.empty();
}
void* Frame::run(Scene* pScene,void* ptr)
{
push(pScene,ptr);
show();
return pop();
}

24
BattleGame/Scene.h Normal file
View File

@ -0,0 +1,24 @@
#pragma once
#include "MiniEngine/MiniEngine.h"
#include "MiniEngine/MiniEngine_Event.h"
#include <stack>
#include <utility>
class Scene
{
public:
virtual void start(void*);
virtual ~Scene()=default;
};
class Frame
{
public:
void push(Scene*,void* ptr=nullptr);
void show();
void* pop();
bool empty();
void* run(Scene*,void* ptr=nullptr);
private:
std::stack<std::pair<Scene*,void*>> _stk;
};

8
BattleGame/Strings.xml Normal file
View File

@ -0,0 +1,8 @@
<zh_CN>
<INPUT_SIZE>输入尺寸</INPUT_SIZE>
<BACK>返回</BACK>
<CREATE_MAP>创建地图</CREATE_MAP>
<SAVE>保存</SAVE>
<SAVE_MAP>保存地图</SAVE_MAP>
<EXIT_EDITOR>退出编辑器</EXIT_EDITOR>
</zh_CN>

98
BattleGame/UnitInit.cpp Normal file
View File

@ -0,0 +1,98 @@
#include "UnitInit.h"
using namespace MiniEngine;
using namespace std;
inline UnitType _ReadUnitType(FILE* fp)
{
UnitType x;
char buff[128];
fscanf(fp, "%s", buff);
if (strcmp(buff, "LAND") == 0)
{
x.loadtype = 0;
}
else if (strcmp(buff, "SEA") == 0)
{
x.loadtype = 1;
}
else if (strcmp(buff, "FLY") == 0)
{
x.loadtype = 2;
}
else
{
x.loadtype = -1;
}
fscanf(fp, "%s", buff);
x.TypeIDStr = buff;
fscanf(fp, "%s", buff);
x.TypeName = buff;
fscanf(fp, "%d", &x.sample.hpmax);
fscanf(fp, "%d", &x.sample.vrange);
fscanf(fp, "%d", &x.sample.tarland);
fscanf(fp, "%d", &x.sample.attland);
fscanf(fp, "%d", &x.sample.arangeland);
fscanf(fp, "%d", &x.sample.erangeland);
fscanf(fp, "%lf", &x.sample.decendland);
fscanf(fp, "%d", &x.sample.tarsea);
fscanf(fp, "%d", &x.sample.attsea);
fscanf(fp, "%d", &x.sample.arangesea);
fscanf(fp, "%d", &x.sample.erangesea);
fscanf(fp, "%lf", &x.sample.decendsea);
fscanf(fp, "%d", &x.sample.tarsky);
fscanf(fp, "%d", &x.sample.attsky);
fscanf(fp, "%d", &x.sample.arangesky);
fscanf(fp, "%d", &x.sample.erangesky);
fscanf(fp, "%lf", &x.sample.decendsky);
fscanf(fp, "%d", &x.sample.canland);
fscanf(fp, "%d", &x.sample.stepland);
fscanf(fp, "%d", &x.sample.cansea);
fscanf(fp, "%d", &x.sample.stepsea);
fscanf(fp, "%d", &x.sample.cansky);
fscanf(fp, "%d", &x.sample.stepsky);
fscanf(fp, "%d", &x.sample.cooltime);
fscanf(fp, "%d", &x.sample.containmax);
return x;
}
inline void _LoadUnitTexture(UnitType& x)
{
char buff[128];
memset(buff,0,128);
sprintf(buff, "res/%s.png", x.TypeIDStr.c_str());
x.pic = global.rnd->loadTexture(buff);
x.text_typename = global.font->renderUTF8(*(global.rnd),x.TypeName,RGBA(255,255,255,255));
}
/// Count of Unit Types
const int _internal_unittype_counter = 25;
UnitType _internal_unittype[_internal_unittype_counter];
void InitUnitData()
{
FILE* fp;
fp = fopen("gamedata.txt", "r");
for (int i = 0; i<_internal_unittype_counter; i++)
{
UnitType x = _ReadUnitType(fp);
_LoadUnitTexture(x);
x.sample.typetag = i;
x.sample.hp = x.sample.hpmax;
x.sample.lv = 1;
x.sample.exp = 0;
x.sample.containing = 0;
x.sample.box = nullptr;
/// undefined: id,x,y,onland,insea,insky,lastcool
_internal_unittype[i] = x;
}
fclose(fp);
}

55
BattleGame/UnitInit.h Normal file
View File

@ -0,0 +1,55 @@
#pragma once
#include "MiniEngine/MiniEngine.h"
#include <string>
#include "global.h"
typedef int UnitID;
struct Unit
{
int hpmax;
int vrange;
int tarland, tarsea, tarsky;///bool
int attland, attsea, attsky;
int arangeland, arangesea, arangesky;
int erangeland, erangesea, erangesky;
double decendland, decendsea, decendsky;
int canland, cansea, cansky;/// bool
int stepland, stepsea, stepsky;
int cooltime;
int containmax;
/// Cannot be defined until load
int typetag;
/// Dynamic Data
UnitID id;
int line, col;
int onland, insea, insky;///bool
int lastcool;
int hp;
int lv, exp;
int containing;
int* box;
int party;
std::string name;
};
struct UnitType
{
std::string TypeIDStr;
std::string TypeName;
int loadtype;///0 Land 1 Sea 2 Sky -1 Unknown
Unit sample;
MiniEngine::Texture pic;
MiniEngine::Texture text_typename;
};
void InitUnitData();

15
BattleGame/global.cpp Normal file
View File

@ -0,0 +1,15 @@
#include "global.h"
Env global;
MiniEngine::Texture text_land;/// Land
MiniEngine::Texture text_sea;/// Sea
MiniEngine::Texture text_mountain;/// Mountain
MiniEngine::Texture text_black;/// Black
MiniEngine::Texture text_dark;/// Dark
MiniEngine::Texture textstr_exp;/// EXP
MiniEngine::Texture textstr_hp;/// HP
MiniEngine::Texture textstr_enemy;/// Enemy
MiniEngine::Texture textstr_player;/// Player
MiniEngine::Texture textstr_cooling;/// Cooling

17
BattleGame/global.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include "Env.h"
extern Env global;
extern MiniEngine::Texture text_land;/// Land
extern MiniEngine::Texture text_sea;/// Sea
extern MiniEngine::Texture text_mountain;/// Mountain
extern MiniEngine::Texture text_black;/// Black
extern MiniEngine::Texture text_dark;/// Dark
extern MiniEngine::Texture textstr_exp;/// EXP
extern MiniEngine::Texture textstr_hp;/// HP
extern MiniEngine::Texture textstr_enemy;/// Enemy
extern MiniEngine::Texture textstr_player;/// Player
extern MiniEngine::Texture textstr_cooling;/// Cooling

BIN
BattleGame/res/MAP_LAND.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
BattleGame/res/MAP_SEA.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 KiB

BIN
BattleGame/res/UNIT_APC.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 726 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 KiB

BIN
BattleGame/res/UNIT_BB.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 723 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 453 KiB

BIN
BattleGame/res/UNIT_CA.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 452 KiB

BIN
BattleGame/res/UNIT_CL.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

BIN
BattleGame/res/UNIT_CV.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 424 KiB

BIN
BattleGame/res/UNIT_CVE.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 KiB

BIN
BattleGame/res/UNIT_DD.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 780 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 516 KiB

BIN
BattleGame/res/UNIT_LST.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 765 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 389 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 441 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB