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
73481e7f
Commit
73481e7f
authored
Apr 30, 2025
by
haiyoucuv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
蛇移动
parent
a5141410
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
100 additions
and
13 deletions
+100
-13
bg.jpg
src/assets/GamePage/bg.jpg
+0
-0
Element.ts
src/pages/GamePage/Components/Element/Element.ts
+48
-3
Filiform.ts
src/pages/GamePage/Components/Element/Filiform.ts
+6
-1
Molecule.ts
src/pages/GamePage/Components/Element/Molecule.ts
+6
-1
Mugwort.ts
src/pages/GamePage/Components/Element/Mugwort.ts
+6
-1
Realgar.ts
src/pages/GamePage/Components/Element/Realgar.ts
+6
-1
Yeast.ts
src/pages/GamePage/Components/Element/Yeast.ts
+6
-1
ElementMgr.ts
src/pages/GamePage/Components/ElementMgr.ts
+4
-4
Game.ts
src/pages/GamePage/Game.ts
+16
-0
GamePage.tsx
src/pages/GamePage/GamePage.tsx
+1
-0
Config.ts
src/pages/GamePage/config/Config.ts
+1
-1
No files found.
src/assets/GamePage/bg.jpg
View replaced file @
a5141410
View file @
73481e7f
136 KB
|
W:
|
H:
136 KB
|
W:
|
H:
2-up
Swipe
Onion skin
src/pages/GamePage/Components/Element/Element.ts
View file @
73481e7f
import
{
Assets
,
Container
,
Sprite
}
from
"pixi.js"
;
import
{
Assets
,
Container
,
DestroyOptions
,
PointData
,
Sprite
}
from
"pixi.js"
;
import
{
Ele
,
EleConfig
}
from
"@/pages/GamePage/config/Config.ts"
;
import
{
Body
}
from
"detect-collisions"
;
import
{
BodyProps
}
from
"detect-collisions/dist/model"
;
import
{
collisionSys
}
from
"@/pages/GamePage/GamePage.tsx"
;
import
{
Tween
}
from
"@/pages/GamePage/tween"
;
export
abstract
class
Element
extends
Container
{
id
:
Ele
=
null
;
sp
:
Sprite
=
null
;
body
:
any
=
null
;
body
:
Body
=
null
;
canEat
:
boolean
=
true
;
abstract
initUI
():
void
;
abstract
initPhy
():
void
;
...
...
@@ -24,4 +29,44 @@ export abstract class Element extends Container {
this
.
initPhy
();
}
onDestroy
():
void
{
}
get
scaleX
()
{
return
this
.
sp
.
scale
.
x
;
}
set
scaleX
(
value
:
number
)
{
this
.
sp
.
scale
.
x
=
value
;
}
get
scaleY
()
{
return
this
.
sp
.
scale
.
y
;
}
set
scaleY
(
value
:
number
)
{
this
.
sp
.
scale
.
y
=
value
;
}
beEaten
(
pos
:
PointData
)
{
if
(
!
this
.
canEat
)
return
;
this
.
canEat
=
false
;
collisionSys
.
remove
(
this
.
body
);
this
.
body
=
null
;
Tween
.
get
(
this
)
.
to
({
x
:
pos
.
x
,
y
:
pos
.
y
,
scaleX
:
0.1
,
scaleY
:
0.1
,
},
444
)
.
call
(()
=>
{
this
.
onDestroy
();
this
.
removeFromParent
();
});
}
}
src/pages/GamePage/Components/Element/Filiform.ts
View file @
73481e7f
...
...
@@ -20,7 +20,12 @@ export class Filiform extends Element {
this
.
body
=
collisionSys
.
createBox
(
this
.
getGlobalPosition
(),
width
,
height
height
,
{
userData
:
{
ele
:
this
}
}
);
this
.
body
.
setOffset
(
new
SATVector
(
-
width
/
2
,
-
height
/
2
));
this
.
body
.
setAngle
(
this
.
angle
*
DEG_TO_RAD
);
...
...
src/pages/GamePage/Components/Element/Molecule.ts
View file @
73481e7f
...
...
@@ -20,7 +20,12 @@ export class Molecule extends Element {
this
.
body
=
collisionSys
.
createBox
(
this
.
getGlobalPosition
(),
width
,
height
height
,
{
userData
:
{
ele
:
this
}
}
);
this
.
body
.
setOffset
(
new
SATVector
(
-
width
/
2
,
-
height
/
2
));
this
.
body
.
setAngle
(
this
.
angle
*
DEG_TO_RAD
);
...
...
src/pages/GamePage/Components/Element/Mugwort.ts
View file @
73481e7f
...
...
@@ -19,7 +19,12 @@ export class Mugwort extends Element {
this
.
body
=
collisionSys
.
createBox
(
this
.
getGlobalPosition
(),
width
/
2.1
,
height
/
2.1
height
/
2.1
,
{
userData
:
{
ele
:
this
}
}
);
this
.
body
.
setOffset
(
new
SATVector
(
-
width
/
2.1
/
2
,
-
height
/
2.1
/
2
));
this
.
body
.
setAngle
(
this
.
angle
*
DEG_TO_RAD
);
...
...
src/pages/GamePage/Components/Element/Realgar.ts
View file @
73481e7f
...
...
@@ -19,7 +19,12 @@ export class Realgar extends Element {
this
.
body
=
collisionSys
.
createBox
(
this
.
getGlobalPosition
(),
width
/
2.1
,
height
/
2.6
height
/
2.6
,
{
userData
:
{
ele
:
this
}
}
);
this
.
body
.
setOffset
(
new
SATVector
(
-
width
/
2.1
/
2
,
-
height
/
2.6
/
2
));
this
.
body
.
setAngle
(
this
.
angle
*
DEG_TO_RAD
);
...
...
src/pages/GamePage/Components/Element/Yeast.ts
View file @
73481e7f
...
...
@@ -16,7 +16,12 @@ export class Yeast extends Element {
initPhy
():
void
{
this
.
body
=
collisionSys
.
createCircle
(
this
.
getGlobalPosition
(),
this
.
sp
.
height
/
2
this
.
sp
.
height
/
2
,
{
userData
:
{
ele
:
this
}
}
);
this
.
body
.
setAngle
(
this
.
angle
*
DEG_TO_RAD
);
}
...
...
src/pages/GamePage/Components/ElementMgr.ts
View file @
73481e7f
...
...
@@ -50,8 +50,8 @@ export class ElementMgr {
if
(
this
.
footCtn
.
children
.
length
>
6
)
return
;
const
eleData
=
foodWeight
.
get
();
const
ele
=
new
eleData
.
cls
();
ele
.
x
=
Math
.
random
()
*
mapSize
.
width
-
1
00
+
5
0
;
ele
.
y
=
Math
.
random
()
*
mapSize
.
height
-
1
00
+
5
0
;
ele
.
x
=
Math
.
random
()
*
mapSize
.
width
-
1
40
+
7
0
;
ele
.
y
=
Math
.
random
()
*
mapSize
.
height
-
1
40
+
7
0
;
this
.
footCtn
.
addChild
(
ele
);
ele
.
init
();
}
...
...
@@ -60,8 +60,8 @@ export class ElementMgr {
if
(
this
.
negCtn
.
children
.
length
>
4
)
return
;
const
eleData
=
negWeight
.
get
();
const
ele
=
new
eleData
.
cls
();
ele
.
x
=
Math
.
random
()
*
mapSize
.
width
-
1
00
+
5
0
;
ele
.
y
=
Math
.
random
()
*
mapSize
.
height
-
1
00
+
5
0
;
ele
.
x
=
Math
.
random
()
*
mapSize
.
width
-
1
40
+
7
0
;
ele
.
y
=
Math
.
random
()
*
mapSize
.
height
-
1
40
+
7
0
;
this
.
negCtn
.
addChild
(
ele
);
ele
.
init
();
}
...
...
src/pages/GamePage/Game.ts
View file @
73481e7f
...
...
@@ -5,6 +5,10 @@ import 'pixi.js/math-extras';
import
{
Snake
}
from
"@/pages/GamePage/Components/Snake.ts"
;
import
{
ElementMgr
}
from
"@/pages/GamePage/Components/ElementMgr.ts"
;
import
{
mapTop
}
from
"@/pages/GamePage/config/Config.ts"
;
import
{
collisionSys
}
from
"@/pages/GamePage/GamePage.tsx"
;
import
{
Element
}
from
"./Components/Element/Element.ts"
;
import
{
Response
,
Body
}
from
"detect-collisions"
;
export
class
Game
extends
Container
{
...
...
@@ -59,10 +63,22 @@ export class Game extends Container {
this
.
joystick
.
visible
=
false
;
}
colliderCallback
=
(
result
:
Response
)
=>
{
const
{
a
,
b
,
aInB
,
bInA
,
overlap
,
overlapV
,
overlapN
}
=
result
;
const
{
userData
:
{
ele
}
}
=
b
as
Body
<
{
ele
:
Element
}
>
;
ele
.
beEaten
(
this
.
snake
.
head
);
}
onUpdate
(
time
:
Ticker
)
{
const
dt
=
time
.
deltaMS
/
1000
;
this
.
snake
.
dir
.
copyFrom
(
this
.
joystick
.
dir
);
this
.
snake
.
onUpdate
(
dt
);
collisionSys
.
checkOne
(
this
.
snake
.
collider
,
this
.
colliderCallback
);
}
destroy
()
{
...
...
src/pages/GamePage/GamePage.tsx
View file @
73481e7f
...
...
@@ -58,6 +58,7 @@ class GamePage extends React.Component {
componentWillUnmount
()
{
this
.
app
?.
destroy
();
window
[
"__app"
]
=
null
;
collisionSys
.
clear
();
}
async
initStage
()
{
...
...
src/pages/GamePage/config/Config.ts
View file @
73481e7f
...
...
@@ -55,7 +55,7 @@ export const winSize = {
height
:
window
.
innerHeight
/
window
.
innerWidth
*
750
,
}
export
const
mapTop
=
290
;
export
const
mapTop
=
464
;
export
const
mapSize
=
{
width
:
winSize
.
width
,
...
...
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