Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
LuzhouLaojiaoSnake_250428
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
SparkProjects
LuzhouLaojiaoSnake_250428
Commits
09ab6878
Commit
09ab6878
authored
May 08, 2025
by
haiyoucuv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
倒计时
parent
0d9329ea
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
34 deletions
+53
-34
App.tsx
src/App.tsx
+1
-1
Snake.ts
src/pages/GamePage/Components/Snake.ts
+2
-2
GamePage.tsx
src/pages/GamePage/GamePage.tsx
+47
-30
BackPanel.tsx
src/panels/BackPanel/BackPanel.tsx
+3
-1
No files found.
src/App.tsx
View file @
09ab6878
...
...
@@ -27,7 +27,7 @@ class App extends Component {
const
defaultPage
=
{
myPrize
:
MyPrize
,
// TODO 举例子 新宿台奖品页
index
:
HomePage
,
}[
skinId
]
||
Ga
mePage
;
}[
skinId
]
||
Ho
mePage
;
PageCtrl
.
changePage
(
defaultPage
);
}
...
...
src/pages/GamePage/Components/Snake.ts
View file @
09ab6878
import
{
Assets
,
Container
,
Point
,
PointData
,
Sprite
}
from
"pixi.js"
;
import
{
Assets
,
Container
,
Point
,
PointData
,
Sprite
,
RAD_TO_DEG
}
from
"pixi.js"
;
import
{
GameConfig
,
mapSize
}
from
"@/pages/GamePage/config/Config.ts"
;
import
{
Circle
}
from
"detect-collisions"
;
...
...
@@ -183,7 +183,7 @@ export class Snake extends Container {
const
bodyLen
=
this
.
bodyArr
.
length
;
const
headAngle
=
this
.
head
.
angle
=
Math
.
atan2
(
this
.
dir
.
y
,
this
.
dir
.
x
)
*
180
/
Math
.
PI
;
const
headAngle
=
this
.
head
.
angle
=
Math
.
atan2
(
this
.
dir
.
y
,
this
.
dir
.
x
)
*
RAD_TO_DEG
;
// 更新头部位置
const
newHeadPos
=
this
.
dir
...
...
src/pages/GamePage/GamePage.tsx
View file @
09ab6878
...
...
@@ -3,7 +3,7 @@ import { observer } from 'mobx-react';
import
'./GamePage.less'
;
import
{
Button
}
from
"@grace/ui"
;
import
{
Application
,
Assets
,
Ticker
}
from
"pixi.js"
;
import
{
Application
,
Assets
,
T
exture
,
TextureGCSystem
,
TexturePool
,
T
icker
}
from
"pixi.js"
;
import
{
Tween
}
from
"./tween"
;
import
{
initBundle
}
from
"@/pages/GamePage/Helper.ts"
;
...
...
@@ -23,6 +23,9 @@ import BackPanel from "@/panels/BackPanel/BackPanel.tsx";
export
const
collisionSys
:
System
=
new
System
();
const
DEBUG
=
true
;
let
gameCanvas
:
HTMLCanvasElement
=
null
;
export
function
getApp
():
Application
{
return
window
[
"__app"
];
}
...
...
@@ -39,7 +42,7 @@ class GamePage extends React.Component {
state
:
IGamePageState
=
{
}
game
Canvas
:
HTMLCanvas
Element
=
null
;
game
Div
:
HTMLDiv
Element
=
null
;
debugCanvas
:
HTMLCanvasElement
=
null
;
debugCtx
:
CanvasRenderingContext2D
=
null
;
...
...
@@ -87,43 +90,55 @@ class GamePage extends React.Component {
}
componentWillUnmount
()
{
this
.
app
?.
destroy
(
);
window
[
"__app"
]
=
null
;
this
.
gameDiv
.
removeChild
(
gameCanvas
);
collisionSys
.
clear
();
Tween
.
removeAllTweens
();
this
.
app
.
ticker
.
remove
(
this
.
onUpdate
);
this
.
game
.
removeFromParent
();
this
.
game
.
destroy
();
}
async
initStage
()
{
const
app
=
this
.
app
=
new
Application
();
await
app
.
init
({
canvas
:
this
.
gameCanvas
,
backgroundColor
:
0xffffff
,
width
:
winSize
.
width
,
height
:
winSize
.
height
,
powerPreference
:
"high-performance"
,
// resolution: Math.min(window.devicePixelRatio, 2) || 1,
resolution
:
1
,
preference
:
"webgl"
,
webgl
:
{
// preserveDrawingBuffer: true,
// antialias: true,
},
eventMode
:
"static"
,
});
window
[
"__app"
]?.
destroy
();
window
[
"__app"
]
=
app
;
if
(
!
gameCanvas
)
{
gameCanvas
=
document
.
createElement
(
"canvas"
);
gameCanvas
.
className
=
"gameCanvas"
;
}
this
.
gameDiv
.
appendChild
(
gameCanvas
);
if
(
!
window
[
"__app"
])
{
const
app
=
window
[
"__app"
]
=
new
Application
();
await
app
.
init
({
canvas
:
gameCanvas
,
backgroundColor
:
0xffffff
,
width
:
winSize
.
width
,
height
:
winSize
.
height
,
powerPreference
:
"high-performance"
,
// resolution: Math.min(window.devicePixelRatio, 2) || 1,
resolution
:
1
,
preference
:
"webgl"
,
webgl
:
{
// preserveDrawingBuffer: true,
// antialias: true,
},
eventMode
:
"static"
,
});
app
.
renderer
.
accessibility
.
destroy
();
}
const
app
=
this
.
app
=
window
[
"__app"
];
if
(
DEBUG
)
{
const
stats
=
new
Stats
(
app
.
renderer
);
}
app
.
renderer
.
accessibility
.
destroy
();
await
Assets
.
loadBundle
(
"Game"
);
app
.
ticker
.
add
(
this
.
onUpdate
);
this
.
app
.
ticker
.
add
(
this
.
onUpdate
);
this
.
game
=
app
.
stage
.
addChild
(
new
Game
());
...
...
@@ -174,10 +189,12 @@ class GamePage extends React.Component {
return
<
div
className=
"GamePage"
>
<
div
className=
"gameBg"
/>
<
canvas
className=
"gameCanvas"
ref=
{
(
el
)
=>
this
.
gameCanvas
=
el
}
/>
<
div
className=
"gameDiv"
ref=
{
(
el
)
=>
this
.
gameDiv
=
el
}
>
{
/*<canvas*/
}
{
/* className="gameCanvas"*/
}
{
/* ref={(el) => this.gameCanvas = el}*/
}
{
/*/>*/
}
</
div
>
{
DEBUG
&&
<
canvas
className=
"gameCanvas debugCanvas"
...
...
src/panels/BackPanel/BackPanel.tsx
View file @
09ab6878
...
...
@@ -4,6 +4,8 @@ import "./BackPanel.less";
import
{
Button
}
from
"@grace/ui"
;
import
{
_asyncThrottle
}
from
"@/utils/utils.ts"
;
import
{
ModalCtrl
}
from
"@/core/ctrls/ModalCtrl.tsx"
;
import
{
PageCtrl
}
from
"@/core/ctrls/PageCtrl.tsx"
;
import
HomePage
from
"@/pages/HomePage/HomePage.tsx"
;
export
interface
IFailPanelProps
{
ok
:
()
=>
void
,
...
...
@@ -26,7 +28,7 @@ class BackPanel extends React.Component<IFailPanelProps> {
const
{
ok
}
=
this
.
props
;
ModalCtrl
.
closeModal
();
ok
&&
ok
();
//
PageCtrl.changePage(HomePage);
PageCtrl
.
changePage
(
HomePage
);
});
render
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment