Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w = require("w") -- allows interaction with krist websocket api (for realtime data)
- local r = require("r") -- makes http requests easier
- local k = require("k") -- the krist api itself
- local jua = require("jua") -- makes events easier
- os.loadAPI("json.lua") -- to parse data returned by the krist api
- local await = jua.await
- r.init(jua)
- w.init(jua)
- k.init(jua, json, w, r)
- local function openWebsocket()
- local success, ws = await(k.connect, k.toKristWalletFormat(6798332999))
- assert(success, "Failed to get websocket URL")
- -- print("Connected to websocket.")
- -- here we subscribe to the 'transactions' event
- local success = await(ws.subscribe, "transactions", function(data)
- -- this function is called every time a transaction is made
- local transaction = data.transaction
- --print("Transaction made:")
- --print("From: " .. transaction.from)
- --print("To: " .. transaction.to)
- --print("Value: " .. transaction.value .. " KST")
- -- Transactions have other properties, including "metadata", "id" and "time".
- -- Metadata can be parsed using k.parseMeta
- end)
- assert(success, "Failed to subscribe to event")
- end
- --
- --
- --
- escore = 0
- py = 14
- ex, y1 = 50, 13
- y2 = 15
- function ggraphic()
- while true do
- term.setBackgroundColor(colors.lightBlue)
- term.clear()
- paintutils.drawFilledBox(1,11,51,19,colors.green)
- paintutils.drawFilledBox(1,13,51,15,colors.black)
- paintutils.drawPixel(ex, y1, colors.red)
- paintutils.drawPixel(ex, y2, colors.red)
- paintutils.drawPixel(10, py, colors.blue)
- term.setBackgroundColor(colors.green)
- term.setCursorPos(10,11)
- term.write("Score: ")
- term.write(escore)
- sleep(0.1)
- end
- end
- function gemove()
- while true do
- sleep()
- if ex < 2 then
- y1 = math.random(13,15)
- y2 = math.random(13,15)
- ex = 51
- end
- if y2 == y1 then
- y2 = y2 + 1
- end
- if y2 == 16 then
- y2 = 13
- end
- ex = ex - 1
- if ex == 10 then
- escore = escore + 1
- end
- end
- end
- function epmove()
- while true do
- e, k = os.pullEvent("key")
- if k == 200 then
- if py > 13 then
- py = py - 1
- end
- elseif k == 208 then
- if py < 15 then
- py = py + 1
- end
- end
- end
- end
- function egameend1()
- repeat
- sleep()
- until ex == 10 and y1 == py or y2 == py and ex == 10
- end
- --
- --
- --
- jua.go(function()
- openWebsocket()
- parallel.waitForAny(ggraphic,gemove,epmove,egameend1)
- paintutils.drawFilledBox(1,13,51,15,colors.black)
- term.setBackgroundColor(colors.black)
- term.setCursorPos(15,13)
- write("Game Over! Insert 1KST to try again!")
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement