| @@ -85,7 +85,9 @@ tutorial/02_cube | |||
| tutorial/03_noise | |||
| tutorial/04_texture | |||
| tutorial/05_easymesh | |||
| tutorial/06_sprite | |||
| tutorial/08_fbo | |||
| tutorial/11_fractal | |||
| tutorial/12_voronoi | |||
| # Our data | |||
| doc/doxygen.cfg | |||
| @@ -0,0 +1,106 @@ | |||
| // | |||
| // Lol Engine - Sprite tutorial | |||
| // | |||
| // Copyright: (c) 2011-2013 Sam Hocevar <sam@hocevar.net> | |||
| // (c) 2012 Daniel Stephens (artwork) | |||
| // This program is free software; you can redistribute it and/or | |||
| // modify it under the terms of the Do What The Fuck You Want To | |||
| // Public License, Version 2, as published by Sam Hocevar. See | |||
| // http://www.wtfpl.net/ for more details. | |||
| // | |||
| #if defined HAVE_CONFIG_H | |||
| # include "config.h" | |||
| #endif | |||
| #include "core.h" | |||
| using namespace std; | |||
| using namespace lol; | |||
| class SpriteTutorial : public WorldEntity | |||
| { | |||
| public: | |||
| SpriteTutorial() | |||
| { | |||
| m_camera = new Camera(); | |||
| m_camera->SetView(mat4(1.f)); | |||
| m_camera->SetProjection(mat4::ortho(0.f, 640.f, 0.f, 480.f, -100.f, 100.f)); | |||
| Scene::GetDefault()->PushCamera(m_camera); | |||
| Ticker::Ref(m_camera); | |||
| m_tileset = Tiler::Register("06_sprite.png"); | |||
| for (int i = 0; i < FRAME_COUNT; ++i) | |||
| m_tileset->AddTile(ibox2(i * 24, 376, 24 + i * 24, 24 + 376)); | |||
| for (int i = 0; i < SPRITE_COUNT; ++i) | |||
| { | |||
| m_sprites.Push(ivec3(rand(-96, 640), rand(-96, 480), 0), | |||
| rand(0.f, 1.f)); | |||
| } | |||
| m_ready = false; | |||
| } | |||
| ~SpriteTutorial() | |||
| { | |||
| Tiler::Deregister(m_tileset); | |||
| Scene::GetDefault()->PopCamera(m_camera); | |||
| Ticker::Unref(m_camera); | |||
| } | |||
| virtual void TickGame(float seconds) | |||
| { | |||
| for (int i = 0; i < SPRITE_COUNT; ++i) | |||
| { | |||
| m_sprites[i].m1.y += 50.f * seconds; | |||
| m_sprites[i].m2 = lol::fmod(m_sprites[i].m2 + seconds, 1.f); | |||
| if (m_sprites[i].m1.y > 480 + 48) | |||
| m_sprites[i].m1.y = rand(-96, -48); | |||
| } | |||
| WorldEntity::TickGame(seconds); | |||
| } | |||
| virtual void TickDraw(float seconds) | |||
| { | |||
| WorldEntity::TickDraw(seconds); | |||
| if (!m_ready) | |||
| { | |||
| Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f)); | |||
| m_ready = true; | |||
| } | |||
| for (int i = 0; i < SPRITE_COUNT; ++i) | |||
| { | |||
| int frame = (int)(m_sprites[i].m2 * FRAME_COUNT); | |||
| // m_sprites[i].m1.z = frame; | |||
| Scene::GetDefault()->AddTile(m_tileset, frame, | |||
| (ivec3)m_sprites[i].m1, 0, vec2(2.f)); | |||
| } | |||
| } | |||
| private: | |||
| Camera *m_camera; | |||
| TileSet *m_tileset; | |||
| static int const SPRITE_COUNT = 192; | |||
| static int const FRAME_COUNT = 16; | |||
| Array<vec3, float> m_sprites; | |||
| bool m_ready; | |||
| }; | |||
| int main(int argc, char **argv) | |||
| { | |||
| System::Init(argc, argv); | |||
| Application app("Tutorial 6: Sprite", ivec2(640, 480), 60.0f); | |||
| new SpriteTutorial(); | |||
| app.Run(); | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -0,0 +1,68 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
| <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
| <ItemGroup Label="ProjectConfigurations"> | |||
| <ProjectConfiguration Include="Debug|PS3"> | |||
| <Configuration>Debug</Configuration> | |||
| <Platform>PS3</Platform> | |||
| </ProjectConfiguration> | |||
| <ProjectConfiguration Include="Debug|Win32"> | |||
| <Configuration>Debug</Configuration> | |||
| <Platform>Win32</Platform> | |||
| </ProjectConfiguration> | |||
| <ProjectConfiguration Include="Debug|x64"> | |||
| <Configuration>Debug</Configuration> | |||
| <Platform>x64</Platform> | |||
| </ProjectConfiguration> | |||
| <ProjectConfiguration Include="Debug|Xbox 360"> | |||
| <Configuration>Debug</Configuration> | |||
| <Platform>Xbox 360</Platform> | |||
| </ProjectConfiguration> | |||
| <ProjectConfiguration Include="Release|PS3"> | |||
| <Configuration>Release</Configuration> | |||
| <Platform>PS3</Platform> | |||
| </ProjectConfiguration> | |||
| <ProjectConfiguration Include="Release|Win32"> | |||
| <Configuration>Release</Configuration> | |||
| <Platform>Win32</Platform> | |||
| </ProjectConfiguration> | |||
| <ProjectConfiguration Include="Release|x64"> | |||
| <Configuration>Release</Configuration> | |||
| <Platform>x64</Platform> | |||
| </ProjectConfiguration> | |||
| <ProjectConfiguration Include="Release|Xbox 360"> | |||
| <Configuration>Release</Configuration> | |||
| <Platform>Xbox 360</Platform> | |||
| </ProjectConfiguration> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <ClCompile Include="06_sprite.cpp" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <ProjectReference Include="$(SolutionDir)\..\..\src\lolcore.vcxproj"> | |||
| <Project>{9e62f2fe-3408-4eae-8238-fd84238ceeda}</Project> | |||
| </ProjectReference> | |||
| <ProjectReference Include="$(SolutionDir)\..\..\src\bullet\lolbullet.vcxproj"> | |||
| <Project>{83d3b207-c601-4025-8f41-01dedc354661}</Project> | |||
| </ProjectReference> | |||
| </ItemGroup> | |||
| <PropertyGroup Label="Globals"> | |||
| <ProjectGuid>{1c5b8702-290c-42da-aa9e-671348f5b747}</ProjectGuid> | |||
| <ConfigurationType>Application</ConfigurationType> | |||
| <Keyword>Win32Proj</Keyword> | |||
| </PropertyGroup> | |||
| <Import Project="$(SolutionDir)\Lol.Core.Config.props" /> | |||
| <ImportGroup Label="ExtensionSettings"> | |||
| <Import Project="$(SolutionDir)\Lol.Fx.props" /> | |||
| </ImportGroup> | |||
| <ImportGroup Label="PropertySheets"> | |||
| <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |||
| <Import Project="$(SolutionDir)\Lol.Core.Vars.props" /> | |||
| </ImportGroup> | |||
| <PropertyGroup Label="UserMacros" /> | |||
| <Import Project="$(SolutionDir)\Lol.Core.Rules.props" /> | |||
| <ItemDefinitionGroup /> | |||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |||
| <ImportGroup Label="ExtensionTargets"> | |||
| <Import Project="$(SolutionDir)\Lol.Fx.targets" /> | |||
| </ImportGroup> | |||
| </Project> | |||
| @@ -2,7 +2,7 @@ | |||
| include $(top_srcdir)/build/autotools/common.am | |||
| noinst_PROGRAMS = 01_triangle 02_cube 03_noise 04_texture 05_easymesh \ | |||
| 08_fbo 11_fractal \ | |||
| 06_sprite 08_fbo 11_fractal \ | |||
| 12_voronoi | |||
| 01_triangle_SOURCES = 01_triangle.cpp 01_triangle.lolfx | |||
| @@ -25,6 +25,14 @@ noinst_PROGRAMS = 01_triangle 02_cube 03_noise 04_texture 05_easymesh \ | |||
| 05_easymesh_CPPFLAGS = $(AM_CPPFLAGS) | |||
| 05_easymesh_DEPENDENCIES = @LOL_DEPS@ | |||
| 06_sprite_SOURCES = 06_sprite.cpp 06_sprite.png | |||
| 06_sprite_CPPFLAGS = $(AM_CPPFLAGS) | |||
| 06_sprite_DEPENDENCIES = @LOL_DEPS@ | |||
| 06_sprite_LDFLAGS = $(AM_LDFLAGS) | |||
| if USE_EMSCRIPTEN | |||
| 06_sprite_LDFLAGS += --preload-file 06_sprite.png | |||
| endif | |||
| 08_fbo_SOURCES = 08_fbo.cpp 08_fbo.lolfx | |||
| 08_fbo_CPPFLAGS = $(AM_CPPFLAGS) | |||
| 08_fbo_DEPENDENCIES = @LOL_DEPS@ | |||