Skip to content

Commit

Permalink
upstream update
Browse files Browse the repository at this point in the history
  • Loading branch information
asafonov committed Apr 19, 2024
1 parent 788a46f commit 152e59e
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 24 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "org.asafonov.accelerace"
minSdkVersion 21
targetSdkVersion 33
versionCode 4
versionName "0.4"
versionCode 5
versionName "0.5"
}
buildTypes {
release {
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,17 @@
<div id="count" class="util_text"></div>
</div>
<div class="util_section control_section">
<div class="game_control game_pause util_text">&#9208;</div>
<div class="game_control game_play util_text">&#9205;</div>
<div class="game_control game_pause">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 19">
<path d="M 0,19 H 6.451 V 0 H 0 Z"/>
<path d="M 9.549,19 H 16 V 0 H 9.549 Z"/>
</svg>
</div>
<div class="game_control game_play">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 19">
<path d="M 1.5209316e-8,-5.9509278e-7 V 18.999999 L 15.884,9.4239994 Z"/>
</svg>
</div>
</div>
<div class="util_section score_section txt_items">
<div id="score" class="util_text">0</div>
Expand Down
22 changes: 12 additions & 10 deletions app/src/main/assets/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class Timer {
}
class CarView {
constructor (speed) {
this.isMoving = false
this.element = document.querySelector('#main_car')
const rect = this.element.querySelector('svg path').getBoundingClientRect()
this.roadRect = document.querySelector('.road_sides').getBoundingClientRect()
Expand Down Expand Up @@ -119,14 +120,13 @@ class CarView {
this.element.style.top = `${this.carRect.top}px`
}
onMoveRight() {
this.stop()
this.moveRight()
if (! this.isMoving) this.moveRight()
}
onMoveLeft() {
this.stop()
this.moveLeft()
if (! this.isMoving) this.moveLeft()
}
move(top, left) {
this.isMoving = true
let movedHorizontally = left !== undefined && left !== null && left !== 0
let movedVertically = top !== undefined && top !== null && top !== 0
if (movedHorizontally) {
Expand All @@ -147,15 +147,15 @@ class CarView {
}
}
this.display()
return movedHorizontally || movedVertically
this.isMoving = movedHorizontally || movedVertically
}
moveLeft() {
const moved = this.move(0, -this.speed)
moved && (this.timeout = asafonov.timer.add(() => this.moveLeft()))
this.move(0, -this.speed)
this.isMoving && (this.timeout = asafonov.timer.add(() => this.moveLeft()))
}
moveRight() {
const moved = this.move(0, this.speed)
moved && (this.timeout = asafonov.timer.add(() => this.moveRight()))
this.move(0, this.speed)
this.isMoving && (this.timeout = asafonov.timer.add(() => this.moveRight()))
}
stop() {
this.timeout && asafonov.timer.remove(this.timeout)
Expand All @@ -168,6 +168,7 @@ class CarView {
this.element = null
this.carSize = null
this.roadSize = null
this.isMoving = null
}
}
class EnemyView {
Expand Down Expand Up @@ -292,6 +293,8 @@ class GameView {
this.carView = new CarView(asafonov.timer.getFPS() / 2)
this.playButton = document.querySelector('.game_play')
this.pauseButton = document.querySelector('.game_pause')
this.playButton.style.display = 'none'
this.pauseButton.style.display = 'none'
this.onPlayClickProxy = this.onPlayClick.bind(this)
this.onPauseClickProxy = this.onPauseClick.bind(this)
this.onTouchProxy = this.onTouch.bind(this)
Expand Down Expand Up @@ -563,7 +566,6 @@ window.asafonov.settings = {
}
window.asafonov.player = null
window.onerror = (msg, url, line) => {
alert(`${msg} on line ${line}`)
}
document.addEventListener("DOMContentLoaded", function (event) {
asafonov.timer.setInterval(80)
Expand Down
25 changes: 18 additions & 7 deletions app/src/main/assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ body,
margin-top: var(--palm_tree);
}

.util_section {
.util_section {
position: absolute;
top: var(--blur);
z-index: 99;

}

.util_section.score_section {
right: var(--tree);
right: var(--tree);
}

.util_section.control_section {
Expand All @@ -262,7 +262,7 @@ body,
font-size: calc(var(--height_car)/4);
color: var(--color_util);
text-shadow: 0 0 calc(var(--blur)*1.5) var(--color_util),
0 0 calc(var(--blur)*2) var(--color_util),
0 0 calc(var(--blur)*2) var(--color_util),
0 0 calc(var(--blur)*2) var(--color_road);
}

Expand All @@ -278,15 +278,26 @@ body,
content: 'ready?';
color: var(--color_red);
font-size: calc(var(--height_car)/4);
animation-fill-mode: forwards;
animation-fill-mode: forwards;
animation-timing-function: ease;
animation-name: countdown;
animation-duration: 5s;
animation-delay: 1s;
}

.game_control.game_play, .game_control.game_pause {
display: none;
.game_control {
height: calc(var(--height_car)/4);
display: flex;
align-items: center;
}

.game_control svg {
height: 70%;
filter: drop-shadow(0 0 calc(var(--blur)*1.5) var(--color_util));
}

.game_control svg path {
fill: var(--color_util);
}

@keyframes countdown {
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/org/asafonov/accelerace/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ public void onAccuracyChanged(Sensor sensor, int accuracy) {

public void onSensorChanged(SensorEvent event) {
float y = event.values[1];
double b = 1;
double b = 2;
String condition = "window !== null && window !== undefined && !! window.asafonov && !! asafonov.messageBus && !! asafonov.messageBus.send";

if (y > b) {
mWebView.evaluateJavascript("asafonov.messageBus.send(asafonov.events.CAR_MOVE_RIGHT)", null);
mWebView.evaluateJavascript("if (" + condition + ") asafonov.messageBus.send(asafonov.events.CAR_MOVE_RIGHT)", null);
}

if (y < -b) {
mWebView.evaluateJavascript("asafonov.messageBus.send(asafonov.events.CAR_MOVE_LEFT)", null);
mWebView.evaluateJavascript("if (" + condition + ") asafonov.messageBus.send(asafonov.events.CAR_MOVE_LEFT)", null);
}
}
};
Expand Down
2 changes: 2 additions & 0 deletions metadata/en-US/changelogs/4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Code cleanup
* Unuded permission removed
3 changes: 3 additions & 0 deletions metadata/en-US/changelogs/5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Add car control via gyroscope sensor
* New application icon
* Minor design fixes

0 comments on commit 152e59e

Please sign in to comment.