add network
This commit is contained in:
parent
67ea971f4f
commit
e434449e93
BIN
.parcel-cache/04bbf51d2981fd30
Normal file
BIN
.parcel-cache/04bbf51d2981fd30
Normal file
Binary file not shown.
BIN
.parcel-cache/11bbd18dcd775dad
Normal file
BIN
.parcel-cache/11bbd18dcd775dad
Normal file
Binary file not shown.
BIN
.parcel-cache/1ba6b0788801943b
Normal file
BIN
.parcel-cache/1ba6b0788801943b
Normal file
Binary file not shown.
BIN
.parcel-cache/2872ead3c955face
Normal file
BIN
.parcel-cache/2872ead3c955face
Normal file
Binary file not shown.
BIN
.parcel-cache/44df4b2b10f6a074
Normal file
BIN
.parcel-cache/44df4b2b10f6a074
Normal file
Binary file not shown.
BIN
.parcel-cache/47cb0478f3aaec0f
Normal file
BIN
.parcel-cache/47cb0478f3aaec0f
Normal file
Binary file not shown.
7157
.parcel-cache/49b3b2b6df744476.txt
Normal file
7157
.parcel-cache/49b3b2b6df744476.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
.parcel-cache/data.mdb
Normal file
BIN
.parcel-cache/data.mdb
Normal file
Binary file not shown.
7133
.parcel-cache/fbccdf9e4afdd61a.txt
Normal file
7133
.parcel-cache/fbccdf9e4afdd61a.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
.parcel-cache/lock.mdb
Normal file
BIN
.parcel-cache/lock.mdb
Normal file
Binary file not shown.
13
client/index.html
Normal file
13
client/index.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>openarras</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body>
|
||||
<canvas width="1000" height="700" id="board"></canvas>
|
||||
<p id="raw-info"></p>
|
||||
<script src="./index.js" type="module"></script>
|
||||
</body>
|
||||
</html>
|
7
client/index.js
Normal file
7
client/index.js
Normal file
@ -0,0 +1,7 @@
|
||||
import { io } from "socket.io-client";
|
||||
|
||||
const socket = io();
|
||||
|
||||
socket.on("update",(tank_info) => {
|
||||
document.querySelector("#raw-info").innerHTML = tank_info;
|
||||
});
|
2
dist/index.5e4f646d.js
vendored
Normal file
2
dist/index.5e4f646d.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/index.5e4f646d.js.map
vendored
Normal file
1
dist/index.5e4f646d.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/index.html
vendored
Normal file
1
dist/index.html
vendored
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html><head><title>openarras</title><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"></head><body> <canvas width="1000" height="700" id="board"></canvas> <p id="raw-info"></p> <script src="/index.5e4f646d.js" type="module"></script> </body></html>
|
4030
package-lock.json
generated
4030
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
@ -2,7 +2,7 @@
|
||||
"name": "openarras",
|
||||
"version": "0.1.0",
|
||||
"description": "",
|
||||
"main": "src/index.js",
|
||||
"source": "client/index.html",
|
||||
"scripts": {
|
||||
"test": "mocha tests/"
|
||||
},
|
||||
@ -14,6 +14,13 @@
|
||||
"license": "Apache-2.0",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"mocha": "^10.2.0"
|
||||
"buffer": "^6.0.3",
|
||||
"mocha": "^10.2.0",
|
||||
"parcel": "^2.9.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^4.18.2",
|
||||
"socket.io": "^4.7.1",
|
||||
"socket.io-client": "^4.7.1"
|
||||
}
|
||||
}
|
||||
|
45
src/main.js
45
src/main.js
@ -1,16 +1,53 @@
|
||||
import { Vec2 } from '../src/2d.js';
|
||||
import { Motion, CollisionBox } from '../src/components.js';
|
||||
import { EntityRegistry } from '../src/ecs.js';
|
||||
import {Server} from 'socket.io';
|
||||
import Express from 'express';
|
||||
import http_server from 'http';
|
||||
import path from 'path';
|
||||
|
||||
const app = Express();
|
||||
const http = new http_server.Server(app);
|
||||
const io = new Server(http);
|
||||
|
||||
io.on("connection", (socket) => {
|
||||
|
||||
});
|
||||
|
||||
function main() {
|
||||
app.use('/', Express.static(path.join('.','./dist')));
|
||||
|
||||
const server_port = parseInt(process.env.PORT) | 3000;
|
||||
http.listen(server_port, () => {
|
||||
console.log(`Server started on port ${server_port}.`);
|
||||
});
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
console.log('\nShutting server...');
|
||||
users.forEach(u => {
|
||||
u.socket.disconnect();
|
||||
console.log(`Disconnected user ${u.name}.`);
|
||||
});
|
||||
http.close(() => {
|
||||
console.log('Closed.');
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
|
||||
let registry = new EntityRegistry();
|
||||
let tank = registry.create();
|
||||
registry.assign(tank, new Motion(new Vec2(0, 0), new Vec2(1, 1)));
|
||||
registry.assign(tank, new CollisionBox(1));
|
||||
registry.forEach([Motion], (id, motion) => {
|
||||
motion.position.addTo(motion.velocity);
|
||||
});
|
||||
console.log(`motion: ${JSON.stringify(registry.get(tank, Motion))}`);
|
||||
|
||||
setInterval(() => {
|
||||
registry.forEach([Motion], (id, motion) => {
|
||||
motion.position.addTo(motion.velocity);
|
||||
});
|
||||
}, 1000/60);
|
||||
|
||||
setInterval(() => {
|
||||
io.emit("update",JSON.stringify(registry.get(tank, Motion)))
|
||||
}, 50);
|
||||
}
|
||||
|
||||
main();
|
Loading…
x
Reference in New Issue
Block a user