Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
game-server-flip-jump
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Gia Vương
game-server-flip-jump
Commits
6246cb5b
Commit
6246cb5b
authored
Aug 15, 2025
by
Vũ Gia Vương
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add end game, update heightJump
parent
c7be7051
Pipeline
#7135
canceled with stages
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
8 deletions
+30
-8
index.ts
src/index.ts
+3
-1
socket.ts
src/socket.ts
+27
-7
No files found.
src/index.ts
View file @
6246cb5b
...
...
@@ -10,10 +10,12 @@ const io = new Server(server, {
cors
:
{
origin
:
'*'
,
methods
:
[
"GET"
,
"POST"
],
credentials
:
true
// origin: ["http://localhost:7456"],
// credentials: true,
}
});
setupSocket
(
io
);
server
.
listen
(
PORT
,
()
=>
{
...
...
src/socket.ts
View file @
6246cb5b
import
{
Server
,
Socket
}
from
"socket.io"
;
import
CONFIG
from
"./Config/config"
;
//
import CONFIG from "./Config/config";
import
User
,
{
IDataPassTower
,
IDataSpawnTower
}
from
"./Model/User"
;
import
v2
from
"./Model/v2"
;
import
{
endGameApi
,
startGameApi
}
from
"./Controller/networkCtrl"
;
...
...
@@ -7,7 +7,19 @@ import { endGameApi, startGameApi } from "./Controller/networkCtrl";
const
users
:
Map
<
string
,
User
>
=
new
Map
<
string
,
User
>
();
const
Y_RADIO
:
number
=
0.5560472
;
const
HALF_SIZE_TOWER
:
number
=
56.43580423808985
;
const
CONFIG
=
{
EVT
:
{
START_GAME
:
'200'
,
END_GAME
:
'204'
,
SPAWN_ITEM
:
'205'
,
PASS_TOWER
:
'207'
,
HISTORY
:
'208'
,
REQUEST_START_GAME
:
'600'
,
REQUEST_PASS_TOWER
:
'601'
,
REQUEST_SPAWN_TOWER
:
'602'
,
REQUEST_HISTORY
:
'603'
,
}
};
export
function
setupSocket
(
io
:
Server
)
{
io
.
use
((
socket
:
Socket
,
next
)
=>
{
...
...
@@ -28,12 +40,13 @@ export function setupSocket(io: Server) {
socket
.
on
(
CONFIG
.
EVT
.
PASS_TOWER
,
async
(
data
:
{
playerPos
:
v2
,
time
:
number
,
distance
:
number
})
=>
await
passTower
(
socket
,
data
));
socket
.
on
(
CONFIG
.
EVT
.
HISTORY
,
async
()
=>
getHistory
(
socket
));
socket
.
on
(
CONFIG
.
EVT
.
END_GAME
,
()
=>
endGame
(
socket
));
socket
.
on
(
"disconnect"
,
()
=>
onDisconnect
(
socket
));
});
}
function
onDisconnect
(
socket
:
Socket
):
void
{
console
.
log
(
`🔴 Client disconnected:
${
socket
.
id
}
`
)
async
function
endGame
(
socket
:
Socket
)
{
const
user
=
getUserBySocket
(
socket
);
user
.
reset
();
...
...
@@ -43,6 +56,11 @@ function onDisconnect(socket: Socket): void {
endGameApi
(
user
);
}
function
onDisconnect
(
socket
:
Socket
):
void
{
console
.
log
(
`🔴 Client disconnected:
${
socket
.
id
}
`
)
endGame
(
socket
);
}
async
function
getHistory
(
socket
:
Socket
)
{
const
user
=
getUserBySocket
(
socket
);
socket
.
emit
(
CONFIG
.
EVT
.
REQUEST_HISTORY
,
user
.
history
);
...
...
@@ -64,7 +82,6 @@ async function startGame(socket: Socket, data: any) {
async
function
passTower
(
socket
:
Socket
,
data
:
{
distance
:
number
})
{
const
user
=
getUserBySocket
(
socket
);
console
.
log
(
'distance'
,
data
.
distance
.
toFixed
(),
user
.
distance2Tower
.
toFixed
());
const
xDistance_
=
data
.
distance
;
const
{
direction
,
nextBlock
,
towerNumber
,
position
}
=
user
;
...
...
@@ -85,7 +102,7 @@ async function passTower(socket: Socket, data: { distance: number }) {
score
=
0
;
}
if
(
minDistance
<
HALF_SIZE_TOWER
*
0.8
)
{
target
=
nextTowerPos
.
clone
().
sub
(
pointEdge
.
clone
().
mul
(
0.
6
));
target
=
nextTowerPos
.
clone
().
sub
(
pointEdge
.
clone
().
mul
(
0.
5
));
score
=
1
;
}
if
(
minDistance
<
HALF_SIZE_TOWER
*
0.3
)
{
...
...
@@ -93,7 +110,10 @@ async function passTower(socket: Socket, data: { distance: number }) {
score
=
2
;
}
const
heightJump
=
nextBlock
.
y
+
100
-
position
.
y
;
// target = nextTowerPos.clone();
// score = 2;
const
heightJump
=
user
.
distance2Tower
*
0.7
;
if
(
score
<=
0
)
{
user
.
isEndGame
=
true
;
...
...
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