跳一跳輔助原始碼學習(主流解析度全適配)
阿新 • • 發佈:2019-01-22
微信跳一跳遊戲輔助
本原始碼主要來自知乎 xtutu 的分享,在此感謝。
在之前原始碼的基礎上,做了以下優化:
增加了配置介面,更方便普通玩家使用。
增加了對更多解析度的支援,目前支援 720x1280,1080x1920,5/5C/5S,6/6s,6P/6sP
開發環境
電腦:Windows 或 Mac
軟體:Lua 編輯器、抓色器(可以在官網 http://www.touchsprite.com/tools 下載)
手機:觸動精靈(iOS 或者安卓都可以)
工作原理
抓色器遠端連線手機截圖,找到座標點和顏色值,作業部落上有使用教程 https://www.zybuluo.com/miniknife/note/629913 。
通過 Lua 實現模擬點選
步驟:
安裝抓色器(用來截圖取點)
越獄手機新增源:apt.touchsprite.com,安裝觸動精靈
安卓手機 root 後訪問官網 http://www.touchsprite.com 下載安卓版觸動精靈
在手機上擷取跳一跳介面,也可以用抓色器遠端截圖:開啟觸動更多介面的區域網廣播開關,手機和電腦在同一區域網就可以
在抓色器上開啟截圖,滑鼠放到小人的底部中心點,同時按下 CTRL 和滑鼠,在周圍也取兩個點
生成程式碼,插入到 main.lua 的找色程式碼部分(可以用觸動精靈的編輯器,遠端除錯比較方便)
編輯器裝置標籤頁搜尋連線裝置(也要在同一個區域網),開啟指令碼點選遠端執行(需要提前進入遊戲介面)
原始碼講解
distanceTimeRate:數字越大表示蓄力時間越長
targetPositionOffset:表示方塊最上方的點,距離中心點的偏移
思路
確定自己的當前位置,直接查詢畫素就可以了(通過抓色器抓小人底部最寬位置的中心點和左右兩邊的點)
確定目標點位置:可以通過自己當前的位置判斷一個大致的範圍。
然後通過從左上,到右下角,依次遍歷畫素。找到方塊最上方的畫素點。
然後把y + 上一個大概的值來確定。
本原始碼主要來自知乎 xtutu 的分享,在此感謝。
在之前原始碼的基礎上,做了以下優化:
增加了配置介面,更方便普通玩家使用。
增加了對更多解析度的支援,目前支援 720x1280,1080x1920,5/5C/5S,6/6s,6P/6sP
開發環境
電腦:Windows 或 Mac
軟體:Lua 編輯器、抓色器(可以在官網 http://www.touchsprite.com/tools 下載)
手機:觸動精靈(iOS 或者安卓都可以)
工作原理
抓色器遠端連線手機截圖,找到座標點和顏色值,作業部落上有使用教程 https://www.zybuluo.com/miniknife/note/629913 。
通過 Lua 實現模擬點選
步驟:
安裝抓色器(用來截圖取點)
越獄手機新增源:apt.touchsprite.com,安裝觸動精靈
安卓手機 root 後訪問官網 http://www.touchsprite.com 下載安卓版觸動精靈
在手機上擷取跳一跳介面,也可以用抓色器遠端截圖:開啟觸動更多介面的區域網廣播開關,手機和電腦在同一區域網就可以
在抓色器上開啟截圖,滑鼠放到小人的底部中心點,同時按下 CTRL 和滑鼠,在周圍也取兩個點
生成程式碼,插入到 main.lua 的找色程式碼部分(可以用觸動精靈的編輯器,遠端除錯比較方便)
編輯器裝置標籤頁搜尋連線裝置(也要在同一個區域網),開啟指令碼點選遠端執行(需要提前進入遊戲介面)
原始碼講解
distanceTimeRate:數字越大表示蓄力時間越長
targetPositionOffset:表示方塊最上方的點,距離中心點的偏移
思路
確定自己的當前位置,直接查詢畫素就可以了(通過抓色器抓小人底部最寬位置的中心點和左右兩邊的點)
確定目標點位置:可以通過自己當前的位置判斷一個大致的範圍。
然後通過從左上,到右下角,依次遍歷畫素。找到方塊最上方的畫素點。
然後把y + 上一個大概的值來確定。
距離與時間轉換:遊戲的公式是線性的,直接乘以係數就可以了
init(0, 0) require("TSLib") w,h = getScreenSize() -- 不同解析度手機的時間係數 a1080 = 1.33 a720 = 1.9 i5 = 2.21 i6 = 1.825 i6p = 1.15 function i5_abu(edt_coef) while true do local x,y = findMultiColorInRegionFuzzy( 0x2b2b49, "0|1|0x2b2b49,0|2|0x2b2b49,0|3|0x2b2b49", 95,1, 297, 307, 1004) if x ~= -1 then local he = x + (1135-y) tap(x,y,695 + (670-he)*3.2) end local x,y = findMultiColorInRegionFuzzy( 0x2b2b49, "0|1|0x2b2b49,0|2|0x2b2b49,0|3|0x2b2b49", 95,309, 297, 636, 956) if x ~= -1 then local he = (639-(x+44)) + (1135-y) tap(x,y,610 + (670-he)*3.2) end mSleep(edt_coef) end end os_type = getOSType(); --獲取裝置系統版本 if ( w == 1080 and h == 1920 ) or ( h == 1080 and w == 1920 ) then -- 安卓 1080p edt_coef = a1080 findColors = {0x38365e, "-16|-6|0x35335a,13|-5|0x39375f", 98, 0, 0, w, h} elseif ( w == 720 and h == 1280 ) or ( h == 720 and w == 1280 ) then -- 安卓 720P edt_coef = a720 findColors = {0x37355d, "-24|0|0x2b2b49,23|0|0x383550,-2|-122|0x35363e", 98, 2, 536, 714, 1024} elseif ( w == 1242 and h == 2208 ) or ( h == 1242 and w == 2208 ) then -- iOS 6p,6sp edt_coef = i6p findColors = {0x373860, "-2|-214|0x34353d,-42|-2|0x2b2b49,40|-4|0x393550", 98, 20, 796, 1212, 1832} elseif ( w == 640 and h == 1136 ) or ( h == 640 and w == 1136 ) then -- iOS 5,5c,5s,touch5,touch6 edt_coef = "固定" -- findColors = {0x373861, "19|1|0x393758,-15|1|0x2e2e51", 98, 5, 514, 628, 922} elseif ( w == 750 and h == 1334 ) or ( h == 750 and w == 1334 ) then -- iOS 6,6s edt_coef = i6 findColors = {0x37355d, "-22|-1|0x2d2c4d,7|-124|0x413955", 98, 14, 564, 722, 1026} else dialog("暫不支援此解析度") lua_exit() end UINew("跳一跳高分輔助","開始","取消","tytb.txt",0,120,w,h) UILabel("關閉所有遮擋遊戲的圖示\r\n例如360加速球、小白點",20,"center","255,69,0") UILabel("--",18,"center","255,69,0") UILabel("") UILabel("設定停頓時間(單位:秒):") UIRadio("rdo","2,3,4,5","1") UILabel("5秒有概率可以成功上傳成績",14,"left","255,69,0") UILabel("裝置資訊",20,"left","0,136,0") UILabel("裝置名稱 : "..getDeviceName(),16,"left","120,120,120") if os_type == "android" then --返回值為純小寫字母 UILabel("裝置品牌 : "..getDeviceBrand(),16,"left","120,120,120") UILabel("裝置型號 : "..getDeviceModel(),16,"left","120,120,120") end UILabel("引擎版本 : "..getTSVer(),16,"left","120,120,120") UILabel("系統版本 : "..getOSVer(),16,"left","120,120,120") UILabel("解析度 : "..w..":"..h,16,"left","120,120,120") UILabel("係數 : "..edt_coef,16,"left","120,120,120") if os_type ~= "ios" and (( w ~= 640 and h ~= 1136 ) or ( h ~= 640 and w ~= 1136 )) then --返回值為純小寫字母 UILabel("") UILabel("") UILabel("") UILabel("") UILabel("") UILabel("") UILabel("") UILabel("") UILabel("") UILabel("") UILabel("") UILabel("") UILabel("") UILabel("") UILabel("") UILabel("") UILabel("") UILabel("") UILabel("") UILabel("") UILabel("預設不用修改係數.") UILabel("如果多次啟動均無法準確跳躍,可以手動進行微調.") UILabel("如需微調,推薦每次加減0.01") UILabel("輸入時間係數:") UIEdit("edt_coef","輸入時間係數",edt_coef.."",15,"left","255,0,0") end UIShow() mSleep(1000) edt_time = tonumber(rdo)*1000 if os_type == "ios" and (( w == 640 and h == 1136 ) or ( h == 640 and w == 1136 )) then i5_abu(edt_time) end local screenWidth, screenHeight= getScreenSize(); edt_coef = tonumber(edt_coef) local distanceTimeRate = edt_coef local targetPositionOffset = screenHeight * 0.012 function Touch(x, y, millsSecond) touchDown(x, y) mSleep(millsSecond) touchUp(x, y) end function DoLoop() while true do keepScreen(true); if DoJump() == false then keepScreen(false); break end keepScreen(false); end end function DoJump() local x, y = GetCalcSelfPosition()--找小人底部中心點 if x == -1 or x == 0 then return false end local startX = 0 -- 找色起始X值是0點 local startY = screenHeight * 0.2 -- 找色起始Y值是螢幕高度*0.2,因為再往上沒有需要找的色. local endX = screenWidth - 3 -- 找色結束X值是螢幕寬度-3,防止迴圈越界. local endY = screenHeight * 0.7 -- 找色結束Y值是螢幕高度*0.7,因為再往下沒有需要找的色. if x < screenWidth / 2 then -- 如果找到黑色人偶的座標在螢幕左半部(X < 螢幕寬度/2) startX = screenWidth / 2 -- 那麼目標點肯定在螢幕右半部,找色起始X值等於螢幕寬度的一半. else -- 如果找到黑色人偶的座標在螢幕右半部(X > 螢幕寬度/2) endX = screenWidth / 2 -- 那麼目標點肯定在螢幕左半部,找色結束X值等於螢幕寬度的一半. end local targetX, targetY = GetTargetPosition(startX, startY, endX, endY) -- 通過三角函式,使用人偶底部中心座標和目標座標計算距離,x,y是人偶底部中心座標,targetX,targetY 是盒子的中心座標, local distance = math.sqrt( (x - targetX) * (x - targetX) + (y - targetY) * (y - targetY) ) local pressTime = CalcHoldTime(distance) -- 通過距離*時間係數得到按壓的延時時長 Touch(targetX,targetY, pressTime) math.randomseed(getRndNum()) -- 隨機種子初始化真隨機數 num = math.random(edt_time-500, edt_time+1000) -- 隨機獲取一個延時-500到延時+1000之間的數字,通過隨機時間間隔跳躍,增加成功上傳成績機率 mSleep(num) return true end function GetCalcSelfPosition() x,y = findMultiColorInRegionFuzzy( findColors[1], findColors[2], findColors[3], findColors[4], findColors[5], findColors[6], findColors[7]) return x, y end function GetTargetPosition(startX, startY, endX, endY) local step = 3 local r, g, b, rr, gg, bb for y = startY , endY, step do--上往下開始每三個畫素取一下顏色值 r, g, b = getColorRGB(1, y)--X 座標點為 1,Y 座標點在起始點與終點之間 for x = startX, endX , step do rr, gg, bb = getColorRGB(x, y) if isColor(r, g, b, rr, gg, bb, 98) then--將取到的顏色值進行對比 r = rr g = gg b = bb else--找到一個和剛才的點顏色不一樣的點 return x, y + targetPositionOffset end end end return -1, -1 end function isColor(rr, gg, bb, r, g, b ,s) local fl,abs = math.floor,math.abs s = fl(0xff*(100-s)*0.01) if abs(r-rr)<s and abs(g-gg)<s and abs(b-bb)<s then return true end return false end function CalcHoldTime(distance) return distance * distanceTimeRate end mSleep(1000) DoLoop()