remove samples
|
|
@ -1,36 +0,0 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
// ¹Ì¶¨µÄľ°å
|
||||
KGE_DECLARE_SMART_PTR(Board);
|
||||
class Board
|
||||
: public GeometryNode
|
||||
{
|
||||
public:
|
||||
Board(b2World* world, const Size& size, const Point& pos)
|
||||
{
|
||||
GeometryPtr geo = new RectangleGeometry(Point(), size);
|
||||
SetGeometry(geo);
|
||||
SetStrokeColor(Color::White);
|
||||
SetFillColor(Color(0, 0, 0, 0));
|
||||
|
||||
SetSize(size);
|
||||
SetAnchor(0.5f, 0.5f);
|
||||
SetRotation(10);
|
||||
SetPosition(pos);
|
||||
|
||||
b2BodyDef groundBodyDef;
|
||||
groundBodyDef.position = Vec2Convert(GetPosition());
|
||||
groundBodyDef.angle = 10 * math::constants::PI_F / 180.f;
|
||||
|
||||
b2Body* groundBody = world->CreateBody(&groundBodyDef);
|
||||
|
||||
b2PolygonShape groundBox;
|
||||
b2Vec2 sz = Vec2Convert(Point{ size.x / 2, size.y / 2 });
|
||||
groundBox.SetAsBox(sz.x, sz.y);
|
||||
groundBody->CreateFixture(&groundBox, 0.0f);
|
||||
}
|
||||
};
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -1,109 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{324CFF47-4EB2-499A-BE5F-53A82E3BA14B}</ProjectGuid>
|
||||
<RootNamespace>Box2DSample</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(SolutionDir)\output\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)\build\$(PlatformToolset)\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)\output\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)\build\$(PlatformToolset)\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\projects\kiwano.vcxproj">
|
||||
<Project>{ff7f943d-a89c-4e6c-97cf-84f7d8ff8edf}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Board.h" />
|
||||
<ClInclude Include="Circle.h" />
|
||||
<ClInclude Include="common.h" />
|
||||
<ClInclude Include="MainScene.h" />
|
||||
<ClInclude Include="Rect.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="..\..\packages\Box2D.2.3.0\build\native\Box2D.targets" Condition="Exists('..\..\packages\Box2D.2.3.0\build\native\Box2D.targets')" />
|
||||
</ImportGroup>
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\..\packages\Box2D.2.3.0\build\native\Box2D.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Box2D.2.3.0\build\native\Box2D.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
// Ô²ÐÎ
|
||||
KGE_DECLARE_SMART_PTR(Circle);
|
||||
class Circle
|
||||
: public Sprite
|
||||
{
|
||||
public:
|
||||
Circle(b2World* world, const Point& pos)
|
||||
{
|
||||
Load(L"circle.png");
|
||||
SetAnchor(0.5f, 0.5f);
|
||||
SetScale(0.7f);
|
||||
|
||||
b2BodyDef bodyDef;
|
||||
bodyDef.type = b2_dynamicBody;
|
||||
bodyDef.position = Vec2Convert(pos);
|
||||
|
||||
b2Body* body = world->CreateBody(&bodyDef);
|
||||
|
||||
SetUserData(body);
|
||||
|
||||
b2CircleShape shape;
|
||||
shape.m_radius = GetWidth() / GLOBAL_SCALE / 2 * 0.7f;
|
||||
|
||||
b2FixtureDef fixtureDef;
|
||||
fixtureDef.shape = &shape;
|
||||
fixtureDef.density = 1.0f;
|
||||
fixtureDef.friction = 0.3f;
|
||||
|
||||
body->CreateFixture(&fixtureDef);
|
||||
body->SetUserData(this);
|
||||
}
|
||||
};
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Circle.h"
|
||||
#include "Rect.h"
|
||||
#include "Board.h"
|
||||
|
||||
KGE_DECLARE_SMART_PTR(MainScene);
|
||||
class MainScene
|
||||
: public Scene
|
||||
{
|
||||
b2World* world_;
|
||||
|
||||
public:
|
||||
MainScene()
|
||||
{
|
||||
// 设置可响应状态, 使场景可以接收到鼠标 Click 消息
|
||||
SetResponsible(true);
|
||||
|
||||
// 添加消息监听
|
||||
AddListener(Event::Click, MakeClosure(this, &MainScene::Click));
|
||||
|
||||
// 创建物理世界
|
||||
world_ = new b2World(b2Vec2(0, 10));
|
||||
|
||||
BoardPtr board = new Board(world_, Size(GetWidth() - 100, 20), Point(GetWidth() / 2, GetHeight() - 50));
|
||||
AddChild(board);
|
||||
|
||||
CirclePtr circle = new Circle(world_, Point(320, 240));
|
||||
AddChild(circle);
|
||||
}
|
||||
|
||||
~MainScene()
|
||||
{
|
||||
if (world_)
|
||||
delete world_;
|
||||
}
|
||||
|
||||
void OnUpdate(Duration dt) override
|
||||
{
|
||||
// 更新 Box2D 世界
|
||||
world_->Step(dt.Seconds(), 6, 2);
|
||||
|
||||
// 更新每一个物理对象的位置和旋转角度
|
||||
b2Body* body = world_->GetBodyList();
|
||||
while (body)
|
||||
{
|
||||
Node* node = (Node*)body->GetUserData();
|
||||
b2Body* next = body->GetNext();
|
||||
if (node)
|
||||
{
|
||||
const b2Vec2& pos = body->GetPosition();
|
||||
node->SetPosition(Vec2Convert(pos));
|
||||
node->SetRotation(body->GetAngle() * 180.f / math::constants::PI_F);
|
||||
|
||||
// 移除掉落到场景外的物体
|
||||
if (node->GetPosition().y > GetHeight() + 50)
|
||||
{
|
||||
body->SetUserData(0);
|
||||
world_->DestroyBody(body);
|
||||
|
||||
node->RemoveFromParent();
|
||||
}
|
||||
}
|
||||
|
||||
body = next;
|
||||
}
|
||||
}
|
||||
|
||||
void Click(Event const& evt)
|
||||
{
|
||||
if (evt.mouse.button == MouseButton::Left)
|
||||
{
|
||||
CirclePtr circle = new Circle(world_, Point{ evt.mouse.x, evt.mouse.y });
|
||||
AddChild(circle);
|
||||
}
|
||||
else if (evt.mouse.button == MouseButton::Right)
|
||||
{
|
||||
SquarePtr rect = new Square(world_, Point{ evt.mouse.x, evt.mouse.y });
|
||||
AddChild(rect);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
// ·½¿é
|
||||
KGE_DECLARE_SMART_PTR(Square);
|
||||
class Square
|
||||
: public Sprite
|
||||
{
|
||||
public:
|
||||
Square(b2World* world, const Point& pos)
|
||||
{
|
||||
Load(L"square.png");
|
||||
SetAnchor(0.5f, 0.5f);
|
||||
SetScale(0.7f);
|
||||
|
||||
b2BodyDef bodyDef;
|
||||
bodyDef.type = b2_dynamicBody;
|
||||
bodyDef.position = Vec2Convert(pos);
|
||||
|
||||
b2Body* body = world->CreateBody(&bodyDef);
|
||||
|
||||
SetUserData(body);
|
||||
|
||||
b2PolygonShape shape;
|
||||
b2Vec2 sz = Vec2Convert(GetSize() / 2 * 0.7f);
|
||||
shape.SetAsBox(sz.x, sz.y);
|
||||
|
||||
b2FixtureDef fixtureDef;
|
||||
fixtureDef.shape = &shape;
|
||||
fixtureDef.density = 1.0f;
|
||||
fixtureDef.friction = 0.3f;
|
||||
|
||||
body->CreateFixture(&fixtureDef);
|
||||
body->SetUserData(this);
|
||||
}
|
||||
};
|
||||
|
Before Width: | Height: | Size: 27 KiB |
|
|
@ -1,29 +0,0 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "kiwano/kiwano.h"
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
using namespace kiwano;
|
||||
|
||||
//
|
||||
// Box2D 非常好地适应了 米/千克/秒 的单位, 所以
|
||||
// 它并不是以像素为单位进行计算.
|
||||
// 我们在平衡 Box2D 和 Kiwano 世界的度量时, 需要
|
||||
// 进行一些转换.
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const float GLOBAL_SCALE = 100.0f;
|
||||
|
||||
b2Vec2 Vec2Convert(const Point& pos)
|
||||
{
|
||||
return b2Vec2(pos.x / GLOBAL_SCALE, pos.y / GLOBAL_SCALE);
|
||||
}
|
||||
|
||||
Point Vec2Convert(const b2Vec2& pos)
|
||||
{
|
||||
return Point(pos.x * GLOBAL_SCALE, pos.y * GLOBAL_SCALE);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#include "MainScene.h"
|
||||
|
||||
int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ PWSTR, _In_ int)
|
||||
{
|
||||
try
|
||||
{
|
||||
Application app;
|
||||
|
||||
Options options(L"Box2D Demo");
|
||||
app.Init(options);
|
||||
|
||||
MainScenePtr scene = new MainScene;
|
||||
app.EnterScene(scene);
|
||||
app.Run();
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
::MessageBoxA(nullptr, e.what(), "An exception has occurred!", MB_ICONERROR | MB_OK);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Box2D" version="2.3.0" targetFramework="native" />
|
||||
</packages>
|
||||
|
Before Width: | Height: | Size: 19 KiB |
|
|
@ -1,94 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{3561A359-F9FD-48AB-A977-34E7E568BC8E}</ProjectGuid>
|
||||
<RootNamespace>HelloWorld</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(SolutionDir)\output\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)\build\$(PlatformToolset)\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)\output\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)\build\$(PlatformToolset)\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\projects\kiwano.vcxproj">
|
||||
<Project>{ff7f943d-a89c-4e6c-97cf-84f7d8ff8edf}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#include "kiwano/kiwano.h"
|
||||
|
||||
using namespace kiwano;
|
||||
|
||||
class MainScene
|
||||
: public Scene
|
||||
{
|
||||
public:
|
||||
MainScene()
|
||||
{
|
||||
TextPtr text = new Text(L"Hello Kiwano!"); // 创建文字节点
|
||||
text->SetSize(text->GetLayoutSize()); // 设置节点大小为文字布局大小
|
||||
text->SetPosition(640 / 2, 480 / 2); // 修改节点位置, 使节点在屏幕上居中
|
||||
text->SetAnchor(0.5, 0.5); // 修改节点锚点, 使文字中心对齐屏幕中心
|
||||
this->AddChild(text); // 添加到场景中
|
||||
}
|
||||
};
|
||||
|
||||
int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ PWSTR, _In_ int)
|
||||
{
|
||||
// 创建 Kiwano 程序实例
|
||||
Application app;
|
||||
|
||||
// 在初始化选项中设置窗口宽高
|
||||
Options options;
|
||||
options.width = 640;
|
||||
options.height = 480;
|
||||
|
||||
// 初始化 app
|
||||
app.Init(options);
|
||||
|
||||
// 创建场景并进入
|
||||
ScenePtr scene = new MainScene;
|
||||
app.EnterScene(scene);
|
||||
|
||||
// 运行
|
||||
app.Run();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
# ImGui Configuration
|
||||
imgui.ini
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{6152D36C-EA40-4968-A696-244B6CA58395}</ProjectGuid>
|
||||
<RootNamespace>ImGuiSample</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(SolutionDir)\output\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)\build\$(PlatformToolset)\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)\output\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)\build\$(PlatformToolset)\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\projects\kiwano-imgui.vcxproj">
|
||||
<Project>{a7062ed8-8910-48a5-a3bc-c1612672571f}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\projects\kiwano.vcxproj">
|
||||
<Project>{ff7f943d-a89c-4e6c-97cf-84f7d8ff8edf}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="MainScene.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="MainScene.h" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "kiwano/kiwano.h"
|
||||
#include "kiwano-imgui/kiwano-imgui.h"
|
||||
|
||||
using namespace kiwano;
|
||||
using namespace kiwano::imgui;
|
||||
|
||||
KGE_DECLARE_SMART_PTR(MainScene);
|
||||
class MainScene
|
||||
: public Scene
|
||||
{
|
||||
bool show_demo_window = true;
|
||||
bool show_another_window = false;
|
||||
Color clear_color = Color(0.45f, 0.55f, 0.6f, 1.f);
|
||||
|
||||
public:
|
||||
MainScene()
|
||||
{
|
||||
// 创建 ImGui 图层
|
||||
ImGuiLayerPtr layer = new ImGuiLayer;
|
||||
AddChild(layer);
|
||||
|
||||
// 添加 ImGui 提供的 Demo 窗口
|
||||
layer->AddItem([=]() {
|
||||
if (show_demo_window)
|
||||
ImGui::ShowDemoWindow(&show_demo_window);
|
||||
}, L"DemoWindow");
|
||||
|
||||
// 添加一个简单窗口
|
||||
layer->AddItem(MakeClosure(this, &MainScene::SimpleWindow), L"SimpleWindow");
|
||||
|
||||
// 再添加一个窗口
|
||||
layer->AddItem(MakeClosure(this, &MainScene::AnotherWindow), L"AnotherWindow");
|
||||
}
|
||||
|
||||
void SimpleWindow()
|
||||
{
|
||||
static float f = 0.0f;
|
||||
static int counter = 0;
|
||||
|
||||
ImGui::Begin("Hello, world!");
|
||||
|
||||
ImGui::Text("This is some useful text.");
|
||||
ImGui::Checkbox("Demo Window", &show_demo_window);
|
||||
ImGui::Checkbox("Another Window", &show_another_window);
|
||||
|
||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
|
||||
ImGui::ColorEdit3("clear color", (float*)&clear_color);
|
||||
|
||||
if (ImGui::Button("Button"))
|
||||
counter++;
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("counter = %d", counter);
|
||||
|
||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
||||
ImGui::End();
|
||||
|
||||
// 修改窗口背景色
|
||||
Renderer::Instance()->SetClearColor(clear_color);
|
||||
}
|
||||
|
||||
void AnotherWindow()
|
||||
{
|
||||
if (show_another_window)
|
||||
{
|
||||
ImGui::Begin("Another Window", &show_another_window);
|
||||
ImGui::Text("Hello from another window!");
|
||||
if (ImGui::Button("Close Me"))
|
||||
show_another_window = false;
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#include "MainScene.h"
|
||||
|
||||
using namespace kiwano;
|
||||
|
||||
class ImGuiApp
|
||||
: public Application
|
||||
{
|
||||
public:
|
||||
ImGuiApp()
|
||||
{
|
||||
// Ìí¼Ó ImGui ×é¼þ
|
||||
Use(ImGuiModule::Instance());
|
||||
|
||||
// ³õʼ»¯
|
||||
Options options(L"ImGui Demo", 1280, 800);
|
||||
Init(options);
|
||||
}
|
||||
|
||||
void OnStart() override
|
||||
{
|
||||
MainScenePtr scene = new MainScene;
|
||||
EnterScene(scene);
|
||||
}
|
||||
};
|
||||
|
||||
int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ PWSTR, _In_ int)
|
||||
{
|
||||
try
|
||||
{
|
||||
ImGuiApp app;
|
||||
app.Run();
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
::MessageBoxA(nullptr, e.what(), "An exception has occurred!", MB_ICONERROR | MB_OK);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.28729.10
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloWorld", "HelloWorld\HelloWorld.vcxproj", "{3561A359-F9FD-48AB-A977-34E7E568BC8E}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Samples", "Samples\Samples.vcxproj", "{45F5738D-CDF2-4024-974D-25B64F9043DE}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImGuiSample", "ImGuiSample\ImGuiSample.vcxproj", "{6152D36C-EA40-4968-A696-244B6CA58395}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Box2DSample", "Box2DSample\Box2DSample.vcxproj", "{324CFF47-4EB2-499A-BE5F-53A82E3BA14B}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "kiwano", "..\projects\kiwano.vcxproj", "{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "kiwano-audio", "..\projects\kiwano-audio.vcxproj", "{1B97937D-8184-426C-BE71-29A163DC76C9}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "kiwano-network", "..\projects\kiwano-network.vcxproj", "{69DFBE92-C06F-4CF8-9495-CA9BF2E3BAF2}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "kiwano-imgui", "..\projects\kiwano-imgui.vcxproj", "{A7062ED8-8910-48A5-A3BC-C1612672571F}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{44D7EDE1-8C27-4608-8018-F891280A77B2}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{3561A359-F9FD-48AB-A977-34E7E568BC8E}.Release|Win32.Build.0 = Release|Win32
|
||||
{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Debug|Win32.Deploy.0 = Debug|Win32
|
||||
{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}.Release|Win32.Build.0 = Release|Win32
|
||||
{45F5738D-CDF2-4024-974D-25B64F9043DE}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{45F5738D-CDF2-4024-974D-25B64F9043DE}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{45F5738D-CDF2-4024-974D-25B64F9043DE}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{45F5738D-CDF2-4024-974D-25B64F9043DE}.Release|Win32.Build.0 = Release|Win32
|
||||
{6152D36C-EA40-4968-A696-244B6CA58395}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{6152D36C-EA40-4968-A696-244B6CA58395}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{6152D36C-EA40-4968-A696-244B6CA58395}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{6152D36C-EA40-4968-A696-244B6CA58395}.Release|Win32.Build.0 = Release|Win32
|
||||
{324CFF47-4EB2-499A-BE5F-53A82E3BA14B}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{324CFF47-4EB2-499A-BE5F-53A82E3BA14B}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{324CFF47-4EB2-499A-BE5F-53A82E3BA14B}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{324CFF47-4EB2-499A-BE5F-53A82E3BA14B}.Release|Win32.Build.0 = Release|Win32
|
||||
{1B97937D-8184-426C-BE71-29A163DC76C9}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{1B97937D-8184-426C-BE71-29A163DC76C9}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{1B97937D-8184-426C-BE71-29A163DC76C9}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{1B97937D-8184-426C-BE71-29A163DC76C9}.Release|Win32.Build.0 = Release|Win32
|
||||
{69DFBE92-C06F-4CF8-9495-CA9BF2E3BAF2}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{69DFBE92-C06F-4CF8-9495-CA9BF2E3BAF2}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{69DFBE92-C06F-4CF8-9495-CA9BF2E3BAF2}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{69DFBE92-C06F-4CF8-9495-CA9BF2E3BAF2}.Release|Win32.Build.0 = Release|Win32
|
||||
{A7062ED8-8910-48A5-A3BC-C1612672571F}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{A7062ED8-8910-48A5-A3BC-C1612672571F}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{A7062ED8-8910-48A5-A3BC-C1612672571F}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{A7062ED8-8910-48A5-A3BC-C1612672571F}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF} = {44D7EDE1-8C27-4608-8018-F891280A77B2}
|
||||
{1B97937D-8184-426C-BE71-29A163DC76C9} = {44D7EDE1-8C27-4608-8018-F891280A77B2}
|
||||
{69DFBE92-C06F-4CF8-9495-CA9BF2E3BAF2} = {44D7EDE1-8C27-4608-8018-F891280A77B2}
|
||||
{A7062ED8-8910-48A5-A3BC-C1612672571F} = {44D7EDE1-8C27-4608-8018-F891280A77B2}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {FAC2BE2F-19AF-477A-8DC6-4645E66868A4}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#pragma once
|
||||
#include "common.h"
|
||||
|
||||
class Demo1
|
||||
: public Scene
|
||||
{
|
||||
public:
|
||||
static ScenePtr Create()
|
||||
{
|
||||
return new Demo1;
|
||||
}
|
||||
|
||||
Demo1()
|
||||
{
|
||||
// 获取人物图片
|
||||
ImagePtr man_image = g_Loader.GetImage(L"man");
|
||||
|
||||
// 缓动方程
|
||||
auto ease_functions = {
|
||||
Ease::Linear, // 线性变化
|
||||
Ease::EaseInOut, // 变化过程中有缓冲
|
||||
Ease::ExpoInOut, // 在开始和结束阶段非常慢,但过程非常快
|
||||
Ease::BounceInOut, // 在开始和结束阶段均赋予弹性
|
||||
Ease::BackInOut // 开始和结束阶段均有一个短暂的反方向运动
|
||||
};
|
||||
|
||||
float height = 100.f;
|
||||
for (auto& func : ease_functions)
|
||||
{
|
||||
SpritePtr man = new Sprite(man_image);
|
||||
man->SetPosition(100, height);
|
||||
man->SetScale(0.5f, 0.3f);
|
||||
this->AddChild(man);
|
||||
|
||||
// 重置人物位置函数
|
||||
auto reset_pos = [ptr = man.Get()]() { ptr->Move(-350, 0); };
|
||||
|
||||
// 执行动画
|
||||
man->AddAction(
|
||||
Tween::Group({ // Tween::Group 组合动画
|
||||
Tween::MoveBy(Point{ 350, 0 }) // Tween::MoveBy 横向位移 350 像素
|
||||
.SetDuration(4000) // 设置位移时间为 4 秒
|
||||
.SetEaseFunc(func), // 设置缓动函数
|
||||
Tween::Delay(1000) // Tween::Delay 延迟 1 秒
|
||||
})
|
||||
.SetLoops(-1) // 无限循环执行
|
||||
.SetLoopDoneCallback(reset_pos) // 设置每次循环结束都重置人物位置
|
||||
);
|
||||
|
||||
height += 60.f;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -1,96 +0,0 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#pragma once
|
||||
#include "common.h"
|
||||
|
||||
// 角色
|
||||
KGE_DECLARE_SMART_PTR(Hero);
|
||||
class Hero
|
||||
: public GifSprite
|
||||
{
|
||||
public:
|
||||
Hero(GifImagePtr image)
|
||||
{
|
||||
// 加载图片
|
||||
Load(image);
|
||||
// 设置 GIF 动图无限循环
|
||||
SetLoopCount(-1);
|
||||
}
|
||||
|
||||
// 每帧渲染前执行 OnUpdate
|
||||
void OnUpdate(Duration dt) override
|
||||
{
|
||||
// 获取输入设备
|
||||
auto input = Input::Instance();
|
||||
|
||||
// 按下左右键
|
||||
if (input->IsDown(KeyCode::Left))
|
||||
{
|
||||
this->Move(-2, 0);
|
||||
}
|
||||
else if (input->IsDown(KeyCode::Right))
|
||||
{
|
||||
this->Move(2, 0);
|
||||
}
|
||||
|
||||
// 按下上下键
|
||||
if (input->IsDown(KeyCode::Up))
|
||||
{
|
||||
this->Move(0, -2);
|
||||
}
|
||||
else if (input->IsDown(KeyCode::Down))
|
||||
{
|
||||
this->Move(0, 2);
|
||||
}
|
||||
|
||||
// 按下鼠标左键,顺时针旋转角色
|
||||
if (input->IsDown(MouseButton::Left))
|
||||
{
|
||||
// 获取当前旋转角度
|
||||
float rotation = this->GetRotation();
|
||||
// 设置角度值+2
|
||||
this->SetRotation(rotation + 2);
|
||||
}
|
||||
|
||||
// 点击鼠标右键,隐藏或显示角色
|
||||
if (input->WasPressed(MouseButton::Right))
|
||||
{
|
||||
// 获取当前显示状态
|
||||
bool visible = this->IsVisible();
|
||||
// 设置相反的显示状态
|
||||
this->SetVisible(!visible);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Demo2
|
||||
: public Scene
|
||||
{
|
||||
public:
|
||||
static ScenePtr Create()
|
||||
{
|
||||
return new Demo2;
|
||||
}
|
||||
|
||||
Demo2()
|
||||
{
|
||||
// 创建角色
|
||||
HeroPtr hero = new Hero(g_Loader.GetGifImage(L"Kusanagi"));
|
||||
// 在屏幕上居中显示
|
||||
hero->SetAnchor(0.5f, 0.5f);
|
||||
hero->SetPosition(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2);
|
||||
|
||||
// 创建说明文字
|
||||
TextPtr text = new Text(L"按上下左右键移动\n按鼠标左键旋转\n点击鼠标右键隐藏");
|
||||
// 设置节点大小为文字布局大小
|
||||
text->SetSize(text->GetLayoutSize());
|
||||
// 设置文字位置
|
||||
text->SetAnchor(0.5f, 0.5f);
|
||||
text->SetPosition(WINDOW_WIDTH / 2, WINDOW_HEIGHT - 50);
|
||||
text->SetAlignment(TextAlign::Center);
|
||||
|
||||
// 添加到场景
|
||||
this->AddChild(hero);
|
||||
this->AddChild(text);
|
||||
}
|
||||
};
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#pragma once
|
||||
#include "common.h"
|
||||
|
||||
class Demo3
|
||||
: public Scene
|
||||
{
|
||||
SoundPtr bgmusic; // 音乐对象
|
||||
TextPtr volume_text; // 音量文字
|
||||
TextPtr state_text; // 播放状态文字
|
||||
|
||||
public:
|
||||
static ScenePtr Create()
|
||||
{
|
||||
return new Demo3;
|
||||
}
|
||||
|
||||
Demo3()
|
||||
{
|
||||
// 加载音乐
|
||||
bgmusic = new Sound;
|
||||
if (!bgmusic->Load(L"res/splash.mp3"))
|
||||
{
|
||||
bgmusic = nullptr;
|
||||
|
||||
TextPtr err = new Text(L"音频文件加载失败");
|
||||
this->AddChild(err);
|
||||
}
|
||||
|
||||
// 播放音乐(参数用来设置播放循环次数,-1 表示循环播放)
|
||||
bgmusic->Play(-1);
|
||||
|
||||
// 创建说明文字
|
||||
TextPtr intro_text = new Text(L"按上下键调整音量\n按空格键暂停或继续");
|
||||
intro_text->SetPosition(WINDOW_WIDTH / 2 - 80, WINDOW_HEIGHT / 2 - 50);
|
||||
|
||||
// 创建音量文字
|
||||
volume_text = new Text(L"当前音量:");
|
||||
volume_text->SetPosition(WINDOW_WIDTH / 2 - 80, WINDOW_HEIGHT / 2 + 30);
|
||||
|
||||
// 创建状态文字
|
||||
state_text = new Text(L"当前状态:");
|
||||
state_text->SetPosition(WINDOW_WIDTH / 2 - 80, WINDOW_HEIGHT / 2 + 60);
|
||||
|
||||
// 添加到场景
|
||||
this->AddChild(intro_text);
|
||||
this->AddChild(volume_text);
|
||||
this->AddChild(state_text);
|
||||
}
|
||||
|
||||
void OnUpdate(Duration dt) override
|
||||
{
|
||||
if (bgmusic == nullptr)
|
||||
return;
|
||||
|
||||
// 获取音量和播放状态
|
||||
float volume = bgmusic->GetVolume();
|
||||
bool playing = bgmusic->IsPlaying();
|
||||
|
||||
// 修改文本
|
||||
volume_text->SetText(L"当前音量:" + std::to_wstring(volume));
|
||||
state_text->SetText(playing ? L"当前状态:正在播放" : L"当前状态:停止播放");
|
||||
|
||||
// 获取输入设备
|
||||
auto input = Input::Instance();
|
||||
|
||||
// 按空格键暂停或继续
|
||||
if (input->WasPressed(KeyCode::Space))
|
||||
{
|
||||
bgmusic->IsPlaying() ? bgmusic->Pause() : bgmusic->Resume();
|
||||
}
|
||||
|
||||
// 按上下键调整音量
|
||||
if (input->WasPressed(KeyCode::Up))
|
||||
{
|
||||
bgmusic->SetVolume(volume + 0.1f);
|
||||
}
|
||||
else if (input->WasPressed(KeyCode::Down))
|
||||
{
|
||||
bgmusic->SetVolume(volume - 0.1f);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -1,178 +0,0 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#pragma once
|
||||
#include "common.h"
|
||||
|
||||
// 老虎
|
||||
KGE_DECLARE_SMART_PTR(Tiger);
|
||||
class Tiger
|
||||
: public Sprite
|
||||
{
|
||||
FramesPtr run_frames; // 跑步序列帧
|
||||
FramesPtr stand_frames; // 站立序列帧
|
||||
bool facing_left; // 面朝左或面朝右
|
||||
bool running; // 是否正在跑步
|
||||
Direction running_direction; // 跑步方向
|
||||
|
||||
public:
|
||||
Tiger()
|
||||
{
|
||||
// 加载帧动画
|
||||
run_frames = g_Loader.GetFrames(L"tiger_running");
|
||||
stand_frames = g_Loader.GetFrames(L"tiger_standing");
|
||||
|
||||
// 执行动画
|
||||
AddAction(
|
||||
Tween::Animation(stand_frames)
|
||||
.SetDuration(1000)
|
||||
.SetLoops(-1)
|
||||
);
|
||||
|
||||
// 添加按键监听
|
||||
AddListener(Event::KeyDown, MakeClosure(this, &Tiger::OnKeyDown));
|
||||
AddListener(Event::KeyUp, MakeClosure(this, &Tiger::OnKeyUp));
|
||||
|
||||
// 默认方向为 Left
|
||||
facing_left = true;
|
||||
running = false;
|
||||
|
||||
// 设置锚点
|
||||
SetAnchor(0.5f, 0.5f);
|
||||
}
|
||||
|
||||
void OnKeyDown(Event const& e)
|
||||
{
|
||||
if (e.key.code == KeyCode::Left)
|
||||
Run(Direction::Left);
|
||||
else if (e.key.code == KeyCode::Right)
|
||||
Run(Direction::Right);
|
||||
else if (e.key.code == KeyCode::Up)
|
||||
Run(Direction::Up);
|
||||
else if (e.key.code == KeyCode::Down)
|
||||
Run(Direction::Down);
|
||||
}
|
||||
|
||||
void OnKeyUp(Event const& e)
|
||||
{
|
||||
switch (e.key.code)
|
||||
{
|
||||
case KeyCode::Left:
|
||||
case KeyCode::Right:
|
||||
case KeyCode::Up:
|
||||
case KeyCode::Down:
|
||||
StopRun();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Run(Direction d)
|
||||
{
|
||||
if (!running)
|
||||
{
|
||||
running = true;
|
||||
StopAllActions();
|
||||
|
||||
// 执行跑步动画
|
||||
AddAction(
|
||||
Tween::Animation(run_frames)
|
||||
.SetDuration(500)
|
||||
.SetLoops(-1)
|
||||
);
|
||||
}
|
||||
|
||||
running_direction = d;
|
||||
if (running_direction == Direction::Left)
|
||||
{
|
||||
facing_left = true;
|
||||
}
|
||||
else if (running_direction == Direction::Right)
|
||||
{
|
||||
facing_left = false;
|
||||
}
|
||||
|
||||
// 缩放可以调整图片显示方向
|
||||
// 缩放至 -1 图片会反转
|
||||
SetScaleX(facing_left ? 1.0f : -1.0f);
|
||||
}
|
||||
|
||||
void StopRun()
|
||||
{
|
||||
if (running)
|
||||
{
|
||||
running = false;
|
||||
StopAllActions();
|
||||
|
||||
// 执行站立动画
|
||||
AddAction(
|
||||
Tween::Animation(stand_frames)
|
||||
.SetDuration(1000)
|
||||
.SetLoops(-1)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void OnUpdate(Duration dt)
|
||||
{
|
||||
if (running)
|
||||
{
|
||||
// 计算移动距离
|
||||
// OnUpdate 并不是一个稳定间隔执行的函数, 如果想实现稳定
|
||||
// 每秒移动 150 像素, 应根据 dt 参数计算移动距离
|
||||
const float moving_per_sec = 150;
|
||||
const float distance = moving_per_sec * dt.Seconds();
|
||||
|
||||
switch (running_direction)
|
||||
{
|
||||
case Direction::Up:
|
||||
Move(0, -distance);
|
||||
break;
|
||||
case Direction::Down:
|
||||
Move(0, distance);
|
||||
break;
|
||||
case Direction::Left:
|
||||
Move(-distance, 0);
|
||||
break;
|
||||
case Direction::Right:
|
||||
Move(distance, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Demo4
|
||||
: public Scene
|
||||
{
|
||||
public:
|
||||
static ScenePtr Create()
|
||||
{
|
||||
return new Demo4;
|
||||
}
|
||||
|
||||
Demo4()
|
||||
{
|
||||
// 创建背景
|
||||
SpritePtr bg = new Sprite(L"res/spring_forest.jpg");
|
||||
bg->SetSize(GetSize());
|
||||
|
||||
// 创建老虎
|
||||
TigerPtr tiger = new Tiger;
|
||||
// 在屏幕上居中显示
|
||||
tiger->SetAnchor(0.5f, 0.5f);
|
||||
tiger->SetPosition(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2);
|
||||
|
||||
// 创建说明文字
|
||||
TextPtr text = new Text(L"按上下左右键移动");
|
||||
// 设置节点大小为文字布局大小
|
||||
text->SetSize(text->GetLayoutSize());
|
||||
// 设置文字位置
|
||||
text->SetAnchor(0.5f, 0.5f);
|
||||
text->SetPosition(WINDOW_WIDTH / 2, WINDOW_HEIGHT - 80);
|
||||
text->SetAlignment(TextAlign::Center);
|
||||
|
||||
// 添加到场景
|
||||
this->AddChild(bg);
|
||||
this->AddChild(tiger);
|
||||
this->AddChild(text);
|
||||
}
|
||||
};
|
||||
|
|
@ -1,176 +0,0 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#pragma once
|
||||
#include "common.h"
|
||||
#include <iostream>
|
||||
|
||||
class Demo5
|
||||
: public Scene
|
||||
{
|
||||
public:
|
||||
static ScenePtr Create()
|
||||
{
|
||||
return new Demo5;
|
||||
}
|
||||
|
||||
Demo5()
|
||||
{
|
||||
// 添加按键监听
|
||||
AddListener(Event::KeyDown, MakeClosure(this, &Demo5::OnKeyDown));
|
||||
|
||||
// 创建说明文字
|
||||
TextPtr text = new Text(L"按G发送GET请求\n按P发送POST请求\n按U发送PUT请求\n按D发送DELETE请求");
|
||||
// 设置节点大小为文字布局大小
|
||||
text->SetSize(text->GetLayoutSize());
|
||||
// 设置文字位置
|
||||
text->SetAnchor(0.5f, 0.5f);
|
||||
text->SetPosition(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2);
|
||||
|
||||
// 添加到场景
|
||||
this->AddChild(text);
|
||||
}
|
||||
|
||||
void OnEnter() override
|
||||
{
|
||||
// 进入场景时打开控制台
|
||||
Logger::Instance()->ShowConsole(true);
|
||||
}
|
||||
|
||||
void OnExit() override
|
||||
{
|
||||
// 退出场景时关闭控制台
|
||||
Logger::Instance()->ShowConsole(false);
|
||||
}
|
||||
|
||||
void OnKeyDown(Event const& e)
|
||||
{
|
||||
// 按不同键发送不同请求
|
||||
if (e.key.code == KeyCode::G)
|
||||
{
|
||||
SendGetRequest();
|
||||
}
|
||||
else if (e.key.code == KeyCode::P)
|
||||
{
|
||||
SendPostRequest();
|
||||
}
|
||||
else if (e.key.code == KeyCode::U)
|
||||
{
|
||||
SendPutRequest();
|
||||
}
|
||||
else if (e.key.code == KeyCode::D)
|
||||
{
|
||||
SendDeleteRequest();
|
||||
}
|
||||
}
|
||||
|
||||
void SendGetRequest()
|
||||
{
|
||||
// 发送 GET 请求
|
||||
Logger::Instance()->Println(L"Start to send GET request...");
|
||||
|
||||
HttpRequestPtr request = new HttpRequest;
|
||||
// 设置请求 URL
|
||||
request->SetUrl(L"http://httpbin.org/get");
|
||||
// 设置请求类型为 GET
|
||||
request->SetType(HttpRequest::Type::Get);
|
||||
// 设置请求完成后的回调函数
|
||||
request->SetResponseCallback(MakeClosure(this, &Demo5::Complete));
|
||||
|
||||
// 发送 HTTP 请求
|
||||
HttpClient::Instance()->Send(request);
|
||||
}
|
||||
|
||||
void SendPostRequest()
|
||||
{
|
||||
// 发送 POST 请求
|
||||
Logger::Instance()->Println(L"Start to send POST request...");
|
||||
|
||||
// 创建 JSON 格式的 POST 数据
|
||||
Json request_data = {
|
||||
{ L"string", L"test中文" },
|
||||
{ L"boolean", true },
|
||||
{ L"integer", 12 },
|
||||
{ L"float", 3.125 },
|
||||
{ L"array", { 1, 2, 3, 4, 4.5 } },
|
||||
{ L"object", { L"key", L"value" } },
|
||||
};
|
||||
|
||||
HttpRequestPtr request = new HttpRequest;
|
||||
request->SetUrl(L"http://httpbin.org/post");
|
||||
request->SetType(HttpRequest::Type::Post);
|
||||
// 设置 POST 请求的数据
|
||||
request->SetJsonData(request_data);
|
||||
request->SetResponseCallback(MakeClosure(this, &Demo5::Complete));
|
||||
|
||||
HttpClient::Instance()->Send(request);
|
||||
}
|
||||
|
||||
void SendPutRequest()
|
||||
{
|
||||
// 发送 PUT 请求
|
||||
Logger::Instance()->Println(L"Start to send PUT request...");
|
||||
|
||||
// 创建 JSON 格式的 PUT 数据
|
||||
Json request_data = Json::array({ 1, 2, 3 });
|
||||
|
||||
HttpRequestPtr request = new HttpRequest;
|
||||
request->SetUrl(L"http://httpbin.org/put");
|
||||
request->SetType(HttpRequest::Type::Put);
|
||||
// 设置 PUT 请求的数据
|
||||
request->SetJsonData(request_data);
|
||||
request->SetResponseCallback(MakeClosure(this, &Demo5::Complete));
|
||||
|
||||
HttpClient::Instance()->Send(request);
|
||||
}
|
||||
|
||||
void SendDeleteRequest()
|
||||
{
|
||||
// 发送 DELETE 请求
|
||||
Logger::Instance()->Println(L"Start to send DELETE request...");
|
||||
|
||||
HttpRequestPtr request = new HttpRequest;
|
||||
request->SetUrl(L"http://httpbin.org/delete");
|
||||
request->SetType(HttpRequest::Type::Delete);
|
||||
request->SetResponseCallback(MakeClosure(this, &Demo5::Complete));
|
||||
|
||||
HttpClient::Instance()->Send(request);
|
||||
}
|
||||
|
||||
void Complete(HttpRequestPtr request, HttpResponsePtr response)
|
||||
{
|
||||
// 判断请求是否成功
|
||||
if (response->IsSucceed())
|
||||
{
|
||||
try
|
||||
{
|
||||
// 将获取到的数据解析成 JSON 格式
|
||||
Json response_data = Json::parse(response->GetData());
|
||||
Json result = {
|
||||
{L"HttpCode", response->GetResponseCode()},
|
||||
{L"Data", response_data},
|
||||
};
|
||||
|
||||
std::wcout << L"Response: " << std::endl << result.dump(4) << std::endl;
|
||||
}
|
||||
catch (json_exception& e)
|
||||
{
|
||||
std::wcout << L"Parse JSON failed: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 请求失败时打印错误信息
|
||||
OutputError(response);
|
||||
}
|
||||
}
|
||||
|
||||
void OutputError(HttpResponsePtr response)
|
||||
{
|
||||
// 打印 HTTP 响应结果的状态码和错误信息
|
||||
Json result = {
|
||||
{L"HttpCode", response->GetResponseCode()},
|
||||
{L"Error", response->GetError()},
|
||||
};
|
||||
std::wcout << L"Response: " << std::endl << result.dump(4) << std::endl;
|
||||
}
|
||||
};
|
||||
|
|
@ -1,133 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{45F5738D-CDF2-4024-974D-25B64F9043DE}</ProjectGuid>
|
||||
<RootNamespace>Samples</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(SolutionDir)\output\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)\build\$(PlatformToolset)\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)\output\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)\build\$(PlatformToolset)\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>
|
||||
xcopy "$(ProjectDir)\res" "$(OutDir)\res\" /D /E /I /F /Y
|
||||
xcopy "$(ProjectDir)..\..\src\kiwano-network\dlls\*.dll" "$(OutDir)" /D /Y
|
||||
</Command>
|
||||
<Message>Copy files</Message>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../../src;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>
|
||||
xcopy "$(ProjectDir)\res" "$(OutDir)\res\" /D /E /I /F /Y
|
||||
xcopy "$(ProjectDir)..\..\src\kiwano-network\dlls\*.dll" "$(OutDir)" /D /Y
|
||||
</Command>
|
||||
<Message>Copy files</Message>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="common.h" />
|
||||
<ClInclude Include="Demo1.h" />
|
||||
<ClInclude Include="Demo2.h" />
|
||||
<ClInclude Include="Demo3.h" />
|
||||
<ClInclude Include="Demo4.h" />
|
||||
<ClInclude Include="Demo5.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\projects\kiwano-audio.vcxproj">
|
||||
<Project>{1b97937d-8184-426c-be71-29a163dc76c9}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\projects\kiwano-network.vcxproj">
|
||||
<Project>{69dfbe92-c06f-4cf8-9495-ca9bf2e3baf2}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\projects\kiwano.vcxproj">
|
||||
<Project>{ff7f943d-a89c-4e6c-97cf-84f7d8ff8edf}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="res\index.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Xml Include="res\index.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Samples.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="..\..\logo\icon.ico" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Demo1.h">
|
||||
<Filter>src</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Demo2.h">
|
||||
<Filter>src</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Demo3.h">
|
||||
<Filter>src</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Demo4.h">
|
||||
<Filter>src</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Demo5.h">
|
||||
<Filter>src</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common.h">
|
||||
<Filter>src</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="resource.h">
|
||||
<Filter>resources</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="src">
|
||||
<UniqueIdentifier>{4460eeec-9e2f-46b6-909a-5ff4443075ce}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="resources">
|
||||
<UniqueIdentifier>{04b65e7e-f0ce-4b83-a73e-501913daf790}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Xml Include="res\index.xml">
|
||||
<Filter>resources</Filter>
|
||||
</Xml>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="res\index.json">
|
||||
<Filter>resources</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="..\..\logo\icon.ico">
|
||||
<Filter>resources</Filter>
|
||||
</Image>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Samples.rc">
|
||||
<Filter>resources</Filter>
|
||||
</ResourceCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#pragma once
|
||||
#include "kiwano/kiwano.h"
|
||||
#include "kiwano-audio/kiwano-audio.h"
|
||||
#include "kiwano-network/kiwano-network.h"
|
||||
|
||||
using namespace kiwano;
|
||||
using namespace kiwano::audio;
|
||||
using namespace kiwano::network;
|
||||
|
||||
const int WINDOW_WIDTH = 640;
|
||||
const int WINDOW_HEIGHT = 480;
|
||||
|
||||
// 栗都속潼묏야
|
||||
extern ResLoader g_Loader;
|
||||
|
|
@ -1,115 +0,0 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#include "Demo1.h"
|
||||
#include "Demo2.h"
|
||||
#include "Demo3.h"
|
||||
#include "Demo4.h"
|
||||
#include "Demo5.h"
|
||||
#include "resource.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
struct Demo
|
||||
{
|
||||
String title;
|
||||
ScenePtr(*Create)();
|
||||
};
|
||||
|
||||
Demo s_Demos[] = {
|
||||
{ L"动画示例", Demo1::Create },
|
||||
{ L"输入示例", Demo2::Create },
|
||||
{ L"音频播放示例", Demo3::Create },
|
||||
{ L"帧动画示例", Demo4::Create },
|
||||
{ L"网络请求示例", Demo5::Create },
|
||||
};
|
||||
int s_CurrIndex = -1;
|
||||
int s_DemoNum = sizeof(s_Demos) / sizeof(Demo);
|
||||
}
|
||||
|
||||
// 资源加载工具
|
||||
ResLoader g_Loader;
|
||||
|
||||
class DemoApp
|
||||
: public Application
|
||||
{
|
||||
public:
|
||||
DemoApp()
|
||||
{
|
||||
// 使用 Audio 组件
|
||||
Use(Audio::Instance());
|
||||
|
||||
// 使用 HttpClient 组件
|
||||
Use(HttpClient::Instance());
|
||||
|
||||
Options options(L"Kiwano示例程序", WINDOW_WIDTH, WINDOW_HEIGHT, MAKEINTRESOURCE(IDI_ICON1));
|
||||
Init(options);
|
||||
}
|
||||
|
||||
void OnStart() override
|
||||
{
|
||||
// 从 JSON 文件中读取资源信息
|
||||
//g_Loader.LoadFromJsonFile(L"res/index.json");
|
||||
|
||||
// 从 XML 文件中读取资源信息
|
||||
g_Loader.LoadFromXmlFile(L"res/index.xml");
|
||||
|
||||
// 切换到第一个场景
|
||||
ChangeDemoScene(0);
|
||||
}
|
||||
|
||||
void OnDestroy() override
|
||||
{
|
||||
// 退出游戏时销毁资源
|
||||
g_Loader.Destroy();
|
||||
}
|
||||
|
||||
void ChangeDemoScene(int index)
|
||||
{
|
||||
if (s_CurrIndex != index)
|
||||
{
|
||||
s_CurrIndex = index;
|
||||
|
||||
String title = s_Demos[index].title;
|
||||
Window::Instance()->SetTitle(L"Kiwano示例程序 - " + title);
|
||||
|
||||
ScenePtr scene = s_Demos[index].Create();
|
||||
EnterScene(scene);
|
||||
|
||||
// 添加按键监听
|
||||
scene->AddListener(Event::KeyUp, MakeClosure(this, &DemoApp::KeyPressed));
|
||||
|
||||
// 显示提示文字
|
||||
String intro_str = String::format(L"按键 1~%d 可切换示例\n", s_DemoNum);
|
||||
TextPtr intro = new Text(intro_str + title);
|
||||
intro->SetFontSize(16.f);
|
||||
intro->SetPosition(10, 10);
|
||||
scene->AddChild(intro);
|
||||
}
|
||||
}
|
||||
|
||||
void KeyPressed(Event const& evt)
|
||||
{
|
||||
KGE_ASSERT(evt.type == Event::KeyUp);
|
||||
|
||||
if (evt.key.code > KeyCode::Num0 &&
|
||||
evt.key.code <= (KeyCode::Num0 + s_DemoNum))
|
||||
{
|
||||
int index = evt.key.code - KeyCode::Num1;
|
||||
ChangeDemoScene(index);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ PWSTR, _In_ int)
|
||||
{
|
||||
try
|
||||
{
|
||||
DemoApp app;
|
||||
app.Run();
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
::MessageBoxA(nullptr, e.what(), "An exception has occurred!", MB_ICONERROR | MB_OK);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Before Width: | Height: | Size: 53 KiB |
|
Before Width: | Height: | Size: 81 KiB |
|
|
@ -1,40 +0,0 @@
|
|||
{
|
||||
"version": "0.1",
|
||||
"path": "./res/",
|
||||
"images": [
|
||||
{
|
||||
"id": "man",
|
||||
"file": "man.png"
|
||||
},
|
||||
{
|
||||
"id": "monster",
|
||||
"file": "akushu.png"
|
||||
},
|
||||
{
|
||||
"id": "forest_bg",
|
||||
"file": "spring_forest.jpg"
|
||||
},
|
||||
{
|
||||
"id": "tiger_running",
|
||||
"files": [
|
||||
"tiger/run/run01.png",
|
||||
"tiger/run/run02.png",
|
||||
"tiger/run/run03.png",
|
||||
"tiger/run/run04.png",
|
||||
"tiger/run/run05.png",
|
||||
"tiger/run/run06.png"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "tiger_standing",
|
||||
"file": "tiger/stand.png",
|
||||
"rows": 2,
|
||||
"cols": 3
|
||||
},
|
||||
{
|
||||
"id": "Kusanagi",
|
||||
"file": "Kusanagi.gif",
|
||||
"type": "gif"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<resources>
|
||||
<version>0.1</version>
|
||||
<path>./res/</path>
|
||||
<images>
|
||||
<image id="man" file="man.png" />
|
||||
<image id="monster" file="akushu.png" />
|
||||
<image id="forest_bg" file="spring_forest.jpg" />
|
||||
<image id="tiger_standing" file="tiger/stand.png" rows="2" cols="3" />
|
||||
<image id="tiger_running">
|
||||
<file path="tiger/run/run01.png"/>
|
||||
<file path="tiger/run/run02.png"/>
|
||||
<file path="tiger/run/run03.png"/>
|
||||
<file path="tiger/run/run04.png"/>
|
||||
<file path="tiger/run/run05.png"/>
|
||||
<file path="tiger/run/run06.png"/>
|
||||
</image>
|
||||
<image id="Kusanagi" file="Kusanagi.gif" type="gif" />
|
||||
</images>
|
||||
</resources>
|
||||
|
Before Width: | Height: | Size: 8.6 KiB |
|
Before Width: | Height: | Size: 209 KiB |
|
Before Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 3.4 KiB |
|
|
@ -1,16 +0,0 @@
|
|||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ 生成的包含文件。
|
||||
// 供 Samples.rc 使用
|
||||
//
|
||||
#define IDI_ICON1 101
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 102
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||