aboutsummaryrefslogtreecommitdiff
path: root/bin/game/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'bin/game/main.lua')
-rw-r--r--bin/game/main.lua77
1 files changed, 54 insertions, 23 deletions
diff --git a/bin/game/main.lua b/bin/game/main.lua
index 324f9dc..b8aa2cd 100644
--- a/bin/game/main.lua
+++ b/bin/game/main.lua
@@ -1,34 +1,44 @@
io.stdout:setvbuf("no")
local shader = [[
#VERTEX_SHADER
-Vertex vert(Vertex v)
-{
- return v;
-}
+
+ Vertex vert(Vertex v)
+ {
+ return v;
+ }
+
#END_VERTEX_SHADER
+
#FRAGMENT_SHADER
-Color frag(Color col, Texture tex, Vertex v)
-{
- return col;
-}
+
+ Color frag(Color col, Texture tex, Vertex v)
+ {
+ return col;
+ }
+
#END_FRAGMENT_SHADER
]]
local shader2 = [[
#VERTEX_SHADER
-Vertex vert(Vertex v)
-{
- return v;
-}
+
+ Vertex vert(Vertex v)
+ {
+ return v;
+ }
+
#END_VERTEX_SHADER
+
#FRAGMENT_SHADER
-Color frag(Color col, Texture tex, Vertex v)
-{
- if(v.xy.x > 30)
- return Color(1, 0, 0, 1);
- Color c = texel(tex, v.uv);
- return c;
-}
+
+ Color frag(Color col, Texture tex, Vertex v)
+ {
+ if(v.xy.x > 30)
+ return Color(1, 0, 0, 1);
+ Color c = texel(tex, v.uv);
+ return c;
+ }
+
#END_FRAGMENT_SHADER
]]
music = nil
@@ -40,6 +50,16 @@ local tb = {x = 1, y = 2}
local t = 0
local spr = nil
local bitmap = nil
+local sprs = {}
+local animator = 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, jin.graphics.SpriteOrigin.BOTTOMCENTER)
+ return jin.graphics.newAnimation(sprs, loop, speed)
+end
+
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}
@@ -48,6 +68,12 @@ function jin.core.onLoad()
shader_program2 = jin.graphics.newShader(shader2)
--tex = jin.graphics.newTexture("1.png")
tex = jin.graphics.newTexture(bitmap)
+ local tex2 = jin.graphics.newTexture("anim.png")
+ local ssheet2 = jin.graphics.newSpriteSheet(tex2)
+ sprs = ssheet2:newSprites(1, 19, 246, 238, jin.graphics.SpriteOrigin.BOTTOMCENTER)
+ local animation = createAnimation("anim2.png", 27, 3, 10, 200, 200, true, 20)
+ animator = jin.graphics.newAnimator(animation)
+ animation = nil
local ssheet = jin.graphics.newSpriteSheet(tex)
spr = ssheet:newSprite({50, 50, 50, 50}, 20, 20)
tex = nil
@@ -59,11 +85,12 @@ function jin.core.onLoad()
jin.graphics.showWindow()
timer = jin.time.newTimer()
local h = timer:every(0.5, function(sp)
-
+
end, spr)
- timer:after(3, function(p)
+ timer:after(6, function(p)
--timer:cancel(h)
- end, h)
+ --animator:pause()
+ end, animator)
jin.graphics.pushMatrix()
jin.graphics.translate(0, 0)
--jin.graphics.rotate(0.2)
@@ -79,6 +106,7 @@ end
function jin.core.onUpdate()
tb.x = t
t = t + jin.time.getDelta()
+ animator:update(jin.time.getDelta())
end
function jin.core.onDraw()
@@ -88,7 +116,10 @@ function jin.core.onDraw()
jin.graphics.rect(jin.graphics.RenderMode.FILL, 30, 50, 100, 200)
jin.graphics.setColor(255, 255, 255, 255)
jin.graphics.unuseShader()
- jin.graphics.draw(spr, 0, 0, 1, 1, 0)
+ --jin.graphics.draw(sprs[2], 150, 150, 1, 1, 0)
+ local x, y = jin.mouse.getPosition()
+ animator:render(x, y, 1, 1, 0)
+ jin.graphics.print(#sprs, 10, 10)
--jin.graphics.draw(spr)
--jin.graphics.useShader(shader_program2)
--jin.graphics.draw(tex, 0, 0,0.2, 0.2)