aboutsummaryrefslogtreecommitdiff
path: root/bin/game/main.lua
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-12-23 01:06:46 +0800
committerchai <chaifix@163.com>2018-12-23 01:06:46 +0800
commit5b8b5c95589e615afda3f0d67db612b64297c2a0 (patch)
tree976de20f8a317c1dfb07ed1914ff8bebc4242005 /bin/game/main.lua
parent6afaad9b9490d4b70a0bea4a8289cc637194abc7 (diff)
*shader and time
Diffstat (limited to 'bin/game/main.lua')
-rw-r--r--bin/game/main.lua37
1 files changed, 33 insertions, 4 deletions
diff --git a/bin/game/main.lua b/bin/game/main.lua
index d521fc2..224da77 100644
--- a/bin/game/main.lua
+++ b/bin/game/main.lua
@@ -4,7 +4,6 @@ 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 = {}
@@ -20,6 +19,7 @@ local function createAnimation(path, count, r, c, w, h, loop, speed)
end
local particle_sprites = {}
local Pi = 3.1415
+local sinShader = nil
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}
@@ -50,6 +50,7 @@ function jin.core.onLoad()
ps:setParticleLife(0.5, 2)
ps:addParticleScalePoint(3, 0)
ps:addParticleScalePoint(0, 1)
+ ps:setPosition(250, 200)
local animation = createAnimation("anim2.png", 27, 3, 10, 200, 200, true, 50)
animator = jin.graphics.newAnimator(animation)
spr = animation:getFrame(1)
@@ -84,6 +85,29 @@ function jin.core.onLoad()
fsm:startup()
print(fsm.current) -- "green"
+ sinShader = jin.graphics.newShader[[
+ #VERTEX_SHADER
+ Vertex vert(Vertex v)
+ {
+ return v;
+ }
+ #END_VERTEX_SHADER
+ #FRAGMENT_SHADER
+ Color frag(Color col, Texture tex, Vertex v)
+ {
+ col.r = 0;
+ col.g = 0;
+ col.b = 0;
+ float t = jin_Time.y * 60;
+ if(t < 0.9)
+ col.b = 1;
+ else
+ col.r = t;
+
+ return col;
+ }
+ #END_FRAGMENT_SHADER
+ ]]
end
function jin.core.onEvent(e)
@@ -92,15 +116,17 @@ function jin.core.onEvent(e)
end
end
+local t = 0
function jin.core.onUpdate(dt)
tb.x = t
t = t + jin.time.getDelta()
+ print(jin.time.getFPS())
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)
+ --ps:setPosition(mx, my)
+ --ps:setEmitDirection(t - 0.3, t + 0.3)
end
function jin.core.onDraw()
@@ -112,10 +138,13 @@ function jin.core.onDraw()
--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.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()
+ jin.graphics.useShader(sinShader)
+ jin.graphics.rect(jin.graphics.RenderMode.FILL, 300, 300, 100, 50)
+ jin.graphics.unuseShader()
end \ No newline at end of file