Skip to content

Commit 2ad1535

Browse files
committed
feat: add booth logo to HexTile
1 parent 6b836cc commit 2ad1535

File tree

6 files changed

+42
-14
lines changed

6 files changed

+42
-14
lines changed

src/components/Danmaku.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ defineProps<{
4242
color: #fff;
4343
font-size: 20px;
4444
visibility: hidden;
45-
animation: danmaku-move 6s linear infinite;
45+
animation: danmaku-move 6s linear;
4646
animation-fill-mode: forwards;
4747
text-shadow:
4848
-1px -1px 0 #333, /* 左上 */

src/components/PhaserGame.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ renderer.link = function ({href, title, text}) {
2323
}
2424
marked.setOptions({ renderer })
2525
26-
onMounted(() => {
27-
game.value = StartGame('game-container')
26+
onMounted(async () => {
27+
game.value = await StartGame('game-container')
2828
2929
const boothsDataUrl = 'https://coscup.org/2024/json/sponsor.json'
3030
fetch(boothsDataUrl)

src/data/GameData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const GameData = {
88
hexSize: 0,
99
bottomBarHeight: 70,
1010
popupOpen: false,
11+
boothIDs: [] as string[],
1112
get hexWidth() {
1213
return this.hexSize * 2
1314
},

src/data/TileData.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,40 @@ export class HexTile extends Phaser.GameObjects.Container {
6969
private skew: number
7070
private hexGraphics: Phaser.GameObjects.Graphics
7171
private ID: string
72+
type: string
7273
centerX: number
7374
centerY: number
7475

75-
constructor({ scene, x, y, size, type, ID = "", skew = 0.6 }: HexTileOptions) {
76+
constructor({ scene, x, y, size, type, ID = "", skew = 0.6}: HexTileOptions) {
7677
super(scene, x, y-100)
7778
this.size = size
7879
this.ID = ID
7980
this.type = type
81+
this.skew = skew
8082
if (this.type === "Base") {
8183
this.color = 0xD3BBDD
8284
}
8385
else if (this.type === "Booths") {
84-
this.color = 0xF8C0C8
86+
this.color = 0xFFFFFF
8587
}
8688
else if (this.type === "Venue") {
8789
this.color = 0xECE3F0
8890
}
89-
this.skew = skew
9091
this.centerX = x
9192
this.centerY = y
9293

9394
this.hexGraphics = this.createHex()
9495
this.add(this.hexGraphics)
96+
if (this.type === "Booths") {
97+
const boothLogo = this.scene.add.image(0, 0, ID)
98+
const maxW = this.size * 1.5
99+
const maxH = this.size * this.skew * 1.5
100+
const scaleX = maxW / boothLogo.width
101+
const scaleY = maxH / boothLogo.height
102+
const scale = Math.min(scaleX, scaleY)
103+
boothLogo.setScale(scale)
104+
this.add(boothLogo)
105+
}
95106
this.setSize(size * 2, Math.sqrt(3) * size * skew)
96107
this.setDepth(this.y)
97108

src/game/main.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,21 @@ const config: Types.Core.GameConfig = {
1313
autoCenter: Phaser.Scale.CENTER_BOTH,
1414
},
1515
parent: "game-container",
16-
backgroundColor: "#EFE7D3",
17-
scene: [MainGame],
16+
backgroundColor: "#EFE7D3"
1817
}
1918

20-
function StartGame(parent: string) {
21-
return new Game({ ...config, parent })
19+
export async function StartGame(parent: string): Promise<Phaser.Game> {
20+
const res = await fetch('https://coscup.org/2024/json/sponsor.json')
21+
const json = await res.json()
22+
const boothIDs: string[] = json.map((s: any) => (s.id))
23+
24+
const scene = new MainGame(boothIDs)
25+
26+
return new Game({
27+
...config,
28+
parent,
29+
scene: [scene],
30+
})
2231
}
2332

2433
export default StartGame

src/game/scenes/Game.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ function randomData(scene: Phaser.Scene, x: number, y: number) {
1717
const r = Math.random()
1818
if (r < 0.25) {
1919
ret.type = 'Booths'
20-
ret.ID = 'Andes'
20+
const index = Math.min(Math.floor(Math.random() * GameData.boothIDs.length), GameData.boothIDs.length - 1)
21+
ret.ID = GameData.boothIDs[index]
2122
}
2223
else {
2324
ret.type = 'Venue'
@@ -30,13 +31,19 @@ export class Game extends Scene {
3031
private contentContainer!: Phaser.GameObjects.Container
3132
private dragStartY = 0
3233
private containerStartY = 0
34+
private boothIDs: string[]
3335

34-
constructor() {
35-
super('Game')
36+
constructor(boothIDs: string[]) {
37+
super('MainGame')
38+
this.boothIDs = boothIDs
3639
}
3740

3841
preload() {
39-
this.load.setPath('assets')
42+
this.boothIDs.forEach((key) => {
43+
const url = `https://coscup.org/2024/images/sponsor/${key}.png`
44+
this.load.image(key, url)
45+
})
46+
GameData.boothIDs = this.boothIDs
4047
}
4148

4249
create() {

0 commit comments

Comments
 (0)