create-cubeforge-game 0.3.13 → 0.3.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState } from 'react'
|
|
2
|
-
import { Game, World, Camera2D, useSnapshot } from 'cubeforge'
|
|
2
|
+
import { Game, World, Camera2D, AssetLoader, useSnapshot } from 'cubeforge'
|
|
3
3
|
import { Player } from './components/Player'
|
|
4
4
|
import { Ground } from './components/Ground'
|
|
5
5
|
import { Coin } from './components/Coin'
|
|
@@ -37,6 +37,14 @@ const btnStyle: React.CSSProperties = {
|
|
|
37
37
|
fontSize: 13,
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
function Loading() {
|
|
41
|
+
return (
|
|
42
|
+
<div style={{ color: '#fff', fontFamily: 'monospace', padding: 20 }}>
|
|
43
|
+
Loading...
|
|
44
|
+
</div>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
40
48
|
export function App() {
|
|
41
49
|
const [score, setScore] = useState(0)
|
|
42
50
|
const [collected, setCollected] = useState<Set<string>>(new Set())
|
|
@@ -49,28 +57,30 @@ export function App() {
|
|
|
49
57
|
|
|
50
58
|
return (
|
|
51
59
|
<div style={{ position: 'relative', display: 'inline-block' }}>
|
|
52
|
-
<Game width={800} height={500} gravity={980}>
|
|
53
|
-
<
|
|
54
|
-
|
|
55
|
-
<
|
|
60
|
+
<Game width={800} height={500} gravity={980} asyncAssets>
|
|
61
|
+
<AssetLoader assets={[]} fallback={<Loading />}>
|
|
62
|
+
<HUD score={score} total={COINS.length} />
|
|
63
|
+
<World background="#1a1d27">
|
|
64
|
+
<Camera2D followEntity="player" smoothing={0.85} />
|
|
56
65
|
|
|
57
|
-
|
|
66
|
+
<Player x={100} y={300} />
|
|
58
67
|
|
|
59
|
-
|
|
60
|
-
|
|
68
|
+
{/* Main ground */}
|
|
69
|
+
<Ground x={400} y={480} width={800} height={40} />
|
|
61
70
|
|
|
62
|
-
|
|
63
|
-
|
|
71
|
+
{/* One-way ledge — jump up through it */}
|
|
72
|
+
<Ground x={400} y={340} width={260} height={16} oneWay />
|
|
64
73
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
{COINS.map(c => (
|
|
75
|
+
<Coin
|
|
76
|
+
key={`${c.x}-${c.y}`}
|
|
77
|
+
x={c.x}
|
|
78
|
+
y={c.y}
|
|
79
|
+
onCollect={() => collect(`${c.x}-${c.y}`)}
|
|
80
|
+
/>
|
|
81
|
+
))}
|
|
82
|
+
</World>
|
|
83
|
+
</AssetLoader>
|
|
74
84
|
</Game>
|
|
75
85
|
</div>
|
|
76
86
|
)
|
|
@@ -1,11 +1,33 @@
|
|
|
1
1
|
import { Entity, Transform, Sprite, RigidBody, BoxCollider } from 'cubeforge'
|
|
2
2
|
|
|
3
|
-
interface GroundProps {
|
|
4
|
-
|
|
3
|
+
interface GroundProps {
|
|
4
|
+
x: number
|
|
5
|
+
y: number
|
|
6
|
+
width: number
|
|
7
|
+
height: number
|
|
8
|
+
oneWay?: boolean
|
|
9
|
+
color?: string
|
|
10
|
+
src?: string
|
|
11
|
+
tileX?: boolean
|
|
12
|
+
tileY?: boolean
|
|
13
|
+
tileSizeX?: number
|
|
14
|
+
tileSizeY?: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function Ground({ x, y, width, height, oneWay, color, src, tileX, tileY, tileSizeX, tileSizeY }: GroundProps) {
|
|
5
18
|
return (
|
|
6
19
|
<Entity tags={['ground']}>
|
|
7
20
|
<Transform x={x} y={y} />
|
|
8
|
-
<Sprite
|
|
21
|
+
<Sprite
|
|
22
|
+
width={width}
|
|
23
|
+
height={height}
|
|
24
|
+
color={color ?? (oneWay ? '#546e7a' : '#37474f')}
|
|
25
|
+
src={src}
|
|
26
|
+
tileX={tileX}
|
|
27
|
+
tileY={tileY}
|
|
28
|
+
tileSizeX={tileSizeX}
|
|
29
|
+
tileSizeY={tileSizeY}
|
|
30
|
+
/>
|
|
9
31
|
<RigidBody isStatic />
|
|
10
32
|
<BoxCollider width={width} height={height} oneWay={oneWay} />
|
|
11
33
|
</Entity>
|