aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/animation/main.cpp102
-rw-r--r--examples/particle_system/main.cpp20
2 files changed, 112 insertions, 10 deletions
diff --git a/examples/animation/main.cpp b/examples/animation/main.cpp
new file mode 100644
index 0000000..033e499
--- /dev/null
+++ b/examples/animation/main.cpp
@@ -0,0 +1,102 @@
+#include <iostream>
+
+#include "libjin/jin.h"
+
+using namespace std;
+using namespace JinEngine::AI;
+using namespace JinEngine::Game;
+using namespace JinEngine::Math;
+using namespace JinEngine::Input;
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Shaders;
+using namespace JinEngine::Graphics::Particles;
+using namespace JinEngine::Graphics::Animations;
+using namespace JinEngine::Filesystem;
+using namespace JinEngine::Time;
+
+Timer timer;
+Timer::Handler* hnd;
+Texture* tex;
+Shader* shader;
+Animation anim;
+const char* shader_code = R"(
+#VERTEX_SHADER
+Vertex vert(Vertex v)
+{
+ return v;
+}
+#END_VERTEX_SHADER
+#FRAGMENT_SHADER
+Color frag(Color col, Texture tex, Vertex v)
+{
+ Color c = texel(tex, v.uv);
+ return c * col;
+}
+#END_FRAGMENT_SHADER
+)";
+const float Pi = 3.14f;
+void onLoad()
+{
+ tex = Texture::createTexture("anim.png");
+ shader = Shader::createShader(shader_code);
+ SpriteSheet ss = SpriteSheet(tex);
+ vector<Sprite*> frames = ss.createSprites(1, 19, 246, 238, Sprite::Origin::BottomCenter);
+ anim.addFrames(frames);
+ anim.setSpeed(0.05);
+}
+
+void onEvent(Event* e)
+{
+ static Application* Application = Application::get();
+ if (e->type == EventType::QUIT)
+ Application->stop();
+}
+
+void onUpdate(int ms)
+{
+ anim.update(ms / 1000.f);
+ timer.update(ms);
+}
+
+void onDraw()
+{
+ shader->use();
+ Mouse* m = Mouse::get();
+ int x, y;
+ m->getState(&x, &y);
+ anim.render(x, y, 1, 1, 0);
+ shader->unuse();
+}
+
+int main(int argc, char* argv[])
+{
+ Application* Application = Application::get();
+ Application::Setting setting;
+ setting.loader = onLoad;
+ setting.eventHandler = onEvent;
+ setting.updater = onUpdate;
+ setting.drawer = onDraw;
+ Application->init(&setting);
+
+ AssetDatabase::get()->mount(".");
+
+ Window* wnd = Window::get();
+ Window::Setting wndSetting;
+ wndSetting.width = 600;
+ wndSetting.height = 512;
+ wndSetting.title = "Jin v0.1.1";
+ wndSetting.fps = 60;
+ wndSetting.vsync = false;
+ wndSetting.fullscreen = false;
+ wndSetting.resizable = false;
+ wndSetting.icon = ".";
+ wnd->init(&wndSetting);
+ wnd->show();
+
+ Application->run();
+
+ Application->quit();
+ wnd->quit();
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/particle_system/main.cpp b/examples/particle_system/main.cpp
index a838bed..9251cc4 100644
--- a/examples/particle_system/main.cpp
+++ b/examples/particle_system/main.cpp
@@ -38,23 +38,23 @@ const float Pi = 3.14f;
void onLoad()
{
tex = Texture::createTexture("texture.png");
- spr = new Sprite(tex, Sprite::Origin::MiddleCenter);
+ spr = new Sprite(tex, Sprite::Origin::BottomCenter);
shader = Shader::createShader(shader_code);
ParticleSystemDef def;
def.maxParticleCount = 30;
def.emitterDef.emitRateDef.rate.rate = 0.01f;
- def.emitterDef.forceDef.force.force = 10.f;
+ def.emitterDef.forceDef.force.force = 50.f;
def.emitterDef.positionDef.enableRandom = true;
- def.emitterDef.positionDef.position.random.floor = Vector2<float>(0, 0);
- def.emitterDef.positionDef.position.random.ceil = Vector2<float>(0, 10);
+ def.emitterDef.positionDef.position.random.floor = Vector2<float>(-20, 0);
+ def.emitterDef.positionDef.position.random.ceil = Vector2<float>(20, 0);
def.emitterDef.directionDef.enableRandom = true;
- def.emitterDef.directionDef.direction.random.floor = 0;
- def.emitterDef.directionDef.direction.random.ceil = Pi*2;
+ def.emitterDef.directionDef.direction.random.floor = -Pi / 2 ;
+ def.emitterDef.directionDef.direction.random.ceil = -Pi / 2 ;
def.particleDef.colorOverTimeDef.enable = true;
- def.particleDef.colorOverTimeDef.colorStart = Color(255, 255, 0, 255);
+ def.particleDef.colorOverTimeDef.colorStart = Color(255, 100, 0, 255);
def.particleDef.colorOverTimeDef.colorEnd = Color(255, 0, 0, 0);
/*
def.particleDef.angularSpeedDef.enableRandom = true;
@@ -62,13 +62,13 @@ void onLoad()
def.particleDef.angularSpeedDef.angularSpeed.random.ceil = 1;
*/
- //def.particleDef.linearAccelarationDef.linearAccelaration = Vector2<float>(0, 10);
+ def.particleDef.linearAccelarationDef.linearAccelaration = Vector2<float>(0, 10);
def.particleDef.sizeOverTimeDef.enable = true;
def.particleDef.sizeOverTimeDef.start = 1;
- def.particleDef.sizeOverTimeDef.end = 0.5;
+ def.particleDef.sizeOverTimeDef.end = 1;
- def.particleDef.lifeTimeDef.life.life = 0.5;
+ def.particleDef.lifeTimeDef.life.life = 3;
p = new ParticleSystem(def);
p->setSprite(spr);
}