expanding map

This commit is contained in:
biglyderv 2024-10-03 05:16:40 -04:00
parent 9f5c99e6a5
commit 55802223c5
No known key found for this signature in database
GPG key ID: 33AC87E9ACE66954
5 changed files with 27 additions and 10 deletions

View file

@ -2,7 +2,7 @@ import Player from "./player.js";
class GameBasic { class GameBasic {
constructor() { constructor() {
let player = new Player(false,true); let player = new Player(false, true);
let entities = [player]; let entities = [player];
/*for (let i = 0; i < 50; i++) { /*for (let i = 0; i < 50; i++) {

View file

@ -1,8 +1,8 @@
import { distF, uuidv4 } from './util.js' import { distF, uuidv4 } from './util.js'
class Player { class Player {
constructor(you, isPlayer) { constructor(you, isPlayer, game = false) {
let pos = { x: Math.random() * 1000 - 50, y: Math.random() * 1000 - 50 }; let pos = { x: (Math.random() - 0.5) * (game ? game.width : 1000), y:(Math.random() - 0.5) * (game ? game.height : 1000) };
let camera = { x: -pos.x, y: -pos.y }; let camera = { x: -pos.x, y: -pos.y };
let vel = { x: 0, y: 0 }; let vel = { x: 0, y: 0 };
@ -30,11 +30,11 @@ class Player {
this.isYou = false; this.isYou = false;
this.serverProps = [ this.serverProps = [
'type', 'camera','pos','vel','rot','dir','ticks','health','you','isPlayer','headCount','isMenu','r','isYou' 'type', 'camera', 'pos', 'vel', 'rot', 'dir', 'ticks', 'health', 'you', 'isPlayer', 'headCount', 'isMenu', 'r', 'isYou'
]; ];
this.legalProps = [ this.legalProps = [
'vel','dir','camera','ticks','isMenu','r' 'vel', 'dir', 'camera', 'ticks', 'isMenu', 'r'
]; ];
} }
bump() { bump() {

View file

@ -7,6 +7,13 @@ class Game extends GameBasic {
this.ws = []; this.ws = [];
} }
sync(full = false) { sync(full = false) {
let onScreen = this.entities.filter(x => x && x.health > 0).length;
onScreen += 4;
this.width = (this.width * 0.99) + (Math.sqrt(onScreen) * 16);
this.height = (this.height * 0.99) + (Math.sqrt(onScreen) * 16);
let { entities } = this; let { entities } = this;
let entList = []; let entList = [];
for (let entity of entities) { for (let entity of entities) {
@ -40,6 +47,8 @@ class Game extends GameBasic {
return props.map(prop => x[prop]); return props.map(prop => x[prop]);
}); });
filtered.push([this.width,this.height])
client.send(JSON.stringify(filtered)); client.send(JSON.stringify(filtered));
wsEnt.isYou = false; wsEnt.isYou = false;

View file

@ -17,7 +17,7 @@ app.use(express.static('./static'));
app.ws('/', function (ws, req) { app.ws('/', function (ws, req) {
game.ws.push(ws); game.ws.push(ws);
let player = new Player(); let player = new Player(false, true, game);
let playerI = game.entities.length; let playerI = game.entities.length;
game.entities[playerI] = player; game.entities[playerI] = player;

View file

@ -147,11 +147,17 @@ class Game extends GameBasic {
let that = this; let that = this;
let entList = JSON.parse(data); let entList = JSON.parse(data);
entList = entList.map(y => { entList = entList.map((y, i) => {
if (i == entList.length - 1) {
that.width = y[0];
that.height = y[1];
return undefined;
}
let type = (Object.keys(legalTypes).indexOf(y[0]) == -1) ? Player : legalTypes[y[0]]; let type = (Object.keys(legalTypes).indexOf(y[0]) == -1) ? Player : legalTypes[y[0]];
let props = new type().serverProps; let props = new type().serverProps;
let x = {}; let x = {};
for (let i in props) { for (let i in props) {
@ -176,11 +182,13 @@ class Game extends GameBasic {
return x; return x;
}) })
let matchingPlayer = entList.filter(x => x.you == you) entList = entList.filter(x => x);
let matchingPlayer = entList.filter(x => x && x.you == you)
if (matchingPlayer.length == 0) { if (matchingPlayer.length == 0) {
matchingPlayer = entList.filter(x => x.isYou); matchingPlayer = entList.filter(x => x && x.isYou);
} }
this.player = Object.assign(this.player || new Player(false, false), matchingPlayer[0]); this.player = Object.assign(this.player || new Player(false, false), matchingPlayer[0]);