Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zjzy_client_game
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
王勇霞
zjzy_client_game
Commits
d7b71a7e
Commit
d7b71a7e
authored
Mar 24, 2023
by
王勇霞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
跳一跳
parent
347546a9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
92 deletions
+103
-92
GameScene.ts
src/scenes/GameScene.ts
+20
-14
MapItem.ts
src/scenes/components/MapItem.ts
+1
-1
ObstacleProp.ts
src/scenes/components/ObstacleProp.ts
+0
-2
Role.ts
src/scenes/components/Role.ts
+82
-75
No files found.
src/scenes/GameScene.ts
View file @
d7b71a7e
...
@@ -34,8 +34,6 @@ export class GameScene extends Scene {
...
@@ -34,8 +34,6 @@ export class GameScene extends Scene {
xiangpop
:
FYGE
.
Sprite
;
xiangpop
:
FYGE
.
Sprite
;
monster
:
FYGE
.
Sprite
;
monster
:
FYGE
.
Sprite
;
jumpLock
=
false
;
isonce
=
false
;
isonce
=
false
;
wordList
=
this
.
getWordList
();
// 待随机出现的列表
wordList
=
this
.
getWordList
();
// 待随机出现的列表
...
@@ -140,7 +138,7 @@ export class GameScene extends Scene {
...
@@ -140,7 +138,7 @@ export class GameScene extends Scene {
this
.
addRole
();
this
.
addRole
();
this
.
addEventListener
(
FYGE
.
Event
.
ENTER_FRAME
,
this
.
onFarm
,
this
);
this
.
addEventListener
(
FYGE
.
Event
.
ENTER_FRAME
,
this
.
onFarm
,
this
);
this
.
composites
.
add
(
this
.
world
,
[
this
.
_role
.
phyBody
]);
//
this.composites.add(this.world, [this._role.phyBody]);
}
}
_role
;
//人物
_role
;
//人物
bgCon
;
//背景移动
bgCon
;
//背景移动
...
@@ -148,12 +146,12 @@ export class GameScene extends Scene {
...
@@ -148,12 +146,12 @@ export class GameScene extends Scene {
addRole
()
{
addRole
()
{
let
offset
=
(
1624
-
this
.
stage
.
viewRect
.
height
)
/
2
;
let
offset
=
(
1624
-
this
.
stage
.
viewRect
.
height
)
/
2
;
let
role
=
this
.
_role
=
new
Role
({
let
role
=
this
.
_role
=
new
Role
({
fx
:
339
,
fy
:
980
-
offset
,
stageY
:
this
.
stage
.
viewRect
.
y
,
stageY
:
this
.
stage
.
viewRect
.
y
,
});
});
role
.
fx
=
339
;
role
.
fy
=
980
-
offset
;
this
.
bgCon
.
addChild
(
role
);
this
.
bgCon
.
addChild
(
role
);
this
.
composites
.
add
(
this
.
world
,
[
role
.
phyBody
]);
this
.
composites
.
add
(
this
.
world
,
[
this
.
_
role
.
phyBody
]);
}
}
engine
;
// matter引擎初始化
engine
;
// matter引擎初始化
composites
;
composites
;
...
@@ -179,7 +177,8 @@ export class GameScene extends Scene {
...
@@ -179,7 +177,8 @@ export class GameScene extends Scene {
this
.
composites
=
Composite
;
this
.
composites
=
Composite
;
Matter
.
Events
.
on
(
this
.
engine
,
"collisionStart"
,
this
.
onCollisionStart
.
bind
(
this
));
Matter
.
Events
.
on
(
this
.
engine
,
"collisionStart"
,
this
.
onCollisionStart
.
bind
(
this
));
Matter
.
Events
.
on
(
this
.
engine
,
"tick"
,
this
.
onCollisionTick
.
bind
(
this
));
// Matter.Events.on(this.engine, "tick", this.onCollisionTick.bind(this));
// Matter.Events.on(this.engine, "beforeUpdate", this.onBeforeUpdate.bind(this));
// 创建一个渲染器
// 创建一个渲染器
const
render
=
Render
.
create
({
const
render
=
Render
.
create
({
// element: document.body,
// element: document.body,
...
@@ -212,8 +211,15 @@ export class GameScene extends Scene {
...
@@ -212,8 +211,15 @@ export class GameScene extends Scene {
});
});
Render
.
run
(
render
);
Render
.
run
(
render
);
}
}
onBeforeUpdate
(
e
)
{
if
(
this
.
engine
.
timing
.
timestamp
-
this
.
lastTime
>=
1000
)
{
this
.
_role
.
jump
()
this
.
lastTime
=
this
.
engine
.
timing
.
timestamp
;
}
}
onCollisionTick
(
e
)
{
onCollisionTick
(
e
)
{
}
}
lastTime
=
0
onCollisionStart
(
e
)
{
onCollisionStart
(
e
)
{
let
pairs
=
e
.
pairs
;
let
pairs
=
e
.
pairs
;
//
//
...
@@ -222,14 +228,11 @@ export class GameScene extends Scene {
...
@@ -222,14 +228,11 @@ export class GameScene extends Scene {
// ip 与 云朵 碰撞
// ip 与 云朵 碰撞
console
.
log
(
p
.
bodyA
.
objType
,
p
.
bodyB
.
objType
)
console
.
log
(
p
.
bodyA
.
objType
,
p
.
bodyB
.
objType
)
if
((
p
.
bodyA
.
objType
==
"cloud"
&&
p
.
bodyB
==
this
.
_role
.
phyBody
)
||
(
p
.
bodyB
.
objType
==
"cloud"
&&
p
.
bodyA
==
this
.
_role
.
phyBody
))
{
if
((
p
.
bodyA
.
objType
==
"cloud"
&&
p
.
bodyB
==
this
.
_role
.
phyBody
)
||
(
p
.
bodyB
.
objType
==
"cloud"
&&
p
.
bodyA
==
this
.
_role
.
phyBody
))
{
// this._role.jump()
if
(
this
.
engine
.
timing
.
timestamp
-
this
.
lastTime
>=
400
)
{
if
(
!
this
.
jumpLock
)
{
this
.
_role
.
jump
()
this
.
_role
.
jump
()
this
.
jumpLock
=
true
;
this
.
lastTime
=
this
.
engine
.
timing
.
timestamp
;
setTimeout
(()
=>
{
this
.
jumpLock
=
false
},
200
)
}
}
}
}
})
})
// pairs.map((p) => {
// pairs.map((p) => {
...
@@ -324,6 +327,9 @@ export class GameScene extends Scene {
...
@@ -324,6 +327,9 @@ export class GameScene extends Scene {
}
}
timer
=
null
;
timer
=
null
;
onFarm
()
{
onFarm
()
{
let
roleY
=
this
.
_role
.
y
+
this
.
bgCon
.
y
;
this
.
moveMap
(
600
-
roleY
)
// let roleY = this._role.y + this.bgCon.y;
// let roleY = this._role.y + this.bgCon.y;
// if (roleY < 600) {
// if (roleY < 600) {
...
@@ -363,7 +369,7 @@ export class GameScene extends Scene {
...
@@ -363,7 +369,7 @@ export class GameScene extends Scene {
}
}
moveMap
(
y
)
{
moveMap
(
y
)
{
//
this.bgCon.y = this.bgCon.y + y;
this
.
bgCon
.
y
=
this
.
bgCon
.
y
+
y
;
}
}
removeWorld
()
{
removeWorld
()
{
...
...
src/scenes/components/MapItem.ts
View file @
d7b71a7e
...
@@ -23,7 +23,7 @@ export default class MapItem extends FYGE.Container {
...
@@ -23,7 +23,7 @@ export default class MapItem extends FYGE.Container {
// 至于为什么比对的位置, FYGE的适配缩放, 以及Main的剪裁
// 至于为什么比对的位置, FYGE的适配缩放, 以及Main的剪裁
this
.
phyBody
=
Matter
.
Bodies
.
rectangle
(
this
.
fx
*
scale
+
itemImg
.
width
*
scale
/
2
,
this
.
fy
*
scale
+
itemImg
.
height
*
scale
/
2
-
data
.
stageY
*
scale
,
itemImg
.
width
*
scale
,
10
,
{
this
.
phyBody
=
Matter
.
Bodies
.
rectangle
(
this
.
fx
*
scale
+
itemImg
.
width
*
scale
/
2
,
this
.
fy
*
scale
+
itemImg
.
height
*
scale
/
2
-
data
.
stageY
*
scale
,
itemImg
.
width
*
scale
,
10
,
{
isStatic
:
true
,
isStatic
:
true
,
friction
:
0
,
friction
:
1
,
isSensor
:
true
,
// 传感器,可以检测到碰撞,但是不参与碰撞
isSensor
:
true
,
// 传感器,可以检测到碰撞,但是不参与碰撞
render
:
{
render
:
{
fillStyle
:
"blue"
// 填充的颜色
fillStyle
:
"blue"
// 填充的颜色
...
...
src/scenes/components/ObstacleProp.ts
View file @
d7b71a7e
...
@@ -14,8 +14,6 @@ export default class ObstacleProp extends FYGE.Container {
...
@@ -14,8 +14,6 @@ export default class ObstacleProp extends FYGE.Container {
this
.
phyBody
=
Matter
.
Bodies
.
rectangle
(
this
.
x
,
this
.
y
,
itemImg
.
width
,
itemImg
.
height
,
{
this
.
phyBody
=
Matter
.
Bodies
.
rectangle
(
this
.
x
,
this
.
y
,
itemImg
.
width
,
itemImg
.
height
,
{
isStatic
:
true
,
isStatic
:
true
,
friction
:
1
,
isSensor
:
true
,
// 传感器,可以检测到碰撞,但是不参与碰撞
isSensor
:
true
,
// 传感器,可以检测到碰撞,但是不参与碰撞
});
});
...
...
src/scenes/components/Role.ts
View file @
d7b71a7e
...
@@ -11,38 +11,39 @@ export default class Role extends FYGE.Container {
...
@@ -11,38 +11,39 @@ export default class Role extends FYGE.Container {
jumpSvga
;
jumpSvga
;
downSvga
;
downSvga
;
lightSvga
;
lightSvga
;
fx
;
//
fx;
fy
;
//
fy;
bili
;
bili
;
staY
;
staY
;
constructor
(
data
?)
{
constructor
(
data
?)
{
super
();
super
();
this
.
fx
=
data
.
fx
;
//
this.fx = data.fx;
this
.
fy
=
data
.
fy
;
//
this.fy = data.fy;
this
.
staY
=
data
.
stageY
;
this
.
staY
=
data
.
stageY
;
this
.
position
.
set
(
this
.
fx
,
this
.
f
y
);
this
.
position
.
set
(
this
.
x
,
this
.
y
);
let
itemImg
=
this
.
itemImg
=
UI
.
Sp
(
this
,
"controlpeo.png"
,
0
,
0
);
let
itemImg
=
this
.
itemImg
=
UI
.
Sp
(
this
,
"controlpeo.png"
,
0
,
0
);
let
scale
=
this
.
bili
=
document
.
body
.
clientWidth
/
750
;
let
scale
=
this
.
bili
=
document
.
body
.
clientWidth
/
750
;
// 至于为什么比对的位置, FYGE的适配缩放, 以及Main的剪裁
// 至于为什么比对的位置, FYGE的适配缩放, 以及Main的剪裁
this
.
phyBody
=
Matter
.
Bodies
.
rectangle
(
this
.
fx
*
scale
+
itemImg
.
width
*
scale
/
2
,
this
.
f
y
*
scale
+
itemImg
.
height
*
scale
/
2
-
data
.
stageY
*
scale
,
itemImg
.
width
*
scale
,
itemImg
.
height
*
scale
,
{
this
.
phyBody
=
Matter
.
Bodies
.
rectangle
(
this
.
x
*
scale
+
itemImg
.
width
*
scale
/
2
,
this
.
y
*
scale
+
itemImg
.
height
*
scale
/
2
-
data
.
stageY
*
scale
,
itemImg
.
width
*
scale
,
itemImg
.
height
*
scale
,
{
isStatic
:
false
,
isStatic
:
false
,
isSensor
:
false
,
// 传感器,可以检测到碰撞,但是不参与碰撞
//
isSensor: false, // 传感器,可以检测到碰撞,但是不参与碰撞
restitution
:
0.8
,
// restitution: 0.1
,
friction
:
0.01
,
//
friction: 0.01,
inverseMass
:
0.2
,
//
inverseMass: 0.2,
// restitution: 0.8, // 定义刚体恢复(弹性)的数字
// restitution: 0.8, // 定义刚体恢复(弹性)的数字
// // // density: 0.05,// 定义刚体密度的数字,即单位面积的质量
// // // density: 0.05,// 定义刚体密度的数字,即单位面积的质量
// // friction: 0.02,
// // friction: 0.02,
// friction: 0.5, // 设置摩擦力
// friction: 0.5, // 设置摩擦力
// frictionAir: 0.01, // 设置空气摩擦力
// frictionAir: 0.01, // 设置空气摩擦力
render
:
{
render
:
{
fillStyle
:
"red"
// 填充的颜色
fillStyle
:
"red"
// 填充的颜色
}
}
});
});
// 绘制ip
// 绘制ip
this
.
getSvga
()
this
.
getSvga
()
this
.
setPhyPos
();
this
.
addEventListener
(
this
.
addEventListener
(
FYGE
.
Event
.
ADDED_TO_STAGE
,
FYGE
.
Event
.
ADDED_TO_STAGE
,
()
=>
{
()
=>
{
...
@@ -96,74 +97,80 @@ export default class Role extends FYGE.Container {
...
@@ -96,74 +97,80 @@ export default class Role extends FYGE.Container {
/** 根据物理刚体,更新当前的坐标。 */
/** 根据物理刚体,更新当前的坐标。 */
private
onFarm
()
{
private
onFarm
()
{
this
.
x
=
(
this
.
phyBody
.
position
.
x
-
this
.
itemImg
.
width
*
this
.
bili
/
2
)
/
this
.
bili
;
let
Tx
=
(
this
.
phyBody
.
position
.
x
-
this
.
itemImg
.
width
*
this
.
bili
/
2
)
/
this
.
bili
;
this
.
y
=
(
this
.
phyBody
.
position
.
y
+
(
this
.
staY
*
this
.
bili
)
-
this
.
itemImg
.
height
*
this
.
bili
/
2
)
/
this
.
bili
;
let
Ty
=
(
this
.
phyBody
.
position
.
y
+
(
this
.
staY
*
this
.
bili
)
-
this
.
itemImg
.
height
*
this
.
bili
/
2
)
/
this
.
bili
;
// if (this.beforeY) {
// if (this.beforeY > this.phyBody.position.y) {
this
.
x
=
Tx
;
this
.
y
=
Ty
;
// this.direction = 'up'
if
(
Tx
>
750
)
{
// }
this
.
fx
=
0
;
this
.
fy
=
Ty
;
// if (this.beforeY < this.phyBody.position.y) {
}
else
if
(
Tx
<
0
)
{
this
.
fx
=
750
;
// this.direction = 'down'
this
.
fy
=
Ty
// }
}
else
{
// }
this
.
fx
=
Tx
;
this
.
fy
=
Ty
// if (this.phyBody.position.x > 750) {
}
// Matter.Body.setPosition(this.phyBody, {
// x: 0,
// y: this.phyBody.position.y
// })
// } else if (this.phyBody.position.x < 0) {
// Matter.Body.setPosition(this.phyBody, {
// x: 750,
// y: this.phyBody.position.y
// })
// } else {
// this.x = this.phyBody.position.x;
// this.y = this.phyBody.position.y;
// }
// this.beforeY = this.phyBody.position.y;
}
}
// this.x = Tx
// }
// this.x =
// this.y =
// if (this.beforeY) {
// if (this.beforeY > this.phyBody.position.y) {
// this.direction = 'up'
// }
// if (this.beforeY < this.phyBody.position.y) {
// this.direction = 'down'
// }
// }
// if (this.phyBody.position.x > 750) {
// Matter.Body.setPosition(this.phyBody, {
// x: 0,
// y: this.phyBody.position.y
// })
// } else if (this.phyBody.position.x < 0) {
// Matter.Body.setPosition(this.phyBody, {
// x: 750,
// y: this.phyBody.position.y
// })
// } else {
// this.x = this.phyBody.position.x;
// this.y = this.phyBody.position.y;
// }
// this.beforeY = this.phyBody.position.y;
jump
()
{
jump
()
{
setTimeout
(()
=>
{
setTimeout
(()
=>
{
Matter
.
Body
.
applyForce
(
this
.
phyBody
,
this
.
phyBody
.
position
,
{
Matter
.
Body
.
setVelocity
(
this
.
phyBody
,
{
x
:
0
,
y
:
-
8
});
// 立即设置刚体的线速度。位置、角度、力等不变
x
:
0
,
// Matter.Body.applyForce(this.phyBody, this.phyBody.position, {
y
:
-
0.1
// x: 0,
});
// y: -10
// });
})
})
}
}
// onMouseDown(e) {
set
fx
(
value
:
number
)
{
// let offsetX = e.stageX - this.x;
this
.
position
.
x
=
value
;
// let offsetY = e.stageY - this.y;
this
.
setPhyPos
();
// this.stage.addEventListener(
}
// FYGE.MouseEvent.MOUSE_MOVE,
// function (event) {
set
fy
(
value
:
number
)
{
// let resx = event.stageX - offsetX;
this
.
position
.
y
=
value
;
// let resy = event.stageY - offsetY;
this
.
setPhyPos
();
// if (resx < 50 || resx > 700) { return }
}
// this.x = resx;
// // this.y = resy;
setPhyPos
()
{
// Matter.Body.setPosition(this.phyBody, {
Matter
.
Body
.
setPosition
(
this
.
phyBody
,
{
// x: resx,
x
:
this
.
x
*
this
.
bili
+
this
.
itemImg
.
width
*
this
.
bili
/
2
,
// y: this.y,
y
:
this
.
y
*
this
.
bili
+
this
.
itemImg
.
height
*
this
.
bili
/
2
-
this
.
staY
*
this
.
bili
,
// });
});
// },
}
// this
// );
// this.stage.addEventListener(
// FYGE.MouseEvent.MOUSE_UP,
// function (event) {
// this.stage.removeAllEventListener()
// },
// this
// );
// }
}
}
\ No newline at end of file
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