Skip to content

Commit 186712e

Browse files
authored
Merge pull request #163 from our-mini-games/dev
Dev
2 parents da98dad + d79db39 commit 186712e

File tree

7 files changed

+32
-17
lines changed

7 files changed

+32
-17
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Mini-games
22

3-
A collection of small games(mine sweeper 扫雷, greedy snake 贪吃蛇, link game 连连看, tetris 俄罗斯方块, spider-solitaire 蜘蛛纸牌, Chinese chess 中国象棋, klotski 华容道 and 2048)
3+
A collection of small games(mine sweeper 扫雷, greedy snake 贪吃蛇, link game 连连看, tetris 俄罗斯方块, spider-solitaire 蜘蛛纸牌, Chinese chess 中国象棋, klotski 华容道 arkanoid 打砖块 and 2048)
44

55
## Playground
66
https://our-mini-games.github.io/mini-games/games/
@@ -22,3 +22,5 @@ https://our-mini-games.github.io/mini-games/games/
2222
- [x] 中国象棋
2323

2424
- [x] 华容道
25+
26+
- [x] 打砖块

packages/arkanoid/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="zh-CN">
33
<head>
44
<meta charset="UTF-8" />
5-
<link rel="icon" type="image/svg+xml" href="/mini-games/arkanoid.svg" />
5+
<link rel="icon" type="image/svg+xml" href="/mini-games/arkanoid.png" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
77
<title>打砖块</title>
88
</head>

packages/arkanoid/src/assets/style.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,21 @@ h1 {
3030

3131
.header .title {
3232
flex: 1;
33-
text-align: left;
33+
text-align: center;
3434
font-size: 20px;
3535
font-weight: bold;
3636
}
3737

3838
.btn {
3939
padding: 5px 10px;
40-
border: 1px solid #ccc;
40+
border: 1px solid #f1f1f1;
4141
border-radius: 5px;
4242
cursor: pointer;
4343
}
4444

4545
.arkanoid {
4646
flex: 1;
47+
min-height: 0;
4748
}
4849

4950
.footer {
@@ -56,7 +57,7 @@ h1 {
5657
position: relative;
5758
width: 300px;
5859
height: 32px;
59-
border: 1px solid #ccc;
60+
border: 1px solid #f1f1f1;
6061
border-radius: 4px;
6162
}
6263

packages/arkanoid/src/lib/Layout.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,14 @@ class Layout {
5353
this.#initControls()
5454
this.#initLights()
5555

56-
this.onWindowResize = this.onWindowResize.bind(this)
57-
window.addEventListener('resize', this.onWindowResize)
56+
const observe = new ResizeObserver((entries) => {
57+
for (const entry of entries) {
58+
if (entry.target === this.el) {
59+
this.onWindowResize(entry.contentRect.width, entry.contentRect.height)
60+
}
61+
}
62+
})
63+
observe.observe(this.el)
5864
}
5965

6066
#initCamera (): void {
@@ -103,9 +109,9 @@ class Layout {
103109
this.el.appendChild(this.renderer.domElement)
104110
}
105111

106-
onWindowResize (): void {
107-
this.width = this.el.offsetWidth
108-
this.height = this.el.offsetHeight
112+
onWindowResize (width: number, height: number): void {
113+
this.width = width
114+
this.height = height
109115

110116
this.camera.aspect = this.width / this.height
111117
this.camera.updateProjectionMatrix()

packages/arkanoid/src/main.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,31 @@ const init = (): void => {
100100

101101
const hammer = new Hammer(target)
102102

103+
hammer.get('pan').set({
104+
threshold: 10,
105+
direction: Hammer.DIRECTION_HORIZONTAL
106+
})
107+
103108
let startTime = performance.now()
109+
let startX = 0
104110
hammer.on('panstart', (e) => {
105111
e.target.classList.add('active')
106112
startTime = performance.now()
113+
startX = e.center.x
107114
})
108115

109116
hammer.on('panmove', (e) => {
110117
e.target.style.transform = `translateX(${Math.max(Math.min(e.deltaX, 123), -123)}px)`
111118
const nowTime = performance.now()
112119
if (nowTime - startTime > 32) {
113-
if (e.deltaX > 0) {
120+
if (startX < e.center.x) {
114121
arkanoid.moveBaffle('right')
115-
} else {
122+
} else if (startX > e.center.x) {
116123
arkanoid.moveBaffle('left')
117124
}
118125
startTime = nowTime
119126
}
127+
startX = e.center.x
120128
})
121129

122130
hammer.on('panend', (e) => {
@@ -125,6 +133,4 @@ const init = (): void => {
125133
})
126134
}
127135

128-
window.addEventListener('DOMContentLoaded', () => {
129-
setTimeout(init, 0)
130-
})
136+
window.addEventListener('DOMContentLoaded', init)

packages/entry/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<link rel="icon" type="image/svg+xml" href="/org.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<meta name="description" content="小游戏合集 A collection of small games" />
8-
<meta name="keywords" content="(mine sweeper 扫雷, greedy snake 贪吃蛇, link game 连连看, tetris 俄罗斯方块, spider-solitaire 蜘蛛纸牌, Chinese chess 中国象棋, klotski 华容道 and 2048)" />
8+
<meta name="keywords" content="(mine sweeper 扫雷, greedy snake 贪吃蛇, link game 连连看, tetris 俄罗斯方块, spider-solitaire 蜘蛛纸牌, Chinese chess 中国象棋, klotski 华容道 arkanoid 打砖块 and 2048)" />
99
<title>小游戏合集</title>
1010
</head>
1111
<body>

packages/entry/src/config/games.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const games: GameConfig[] = [
4848
{
4949
path: '/mini-games/arkanoid/index.html',
5050
name: '打砖块',
51-
cover: 'org.svg'
51+
cover: 'arkanoid.png'
5252
},
5353
{
5454
path: 'https://github.com/our-mini-games/mini-games/discussions',

0 commit comments

Comments
 (0)