aboutsummaryrefslogtreecommitdiff
path: root/bin/game/main.lua
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-11-16 00:24:51 +0800
committerchai <chaifix@163.com>2018-11-16 00:24:51 +0800
commit831e814ce9bdb84e86c06c4a52008f6bdaaa00d6 (patch)
treef91fccc7d2628d6e0a39886134b2bb174f5eede4 /bin/game/main.lua
parent6dc75930fe5fe02f1af5489917752d315cf9e48f (diff)
*合并master到minimal分支
Diffstat (limited to 'bin/game/main.lua')
-rw-r--r--bin/game/main.lua102
1 files changed, 102 insertions, 0 deletions
diff --git a/bin/game/main.lua b/bin/game/main.lua
new file mode 100644
index 0000000..ce22f46
--- /dev/null
+++ b/bin/game/main.lua
@@ -0,0 +1,102 @@
+io.stdout:setvbuf("no")
+local shader = [[
+#VERTEX_SHADER
+Vertex vert(Vertex v)
+{
+ return v;
+}
+#END_VERTEX_SHADER
+#FRAGMENT_SHADER
+Color frag(Color col, Texture tex, Vertex v)
+{
+ return col;
+}
+#END_FRAGMENT_SHADER
+]]
+
+local shader2 = [[
+#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;
+}
+#END_FRAGMENT_SHADER
+]]
+music = nil
+local tex = nil
+local shader_program = nil
+local shader_program2 = nil
+local timer = nil
+local tb = {x = 1, y = 2}
+local t = 0
+local spr = nil
+local bitmap = nil
+function jin.core.onLoad()
+ bitmap = jin.graphics.newBitmap(128, 128, function(w, h, x, y)
+ return {255*math.sin(x/w),255 - 255*math.cos(y/w),0,255}
+ end)
+ shader_program = jin.graphics.newShader(shader)
+ shader_program2 = jin.graphics.newShader(shader2)
+ --tex = jin.graphics.newTexture("1.png")
+ tex = jin.graphics.newTexture(bitmap)
+ local ssheet = jin.graphics.newSpriteSheet(tex)
+ spr = ssheet:newSprite(50, 50, 50, 50)
+ spr:setPosition(0, 50)
+ spr:setShader(shader_program2)
+ tex = nil
+ spr:setScale(2, 2)
+ spr:setColor(100, 0, 100, 255)
+ spr:setOrigin(jin.graphics.SpriteOrigin.BOTTOMCENTER)
+ -- 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()
+ local h = timer:every(0.5, function(sp)
+ local x, y = spr:getPosition()
+ spr:move(5, 0)
+ end, spr)
+ timer:after(3, function(p)
+ --timer:cancel(h)
+ end, h)
+ jin.graphics.pushMatrix()
+ --jin.graphics.translate(100, 0)
+ jin.graphics.rotate(0.2)
+end
+local stop = false
+
+function jin.core.onEvent(e)
+ if e.type == "Quit" then
+ jin.core.stop()
+ end
+end
+
+function jin.core.onUpdate()
+ tb.x = t
+ t = t + jin.time.getDelta()
+end
+
+function jin.core.onDraw()
+ timer:update(jin.time.getDelta())
+ jin.graphics.useShader(shader_program)
+ 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()
+ spr:render()
+ --jin.graphics.useShader(shader_program2)
+ --jin.graphics.draw(tex, 0, 0,0.2, 0.2)
+ --jin.graphics.unuseShader()
+ if stop then
+ jin.graphics.print("Quit", 100, 300)
+ end
+end \ No newline at end of file