io.stdout:setvbuf("no") music = nil local tex = nil local timer = nil local tb = {x = 1, y = 2} local t = 0 local spr = nil local bitmap = nil local sprs = {} local animator = nil local spr = nil local ps = nil local mesh = nil local function createAnimation(path, count, r, c, w, h, loop, speed) local tex = jin.graphics.newTexture(path) local ssheet = jin.graphics.newSpriteSheet(tex) local sprs = ssheet:newSprites(count, r, c, w, h, 96, 168) return jin.graphics.newAnimation(sprs, loop, speed) end local particle_sprites = {} local Pi = 3.1415 function jin.core.onLoad() -- bitmap = jin.graphics.newBitmap(200, 200, function(w, h, x, y) -- return {255*math.sin(x/w),255 - 255,255*math.cos(y/w),255} -- end) local tex = jin.graphics.newTexture("splash.png") mesh = jin.graphics.newMesh() mesh:setGraphic(tex) mesh:pushVertex(-20, -20, 0, 0, {255, 0, 0, 255}) mesh:pushVertex(20, -20, 0.8, 0, {255, 0, 255, 255}) mesh:pushVertex(20, 20, 0.8, 0.8, {255, 255, 0, 255}) mesh:pushVertex(-20, 120, 0, 0.8, {255, 255, 255, 255}) ps = jin.graphics.newParticleSystem() for i = 0, 10 do local t = jin.graphics.newTexture("dust/s_dust_A_" .. i .. ".png") local spr = jin.graphics.newSprite(t, jin.graphics.SpriteOrigin.MIDDLECENTER) ps:addParticleSprite(spr) end ps:setEmitRate(0.02) ps:setEmitForce(80, 120) ps:setEmitPosition({0, 0}) ps:setEmitDirection(-Pi / 10 - Pi / 2, Pi / 10 - Pi / 2) ps:setParticleLinearAccelaration({0, 10}) ps:setParticleSpritesMode(jin.graphics.SpriteMode.ANIMATED) ps:setParticleColor({255, 30, 0, 255}) ps:addParticleTransparencyPoint(1, 0) ps:addParticleTransparencyPoint(0, 0.5) ps:enableParticleBlendAdditive(true) ps:setParticleLife(0.5, 2) ps:addParticleScalePoint(3, 0) ps:addParticleScalePoint(0, 1) local animation = createAnimation("anim2.png", 27, 3, 10, 200, 200, true, 50) animator = jin.graphics.newAnimator(animation) spr = animation:getFrame(1) local tex3 = jin.graphics.newTexture("anim2.png") tex3 = nil -- music = jin.audio.newSource("forest.ogg") -- music:setVolume(0.5) -- music:setLoop(true) -- music:play() jin.graphics.clear() jin.graphics.showWindow() timer = jin.time.newTimer() timer:every(3, function(p) --timer:cancel(h) if animator:getSpeed() == 50 then animator:setSpeed(100) elseif animator:getSpeed() == 100 then animator:setSpeed(50) end end, animator) jin.graphics.pushMatrix() jin.graphics.translate(0, 0) --jin.graphics.rotate(0.2) local fsm = jin.ai.newStateMachine({ events = { { name = 'startup', from = 'none', to = 'green' }, { name = 'panic', from = 'green', to = 'red' }, { name = 'calm', from = 'red', to = 'green' }, }}) print(fsm.current) -- "none" fsm:startup() print(fsm.current) -- "green" end function jin.core.onEvent(e) if e.type == "Quit" then jin.core.stop() end end function jin.core.onUpdate(dt) tb.x = t t = t + jin.time.getDelta() animator:update(jin.time.getDelta()) timer:update(jin.time.getDelta()) ps:update(dt) local mx, my = jin.mouse.getPosition() ps:setPosition(mx, my) ps:setEmitDirection(t - 0.3, t + 0.3) end function jin.core.onDraw() jin.graphics.useShader(jin.graphics.Shaders.Shape) jin.graphics.setColor(255, 0, 255, 255) jin.graphics.rect(jin.graphics.RenderMode.FILL, 30, 50, 100, 200) jin.graphics.setColor(255, 255, 255, 255) jin.graphics.unuseShader() --jin.graphics.draw(sprs[2], 150, 150, 1, 1, 0) local x, y = jin.mouse.getPosition() animator:render(350, 150, 1, 1, 0) jin.graphics.print("* Particle system test\n* Animation test", 10, 10) jin.graphics.draw(spr, 100, 200, 1, 1, 0) jin.graphics.useShader(jin.graphics.Shaders.Mesh) jin.graphics.draw(mesh, 200, 100) jin.graphics.unuseShader(); ps:render() end