From 7e0c2825c3831ac460ecf06c5639bdc219e4e7c8 Mon Sep 17 00:00:00 2001 From: Li Jia Date: Sun, 1 Nov 2015 11:43:34 +0800 Subject: [PATCH] Fix some bugs. --- index.html | 7 +++++-- lib.js | 23 +++++++++++++---------- main.cpp | 10 +++++++--- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/index.html b/index.html index 675a452..d8c7a49 100644 --- a/index.html +++ b/index.html @@ -67,10 +67,13 @@ Module.setStatus('Loading...'); window.onerror = function (event) { + document.documentElement.innerHTML = event; }; - Module.print(document.documentElement.clientWidth, document.documentElement.clientHeight); - canvas.height = document.documentElement.clientHeight; + if (true) { + var rect = canvas.getBoundingClientRect(); + canvas.height = Math.max(document.documentElement.clientHeight - rect.top, 420); + } var angle = 0; var drawLoading = function () { diff --git a/lib.js b/lib.js index b4eac1f..41048e0 100644 --- a/lib.js +++ b/lib.js @@ -240,25 +240,28 @@ var LibraryDLM = { } } - var check_touch = function (t, x1, y1, x2, y2) { - return (t.clientX > x1 && t.clientX < x2 && - t.clientY > y1 && t.clientY < y2); + var check_touch = function (x, y, x1, y1, x2, y2) { + return (x > x1 && x < x2 && y > y1 && y < y2); } var touch_callback = function (e) { e.preventDefault(); var touch = 0; - var centerY = 420 + (Module['canvas'].height - 420) / 2; + var centerY = 420 + (canvas.height - 420) / 2; + var rect = canvas.getBoundingClientRect(); for (var i = 0; i < e.touches.length; i++) { var t = e.touches.item(i); - if (check_touch(t, 140 - 40, centerY + 20, 140 + 40, centerY + 100)) touch |= 4; - else if (check_touch(t, 140 - 40, centerY - 100, 140 + 40, centerY - 40)) touch |= 8; - else if (check_touch(t, 140 - 100, centerY - 40, 140, centerY + 40)) touch |= 1; - else if (check_touch(t, 140, centerY - 40, 140 + 100, centerY + 40)) touch |= 2; + var x = (t.clientX - rect.left) / (rect.right - rect.left) * canvas.width; + var y = (t.clientY - rect.top) / (rect.bottom - rect.top) * canvas.height; - if (check_touch(t, 340 - 100, centerY - 100, 340 + 100, centerY + 100)) touch |= 0x10; - touch |= 0x20; + if (check_touch(x, y, 140 - 40, centerY + 20, 140 + 40, centerY + 100)) touch |= 4; + else if (check_touch(x, y, 140 - 40, centerY - 100, 140 + 40, centerY - 40)) touch |= 8; + else if (check_touch(x, y, 140 - 100, centerY - 40, 140, centerY + 40)) touch |= 1; + else if (check_touch(x, y, 140, centerY - 40, 140 + 100, centerY + 40)) touch |= 2; + + if (check_touch(x, y, 340 - 100, centerY - 100, 340 + 100, centerY + 100)) touch |= 0x10; + if (check_touch(x, y, 0, 0, 480, 420)) touch |= 0x20; } DLM.touch = touch; } diff --git a/main.cpp b/main.cpp index 592ec9c..3667dda 100644 --- a/main.cpp +++ b/main.cpp @@ -998,11 +998,15 @@ void rpaint() { if (tmsgtm == 1) {tmsgtm = 80000000; tmsgtype = 2; } } //1 else if (tmsgtype == 2) { - tmsgy = 0; tmsgtype = 3; tmsgtm = 15 + 1; + if (key & (PAD_INPUT_DECIDE | PAD_INPUT_JUMP)) { + tmsgy = 0; tmsgtype = 3; tmsgtm = 15 + 1; + } + else { + tmsgtm++; + } } else if (tmsgtype == 3) { xx[0] = 1200; tmsgy += xx[0]; - if (tmsgtm == 15) input_waitkey(); if (tmsgtm == 1) {tmsgtm = 0; tmsgtype = 0; tmsgy = 0; } } //1 @@ -3276,7 +3280,7 @@ void Mainprogram() { */ //if (CheckHitKeyAll() == 0){end();} - if (key != 0) { xx[0] = 1; } + if (key & (PAD_INPUT_DECIDE | PAD_INPUT_JUMP)) { xx[0] = 1; } //if (input_keydown(KEY_INPUT_RETURN) == 1) {xx[0] = 1; } //if (input_keydown(KEY_INPUT_SPACE)==1){xx[0]=1;} //if (input_keydown(KEY_INPUT_Z) == 1) {xx[0] = 1; }